feat: autoupdates

This commit is contained in:
2025-03-29 02:04:33 +00:00
parent 17411e8f0d
commit 536f289cfe
7 changed files with 174 additions and 11 deletions

View File

@ -18,6 +18,7 @@ use pkg_store::Payload;
use tauri::{AppHandle, Listener, Manager, RunEvent};
use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_cli::CliExt;
use tauri_plugin_updater::UpdaterExt;
use tokio::{fs, sync::Mutex, try_join};
static EXIT_REQUESTED: OnceLock<()> = OnceLock::new();
@ -35,6 +36,7 @@ pub async fn run(_args: Vec<String>) {
);
let tauri = tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
let _ = app
.get_webview_window("main")
@ -165,6 +167,11 @@ pub async fn run(_args: Vec<String>) {
apph.exit(1);
}
});
} else {
let apph = apph.clone();
tauri::async_runtime::spawn(async move {
update(apph).await.unwrap();
});
}
Ok(())
@ -252,4 +259,26 @@ fn deep_link(app: AppHandle, args: Vec<String>) {
}
}
}
}
async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
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");
},
)
.await?;
log::info!("update installed");
app.restart();
}
Ok(())
}