From 35c30b8213b88d4b1dcb4ac55184abde0c51cad0 Mon Sep 17 00:00:00 2001 From: Richard Toth Date: Sun, 30 Aug 2026 18:48:42 +0200 Subject: [PATCH] feat(tauri): setup auto-update on startup --- package-lock.json | 10 +++++ package.json | 1 + src-tauri/Cargo.lock | 11 ++++++ src-tauri/Cargo.toml | 1 + src-tauri/capabilities/default.json | 5 ++- src-tauri/src/lib.rs | 1 + src/app/app.component.ts | 60 +++++++++++++++++++++++++++-- src/app/i18n/translations.ts | 4 ++ 8 files changed, 87 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 215ab07..9291f1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,7 @@ "@capacitor/keyboard": "8.0.3", "@capacitor/status-bar": "8.0.2", "@ionic/angular": "^8.0.0", + "@tauri-apps/plugin-process": "^2.3.1", "@tauri-apps/plugin-updater": "^2.10.1", "dexie": "^4.4.2", "ionicons": "^7.0.0", @@ -6832,6 +6833,15 @@ "node": ">= 10" } }, + "node_modules/@tauri-apps/plugin-process": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-process/-/plugin-process-2.3.1.tgz", + "integrity": "sha512-nCa4fGVaDL/B9ai03VyPOjfAHRHSBz5v6F/ObsB73r/dA3MHHhZtldaDMIc0V/pnUw9ehzr2iEG+XkSEyC0JJA==", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.8.0" + } + }, "node_modules/@tauri-apps/plugin-updater": { "version": "2.10.1", "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-updater/-/plugin-updater-2.10.1.tgz", diff --git a/package.json b/package.json index 394bfe1..3e43c2b 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@capacitor/keyboard": "8.0.3", "@capacitor/status-bar": "8.0.2", "@ionic/angular": "^8.0.0", + "@tauri-apps/plugin-process": "^2.3.1", "@tauri-apps/plugin-updater": "^2.10.1", "dexie": "^4.4.2", "ionicons": "^7.0.0", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6ca03dc..05e5ab3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -85,6 +85,7 @@ dependencies = [ "tauri", "tauri-build", "tauri-plugin-log", + "tauri-plugin-process", "tauri-plugin-updater", ] @@ -3715,6 +3716,16 @@ dependencies = [ "time", ] +[[package]] +name = "tauri-plugin-process" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d55511a7bf6cd70c8767b02c97bf8134fa434daf3926cfc1be0a0f94132d165a" +dependencies = [ + "tauri", + "tauri-plugin", +] + [[package]] name = "tauri-plugin-updater" version = "2.10.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ae8f23f..00bba35 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -23,6 +23,7 @@ serde = { version = "1.0", features = ["derive"] } log = "0.4" tauri = { version = "2.11.2", features = [] } tauri-plugin-log = "2" +tauri-plugin-process = "2" [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-updater = "2" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index c135d7f..40da078 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -6,6 +6,7 @@ "main" ], "permissions": [ - "core:default" + "core:default", + "process:default" ] -} +} \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bb8e129..f2d3d5a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,6 +1,7 @@ #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_updater::Builder::new().build()) .setup(|app| { if cfg!(debug_assertions) { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1da531b..f2960b2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,11 +1,63 @@ -import { Component } from '@angular/core'; -import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone'; +import { Component, inject } from '@angular/core'; +import { + AlertController, + IonApp, + IonRouterOutlet +} from '@ionic/angular/standalone'; +import { check } from '@tauri-apps/plugin-updater'; +import { isTauri } from '@tauri-apps/api/core'; +import { relaunch } from '@tauri-apps/plugin-process'; +import { TranslationService } from './i18n/translation.service'; @Component({ selector: 'app-root', templateUrl: 'app.component.html', - imports: [IonApp, IonRouterOutlet], + imports: [IonApp, IonRouterOutlet] }) export class AppComponent { - constructor() {} + readonly alertController: AlertController = inject(AlertController); + readonly translationService: TranslationService = inject(TranslationService); + + constructor() { + this.checkForUpdates(); + } + + private async checkForUpdates(): Promise { + if (!isTauri()) { + return; + } + + try { + const update = await check(); + + if (update) { + const alert = await this.alertController.create({ + header: this.translationService.translate('updateAvailable'), + message: this.translationService.translate('newVersion', { + version: update.version + }), + buttons: [ + { + text: 'OK', + handler: async () => { + try { + await update.downloadAndInstall(); + await relaunch(); + } catch (error) { + console.error('Failed to install update:', error); + } + } + } + ] + }); + + await alert.present(); + return; + } + + console.log('No updates available.'); + } catch (error) { + console.error('Failed to check for updates:', error); + } + } } diff --git a/src/app/i18n/translations.ts b/src/app/i18n/translations.ts index 9075873..665ce3f 100644 --- a/src/app/i18n/translations.ts +++ b/src/app/i18n/translations.ts @@ -41,6 +41,8 @@ export const translations = { sendUmpireMessage: '{umpire}', sendUmpiresMessage: '{umpire} - {serviceJudge}', version: 'Version', + updateAvailable: 'Update available', + newVersion: 'A new version {version} is available. The application will restart to install the update.' }, hu: { @@ -80,6 +82,8 @@ export const translations = { sendUmpireMessage: '{umpire}', sendUmpiresMessage: '{umpire} - {serviceJudge}', version: 'Verzió', + updateAvailable: 'Új verzió elérhető', + newVersion: 'Új elérhető verzió: {version} is available. A frissítések telepítése után az alkalmazás újraindul.', } } as const;