chore: More cleanup after cargo clippy

Also added some type efficiency improvements (using references where possible and added SliceDeque crate)

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-01-05 21:08:27 +11:00
parent 82804ebc67
commit 2822b7a593
15 changed files with 45 additions and 53 deletions

21
src-tauri/Cargo.lock generated
View File

@ -1020,6 +1020,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_with", "serde_with",
"shared_child", "shared_child",
"slice-deque",
"tauri", "tauri",
"tauri-build", "tauri-build",
"tauri-plugin-autostart", "tauri-plugin-autostart",
@ -2359,6 +2360,15 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
[[package]]
name = "mach"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@ -3998,6 +4008,17 @@ dependencies = [
"autocfg", "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]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.13.2" version = "1.13.2"

View File

@ -46,6 +46,7 @@ umu-wrapper-lib = "0.1.0"
tauri-plugin-autostart = "2.0.0" tauri-plugin-autostart = "2.0.0"
shared_child = "1.0.1" shared_child = "1.0.1"
serde_with = "3.12.0" serde_with = "3.12.0"
slice-deque = "0.3.0"
[dependencies.tauri] [dependencies.tauri]
version = "2.1.1" version = "2.1.1"

View File

@ -189,7 +189,7 @@ fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> {
} }
#[tauri::command] #[tauri::command]
pub fn auth_initiate<'a>() -> Result<(), String> { pub fn auth_initiate() -> Result<(), String> {
let result = auth_initiate_wrapper(); let result = auth_initiate_wrapper();
if result.is_err() { if result.is_err() {
return Err(result.err().unwrap().to_string()); return Err(result.err().unwrap().to_string());

View File

@ -1,5 +0,0 @@
use super::{download_manager_builder::DownloadAgent, downloadable_metadata::DownloadableMetadata};
pub fn generate_downloadable(meta: DownloadableMetadata) -> DownloadAgent {
todo!()
}

View File

@ -4,6 +4,5 @@ pub mod download_manager_builder;
pub mod download_thread_control_flag; pub mod download_thread_control_flag;
pub mod downloadable; pub mod downloadable;
pub mod downloadable_metadata; pub mod downloadable_metadata;
pub mod generate_downloadable;
pub mod progress_object; pub mod progress_object;
pub mod queue; pub mod queue;

View File

@ -14,7 +14,7 @@ use crate::remote::RemoteAccessError;
use crate::DB; use crate::DB;
use log::{debug, error, info}; use log::{debug, error, info};
use rayon::ThreadPoolBuilder; use rayon::ThreadPoolBuilder;
use std::collections::VecDeque; use slice_deque::SliceDeque;
use std::fs::{create_dir_all, File}; use std::fs::{create_dir_all, File};
use std::path::Path; use std::path::Path;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
@ -34,7 +34,7 @@ pub struct GameDownloadAgent {
pub version: String, pub version: String,
pub control_flag: DownloadThreadControl, pub control_flag: DownloadThreadControl,
contexts: Mutex<Vec<DropDownloadContext>>, contexts: Mutex<Vec<DropDownloadContext>>,
completed_contexts: Mutex<VecDeque<usize>>, completed_contexts: Mutex<SliceDeque<usize>>,
pub manifest: Mutex<Option<DropManifest>>, pub manifest: Mutex<Option<DropManifest>>,
pub progress: Arc<ProgressObject>, pub progress: Arc<ProgressObject>,
sender: Sender<DownloadManagerSignal>, sender: Sender<DownloadManagerSignal>,
@ -68,7 +68,7 @@ impl GameDownloadAgent {
control_flag, control_flag,
manifest: Mutex::new(None), manifest: Mutex::new(None),
contexts: Mutex::new(Vec::new()), 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())), progress: Arc::new(ProgressObject::new(0, 0, sender.clone())),
sender, sender,
stored_manifest, stored_manifest,
@ -312,7 +312,7 @@ impl GameDownloadAgent {
if completed_lock_len != contexts.len() { if completed_lock_len != contexts.len() {
info!("da for {} exited without completing", self.id.clone()); info!("da for {} exited without completing", self.id.clone());
self.stored_manifest 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"); info!("Setting completed contexts");
self.stored_manifest.write(); self.stored_manifest.write();
info!("Wrote completed contexts"); info!("Wrote completed contexts");

View File

@ -56,19 +56,3 @@ pub fn move_game_in_queue(
pub fn cancel_game(state: tauri::State<'_, Mutex<AppState>>, meta: DownloadableMetadata) { pub fn cancel_game(state: tauri::State<'_, Mutex<AppState>>, meta: DownloadableMetadata) {
state.lock().unwrap().download_manager.cancel(meta) state.lock().unwrap().download_manager.cancel(meta)
} }
/*
#[tauri::command]
pub fn get_current_write_speed(state: tauri::State<'_, Mutex<AppState>>) {}
*/
/*
fn use_download_agent(
state: tauri::State<'_, Mutex<AppState>>,
game_id: String,
) -> Result<Arc<GameDownloadAgent>, 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
}
*/

View File

@ -70,8 +70,8 @@ impl StoredManifest {
Err(e) => error!("{}", e), Err(e) => error!("{}", e),
}; };
} }
pub fn set_completed_contexts(&self, completed_contexts: &Vec<usize>) { pub fn set_completed_contexts(&self, completed_contexts: &[usize]) {
*self.completed_contexts.lock().unwrap() = completed_contexts.clone(); *self.completed_contexts.lock().unwrap() = completed_contexts.to_owned();
} }
pub fn get_completed_contexts(&self) -> Vec<usize> { pub fn get_completed_contexts(&self) -> Vec<usize> {
self.completed_contexts.lock().unwrap().clone() self.completed_contexts.lock().unwrap().clone()

View File

@ -200,7 +200,7 @@ pub fn fetch_game_status(id: String) -> Result<GameStatusWithTransient, String>
Ok(status) Ok(status)
} }
fn fetch_game_verion_options_logic<'a>( fn fetch_game_verion_options_logic(
game_id: String, game_id: String,
state: tauri::State<'_, Mutex<AppState>>, state: tauri::State<'_, Mutex<AppState>>,
) -> Result<Vec<GameVersionOption>, RemoteAccessError> { ) -> Result<Vec<GameVersionOption>, RemoteAccessError> {
@ -239,7 +239,6 @@ fn fetch_game_verion_options_logic<'a>(
#[tauri::command] #[tauri::command]
pub fn uninstall_game( pub fn uninstall_game(
game_id: String, game_id: String,
state: tauri::State<'_, Mutex<AppState>>,
app_handle: AppHandle, app_handle: AppHandle,
) -> Result<(), String> { ) -> Result<(), String> {
let meta = get_current_meta(&game_id)?; let meta = get_current_meta(&game_id)?;
@ -270,7 +269,7 @@ fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle) {
return; return;
} }
let previous_state = previous_state.unwrap(); 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 { GameDownloadStatus::Installed {
version_name, version_name,
install_dir, install_dir,
@ -330,7 +329,7 @@ pub fn get_current_meta(game_id: &String) -> Result<DownloadableMetadata, String
} }
#[tauri::command] #[tauri::command]
pub fn fetch_game_verion_options<'a>( pub fn fetch_game_verion_options(
game_id: String, game_id: String,
state: tauri::State<'_, Mutex<AppState>>, state: tauri::State<'_, Mutex<AppState>>,
) -> Result<Vec<GameVersionOption>, String> { ) -> Result<Vec<GameVersionOption>, String> {

View File

@ -402,7 +402,7 @@ pub fn run() {
.build(tauri::generate_context!()) .build(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
app.run(|app_handle, event| { app.run(|_app_handle, event| {
if let RunEvent::ExitRequested { code, api, .. } = event { if let RunEvent::ExitRequested { code, api, .. } = event {
if code.is_none() { if code.is_none() {
api.prevent_exit(); api.prevent_exit();

View File

@ -22,11 +22,10 @@ pub fn launch_game(id: String, state: tauri::State<'_, Mutex<AppState>>) -> Resu
{ {
Some(GameDownloadStatus::Installed { Some(GameDownloadStatus::Installed {
version_name, version_name,
install_dir, ..
}) => version_name, }) => version_name,
Some(GameDownloadStatus::SetupRequired { Some(GameDownloadStatus::SetupRequired {
version_name, ..
install_dir,
}) => return Err(String::from("Game setup still required")), }) => return Err(String::from("Game setup still required")),
_ => return Err(String::from("Game not installed")), _ => return Err(String::from("Game not installed")),
}; };

View File

@ -255,7 +255,7 @@ impl ProcessManager<'_> {
&meta, &meta,
command.to_str().unwrap().to_owned(), command.to_str().unwrap().to_owned(),
args, args,
&target_current_dir.to_string(), target_current_dir,
log_file, log_file,
error_file, error_file,
)?; )?;
@ -313,7 +313,7 @@ pub trait ProcessHandler: Send + 'static {
meta: &DownloadableMetadata, meta: &DownloadableMetadata,
command: String, command: String,
args: Vec<String>, args: Vec<String>,
current_dir: &String, current_dir: &str,
log_file: File, log_file: File,
error_file: File, error_file: File,
) -> Result<Child, String>; ) -> Result<Child, String>;
@ -323,10 +323,10 @@ struct NativeGameLauncher;
impl ProcessHandler for NativeGameLauncher { impl ProcessHandler for NativeGameLauncher {
fn launch_process( fn launch_process(
&self, &self,
meta: &DownloadableMetadata, _meta: &DownloadableMetadata,
command: String, command: String,
args: Vec<String>, args: Vec<String>,
current_dir: &String, current_dir: &str,
log_file: File, log_file: File,
error_file: File, error_file: File,
) -> Result<Child, String> { ) -> Result<Child, String> {
@ -345,12 +345,12 @@ struct UMULauncher;
impl ProcessHandler for UMULauncher { impl ProcessHandler for UMULauncher {
fn launch_process( fn launch_process(
&self, &self,
meta: &DownloadableMetadata, _meta: &DownloadableMetadata,
command: String, command: String,
args: Vec<String>, args: Vec<String>,
current_dir: &String, _current_dir: &str,
log_file: File, _log_file: File,
error_file: File, _error_file: File,
) -> Result<Child, String> { ) -> Result<Child, String> {
UmuCommandBuilder::new(UMU_LAUNCHER_EXECUTABLE, command) UmuCommandBuilder::new(UMU_LAUNCHER_EXECUTABLE, command)
.game_id(String::from("0")) .game_id(String::from("0"))

View File

@ -1,4 +1,3 @@
mod compatibility_layer; mod compatibility_layer;
mod prefix; mod prefix;
mod registry;
mod tool; mod tool;

View File

@ -1,7 +0,0 @@
use std::collections::HashMap;
use crate::download_manager::downloadable::Downloadable;
pub struct Registry<T: Downloadable> {
tools: HashMap<String, T>,
}

View File

@ -8,6 +8,7 @@ use crate::download_manager::{
downloadable_metadata::DownloadableMetadata, progress_object::ProgressObject, downloadable_metadata::DownloadableMetadata, progress_object::ProgressObject,
}; };
#[allow(unused)]
pub struct ToolDownloadAgent { pub struct ToolDownloadAgent {
id: String, id: String,
version: String, version: String,
@ -15,6 +16,7 @@ pub struct ToolDownloadAgent {
control_flag: DownloadThreadControl, control_flag: DownloadThreadControl,
progress: Arc<ProgressObject>, progress: Arc<ProgressObject>,
} }
#[allow(unused)]
impl Downloadable for ToolDownloadAgent { impl Downloadable for ToolDownloadAgent {
fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> { fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
todo!() todo!()