From 8f1a3dca94d9b526d3f20f915187204d2cab2032 Mon Sep 17 00:00:00 2001 From: llama Date: Fri, 24 Oct 2025 19:33:39 +0800 Subject: [PATCH] implement uninstall rpcs --- qt/launcher-gui/src-tauri/src/commands.rs | 21 +++++++++++++++++++ qt/launcher-gui/src-tauri/src/state.rs | 25 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/qt/launcher-gui/src-tauri/src/commands.rs b/qt/launcher-gui/src-tauri/src/commands.rs index f9177e936..57cba37ec 100644 --- a/qt/launcher-gui/src-tauri/src/commands.rs +++ b/qt/launcher-gui/src-tauri/src/commands.rs @@ -14,6 +14,9 @@ use anki_proto::launcher::Mirror; use anki_proto::launcher::NormalState as NormalStateProto; use anki_proto::launcher::Options; use anki_proto::launcher::State as StateProto; +use anki_proto::launcher::Uninstall as UninstallProto; +use anki_proto::launcher::UninstallRequest; +use anki_proto::launcher::UninstallResponse; use anki_proto::launcher::ZoomWebviewRequest; use anyhow::anyhow; use anyhow::Context; @@ -32,6 +35,7 @@ use crate::lang::LANGS_DEFAULT_REGION; use crate::lang::LANGS_WITH_REGIONS; use crate::state::ExistingVersions; use crate::state::State; +use crate::state::Uninstall; use crate::state::Versions; use crate::uv; @@ -218,6 +222,23 @@ pub async fn exit(app: AppHandle, window: WebviewWindow) -> Re Ok(()) } +pub async fn get_uninstall_info( + app: AppHandle, + _window: WebviewWindow, +) -> Result { + app.flow().paths().map(Uninstall::from).map(Into::into) +} + +pub async fn uninstall_anki( + app: AppHandle, + _window: WebviewWindow, + input: UninstallRequest, +) -> Result { + let paths = app.flow().paths()?; + let action_needed = uv::handle_uninstall(paths, input.delete_base_folder)?; + Ok(UninstallResponse { action_needed }) +} + /// NOTE: [zoomHotkeysEnabled](https://v2.tauri.app/reference/config/#zoomhotkeysenabled) exists /// but the polyfill it uses on linux doesn't allow regular scrolling pub async fn zoom_webview( diff --git a/qt/launcher-gui/src-tauri/src/state.rs b/qt/launcher-gui/src-tauri/src/state.rs index f941eac73..7f230a9c1 100644 --- a/qt/launcher-gui/src-tauri/src/state.rs +++ b/qt/launcher-gui/src-tauri/src/state.rs @@ -6,6 +6,7 @@ use std::sync::Arc; pub use anki_proto::launcher::ExistingVersions; use anki_proto::launcher::Mirror; use anki_proto::launcher::Options as OptionsProto; +use anki_proto::launcher::Uninstall as UninstallProto; pub use anki_proto::launcher::Version; pub use anki_proto::launcher::Versions; use anyhow::anyhow; @@ -71,6 +72,30 @@ impl From for State { } } +pub struct Uninstall { + anki_program_files_exists: bool, + anki_base_folder_exists: bool, +} + +impl> From for Uninstall { + fn from(paths: T) -> Self { + let paths = paths.as_ref(); + Self { + anki_program_files_exists: paths.uv_install_root.exists(), + anki_base_folder_exists: paths.anki_base_folder.exists(), + } + } +} + +impl From for UninstallProto { + fn from(u: Uninstall) -> Self { + Self { + anki_program_files_exists: u.anki_program_files_exists, + anki_base_folder_exists: u.anki_base_folder_exists, + } + } +} + pub enum State { LaunchAnki(Arc), OsUnsupported(anyhow::Error),