From 2822b7a5931e723a73ebcced03495bfc2cc12eb3 Mon Sep 17 00:00:00 2001 From: quexeky Date: Sun, 5 Jan 2025 21:08:27 +1100 Subject: [PATCH] chore: More cleanup after cargo clippy Also added some type efficiency improvements (using references where possible and added SliceDeque crate) Signed-off-by: quexeky --- src-tauri/Cargo.lock | 21 +++++++++++++++++++ src-tauri/Cargo.toml | 1 + src-tauri/src/auth.rs | 2 +- .../download_manager/generate_downloadable.rs | 5 ----- src-tauri/src/download_manager/mod.rs | 1 - .../src/games/downloads/download_agent.rs | 8 +++---- .../src/games/downloads/download_commands.rs | 16 -------------- .../src/games/downloads/stored_manifest.rs | 4 ++-- src-tauri/src/games/library.rs | 7 +++---- src-tauri/src/lib.rs | 2 +- src-tauri/src/process/process_commands.rs | 5 ++--- src-tauri/src/process/process_manager.rs | 16 +++++++------- src-tauri/src/tools/mod.rs | 1 - src-tauri/src/tools/registry.rs | 7 ------- src-tauri/src/tools/tool.rs | 2 ++ 15 files changed, 45 insertions(+), 53 deletions(-) delete mode 100644 src-tauri/src/download_manager/generate_downloadable.rs delete mode 100644 src-tauri/src/tools/registry.rs diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 069c108..e62b782 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1020,6 +1020,7 @@ dependencies = [ "serde_json", "serde_with", "shared_child", + "slice-deque", "tauri", "tauri-build", "tauri-plugin-autostart", @@ -2359,6 +2360,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -3998,6 +4008,17 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slice-deque" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25" +dependencies = [ + "libc", + "mach", + "winapi", +] + [[package]] name = "smallvec" version = "1.13.2" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 73aa54e..93f1fc5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -46,6 +46,7 @@ umu-wrapper-lib = "0.1.0" tauri-plugin-autostart = "2.0.0" shared_child = "1.0.1" serde_with = "3.12.0" +slice-deque = "0.3.0" [dependencies.tauri] version = "2.1.1" diff --git a/src-tauri/src/auth.rs b/src-tauri/src/auth.rs index c2cd6e2..d398cc6 100644 --- a/src-tauri/src/auth.rs +++ b/src-tauri/src/auth.rs @@ -189,7 +189,7 @@ fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { } #[tauri::command] -pub fn auth_initiate<'a>() -> Result<(), String> { +pub fn auth_initiate() -> Result<(), String> { let result = auth_initiate_wrapper(); if result.is_err() { return Err(result.err().unwrap().to_string()); diff --git a/src-tauri/src/download_manager/generate_downloadable.rs b/src-tauri/src/download_manager/generate_downloadable.rs deleted file mode 100644 index 8b0c2ca..0000000 --- a/src-tauri/src/download_manager/generate_downloadable.rs +++ /dev/null @@ -1,5 +0,0 @@ -use super::{download_manager_builder::DownloadAgent, downloadable_metadata::DownloadableMetadata}; - -pub fn generate_downloadable(meta: DownloadableMetadata) -> DownloadAgent { - todo!() -} diff --git a/src-tauri/src/download_manager/mod.rs b/src-tauri/src/download_manager/mod.rs index 3c4904a..67ceb00 100644 --- a/src-tauri/src/download_manager/mod.rs +++ b/src-tauri/src/download_manager/mod.rs @@ -4,6 +4,5 @@ pub mod download_manager_builder; pub mod download_thread_control_flag; pub mod downloadable; pub mod downloadable_metadata; -pub mod generate_downloadable; pub mod progress_object; pub mod queue; diff --git a/src-tauri/src/games/downloads/download_agent.rs b/src-tauri/src/games/downloads/download_agent.rs index d6f0fab..86b77a2 100644 --- a/src-tauri/src/games/downloads/download_agent.rs +++ b/src-tauri/src/games/downloads/download_agent.rs @@ -14,7 +14,7 @@ use crate::remote::RemoteAccessError; use crate::DB; use log::{debug, error, info}; use rayon::ThreadPoolBuilder; -use std::collections::VecDeque; +use slice_deque::SliceDeque; use std::fs::{create_dir_all, File}; use std::path::Path; use std::sync::mpsc::Sender; @@ -34,7 +34,7 @@ pub struct GameDownloadAgent { pub version: String, pub control_flag: DownloadThreadControl, contexts: Mutex>, - completed_contexts: Mutex>, + completed_contexts: Mutex>, pub manifest: Mutex>, pub progress: Arc, sender: Sender, @@ -68,7 +68,7 @@ impl GameDownloadAgent { control_flag, manifest: Mutex::new(None), contexts: Mutex::new(Vec::new()), - completed_contexts: Mutex::new(VecDeque::new()), + completed_contexts: Mutex::new(SliceDeque::new()), progress: Arc::new(ProgressObject::new(0, 0, sender.clone())), sender, stored_manifest, @@ -312,7 +312,7 @@ impl GameDownloadAgent { if completed_lock_len != contexts.len() { info!("da for {} exited without completing", self.id.clone()); self.stored_manifest - .set_completed_contexts(&self.completed_contexts.lock().unwrap().clone().into()); + .set_completed_contexts(self.completed_contexts.lock().unwrap().as_slice()); info!("Setting completed contexts"); self.stored_manifest.write(); info!("Wrote completed contexts"); diff --git a/src-tauri/src/games/downloads/download_commands.rs b/src-tauri/src/games/downloads/download_commands.rs index d4c0cd4..c9ea576 100644 --- a/src-tauri/src/games/downloads/download_commands.rs +++ b/src-tauri/src/games/downloads/download_commands.rs @@ -56,19 +56,3 @@ pub fn move_game_in_queue( pub fn cancel_game(state: tauri::State<'_, Mutex>, meta: DownloadableMetadata) { state.lock().unwrap().download_manager.cancel(meta) } - -/* -#[tauri::command] -pub fn get_current_write_speed(state: tauri::State<'_, Mutex>) {} -*/ - -/* -fn use_download_agent( - state: tauri::State<'_, Mutex>, - game_id: String, -) -> Result, String> { - let lock = state.lock().unwrap(); - let download_agent = lock.download_manager.get(&game_id).ok_or("Invalid game ID")?; - Ok(download_agent.clone()) // Clones the Arc, not the underlying data structure -} -*/ diff --git a/src-tauri/src/games/downloads/stored_manifest.rs b/src-tauri/src/games/downloads/stored_manifest.rs index fba8afa..b02821c 100644 --- a/src-tauri/src/games/downloads/stored_manifest.rs +++ b/src-tauri/src/games/downloads/stored_manifest.rs @@ -70,8 +70,8 @@ impl StoredManifest { Err(e) => error!("{}", e), }; } - pub fn set_completed_contexts(&self, completed_contexts: &Vec) { - *self.completed_contexts.lock().unwrap() = completed_contexts.clone(); + pub fn set_completed_contexts(&self, completed_contexts: &[usize]) { + *self.completed_contexts.lock().unwrap() = completed_contexts.to_owned(); } pub fn get_completed_contexts(&self) -> Vec { self.completed_contexts.lock().unwrap().clone() diff --git a/src-tauri/src/games/library.rs b/src-tauri/src/games/library.rs index d5d2630..d2340ee 100644 --- a/src-tauri/src/games/library.rs +++ b/src-tauri/src/games/library.rs @@ -200,7 +200,7 @@ pub fn fetch_game_status(id: String) -> Result Ok(status) } -fn fetch_game_verion_options_logic<'a>( +fn fetch_game_verion_options_logic( game_id: String, state: tauri::State<'_, Mutex>, ) -> Result, RemoteAccessError> { @@ -239,7 +239,6 @@ fn fetch_game_verion_options_logic<'a>( #[tauri::command] pub fn uninstall_game( game_id: String, - state: tauri::State<'_, Mutex>, app_handle: AppHandle, ) -> Result<(), String> { let meta = get_current_meta(&game_id)?; @@ -270,7 +269,7 @@ fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle) { return; } let previous_state = previous_state.unwrap(); - if let Some((version_name, install_dir)) = match previous_state { + if let Some((_, install_dir)) = match previous_state { GameDownloadStatus::Installed { version_name, install_dir, @@ -330,7 +329,7 @@ pub fn get_current_meta(game_id: &String) -> Result( +pub fn fetch_game_verion_options( game_id: String, state: tauri::State<'_, Mutex>, ) -> Result, String> { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3484f3e..b6ca3f5 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -402,7 +402,7 @@ pub fn run() { .build(tauri::generate_context!()) .expect("error while running tauri application"); - app.run(|app_handle, event| { + app.run(|_app_handle, event| { if let RunEvent::ExitRequested { code, api, .. } = event { if code.is_none() { api.prevent_exit(); diff --git a/src-tauri/src/process/process_commands.rs b/src-tauri/src/process/process_commands.rs index 323d8be..53bb11e 100644 --- a/src-tauri/src/process/process_commands.rs +++ b/src-tauri/src/process/process_commands.rs @@ -22,11 +22,10 @@ pub fn launch_game(id: String, state: tauri::State<'_, Mutex>) -> Resu { Some(GameDownloadStatus::Installed { version_name, - install_dir, + .. }) => version_name, Some(GameDownloadStatus::SetupRequired { - version_name, - install_dir, + .. }) => return Err(String::from("Game setup still required")), _ => return Err(String::from("Game not installed")), }; diff --git a/src-tauri/src/process/process_manager.rs b/src-tauri/src/process/process_manager.rs index 37ae60e..51e59fd 100644 --- a/src-tauri/src/process/process_manager.rs +++ b/src-tauri/src/process/process_manager.rs @@ -255,7 +255,7 @@ impl ProcessManager<'_> { &meta, command.to_str().unwrap().to_owned(), args, - &target_current_dir.to_string(), + target_current_dir, log_file, error_file, )?; @@ -313,7 +313,7 @@ pub trait ProcessHandler: Send + 'static { meta: &DownloadableMetadata, command: String, args: Vec, - current_dir: &String, + current_dir: &str, log_file: File, error_file: File, ) -> Result; @@ -323,10 +323,10 @@ struct NativeGameLauncher; impl ProcessHandler for NativeGameLauncher { fn launch_process( &self, - meta: &DownloadableMetadata, + _meta: &DownloadableMetadata, command: String, args: Vec, - current_dir: &String, + current_dir: &str, log_file: File, error_file: File, ) -> Result { @@ -345,12 +345,12 @@ struct UMULauncher; impl ProcessHandler for UMULauncher { fn launch_process( &self, - meta: &DownloadableMetadata, + _meta: &DownloadableMetadata, command: String, args: Vec, - current_dir: &String, - log_file: File, - error_file: File, + _current_dir: &str, + _log_file: File, + _error_file: File, ) -> Result { UmuCommandBuilder::new(UMU_LAUNCHER_EXECUTABLE, command) .game_id(String::from("0")) diff --git a/src-tauri/src/tools/mod.rs b/src-tauri/src/tools/mod.rs index 0831364..1f17f83 100644 --- a/src-tauri/src/tools/mod.rs +++ b/src-tauri/src/tools/mod.rs @@ -1,4 +1,3 @@ mod compatibility_layer; mod prefix; -mod registry; mod tool; diff --git a/src-tauri/src/tools/registry.rs b/src-tauri/src/tools/registry.rs deleted file mode 100644 index c0de4a4..0000000 --- a/src-tauri/src/tools/registry.rs +++ /dev/null @@ -1,7 +0,0 @@ -use std::collections::HashMap; - -use crate::download_manager::downloadable::Downloadable; - -pub struct Registry { - tools: HashMap, -} diff --git a/src-tauri/src/tools/tool.rs b/src-tauri/src/tools/tool.rs index 6e6fcfb..8893005 100644 --- a/src-tauri/src/tools/tool.rs +++ b/src-tauri/src/tools/tool.rs @@ -8,6 +8,7 @@ use crate::download_manager::{ downloadable_metadata::DownloadableMetadata, progress_object::ProgressObject, }; +#[allow(unused)] pub struct ToolDownloadAgent { id: String, version: String, @@ -15,6 +16,7 @@ pub struct ToolDownloadAgent { control_flag: DownloadThreadControl, progress: Arc, } +#[allow(unused)] impl Downloadable for ToolDownloadAgent { fn download(&self, app_handle: &AppHandle) -> Result { todo!()