Tauri Updater attempt hopefully works first try

This commit is contained in:
2026-03-18 02:20:54 +08:00
parent aa2ccf6c3f
commit f8e88dfba6
10 changed files with 329 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
use crate::{
init::{lifecycle::validate_server_health, tracing::init_logging},
services::{
app_update::update_app,
auth::get_session_token,
cursor::init_cursor_tracking,
presence_modules::init_modules,
@@ -20,6 +21,7 @@ pub mod tracing;
pub async fn launch_app() {
init_logging();
open_splash_window();
update_app().await;
init_app_state();
init_system_tray();
init_cursor_tracking().await;

View File

@@ -133,6 +133,7 @@ pub fn run() {
.expect("Failed to export TypeScript bindings");
tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_positioner::init())
.plugin(tauri_plugin_dialog::init())

View File

@@ -0,0 +1,48 @@
use tauri_plugin_updater::UpdaterExt;
use tracing::{error, info};
use crate::get_app_handle;
pub async fn update_app() {
let app = get_app_handle();
if let Some(update) = match match app.updater() {
Ok(it) => it,
Err(err) => {
error!("failed to get updater: {err:?}");
return;
}
}
.check()
.await
{
Ok(it) => it,
Err(err) => {
error!("failed to check for update: {err:?}");
return;
}
} {
let mut downloaded = 0;
match update
.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
println!("downloaded {downloaded} from {content_length:?}");
},
|| {
info!("download finished");
},
)
.await
{
Ok(it) => it,
Err(err) => {
error!("failed to install update: {err:?}");
return;
}
};
info!("update installed");
app.restart();
}
}

View File

@@ -1,6 +1,7 @@
pub mod app_data;
pub mod app_events;
pub mod app_menu;
pub mod app_update;
pub mod auth;
pub mod client_config;
pub mod cursor;