diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index e55c908..d7320db 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -220,9 +220,9 @@ pub fn fetch_download_dir_stats() -> Result, String> { Ok(directories) } -pub fn set_game_status, &Arc)>( +pub fn set_game_status, &DownloadableMetadata)>( app_handle: &AppHandle, - id: Arc, + id: DownloadableMetadata, setter: F, ) { let mut db_handle = DB.borrow_data_mut().unwrap(); diff --git a/src-tauri/src/download_manager/download_manager.rs b/src-tauri/src/download_manager/download_manager.rs index f8c91aa..5e6cc53 100644 --- a/src-tauri/src/download_manager/download_manager.rs +++ b/src-tauri/src/download_manager/download_manager.rs @@ -21,7 +21,7 @@ pub enum DownloadManagerSignal { /// Pauses the DownloadManager Stop, /// Called when a DownloadAgent has fully completed a download. - Completed(Arc), + Completed(DownloadableMetadata), /// Generates and appends a DownloadAgent /// to the registry and queue Queue(DownloadAgent), @@ -30,9 +30,9 @@ pub enum DownloadManagerSignal { /// then exit Finish, /// Stops, removes, and tells a download to cleanup - Cancel(Arc), + Cancel(DownloadableMetadata), /// Removes a given application - Remove(Arc), + Remove(DownloadableMetadata), /// Any error which occurs in the agent Error(ApplicationDownloadError), /// Pushes UI update @@ -40,7 +40,7 @@ pub enum DownloadManagerSignal { UpdateUIStats(usize, usize), //kb/s and seconds /// Uninstall download /// Takes download ID - Uninstall(Arc), + Uninstall(DownloadableMetadata), } #[derive(Debug, Clone)] @@ -109,17 +109,17 @@ impl DownloadManager { self.command_sender.send(DownloadManagerSignal::Queue(download))?; self.command_sender.send(DownloadManagerSignal::Go) } - pub fn edit(&self) -> MutexGuard<'_, VecDeque>> { + pub fn edit(&self) -> MutexGuard<'_, VecDeque> { self.download_queue.edit() } - pub fn read_queue(&self) -> VecDeque> { + pub fn read_queue(&self) -> VecDeque { self.download_queue.read() } pub fn get_current_download_progress(&self) -> Option { let progress_object = (*self.progress.lock().unwrap()).clone()?; Some(progress_object.get_progress()) } - pub fn rearrange_string(&self, meta: &Arc, new_index: usize) { + pub fn rearrange_string(&self, meta: &DownloadableMetadata, new_index: usize) { let mut queue = self.edit(); let current_index = get_index_from_id(&mut queue, meta).unwrap(); let to_move = queue.remove(current_index).unwrap(); @@ -128,7 +128,7 @@ impl DownloadManager { .send(DownloadManagerSignal::UpdateUIQueue) .unwrap(); } - pub fn cancel(&self, meta: Arc) { + pub fn cancel(&self, meta: DownloadableMetadata) { self.command_sender .send(DownloadManagerSignal::Remove(meta)) .unwrap(); @@ -174,7 +174,7 @@ impl DownloadManager { .unwrap(); self.terminator.join() } - pub fn uninstall_application(&self, meta: Arc) { + pub fn uninstall_application(&self, meta: DownloadableMetadata) { self.command_sender .send(DownloadManagerSignal::Uninstall(meta)) .unwrap(); @@ -187,8 +187,8 @@ impl DownloadManager { /// 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>>, - meta: &Arc, + queue: &mut MutexGuard<'_, VecDeque>, + meta: &DownloadableMetadata, ) -> Option { queue .iter() diff --git a/src-tauri/src/download_manager/download_manager_builder.rs b/src-tauri/src/download_manager/download_manager_builder.rs index 8be4e1d..3276cb2 100644 --- a/src-tauri/src/download_manager/download_manager_builder.rs +++ b/src-tauri/src/download_manager/download_manager_builder.rs @@ -58,7 +58,7 @@ Behold, my madness - quexeky */ pub struct DownloadManagerBuilder { - download_agent_registry: HashMap, DownloadAgent>, + download_agent_registry: HashMap, download_queue: Queue, command_receiver: Receiver, sender: Sender, @@ -100,7 +100,7 @@ impl DownloadManagerBuilder { *self.status.lock().unwrap() = status; } - fn remove_and_cleanup_front_download(&mut self, meta: &Arc) -> DownloadAgent { + fn remove_and_cleanup_front_download(&mut self, meta: &DownloadableMetadata) -> DownloadAgent { self.download_queue.pop_front(); let download_agent = self.download_agent_registry.remove(meta).unwrap(); self.cleanup_current_download(); @@ -249,7 +249,7 @@ impl DownloadManagerBuilder { active_control_flag.set(DownloadThreadControlFlag::Stop); } } - fn manage_completed_signal(&mut self, meta: Arc) { + fn manage_completed_signal(&mut self, meta: DownloadableMetadata) { info!("Got signal Completed"); if let Some(interface) = &self.current_download_agent { if interface.metadata() == meta { @@ -270,7 +270,7 @@ impl DownloadManagerBuilder { self.set_status(DownloadManagerStatus::Error(error)); } - fn manage_cancel_signal(&mut self, meta: &Arc) { + fn manage_cancel_signal(&mut self, meta: &DownloadableMetadata) { info!("Got signal Cancel"); if let Some(current_download) = &self.current_download_agent { @@ -293,7 +293,7 @@ impl DownloadManagerBuilder { } } } - fn uninstall_application(&mut self, meta: &Arc) { + fn uninstall_application(&mut self, meta: &DownloadableMetadata) { let download_agent = match self.download_agent_registry.get(meta) { Some(download_agent) => download_agent.clone(), None => return, diff --git a/src-tauri/src/download_manager/downloadable.rs b/src-tauri/src/download_manager/downloadable.rs index 8eb4956..f0af168 100644 --- a/src-tauri/src/download_manager/downloadable.rs +++ b/src-tauri/src/download_manager/downloadable.rs @@ -11,7 +11,7 @@ pub trait Downloadable: Send + Sync { fn progress(&self) -> Arc; fn control_flag(&self) -> DownloadThreadControl; fn status(&self) -> DownloadStatus; - fn metadata(&self) -> Arc; + fn metadata(&self) -> DownloadableMetadata; fn on_initialised(&self, app_handle: &AppHandle); fn on_error(&self, app_handle: &AppHandle, error: ApplicationDownloadError); fn on_complete(&self, app_handle: &AppHandle); diff --git a/src-tauri/src/download_manager/generate_downloadable.rs b/src-tauri/src/download_manager/generate_downloadable.rs index 254436f..8f53185 100644 --- a/src-tauri/src/download_manager/generate_downloadable.rs +++ b/src-tauri/src/download_manager/generate_downloadable.rs @@ -2,6 +2,6 @@ use std::sync::Arc; use super::{download_manager_builder::DownloadAgent, downloadable_metadata::DownloadableMetadata}; -pub fn generate_downloadable(meta: Arc) -> DownloadAgent { +pub fn generate_downloadable(meta: DownloadableMetadata) -> DownloadAgent { todo!() } \ No newline at end of file diff --git a/src-tauri/src/download_manager/queue.rs b/src-tauri/src/download_manager/queue.rs index 2e8cddf..cda08df 100644 --- a/src-tauri/src/download_manager/queue.rs +++ b/src-tauri/src/download_manager/queue.rs @@ -7,7 +7,7 @@ use super::downloadable_metadata::DownloadableMetadata; #[derive(Clone)] pub struct Queue { - inner: Arc>>>, + inner: Arc>>, } #[allow(dead_code)] @@ -17,37 +17,37 @@ impl Queue { inner: Arc::new(Mutex::new(VecDeque::new())), } } - pub fn read(&self) -> VecDeque> { + pub fn read(&self) -> VecDeque { self.inner.lock().unwrap().clone() } - pub fn edit(&self) -> MutexGuard<'_, VecDeque>> { + pub fn edit(&self) -> MutexGuard<'_, VecDeque> { self.inner.lock().unwrap() } - pub fn pop_front(&self) -> Option> { + pub fn pop_front(&self) -> Option { self.edit().pop_front() } pub fn empty(&self) -> bool { self.inner.lock().unwrap().len() == 0 } - pub fn exists(&self, meta: Arc) -> bool { + pub fn exists(&self, meta: DownloadableMetadata) -> bool { self.read().contains(&meta) } /// Either inserts `interface` at the specified index, or appends to /// the back of the deque if index is greater than the length of the deque - pub fn insert(&self, interface: Arc, index: usize) { + pub fn insert(&self, interface: DownloadableMetadata, index: usize) { if self.read().len() > index { self.append(interface); } else { self.edit().insert(index, interface); } } - pub fn append(&self, interface: Arc) { + pub fn append(&self, interface: DownloadableMetadata) { self.edit().push_back(interface); } pub fn pop_front_if_equal( &self, - meta: &Arc, - ) -> Option> { + meta: &DownloadableMetadata, + ) -> Option { let mut queue = self.edit(); let front = match queue.front() { Some(front) => front, @@ -58,10 +58,10 @@ impl Queue { } None } - pub fn get_by_meta(&self, meta: &Arc) -> Option { + pub fn get_by_meta(&self, meta: &DownloadableMetadata) -> Option { self.read().iter().position(|data| data == meta) } - pub fn move_to_index_by_meta(&self, meta: &Arc, new_index: usize) -> Result<(), ()> { + pub fn move_to_index_by_meta(&self, meta: &DownloadableMetadata, new_index: usize) -> Result<(), ()> { let index = match self.get_by_meta(meta) { Some(index) => index, None => return Err(()), diff --git a/src-tauri/src/downloads/download_agent.rs b/src-tauri/src/downloads/download_agent.rs index 1c9af86..4800ac4 100644 --- a/src-tauri/src/downloads/download_agent.rs +++ b/src-tauri/src/downloads/download_agent.rs @@ -1,7 +1,7 @@ use crate::auth::generate_authorization_header; use crate::db::{set_game_status, DatabaseImpls}; use crate::download_manager::application_download_error::ApplicationDownloadError; -use crate::download_manager::download_manager::DownloadManagerSignal; +use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus}; use crate::download_manager::download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag}; use crate::download_manager::downloadable::Downloadable; use crate::download_manager::downloadable_metadata::DownloadableMetadata; @@ -317,7 +317,7 @@ impl Downloadable for GameDownloadAgent { self.control_flag.clone() } - fn metadata(&self) -> Arc { + fn metadata(&self) -> DownloadableMetadata { todo!() } @@ -354,7 +354,7 @@ impl Downloadable for GameDownloadAgent { todo!() } - fn status(&self) -> crate::download_manager::download_manager::DownloadStatus { + fn status(&self) -> DownloadStatus { todo!() } } \ No newline at end of file diff --git a/src-tauri/src/library.rs b/src-tauri/src/library.rs index 969945b..beb47a6 100644 --- a/src-tauri/src/library.rs +++ b/src-tauri/src/library.rs @@ -191,7 +191,7 @@ pub fn fetch_game(id: DownloadableMetadata, app: tauri::AppHandle) -> Result) -> Result { +pub fn fetch_game_status(meta: DownloadableMetadata) -> Result { let status = DownloadStatusManager::fetch_state(&meta); Ok(status) @@ -243,7 +243,7 @@ pub fn fetch_game_verion_options<'a>( #[tauri::command] pub fn uninstall_game( - game_id: Arc, + game_id: DownloadableMetadata, state: tauri::State<'_, Mutex>, ) -> Result<(), String> { let state_lock = state.lock().unwrap(); @@ -266,7 +266,7 @@ pub fn push_game_update(app_handle: &AppHandle, meta: DownloadableMetadata, stat } pub fn on_game_complete( - meta: Arc, + meta: DownloadableMetadata, install_dir: String, app_handle: &AppHandle, ) -> Result<(), RemoteAccessError> { @@ -303,7 +303,7 @@ pub fn on_game_complete( handle .applications .versions - .entry(*meta.clone()) + .entry(meta.clone()) .or_default() .insert(meta.version.clone(), data.clone()); drop(handle); @@ -325,7 +325,7 @@ pub fn on_game_complete( db_handle .applications .statuses - .insert(*meta.clone(), status.clone()); + .insert(meta.clone(), status.clone()); drop(db_handle); DB.save().unwrap(); app_handle diff --git a/src-tauri/src/tools/tool.rs b/src-tauri/src/tools/tool.rs index 0974037..4d6fce2 100644 --- a/src-tauri/src/tools/tool.rs +++ b/src-tauri/src/tools/tool.rs @@ -26,7 +26,7 @@ impl Downloadable for ToolDownloadAgent { todo!() } - fn metadata(&self) -> Arc { + fn metadata(&self) -> DownloadableMetadata { todo!() }