chore(exit): Progress on cleanup and exit

This commit is contained in:
quexeky
2025-01-16 17:51:30 +11:00
committed by quexeky
parent 968fcef456
commit 441914b7b8
3 changed files with 14 additions and 8 deletions
+10 -3
View File
@@ -1,13 +1,20 @@
use log::{debug, info}; use log::{debug, info};
use tauri::AppHandle; use tauri::AppHandle;
use crate::AppState;
#[tauri::command] #[tauri::command]
pub fn quit(app: tauri::AppHandle) { pub fn quit(app: tauri::AppHandle, state: tauri::State<'_, std::sync::Mutex<AppState<'_>>>) {
cleanup_and_exit(&app); cleanup_and_exit(&app, &state);
} }
pub fn cleanup_and_exit(app: &AppHandle) { pub fn cleanup_and_exit(app: &AppHandle, state: &tauri::State<'_, std::sync::Mutex<AppState<'_>>>) {
debug!("Cleaning up and exiting application"); debug!("Cleaning up and exiting application");
let download_manager = state.lock().unwrap().download_manager.clone();
match download_manager.ensure_terminated() {
Ok(_) => {},
Err(e) => panic!("{:?}", e),
}
app.exit(0); app.exit(0);
} }
@@ -3,8 +3,7 @@ use std::{
collections::VecDeque, collections::VecDeque,
fmt::Debug, fmt::Debug,
sync::{ sync::{
mpsc::{SendError, Sender}, mpsc::{SendError, Sender}, Mutex, MutexGuard
MutexGuard,
}, },
thread::JoinHandle, thread::JoinHandle,
}; };
@@ -84,7 +83,7 @@ pub enum DownloadStatus {
/// which provides raw access to the underlying queue. /// which provides raw access to the underlying queue.
/// THIS EDITING IS BLOCKING!!! /// THIS EDITING IS BLOCKING!!!
pub struct DownloadManager { pub struct DownloadManager {
terminator: JoinHandle<Result<(), ()>>, terminator: Mutex<JoinHandle<Result<(), ()>>>,
download_queue: Queue, download_queue: Queue,
progress: CurrentProgressObject, progress: CurrentProgressObject,
command_sender: Sender<DownloadManagerSignal>, command_sender: Sender<DownloadManagerSignal>,
@@ -174,7 +173,7 @@ impl DownloadManager {
pub fn resume_downloads(&self) { pub fn resume_downloads(&self) {
self.command_sender.send(DownloadManagerSignal::Go).unwrap(); self.command_sender.send(DownloadManagerSignal::Go).unwrap();
} }
pub fn ensure_terminated(self) -> Result<Result<(), ()>, Box<dyn Any + Send>> { pub fn ensure_terminated(&self) -> Result<Result<(), ()>, Box<dyn Any + Send>> {
self.command_sender self.command_sender
.send(DownloadManagerSignal::Finish) .send(DownloadManagerSignal::Finish)
.unwrap(); .unwrap();
+1 -1
View File
@@ -315,7 +315,7 @@ pub fn run() {
app.webview_windows().get("main").unwrap().show().unwrap(); app.webview_windows().get("main").unwrap().show().unwrap();
} }
"quit" => { "quit" => {
cleanup_and_exit(app); cleanup_and_exit(app, &state);
} }
_ => { _ => {