mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-16 09:41:17 +10:00
Squashed commit of the following:
commit3b09dcfb73Author: quexeky <git@quexeky.dev> Date: Mon Oct 13 08:10:52 2025 +1100 fix: #159 Signed-off-by: quexeky <git@quexeky.dev> commit2859a59622Author: quexeky <git@quexeky.dev> Date: Mon Oct 13 08:03:49 2025 +1100 Squashed commit of the following: commit0f48f3fb44Author: quexeky <git@quexeky.dev> Date: Sun Oct 12 19:35:04 2025 +1100 chore: Run cargo clippy && cargo fmt Signed-off-by: quexeky <git@quexeky.dev> commit974666efe2Author: quexeky <git@quexeky.dev> Date: Sun Oct 12 19:17:40 2025 +1100 refactor: Finish refactor Signed-off-by: quexeky <git@quexeky.dev> commit9e1bf9852fAuthor: quexeky <git@quexeky.dev> Date: Sun Oct 12 18:33:43 2025 +1100 refactor: Builds, but some logic still left to move back Signed-off-by: quexeky <git@quexeky.dev> commit5d22b883d5Author: quexeky <git@quexeky.dev> Date: Sun Oct 12 17:04:27 2025 +1100 refactor: Improvements to src-tauri Signed-off-by: quexeky <git@quexeky.dev> commit62a2561539Author: quexeky <git@quexeky.dev> Date: Sat Oct 11 09:51:04 2025 +1100 fix: Remote tauri dependency from process Signed-off-by: quexeky <git@quexeky.dev> commit59f040bc8bAuthor: quexeky <git@quexeky.dev> Date: Thu Oct 9 07:46:17 2025 +1100 chore: Major refactoring Still needs a massive go-over because there shouldn't be anything referencing tauri in any of the workspaces except the original one. Process manager has been refactored as an example Signed-off-by: quexeky <git@quexeky.dev> Signed-off-by: quexeky <git@quexeky.dev> Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
100
src-tauri/src/settings.rs
Normal file
100
src-tauri/src/settings.rs
Normal file
@ -0,0 +1,100 @@
|
||||
use std::{
|
||||
fs::create_dir_all,
|
||||
io::{Error, ErrorKind},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use database::{
|
||||
Settings, borrow_db_checked, borrow_db_mut_checked, db::DATA_ROOT_DIR, debug::SystemData,
|
||||
};
|
||||
use download_manager::error::DownloadManagerError;
|
||||
use games::scan::scan_install_dirs;
|
||||
use log::error;
|
||||
use serde_json::Value;
|
||||
|
||||
// Will, in future, return disk/remaining size
|
||||
// Just returns the directories that have been set up
|
||||
#[tauri::command]
|
||||
pub fn fetch_download_dir_stats() -> Vec<PathBuf> {
|
||||
let lock = borrow_db_checked();
|
||||
lock.applications.install_dirs.clone()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn delete_download_dir(index: usize) {
|
||||
let mut lock = borrow_db_mut_checked();
|
||||
lock.applications.install_dirs.remove(index);
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn add_download_dir(new_dir: PathBuf) -> Result<(), DownloadManagerError<()>> {
|
||||
// Check the new directory is all good
|
||||
let new_dir_path = Path::new(&new_dir);
|
||||
if new_dir_path.exists() {
|
||||
let dir_contents = new_dir_path.read_dir()?;
|
||||
if dir_contents.count() != 0 {
|
||||
return Err(Error::new(
|
||||
ErrorKind::DirectoryNotEmpty,
|
||||
"Selected directory cannot contain any existing files",
|
||||
)
|
||||
.into());
|
||||
}
|
||||
} else {
|
||||
create_dir_all(new_dir_path)?;
|
||||
}
|
||||
|
||||
// Add it to the dictionary
|
||||
let mut lock = borrow_db_mut_checked();
|
||||
if lock.applications.install_dirs.contains(&new_dir) {
|
||||
return Err(Error::new(
|
||||
ErrorKind::AlreadyExists,
|
||||
"Selected directory already exists in database",
|
||||
)
|
||||
.into());
|
||||
}
|
||||
lock.applications.install_dirs.push(new_dir);
|
||||
drop(lock);
|
||||
|
||||
scan_install_dirs();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn update_settings(new_settings: Value) {
|
||||
let mut db_lock = borrow_db_mut_checked();
|
||||
let mut current_settings =
|
||||
serde_json::to_value(db_lock.settings.clone()).expect("Failed to parse existing settings");
|
||||
let values = match new_settings.as_object() {
|
||||
Some(values) => values,
|
||||
None => {
|
||||
error!("Could not parse settings values into object");
|
||||
return;
|
||||
}
|
||||
};
|
||||
for (key, value) in values {
|
||||
current_settings[key] = value.clone();
|
||||
}
|
||||
let new_settings: Settings = match serde_json::from_value(current_settings) {
|
||||
Ok(settings) => settings,
|
||||
Err(e) => {
|
||||
error!("Could not parse settings with error {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
db_lock.settings = new_settings;
|
||||
}
|
||||
#[tauri::command]
|
||||
pub fn fetch_settings() -> Settings {
|
||||
borrow_db_checked().settings.clone()
|
||||
}
|
||||
#[tauri::command]
|
||||
pub fn fetch_system_data() -> SystemData {
|
||||
let db_handle = borrow_db_checked();
|
||||
SystemData::new(
|
||||
db_handle.auth.as_ref().unwrap().client_id.clone(),
|
||||
db_handle.base_url.clone(),
|
||||
DATA_ROOT_DIR.to_string_lossy().to_string(),
|
||||
std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user