chore(downloads): Ran cargo clippy & cargo fmt

Side note, I'm going to start using chore to declare these rather than refactor because I don't think that it actually qualifies

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-11-16 17:05:24 +11:00
parent 63c3cc1096
commit bd3deacf38
3 changed files with 38 additions and 36 deletions

View File

@ -207,7 +207,6 @@ impl GameDownloadAgent {
.build()
.unwrap();
pool.scope(move |scope| {
let contexts = self.contexts.lock().unwrap();

View File

@ -79,7 +79,7 @@ pub enum DownloadManagerSignal {
/// download and return
Finish,
/// Any error which occurs in the agent
Error(GameDownloadError)
Error(GameDownloadError),
}
pub enum DownloadManagerStatus {
Downloading,
@ -128,7 +128,6 @@ impl DownloadManager {
match signal {
DownloadManagerSignal::Go => {
self.manage_go_signal();
}
DownloadManagerSignal::Stop => {
self.manage_stop_signal();
@ -140,17 +139,14 @@ impl DownloadManager {
self.manage_queue_signal(game_id, version, target_download_dir);
}
DownloadManagerSignal::Finish => {
match self.active_control_flag {
Some(active_control_flag) => {
active_control_flag.set(DownloadThreadControlFlag::Stop)
}
None => {}
if let Some(active_control_flag) = self.active_control_flag {
active_control_flag.set(DownloadThreadControlFlag::Stop)
}
return Ok(());
}
DownloadManagerSignal::Error(game_download_error) => {
self.manage_error_signal(game_download_error);
},
}
};
}
}
@ -177,12 +173,7 @@ impl DownloadManager {
self.sender.send(DownloadManagerSignal::Go).unwrap();
}
fn manage_queue_signal(
&mut self,
id: String,
version: String,
target_download_dir: usize,
) {
fn manage_queue_signal(&mut self, id: String, version: String, target_download_dir: usize) {
info!("Got signal Queue");
let download_agent = Arc::new(GameDownloadAgent::new(
id.clone(),
@ -196,7 +187,10 @@ impl DownloadManager {
});
self.download_agent_registry
.insert(interface_data.id.clone(), download_agent);
self.download_queue.lock().unwrap().push_back(interface_data);
self.download_queue
.lock()
.unwrap()
.push_back(interface_data);
}
fn manage_go_signal(&mut self) {
@ -210,7 +204,8 @@ impl DownloadManager {
.unwrap()
.clone()
};
let download_agent_interface = Arc::new(AgentInterfaceData::from(download_agent.clone()));
let download_agent_interface =
Arc::new(AgentInterfaceData::from(download_agent.clone()));
self.current_game_interface = Some(download_agent_interface);
let progress_object = download_agent.progress.clone();
@ -224,12 +219,8 @@ impl DownloadManager {
info!("Spawning download");
spawn(move || {
let signal = match download_agent.download() {
Ok(_) => {
DownloadManagerSignal::Completed(download_agent.id.clone())
},
Err(e) => {
DownloadManagerSignal::Error(e)
},
Ok(_) => DownloadManagerSignal::Completed(download_agent.id.clone()),
Err(e) => DownloadManagerSignal::Error(e),
};
sender.send(signal).unwrap();
});

View File

@ -1,13 +1,20 @@
use std::{
any::Any, collections::VecDeque, sync::{
any::Any,
collections::VecDeque,
sync::{
mpsc::{SendError, Sender},
Arc, Mutex, MutexGuard,
}, thread::JoinHandle
},
thread::JoinHandle,
};
use log::info;
use super::{download_agent::GameDownloadAgent, download_manager::{DownloadManagerSignal, DownloadManagerStatus, GameDownloadStatus}, progress_object::ProgressObject};
use super::{
download_agent::GameDownloadAgent,
download_manager::{DownloadManagerSignal, GameDownloadStatus},
progress_object::ProgressObject,
};
/// Accessible front-end for the DownloadManager
///
@ -33,7 +40,7 @@ impl From<Arc<GameDownloadAgent>> for AgentInterfaceData {
fn from(value: Arc<GameDownloadAgent>) -> Self {
Self {
id: value.id.clone(),
status: Mutex::from(GameDownloadStatus::Uninitialised)
status: Mutex::from(GameDownloadStatus::Uninitialised),
}
}
}
@ -102,15 +109,20 @@ impl DownloadManagerInterface {
pub fn resume_downloads(&self) -> Result<(), SendError<DownloadManagerSignal>> {
self.command_sender.send(DownloadManagerSignal::Go)
}
pub fn ensure_terminated(self) -> Result<Result<(),()>, Box<dyn Any + Send>> {
self.command_sender.send(DownloadManagerSignal::Finish).unwrap();
pub fn ensure_terminated(self) -> Result<Result<(), ()>, Box<dyn Any + Send>> {
self.command_sender
.send(DownloadManagerSignal::Finish)
.unwrap();
self.terminator.join()
}
}
/// Takes in the locked value from .edit() and attempts to
/// get the index of whatever game_id is passed in
fn get_index_from_id(queue: &mut MutexGuard<'_, VecDeque<Arc<AgentInterfaceData>>>, id: String) -> Option<usize> {
fn get_index_from_id(
queue: &mut MutexGuard<'_, VecDeque<Arc<AgentInterfaceData>>>,
id: String,
) -> Option<usize> {
queue
.iter()
.position(|download_agent| download_agent.id == id)