host: keyword alert settings are the host's (AppConfig::with_alerts, commands::ALERTS)
alerts_commands keeps the owner's AlertSettings (saved in app data, validated by alerts), serves the shell-only alerts_get / alerts_set (testkit::assert_alerts_guards) and builds the script that hands the page runtime the keywords to watch. The app names the file and the runtime member (AlertsConfig); store()/script() are the app's own writers (backup import). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d47a77d95d
commit
1539cb68e1
5 changed files with 128 additions and 22 deletions
|
|
@ -99,6 +99,9 @@ pub struct AppConfig {
|
|||
/// Site themes (the owner's theme, account and pane themes, the live preview): serves
|
||||
/// [`commands::THEME`]; the app names its built-in themes and the files they are saved in.
|
||||
pub themes: Option<&'static crate::theme_commands::ThemeConfig>,
|
||||
/// Keyword alert settings (saved in app data, handed to the page runtime): serves
|
||||
/// [`commands::ALERTS`]; the match and the notification are the app's.
|
||||
pub alerts: Option<&'static crate::alerts_commands::AlertsConfig>,
|
||||
/// 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")]
|
||||
|
|
@ -130,6 +133,7 @@ impl AppConfig {
|
|||
sync: false,
|
||||
dev: false,
|
||||
themes: None,
|
||||
alerts: None,
|
||||
#[cfg(feature = "net")]
|
||||
updates: None,
|
||||
}
|
||||
|
|
@ -154,6 +158,12 @@ impl AppConfig {
|
|||
self
|
||||
}
|
||||
|
||||
/// Serves the alert settings commands ([`commands::ALERTS`]).
|
||||
pub const fn with_alerts(mut self, alerts: &'static crate::alerts_commands::AlertsConfig) -> Self {
|
||||
self.alerts = Some(alerts);
|
||||
self
|
||||
}
|
||||
|
||||
/// Serves the sync commands ([`commands::SYNC`]).
|
||||
pub const fn with_sync(mut self) -> Self {
|
||||
self.sync = true;
|
||||
|
|
@ -699,7 +709,7 @@ async fn tab_zoom(webview: Webview, app: AppHandle, id: String, factor: Option<f
|
|||
|
||||
/// Find in page for tab `id` (the shell's find bar): `start` with a query, `next`, `previous`, `stop`.
|
||||
/// The engine's own find where this build can drive it (counts arrive as `tab-find` events), else the
|
||||
/// evaluated Custom Highlight script. The query is one typed line (validated) and is kept nowhere.
|
||||
/// evaluated `window.find`. The query is one typed line (validated) and is kept nowhere.
|
||||
#[tauri::command]
|
||||
async fn tab_find(webview: Webview, app: AppHandle, id: String, action: String, query: Option<String>) -> Result<(), String> {
|
||||
shell_only(&webview)?;
|
||||
|
|
@ -1256,6 +1266,11 @@ fn dev_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'st
|
|||
crate::dev_commands::handler()
|
||||
}
|
||||
|
||||
/// The alert settings commands ([`commands::ALERTS`]).
|
||||
fn alerts_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
|
||||
crate::alerts_commands::handler()
|
||||
}
|
||||
|
||||
/// The theme commands ([`commands::THEME`]).
|
||||
fn theme_handler() -> impl Fn(tauri::ipc::Invoke<Wry>) -> bool + Send + Sync + 'static {
|
||||
crate::theme_commands::handler()
|
||||
|
|
@ -1330,6 +1345,7 @@ impl App {
|
|||
let sync_handler = sync_handler();
|
||||
let dev_handler = dev_handler();
|
||||
let theme_handler = theme_handler();
|
||||
let alerts_handler = alerts_handler();
|
||||
let backup_handler = backup_handler();
|
||||
let builder = tauri::Builder::<Wry>::default()
|
||||
// Must be first: a second launch focuses the running window instead of fighting over
|
||||
|
|
@ -1414,6 +1430,7 @@ impl App {
|
|||
crate::sync_commands::init(&handle);
|
||||
crate::dev_commands::init(&handle);
|
||||
crate::theme_commands::init(&handle);
|
||||
crate::alerts_commands::init(&handle);
|
||||
#[cfg(feature = "net")]
|
||||
crate::fonts_commands::init(&handle);
|
||||
#[cfg(feature = "net")]
|
||||
|
|
@ -1448,28 +1465,16 @@ impl App {
|
|||
backup_handler(invoke)
|
||||
} else if commands::THEME.contains(&invoke.message.command()) {
|
||||
theme_handler(invoke)
|
||||
} else if commands::ALERTS.contains(&invoke.message.command()) {
|
||||
alerts_handler(invoke)
|
||||
} else if commands::is_host(invoke.message.command()) {
|
||||
host_handler(invoke)
|
||||
} else {
|
||||
handler(invoke)
|
||||
}
|
||||
})
|
||||
.build(context)
|
||||
.unwrap_or_else(|error| panic!("Failed to launch {}: {error}", config.title))
|
||||
.run(|_, event| log_run_event(&event));
|
||||
}
|
||||
}
|
||||
|
||||
/// Why the app is going away, for `--diag` ([`crate::diag`]): an exit request with its code (None is a
|
||||
/// polite quit from outside: Cmd+Q, the Dock, or another app such as an auto-quitter closing the last
|
||||
/// window), window close/destroy events and the final exit. Nothing is written without diagnostics.
|
||||
fn log_run_event(event: &tauri::RunEvent) {
|
||||
match event {
|
||||
tauri::RunEvent::ExitRequested { code, .. } => crate::diag::log("host", &format!("exit requested code={code:?}")),
|
||||
tauri::RunEvent::Exit => crate::diag::log("host", "exit"),
|
||||
tauri::RunEvent::WindowEvent { label, event: tauri::WindowEvent::CloseRequested { .. }, .. } => crate::diag::log("host", &format!("window {label} close requested")),
|
||||
tauri::RunEvent::WindowEvent { label, event: tauri::WindowEvent::Destroyed, .. } => crate::diag::log("host", &format!("window {label} destroyed")),
|
||||
_ => {}
|
||||
.run(context)
|
||||
.unwrap_or_else(|error| panic!("Failed to launch {}: {error}", config.title));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue