Host: native update commands (update_status, update_check, apply_update, app_ready) and the update loop are served for every app that sets AppConfig::with_updates; commands::UPDATE, testkit::assert_update_guards

This commit is contained in:
CRTkafa 2026-10-01 04:18:34 +07:00
parent bcd219d9b7
commit c94f3d508f
6 changed files with 103 additions and 5 deletions

View file

@ -89,6 +89,10 @@ pub struct AppConfig {
/// Google Fonts (install, remove, preview; the cache in app data): serves [`commands::GFONTS`]
/// and calls [`SiteHooks::fonts_changed`]. Needs the `net` feature.
pub fonts: bool,
/// Native updates and the hotfix channel: serves [`commands::UPDATE`] and runs the update loop.
/// Needs `updater` (the plugin) and the `net` feature.
#[cfg(feature = "net")]
pub updates: Option<&'static crate::updater::UpdaterConfig>,
}
impl AppConfig {
@ -113,9 +117,18 @@ impl AppConfig {
store: None,
media: false,
fonts: false,
#[cfg(feature = "net")]
updates: None,
}
}
/// Serves the update commands ([`commands::UPDATE`]) and runs the update loop.
#[cfg(feature = "net")]
pub const fn with_updates(mut self, updates: &'static crate::updater::UpdaterConfig) -> Self {
self.updates = Some(updates);
self
}
/// Serves the Google Fonts commands ([`commands::GFONTS`]).
pub const fn with_fonts(mut self) -> Self {
self.fonts = true;
@ -1134,6 +1147,17 @@ fn store_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + '
|_| false
}
/// The update commands ([`commands::UPDATE`]): with the `net` feature only.
#[cfg(feature = "net")]
fn update_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
crate::update_commands::handler()
}
#[cfg(not(feature = "net"))]
fn update_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
|_| false
}
/// The Google Fonts commands ([`commands::GFONTS`]): with the `net` feature (downloads) only.
#[cfg(feature = "net")]
fn fonts_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
@ -1183,6 +1207,7 @@ impl App {
let store_handler = store_handler();
let media_handler = media_handler();
let fonts_handler = fonts_handler();
let update_handler = update_handler();
let builder = tauri::Builder::<Wry>::default()
// Must be first: a second launch focuses the running window instead of fighting over
// the app's data and WebView profile (and hands over its link).
@ -1265,6 +1290,8 @@ impl App {
crate::media_commands::init(&handle);
#[cfg(feature = "net")]
crate::fonts_commands::init(&handle);
#[cfg(feature = "net")]
crate::update_commands::init(&handle);
// Safe mode for this run: the launch argument, or Shift held while starting (Windows).
crate::safe::set(crate::safe::at_launch(std::env::args(), host::shift_held()));
// Focus and layering diagnostics for this run: `--diag` or WAYBETTER_DIAG=1 (app log folder, diag.log).
@ -1285,6 +1312,8 @@ impl App {
media_handler(invoke)
} else if commands::GFONTS.contains(&invoke.message.command()) {
fonts_handler(invoke)
} else if commands::UPDATE.contains(&invoke.message.command()) {
update_handler(invoke)
} else if commands::is_host(invoke.message.command()) {
host_handler(invoke)
} else {