Host: developer mode (dev_* commands and the watcher) is served for every app that sets AppConfig::with_dev; SiteHooks::dev_theme_apply and dev_theme_end carry the app's theme file; commands::DEV, testkit::assert_dev_guards

This commit is contained in:
CRTkafa 2026-10-01 04:32:54 +07:00
parent 01424373d1
commit edc3655b2a
5 changed files with 396 additions and 5 deletions

View file

@ -92,6 +92,10 @@ pub struct AppConfig {
/// Encrypted folder sync of the settings backup: serves [`commands::SYNC`] and needs
/// [`SiteHooks::backup_sections`]. ([`commands::WORKSPACES`] is served for every app.)
pub sync: bool,
/// Developer mode (live reload of plugins, custom CSS and a theme file): serves
/// [`commands::DEV`] and runs the watcher while it is on; the theme file is the app's
/// ([`SiteHooks::dev_theme_apply`]).
pub dev: 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")]
@ -121,6 +125,7 @@ impl AppConfig {
media: false,
fonts: false,
sync: false,
dev: false,
#[cfg(feature = "net")]
updates: None,
}
@ -133,6 +138,12 @@ impl AppConfig {
self
}
/// Serves the developer-mode commands ([`commands::DEV`]).
pub const fn with_dev(mut self) -> Self {
self.dev = true;
self
}
/// Serves the sync commands ([`commands::SYNC`]).
pub const fn with_sync(mut self) -> Self {
self.sync = true;
@ -251,6 +262,16 @@ pub trait SiteHooks: Send + Sync + 'static {
&[]
}
/// Developer mode: show the theme file the owner picked (read `path`, make it the theme preview
/// in every site tab). An error is shown with its file and line. By default themes are not
/// supported and this does nothing.
fn dev_theme_apply(&self, _app: &AppHandle, _path: &std::path::Path) -> Result<(), crate::devmode::DevError> {
Ok(())
}
/// Developer mode ended (or the theme file was cleared): end the preview [`Self::dev_theme_apply`] made.
fn dev_theme_end(&self, _app: &AppHandle) {}
/// `tab` was laid out for `item` (existing or new), before it is placed.
fn tab_placed(&self, _app: &AppHandle, _tab: &Webview, _item: &TabLayout) {}
@ -1169,6 +1190,11 @@ fn store_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + '
|_| false
}
/// The developer-mode commands ([`commands::DEV`]).
fn dev_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
crate::dev_commands::handler()
}
/// The workspaces and sync commands ([`commands::WORKSPACES`], [`commands::SYNC`]).
fn sync_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
crate::sync_commands::handler()
@ -1236,6 +1262,7 @@ impl App {
let fonts_handler = fonts_handler();
let update_handler = update_handler();
let sync_handler = sync_handler();
let dev_handler = dev_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).
@ -1317,6 +1344,7 @@ impl App {
crate::store_commands::init(&handle, &config);
crate::media_commands::init(&handle);
crate::sync_commands::init(&handle);
crate::dev_commands::init(&handle);
#[cfg(feature = "net")]
crate::fonts_commands::init(&handle);
#[cfg(feature = "net")]
@ -1345,6 +1373,8 @@ impl App {
update_handler(invoke)
} else if commands::WORKSPACES.contains(&invoke.message.command()) || commands::SYNC.contains(&invoke.message.command()) {
sync_handler(invoke)
} else if commands::DEV.contains(&invoke.message.command()) {
dev_handler(invoke)
} else if commands::is_host(invoke.message.command()) {
host_handler(invoke)
} else {