Add auto updater to the launcher

This commit is contained in:
Lncvrt committed 2026-04-02 17:11:25 -07:00
1 parent dfd99ab12e
commit 04d1f2822b
19 files changed
+170 -39

No files matched your search

+39
View File
@@ -19,6 +19,7 @@ use tauri::window::{ProgressBarState, ProgressBarStatus};
use tauri::{AppHandle, Emitter, Manager};
use tauri_plugin_os::platform;
use tauri_plugin_prevent_default::Flags;
use tauri_plugin_updater::UpdaterExt;
use tokio::io::AsyncReadExt;
use tokio::{io::AsyncWriteExt, time::timeout};
use zip::ZipArchive;
@@ -520,6 +521,7 @@ async fn cancel_download(name: String) {
pub fn run() {
#[allow(unused_variables)]
tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_http::init())
.plugin(
@@ -568,8 +570,45 @@ pub fn run() {
}
}
}
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
update(handle).await.unwrap();
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
let window = app.get_webview_window("main").unwrap();
if let Some(update) = app.updater()?.check().await? {
let mut new_url = window.url().unwrap();
new_url.set_path("/update/updating");
window.navigate(new_url).unwrap();
let mut downloaded = 0;
update
.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
println!("downloaded {downloaded} from {content_length:?}");
},
|| {
println!("download finished");
},
)
.await?;
println!("update installed");
app.restart();
}
let mut new_url = window.url().unwrap();
new_url.set_path("/main");
window.navigate(new_url).unwrap();
Ok(())
}