mirror of
https://github.com/Drop-OSS/drop-app-kt.git
synced 2026-02-04 06:51:18 +01:00
feat(settings): Implemented settings editing from UI
This commit is contained in:
23
src-tauri/Cargo.lock
generated
23
src-tauri/Cargo.lock
generated
@@ -1042,6 +1042,7 @@ dependencies = [
|
||||
"log",
|
||||
"log4rs",
|
||||
"md5",
|
||||
"merge-struct",
|
||||
"openssl",
|
||||
"parking_lot 0.12.3",
|
||||
"rayon",
|
||||
@@ -1051,6 +1052,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde-binary",
|
||||
"serde_json",
|
||||
"serde_merge",
|
||||
"serde_with",
|
||||
"shared_child",
|
||||
"slice-deque",
|
||||
@@ -2453,6 +2455,16 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "merge-struct"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d82012d21e24135b839b6b9bebd622b7ff0cb40071498bc2d066d3a6d04dd4a"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
@@ -3901,6 +3913,17 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_merge"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "606e91878516232ac3b16c12e063d4468d762f16d77e7aef14a1f2326c5f409b"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_repr"
|
||||
version = "0.1.19"
|
||||
|
||||
@@ -50,6 +50,8 @@ slice-deque = "0.3.0"
|
||||
derive_builder = "0.20.2"
|
||||
throttle_my_fn = "0.2.6"
|
||||
parking_lot = "0.12.3"
|
||||
merge-struct = "0.1.0"
|
||||
serde_merge = "0.1.3"
|
||||
|
||||
[dependencies.tauri]
|
||||
version = "2.1.1"
|
||||
|
||||
@@ -4,9 +4,10 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use log::debug;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{error::user_error::UserValue, DB};
|
||||
use crate::{database::settings::Settings, error::user_error::UserValue, DB};
|
||||
|
||||
use super::{db::DATA_ROOT_DIR, debug::SystemData};
|
||||
|
||||
@@ -58,10 +59,17 @@ pub fn add_download_dir(new_dir: PathBuf) -> UserValue<(), Error> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn amend_settings(new_settings: Value) {
|
||||
pub fn update_settings(new_settings: Value) {
|
||||
println!("{}", new_settings);
|
||||
let db_lock = DB.borrow_data_mut().unwrap();
|
||||
let mut current_settings = db_lock.settings.clone();
|
||||
let mut db_lock = DB.borrow_data_mut().unwrap();
|
||||
let mut current_settings = serde_json::to_value(db_lock.settings.clone()).unwrap();
|
||||
for (key, value) in new_settings.as_object().unwrap() {
|
||||
current_settings[key] = value.clone();
|
||||
}
|
||||
println!("New settings unset: {}", ¤t_settings);
|
||||
let new_settings: Settings = serde_json::from_value(current_settings).unwrap();
|
||||
db_lock.settings = new_settings;
|
||||
println!("New Settings: {:?}", db_lock.settings);
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -22,6 +22,3 @@ impl Default for Settings {
|
||||
// *t = serde_json::from_value(v)?;
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::auth::generate_authorization_header;
|
||||
use crate::database::db::{set_game_status, ApplicationTransientStatus, DatabaseImpls};
|
||||
use crate::database::db::{
|
||||
set_game_status, ApplicationTransientStatus, DatabaseImpls, GameDownloadStatus,
|
||||
};
|
||||
use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus};
|
||||
use crate::download_manager::download_thread_control_flag::{
|
||||
DownloadThreadControl, DownloadThreadControlFlag,
|
||||
@@ -10,7 +12,7 @@ use crate::download_manager::progress_object::{ProgressHandle, ProgressObject};
|
||||
use crate::error::application_download_error::ApplicationDownloadError;
|
||||
use crate::error::remote_access_error::RemoteAccessError;
|
||||
use crate::games::downloads::manifest::{DropDownloadContext, DropManifest};
|
||||
use crate::games::library::{on_game_complete, push_game_update};
|
||||
use crate::games::library::{on_game_complete, push_game_update, GameUpdateEvent};
|
||||
use crate::DB;
|
||||
use log::{debug, error, info};
|
||||
use rayon::ThreadPoolBuilder;
|
||||
@@ -248,9 +250,12 @@ impl GameDownloadAgent {
|
||||
|
||||
// TODO: Change return value on Err
|
||||
pub fn run(&self) -> Result<bool, ()> {
|
||||
info!("downloading game: {}", self.id);
|
||||
let max_download_threads = DB.borrow_data().unwrap().settings.max_download_threads;
|
||||
|
||||
info!(
|
||||
"downloading game: {} with {} threads",
|
||||
self.id, max_download_threads
|
||||
);
|
||||
let pool = ThreadPoolBuilder::new()
|
||||
.num_threads(max_download_threads)
|
||||
.build()
|
||||
@@ -402,8 +407,18 @@ impl Downloadable for GameDownloadAgent {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_incomplete(&self, _app_handle: &tauri::AppHandle) {
|
||||
fn on_incomplete(&self, app_handle: &tauri::AppHandle) {
|
||||
let meta = self.metadata();
|
||||
*self.status.lock().unwrap() = DownloadStatus::Queued;
|
||||
app_handle
|
||||
.emit(
|
||||
&format!("update_game/{}", meta.id),
|
||||
GameUpdateEvent {
|
||||
game_id: meta.id.clone(),
|
||||
status: (Some(GameDownloadStatus::Remote {}), None),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_cancelled(&self, _app_handle: &tauri::AppHandle) {}
|
||||
|
||||
@@ -16,8 +16,8 @@ use crate::database::db::DatabaseImpls;
|
||||
use cleanup::{cleanup_and_exit, quit};
|
||||
use commands::fetch_state;
|
||||
use database::commands::{
|
||||
add_download_dir, amend_settings, delete_download_dir, fetch_download_dir_stats,
|
||||
fetch_system_data,
|
||||
add_download_dir, delete_download_dir, fetch_download_dir_stats, fetch_system_data,
|
||||
update_settings,
|
||||
};
|
||||
use database::db::{DatabaseInterface, GameDownloadStatus, DATA_ROOT_DIR};
|
||||
use download_manager::commands::{
|
||||
@@ -216,7 +216,7 @@ pub fn run() {
|
||||
quit,
|
||||
fetch_system_data,
|
||||
// User utils
|
||||
amend_settings,
|
||||
update_settings,
|
||||
// Auth
|
||||
auth_initiate,
|
||||
retry_connect,
|
||||
|
||||
Reference in New Issue
Block a user