Skip to content

Commit c232fcb

Browse files
committed
fix(tauri): update from the Windows Help menu
Route Help > Get Updates through the native WinGet updater on Windows now that PR NeuralNomadsAI#597 is merged. Run the command asynchronously so the Tauri menu event loop remains responsive. Open the latest GitHub Releases page when WinGet cannot start, exits unsuccessfully, or cannot be monitored. macOS and Linux keep the existing direct releases-page behavior. Add a focused regression test for the failed-update fallback. Validated with cargo check and all 65 Tauri tests.
1 parent 0259932 commit c232fcb

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

  • packages/tauri-app/src-tauri/src

packages/tauri-app/src-tauri/src/main.rs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use keepawake::KeepAwake;
1919
use serde::Deserialize;
2020
use serde_json::json;
2121
use std::collections::{HashMap, HashSet};
22+
#[cfg(any(windows, test))]
23+
use std::future::Future;
2224
use std::sync::Mutex;
2325
use std::time::{SystemTime, UNIX_EPOCH};
2426
use tauri::menu::{AboutMetadata, MenuBuilder, MenuItem, PredefinedMenuItem, SubmenuBuilder};
@@ -726,12 +728,17 @@ fn main() {
726728
}
727729

728730
"get_updates" => {
729-
if let Err(err) = app_handle
730-
.opener()
731-
.open_url(RELEASES_URL, None::<&str>)
731+
#[cfg(windows)]
732732
{
733-
eprintln!("[tauri] failed to open the CodeNomad releases page: {err}");
733+
let app_handle = app_handle.clone();
734+
tauri::async_runtime::spawn(run_update_with_fallback(
735+
windows_update::install_stable_update(),
736+
move || open_releases_page(&app_handle),
737+
));
734738
}
739+
740+
#[cfg(not(windows))]
741+
open_releases_page(app_handle);
735742
}
736743
// App menu (macOS)
737744
"hide" => {
@@ -1012,6 +1019,23 @@ fn build_menu(app: &AppHandle) -> tauri::Result<()> {
10121019
Ok(())
10131020
}
10141021

1022+
#[cfg(any(windows, test))]
1023+
async fn run_update_with_fallback(
1024+
update: impl Future<Output = Result<(), String>>,
1025+
fallback: impl FnOnce(),
1026+
) {
1027+
if let Err(err) = update.await {
1028+
eprintln!("[tauri] WinGet update failed, opening the releases page: {err}");
1029+
fallback();
1030+
}
1031+
}
1032+
1033+
fn open_releases_page(app_handle: &AppHandle) {
1034+
if let Err(err) = app_handle.opener().open_url(RELEASES_URL, None::<&str>) {
1035+
eprintln!("[tauri] failed to open the CodeNomad releases page: {err}");
1036+
}
1037+
}
1038+
10151039
fn build_about_metadata(version: &str, include_update_link: bool) -> AboutMetadata<'static> {
10161040
AboutMetadata {
10171041
name: Some("CodeNomad".to_string()),
@@ -1026,8 +1050,21 @@ fn build_about_metadata(version: &str, include_update_link: bool) -> AboutMetada
10261050
}
10271051

10281052
#[cfg(test)]
1029-
mod about_tests {
1030-
use super::{build_about_metadata, RELEASES_URL};
1053+
mod menu_tests {
1054+
use super::{build_about_metadata, run_update_with_fallback, RELEASES_URL};
1055+
use std::sync::atomic::{AtomicBool, Ordering};
1056+
1057+
#[test]
1058+
fn failed_update_uses_release_fallback() {
1059+
let fallback_called = AtomicBool::new(false);
1060+
1061+
tauri::async_runtime::block_on(run_update_with_fallback(
1062+
async { Err("update failed".to_string()) },
1063+
|| fallback_called.store(true, Ordering::Relaxed),
1064+
));
1065+
1066+
assert!(fallback_called.load(Ordering::Relaxed));
1067+
}
10311068

10321069
#[test]
10331070
fn about_metadata_includes_version_and_supported_update_link() {

0 commit comments

Comments
 (0)