diff --git a/src-tauri/build.rs b/src-tauri/build.rs index d860e1e..261851f 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,3 +1,3 @@ fn main() { - tauri_build::build() + tauri_build::build(); } diff --git a/src-tauri/src/client/cleanup.rs b/src-tauri/src/client/cleanup.rs index f847b09..c6f0e80 100644 --- a/src-tauri/src/client/cleanup.rs +++ b/src-tauri/src/client/cleanup.rs @@ -13,8 +13,8 @@ pub fn cleanup_and_exit(app: &AppHandle, state: &tauri::State<'_, std::sync::Mut let download_manager = state.lock().unwrap().download_manager.clone(); match download_manager.ensure_terminated() { Ok(res) => match res { - Ok(_) => debug!("download manager terminated correctly"), - Err(_) => error!("download manager failed to terminate correctly"), + Ok(()) => debug!("download manager terminated correctly"), + Err(()) => error!("download manager failed to terminate correctly"), }, Err(e) => panic!("{e:?}"), } diff --git a/src-tauri/src/database/db.rs b/src-tauri/src/database/db.rs index b4c5161..39229c8 100644 --- a/src-tauri/src/database/db.rs +++ b/src-tauri/src/database/db.rs @@ -67,20 +67,17 @@ impl DatabaseImpls for DatabaseInterface { let exists = fs::exists(db_path.clone()).unwrap(); - match exists { - true => match PathDatabase::load_from_path(db_path.clone()) { - Ok(db) => db, - Err(e) => handle_invalid_database(e, db_path, games_base_dir, cache_dir), - }, - false => { - let default = Database::new(games_base_dir, None, cache_dir); - debug!( - "Creating database at path {}", - db_path.as_os_str().to_str().unwrap() - ); - PathDatabase::create_at_path(db_path, default) - .expect("Database could not be created") - } + if exists { match PathDatabase::load_from_path(db_path.clone()) { + Ok(db) => db, + Err(e) => handle_invalid_database(e, db_path, games_base_dir, cache_dir), + } } else { + let default = Database::new(games_base_dir, None, cache_dir); + debug!( + "Creating database at path {}", + db_path.as_os_str().to_str().unwrap() + ); + PathDatabase::create_at_path(db_path, default) + .expect("Database could not be created") } } @@ -137,19 +134,19 @@ impl<'a> Deref for DBRead<'a> { &self.0 } } -impl<'a> DerefMut for DBWrite<'a> { +impl DerefMut for DBWrite<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -impl<'a> Drop for DBWrite<'a> { +impl Drop for DBWrite<'_> { fn drop(&mut self) { unsafe { ManuallyDrop::drop(&mut self.0); } match DB.save() { - Ok(_) => {} + Ok(()) => {} Err(e) => { error!("database failed to save with error {e}"); panic!("database failed to save with error {e}") diff --git a/src-tauri/src/database/models.rs b/src-tauri/src/database/models.rs index 179f841..b039c9b 100644 --- a/src-tauri/src/database/models.rs +++ b/src-tauri/src/database/models.rs @@ -27,7 +27,7 @@ pub mod data { use serde_with::serde_as; use std::{collections::HashMap, path::PathBuf}; - use super::*; + use super::{Serialize, Deserialize, native_model}; fn default_template() -> String { "{}".to_owned() @@ -174,7 +174,7 @@ pub mod data { use serde_with::serde_as; - use super::*; + use super::{Serialize, Deserialize, native_model, Settings, DatabaseAuth, v1, GameVersion, DownloadableMetadata, ApplicationTransientStatus}; #[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] #[derive(Serialize, Deserialize, Clone, Default)] @@ -283,7 +283,7 @@ pub mod data { mod v3 { use std::path::PathBuf; - use super::*; + use super::{Serialize, Deserialize, native_model, Settings, DatabaseAuth, DatabaseApplications, DatabaseCompatInfo, v2}; #[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde)] #[derive(Serialize, Deserialize, Clone, Default)] pub struct Database { @@ -336,7 +336,7 @@ pub mod data { transient_statuses: HashMap::new(), }, prev_database, - base_url: "".to_owned(), + base_url: String::new(), auth: None, settings: Settings::default(), cache_dir, diff --git a/src-tauri/src/download_manager/commands.rs b/src-tauri/src/download_manager/commands.rs index 5156f30..e336c23 100644 --- a/src-tauri/src/download_manager/commands.rs +++ b/src-tauri/src/download_manager/commands.rs @@ -4,12 +4,12 @@ use crate::{database::models::data::DownloadableMetadata, AppState}; #[tauri::command] pub fn pause_downloads(state: tauri::State<'_, Mutex>) { - state.lock().unwrap().download_manager.pause_downloads() + state.lock().unwrap().download_manager.pause_downloads(); } #[tauri::command] pub fn resume_downloads(state: tauri::State<'_, Mutex>) { - state.lock().unwrap().download_manager.resume_downloads() + state.lock().unwrap().download_manager.resume_downloads(); } #[tauri::command] @@ -22,10 +22,10 @@ pub fn move_download_in_queue( .lock() .unwrap() .download_manager - .rearrange(old_index, new_index) + .rearrange(old_index, new_index); } #[tauri::command] pub fn cancel_game(state: tauri::State<'_, Mutex>, meta: DownloadableMetadata) { - state.lock().unwrap().download_manager.cancel(meta) + state.lock().unwrap().download_manager.cancel(meta); } diff --git a/src-tauri/src/download_manager/download_manager_builder.rs b/src-tauri/src/download_manager/download_manager_builder.rs index 15bd6e9..54c2d88 100644 --- a/src-tauri/src/download_manager/download_manager_builder.rs +++ b/src-tauri/src/download_manager/download_manager_builder.rs @@ -176,7 +176,7 @@ impl DownloadManagerBuilder { DownloadManagerSignal::Cancel(meta) => { self.manage_cancel_signal(&meta); } - }; + } } } fn manage_queue_signal(&mut self, download_agent: DownloadAgent) { diff --git a/src-tauri/src/download_manager/download_manager_frontend.rs b/src-tauri/src/download_manager/download_manager_frontend.rs index 359903d..46ee853 100644 --- a/src-tauri/src/download_manager/download_manager_frontend.rs +++ b/src-tauri/src/download_manager/download_manager_frontend.rs @@ -23,13 +23,13 @@ use super::{ }; pub enum DownloadManagerSignal { - /// Resumes (or starts) the DownloadManager + /// Resumes (or starts) the `DownloadManager` Go, - /// Pauses the DownloadManager + /// Pauses the `DownloadManager` Stop, - /// Called when a DownloadAgent has fully completed a download. + /// Called when a `DownloadAgent` has fully completed a download. Completed(DownloadableMetadata), - /// Generates and appends a DownloadAgent + /// Generates and appends a `DownloadAgent` /// to the registry and queue Queue(DownloadAgent), /// Tells the Manager to stop the current @@ -70,14 +70,14 @@ pub enum DownloadStatus { Error, } -/// Accessible front-end for the DownloadManager +/// Accessible front-end for the `DownloadManager` /// /// The system works entirely through signals, both internally and externally, -/// all of which are accessible through the DownloadManagerSignal type, but +/// all of which are accessible through the `DownloadManagerSignal` type, but /// should not be used directly. Rather, signals are abstracted through this /// interface. /// -/// The actual download queue may be accessed through the .edit() function, +/// The actual download queue may be accessed through the .`edit()` function, /// which provides raw access to the underlying queue. /// THIS EDITING IS BLOCKING!!! pub struct DownloadManager { @@ -139,7 +139,7 @@ impl DownloadManager { pub fn rearrange(&self, current_index: usize, new_index: usize) { if current_index == new_index { return; - }; + } let needs_pause = current_index == 0 || new_index == 0; if needs_pause { @@ -183,7 +183,7 @@ impl DownloadManager { } } -/// Takes in the locked value from .edit() and attempts to +/// Takes in the locked value from .`edit()` and attempts to /// get the index of whatever id is passed in fn get_index_from_id( queue: &mut MutexGuard<'_, VecDeque>, diff --git a/src-tauri/src/download_manager/util/download_thread_control_flag.rs b/src-tauri/src/download_manager/util/download_thread_control_flag.rs index 154fcfc..247ab58 100644 --- a/src-tauri/src/download_manager/util/download_thread_control_flag.rs +++ b/src-tauri/src/download_manager/util/download_thread_control_flag.rs @@ -22,10 +22,7 @@ impl From for bool { /// false => Stop impl From for DownloadThreadControlFlag { fn from(value: bool) -> Self { - match value { - true => DownloadThreadControlFlag::Go, - false => DownloadThreadControlFlag::Stop, - } + if value { DownloadThreadControlFlag::Go } else { DownloadThreadControlFlag::Stop } } } diff --git a/src-tauri/src/download_manager/util/rolling_progress_updates.rs b/src-tauri/src/download_manager/util/rolling_progress_updates.rs index 39ee041..420f601 100644 --- a/src-tauri/src/download_manager/util/rolling_progress_updates.rs +++ b/src-tauri/src/download_manager/util/rolling_progress_updates.rs @@ -11,7 +11,7 @@ pub struct RollingProgressWindow { impl RollingProgressWindow { pub fn new() -> Self { Self { - window: Arc::new([(); S].map(|_| AtomicUsize::new(0))), + window: Arc::new([(); S].map(|()| AtomicUsize::new(0))), current: Arc::new(AtomicUsize::new(0)), } } diff --git a/src-tauri/src/error/remote_access_error.rs b/src-tauri/src/error/remote_access_error.rs index 71306b8..1d60937 100644 --- a/src-tauri/src/error/remote_access_error.rs +++ b/src-tauri/src/error/remote_access_error.rs @@ -38,7 +38,7 @@ impl Display for RemoteAccessError { error, error .source() - .map(|e| e.to_string()) + .map(std::string::ToString::to_string) .or_else(|| Some("Unknown error".to_string())) .unwrap() ) diff --git a/src-tauri/src/games/downloads/download_agent.rs b/src-tauri/src/games/downloads/download_agent.rs index 9299436..cc00a0b 100644 --- a/src-tauri/src/games/downloads/download_agent.rs +++ b/src-tauri/src/games/downloads/download_agent.rs @@ -115,7 +115,7 @@ impl GameDownloadAgent { ); let res = self .run() - .map_err(|_| ApplicationDownloadError::DownloadError); + .map_err(|()| ApplicationDownloadError::DownloadError); debug!( "{} took {}ms to download", @@ -322,7 +322,7 @@ impl GameDownloadAgent { } }); - let newly_completed = completed_contexts.to_owned(); + let newly_completed = completed_contexts.clone(); let completed_lock_len = { let mut context_map_lock = self.context_map.lock().unwrap(); @@ -338,7 +338,7 @@ impl GameDownloadAgent { .map(|x| { ( x.checksum.clone(), - context_map_lock.get(&x.checksum).cloned().unwrap_or(false), + context_map_lock.get(&x.checksum).copied().unwrap_or(false), ) }) .collect::>(); diff --git a/src-tauri/src/games/downloads/download_logic.rs b/src-tauri/src/games/downloads/download_logic.rs index 05bd60f..4b35693 100644 --- a/src-tauri/src/games/downloads/download_logic.rs +++ b/src-tauri/src/games/downloads/download_logic.rs @@ -151,7 +151,7 @@ pub fn download_game_chunk( return Err(ApplicationDownloadError::Communication( RemoteAccessError::InvalidResponse(err), )); - }; + } return Err(ApplicationDownloadError::Communication( RemoteAccessError::UnparseableResponse(raw_res), )); @@ -187,7 +187,7 @@ pub fn download_game_chunk( .map_err(|e| ApplicationDownloadError::IoError(e.kind()))?; if !completed { return Ok(false); - }; + } // If we complete the file, set the permissions (if on Linux) #[cfg(unix)] diff --git a/src-tauri/src/games/downloads/drop_data.rs b/src-tauri/src/games/downloads/drop_data.rs index 4858b13..a614624 100644 --- a/src-tauri/src/games/downloads/drop_data.rs +++ b/src-tauri/src/games/downloads/drop_data.rs @@ -38,12 +38,9 @@ pub mod v1 { impl DropData { pub fn generate(game_id: String, game_version: String, base_path: PathBuf) -> Self { - let mut file = match File::open(base_path.join(DROP_DATA_PATH)) { - Ok(file) => file, - Err(_) => { - debug!("Generating new dropdata for game {game_id}"); - return DropData::new(game_id, game_version, base_path); - } + let mut file = if let Ok(file) = File::open(base_path.join(DROP_DATA_PATH)) { file } else { + debug!("Generating new dropdata for game {game_id}"); + return DropData::new(game_id, game_version, base_path); }; let mut s = Vec::new(); @@ -53,7 +50,7 @@ impl DropData { error!("{e}"); return DropData::new(game_id, game_version, base_path); } - }; + } match native_model::rmp_serde_1_3::RmpSerde::decode(s) { Ok(manifest) => manifest, @@ -78,9 +75,9 @@ impl DropData { }; match file.write_all(&manifest_raw) { - Ok(_) => {} + Ok(()) => {} Err(e) => error!("{e}"), - }; + } } pub fn set_contexts(&self, completed_contexts: &[(String, bool)]) { *self.contexts.lock().unwrap() = completed_contexts.iter().map(|s| (s.0.clone(), s.1)).collect(); diff --git a/src-tauri/src/games/downloads/validate.rs b/src-tauri/src/games/downloads/validate.rs index e6d04ce..dad9035 100644 --- a/src-tauri/src/games/downloads/validate.rs +++ b/src-tauri/src/games/downloads/validate.rs @@ -125,7 +125,7 @@ pub fn validate_game_chunk( validate_copy(&mut source, &mut hasher, ctx.length, control_flag, progress).unwrap(); if !completed { return Ok(false); - }; + } let res = hex::encode(hasher.compute().0); if res != ctx.checksum { diff --git a/src-tauri/src/games/library.rs b/src-tauri/src/games/library.rs index 06a1a2e..f7c80d7 100644 --- a/src-tauri/src/games/library.rs +++ b/src-tauri/src/games/library.rs @@ -96,7 +96,7 @@ pub fn fetch_library_logic( let mut db_handle = borrow_db_mut_checked(); - for game in games.iter() { + for game in &games { handle.games.insert(game.id.clone(), game.clone()); if !db_handle.applications.game_statuses.contains_key(&game.id) { db_handle @@ -329,37 +329,34 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle) drop(db_handle); let app_handle = app_handle.clone(); - spawn(move || match remove_dir_all(install_dir) { - Err(e) => { - error!("{e}"); - } - Ok(_) => { - let mut db_handle = borrow_db_mut_checked(); - db_handle.applications.transient_statuses.remove(&meta); - db_handle - .applications - .installed_game_version - .remove(&meta.id); - db_handle - .applications - .game_statuses - .entry(meta.id.clone()) - .and_modify(|e| *e = GameDownloadStatus::Remote {}); - drop(db_handle); + spawn(move || if let Err(e) = remove_dir_all(install_dir) { + error!("{e}"); + } else { + let mut db_handle = borrow_db_mut_checked(); + db_handle.applications.transient_statuses.remove(&meta); + db_handle + .applications + .installed_game_version + .remove(&meta.id); + db_handle + .applications + .game_statuses + .entry(meta.id.clone()) + .and_modify(|e| *e = GameDownloadStatus::Remote {}); + drop(db_handle); - debug!("uninstalled game id {}", &meta.id); - app_handle.emit("update_library", ()).unwrap(); + debug!("uninstalled game id {}", &meta.id); + app_handle.emit("update_library", ()).unwrap(); - push_game_update( - &app_handle, - &meta.id, - None, - (Some(GameDownloadStatus::Remote {}), None), - ); - } + push_game_update( + &app_handle, + &meta.id, + None, + (Some(GameDownloadStatus::Remote {}), None), + ); }); } else { - warn!("invalid previous state for uninstall, failing silently.") + warn!("invalid previous state for uninstall, failing silently."); } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d3950fe..0049dfb 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -163,7 +163,7 @@ fn setup(handle: AppHandle) -> AppState<'static> { let mut missing_games = Vec::new(); let statuses = db_handle.applications.game_statuses.clone(); drop(db_handle); - for (game_id, status) in statuses.into_iter() { + for (game_id, status) in statuses { match status { GameDownloadStatus::Remote {} => {} GameDownloadStatus::PartiallyInstalled { .. } => {} @@ -344,7 +344,7 @@ pub fn run() { let binding = event.urls(); let url = binding.first().unwrap(); if url.host_str().unwrap() == "handshake" { - recieve_handshake(handle.clone(), url.path().to_string()) + recieve_handshake(handle.clone(), url.path().to_string()); } }); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a6a1453..743eee3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,5 +2,5 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - drop_app_lib::run() + drop_app_lib::run(); } diff --git a/src-tauri/src/process/commands.rs b/src-tauri/src/process/commands.rs index 93cd86a..fda520f 100644 --- a/src-tauri/src/process/commands.rs +++ b/src-tauri/src/process/commands.rs @@ -17,9 +17,9 @@ pub fn launch_game( //}; match process_manager_lock.launch_process(id) { - Ok(_) => {} + Ok(()) => {} Err(e) => return Err(e), - }; + } drop(process_manager_lock); drop(state_lock); diff --git a/src-tauri/src/process/process_manager.rs b/src-tauri/src/process/process_manager.rs index e151653..5113b54 100644 --- a/src-tauri/src/process/process_manager.rs +++ b/src-tauri/src/process/process_manager.rs @@ -281,7 +281,7 @@ impl ProcessManager<'_> { let launch_string = game_launcher.create_launch_process( &meta, launch.to_string(), - args.to_vec(), + args.clone(), game_version, install_dir, ); diff --git a/src-tauri/src/remote/auth.rs b/src-tauri/src/remote/auth.rs index 1e8d533..3f4b63b 100644 --- a/src-tauri/src/remote/auth.rs +++ b/src-tauri/src/remote/auth.rs @@ -81,11 +81,11 @@ pub fn fetch_user() -> Result { return Err(RemoteAccessError::InvalidResponse(err)); } - response.json::().map_err(|e| e.into()) + response.json::().map_err(std::convert::Into::into) } fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), RemoteAccessError> { - let path_chunks: Vec<&str> = path.split("/").collect(); + let path_chunks: Vec<&str> = path.split('/').collect(); if path_chunks.len() != 3 { app.emit("auth/failed", ()).unwrap(); return Err(RemoteAccessError::HandshakeFailed( @@ -101,8 +101,8 @@ fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), RemoteAc let client_id = path_chunks.get(1).unwrap(); let token = path_chunks.get(2).unwrap(); let body = HandshakeRequestBody { - client_id: client_id.to_string(), - token: token.to_string(), + client_id: (*client_id).to_string(), + token: (*token).to_string(), }; let endpoint = base_url.join("/api/v1/client/auth/handshake")?; diff --git a/src-tauri/src/remote/fetch_object.rs b/src-tauri/src/remote/fetch_object.rs index cd14400..964769c 100644 --- a/src-tauri/src/remote/fetch_object.rs +++ b/src-tauri/src/remote/fetch_object.rs @@ -30,7 +30,7 @@ pub async fn fetch_object(request: http::Request>, responder: UriSchemeR match cache_result { Ok(cache_result) => responder.respond(cache_result.into()), Err(e) => { - warn!("{e}") + warn!("{e}"); } } return;