implement uninstall rpcs

This commit is contained in:
llama 2025-10-24 19:33:39 +08:00
parent dfe77c8a8a
commit 8f1a3dca94
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3
2 changed files with 46 additions and 0 deletions

View file

@ -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<R: Runtime>(app: AppHandle<R>, window: WebviewWindow<R>) -> Re
Ok(())
}
pub async fn get_uninstall_info<R: Runtime>(
app: AppHandle<R>,
_window: WebviewWindow<R>,
) -> Result<UninstallProto> {
app.flow().paths().map(Uninstall::from).map(Into::into)
}
pub async fn uninstall_anki<R: Runtime>(
app: AppHandle<R>,
_window: WebviewWindow<R>,
input: UninstallRequest,
) -> Result<UninstallResponse> {
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<R: Runtime>(

View file

@ -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<NormalState> for State {
}
}
pub struct Uninstall {
anki_program_files_exists: bool,
anki_base_folder_exists: bool,
}
impl<T: AsRef<uv::Paths>> From<T> 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<Uninstall> 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<uv::Paths>),
OsUnsupported(anyhow::Error),