fix(updater): retry slow update downloads from other sources and honour cancel

This commit is contained in:
wonfen
2026-10-06 14:21:09 +08:00
parent c341b9b238
commit dba0f471bf
6 changed files with 196 additions and 42 deletions
+20 -4
View File
@@ -1,7 +1,12 @@
use super::CmdResult;
use crate::{cmd::StringifyErr as _, core::SilentUpdater, feat, utils::dirs};
use crate::{
cmd::StringifyErr as _,
core::{SilentUpdater, updater::DownloadEvent},
feat,
utils::dirs,
};
use smartstring::alias::String;
use tauri::{AppHandle, Manager as _};
use tauri::{AppHandle, Manager as _, ipc::Channel};
#[tauri::command]
pub async fn open_app_dir() -> CmdResult<()> {
@@ -45,13 +50,24 @@ pub async fn restart_app() -> CmdResult<()> {
}
#[tauri::command]
pub async fn install_cached_update(app_handle: AppHandle, version: String) -> CmdResult<bool> {
pub async fn install_update(
app_handle: AppHandle,
version: String,
on_event: Channel<DownloadEvent>,
) -> CmdResult<bool> {
SilentUpdater::global()
.install_cached(&app_handle, &version)
.install_update(&app_handle, &version, |event| {
let _ = on_event.send(event);
})
.await
.stringify_err()
}
#[tauri::command]
pub fn cancel_update_download() {
SilentUpdater::global().cancel_download();
}
#[tauri::command]
pub fn get_app_dir() -> CmdResult<String> {
let app_home_dir = dirs::app_home_dir().stringify_err()?.to_string_lossy().into();