From dd0a676fcdc7cbac2cb0289f2728ddba714d5d36 Mon Sep 17 00:00:00 2001 From: llama Date: Fri, 24 Oct 2025 19:35:32 +0800 Subject: [PATCH] update platform-specific uninstall fns --- qt/launcher-gui/src-tauri/src/platform/mac.rs | 18 ++++++-------- .../src-tauri/src/platform/unix.rs | 21 ++++++---------- .../src-tauri/src/platform/windows.rs | 24 ++++++++++--------- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/qt/launcher-gui/src-tauri/src/platform/mac.rs b/qt/launcher-gui/src-tauri/src/platform/mac.rs index bc9759fce..863a05c89 100644 --- a/qt/launcher-gui/src-tauri/src/platform/mac.rs +++ b/qt/launcher-gui/src-tauri/src/platform/mac.rs @@ -5,6 +5,7 @@ use std::path::Path; use std::process::Command; use anki_process::CommandExt as AnkiCommandExt; +use anki_proto::launcher::uninstall_response::ActionNeeded; use anyhow::Result; pub fn prepare_for_launch_after_update(mut cmd: Command, root: &Path) -> Result<()> { @@ -34,7 +35,7 @@ pub fn prepare_for_launch_after_update(mut cmd: Command, root: &Path) -> Result< Ok(()) } -pub fn finalize_uninstall() { +pub fn finalize_uninstall() -> Result> { if let Ok(exe_path) = std::env::current_exe() { // Find the .app bundle by walking up the directory tree let mut app_bundle_path = exe_path.as_path(); @@ -43,22 +44,17 @@ pub fn finalize_uninstall() { if name.to_string_lossy().ends_with(".app") { let result = Command::new("trash").arg(parent).output(); - match result { - Ok(output) if output.status.success() => { - println!("Anki has been uninstalled."); - return; - } + return Ok(match result { + Ok(output) if output.status.success() => None, _ => { // Fall back to manual instructions - println!( - "Please manually drag Anki.app to the trash to complete uninstall." - ); + Some(ActionNeeded::MacManual(())) } - } - return; + }); } } app_bundle_path = parent; } } + Ok(None) } diff --git a/qt/launcher-gui/src-tauri/src/platform/unix.rs b/qt/launcher-gui/src-tauri/src/platform/unix.rs index 29e860033..771b6c5ba 100644 --- a/qt/launcher-gui/src-tauri/src/platform/unix.rs +++ b/qt/launcher-gui/src-tauri/src/platform/unix.rs @@ -1,24 +1,17 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use anki_proto::launcher::uninstall_response::ActionNeeded; use anyhow::Result; -pub fn finalize_uninstall() { - use std::io::stdin; - use std::io::stdout; - use std::io::Write; - +pub fn finalize_uninstall() -> Result> { let uninstall_script = std::path::Path::new("/usr/local/share/anki/uninstall.sh"); - if uninstall_script.exists() { - println!("To finish uninstalling, run 'sudo /usr/local/share/anki/uninstall.sh'"); - } else { - println!("Anki has been uninstalled."); - } - println!("Press enter to quit."); - let _ = stdout().flush(); - let mut input = String::new(); - let _ = stdin().read_line(&mut input); + Ok(uninstall_script + .exists() + .then_some(ActionNeeded::UnixScript( + uninstall_script.display().to_string(), + ))) } pub fn ensure_glibc_supported() -> Result<()> { diff --git a/qt/launcher-gui/src-tauri/src/platform/windows.rs b/qt/launcher-gui/src-tauri/src/platform/windows.rs index 72725058f..b255c9ae8 100644 --- a/qt/launcher-gui/src-tauri/src/platform/windows.rs +++ b/qt/launcher-gui/src-tauri/src/platform/windows.rs @@ -4,7 +4,8 @@ use std::io::stdin; use std::process::Command; -use anyhow::Context; +use anki_proto::launcher::uninstall_response::ActionNeeded; +use anki_proto::launcher::uninstall_response::WindowsInstallerError; use anyhow::Result; use widestring::u16cstr; use windows::core::PCWSTR; @@ -58,33 +59,34 @@ pub fn ensure_windows_version_supported() -> Result<()> { } } -pub fn finalize_uninstall() { +pub fn finalize_uninstall() -> Result> { let uninstaller_path = get_uninstaller_path(); - match uninstaller_path { + Ok(match uninstaller_path { Some(path) => { println!("Launching Windows uninstaller..."); let result = Command::new(&path).env("ANKI_LAUNCHER", "1").spawn(); match result { - Ok(_) => { - println!("Uninstaller launched successfully."); - return; - } + Ok(_) => None, Err(e) => { println!("Failed to launch uninstaller: {e}"); println!("You can manually run: {}", path.display()); + Some(ActionNeeded::WindowsInstallerFailed( + WindowsInstallerError { + error: format!("{e:?}"), + path: path.display().to_string(), + }, + )) } } } None => { println!("Windows uninstaller not found."); println!("You may need to uninstall via Windows Settings > Apps."); + Some(ActionNeeded::WindowsInstallerNotFound(())) } - } - println!("Press enter to close..."); - let mut input = String::new(); - let _ = stdin().read_line(&mut input); + }) } fn get_uninstaller_path() -> Option {