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 9369ff14b8
commit 0381b8b8cb
3 changed files with 14 additions and 8 deletions

View File

@ -1,13 +1,20 @@
use log::{debug, info};
use tauri::AppHandle;
use crate::AppState;
#[tauri::command]
pub fn quit(app: tauri::AppHandle) {
cleanup_and_exit(&app);
pub fn quit(app: tauri::AppHandle, state: tauri::State<'_, std::sync::Mutex<AppState<'_>>>) {
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");
let download_manager = state.lock().unwrap().download_manager.clone();
match download_manager.ensure_terminated() {
Ok(_) => {},
Err(e) => panic!("{:?}", e),
}
app.exit(0);
}

View File

@ -3,8 +3,7 @@ use std::{
collections::VecDeque,
fmt::Debug,
sync::{
mpsc::{SendError, Sender},
MutexGuard,
mpsc::{SendError, Sender}, Mutex, MutexGuard
},
thread::JoinHandle,
};
@ -84,7 +83,7 @@ pub enum DownloadStatus {
/// which provides raw access to the underlying queue.
/// THIS EDITING IS BLOCKING!!!
pub struct DownloadManager {
terminator: JoinHandle<Result<(), ()>>,
terminator: Mutex<JoinHandle<Result<(), ()>>>,
download_queue: Queue,
progress: CurrentProgressObject,
command_sender: Sender<DownloadManagerSignal>,
@ -174,7 +173,7 @@ impl DownloadManager {
pub fn resume_downloads(&self) {
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
.send(DownloadManagerSignal::Finish)
.unwrap();

View File

@ -315,7 +315,7 @@ pub fn run() {
app.webview_windows().get("main").unwrap().show().unwrap();
}
"quit" => {
cleanup_and_exit(app);
cleanup_and_exit(app, &state);
}
_ => {