feat: autoupdate toggle

This commit is contained in:
2025-04-04 19:41:38 +00:00
parent 8c3f9762a4
commit ca871f069f
8 changed files with 107 additions and 33 deletions

View File

@ -200,8 +200,8 @@ pub async fn run(_args: Vec<String>) {
cmd::sync_current_profile,
cmd::save_current_profile,
cmd::is_offline,
cmd::set_offline,
cmd::get_global_config,
cmd::set_global_config,
cmd::list_displays,
cmd::list_platform_capabilities,
@ -265,22 +265,28 @@ fn deep_link(app: AppHandle, args: Vec<String>) {
}
async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
let mutex = app.state::<Mutex<AppData>>();
let appd = mutex.lock().await;
if !appd.cfg.enable_autoupdates {
log::info!("skipping autoupdate");
return Ok(());
}
if let Some(update) = app.updater()?.check().await? {
let mut downloaded = 0;
update
.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
log::debug!("downloaded {downloaded} from {content_length:?}");
},
|| {
log::info!("download finished");
},
let mut downloaded = 0;
update.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
log::debug!("downloaded {downloaded} from {content_length:?}");
},
|| {
log::info!("download finished");
},
)
.await?;
log::info!("update installed");
app.restart();
log::info!("update installed");
app.restart();
}
Ok(())