Configure data sources (#259)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2025-01-13 19:51:26 +01:00
1 parent 06f66fdab2
commit 63be312bb4
47 files changed
+3388 -283

No files matched your search

+49
View File
@@ -270,4 +270,53 @@ pub struct PreviousDirectory {
pub struct DirectorySelectionResponse {
user_cancelled: bool,
selected_directory: String,
}
/// Let the user select a file.
#[post("/select/file?<title>", data = "<previous_file>")]
pub fn select_file(_token: APIToken, title: &str, previous_file: Option<Json<PreviousFile>>) -> Json<FileSelectionResponse> {
let file_path = match previous_file {
Some(previous) => {
let previous_path = previous.file_path.as_str();
FileDialogBuilder::new()
.set_title(title)
.set_directory(previous_path)
.pick_file()
},
None => {
FileDialogBuilder::new()
.set_title(title)
.pick_file()
},
};
match file_path {
Some(path) => {
info!("User selected file: {path:?}");
Json(FileSelectionResponse {
user_cancelled: false,
selected_file_path: path.to_str().unwrap().to_string(),
})
},
None => {
info!("User cancelled file selection.");
Json(FileSelectionResponse {
user_cancelled: true,
selected_file_path: String::from(""),
})
},
}
}
#[derive(Clone, Deserialize)]
pub struct PreviousFile {
file_path: String,
}
#[derive(Serialize)]
pub struct FileSelectionResponse {
user_cancelled: bool,
selected_file_path: String,
}
+1
View File
@@ -85,6 +85,7 @@ pub fn start_runtime_api() {
crate::app_window::check_for_update,
crate::app_window::install_update,
crate::app_window::select_directory,
crate::app_window::select_file,
crate::secret::get_secret,
crate::secret::store_secret,
crate::secret::delete_secret,