String packs: the site tab's delivery layer lives in app.rs, so a host without the net feature builds again (a generated app's cargo check failed on the net-gated store_commands module)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
38b877f03a
commit
198b1160f2
3 changed files with 10 additions and 9 deletions
|
|
@ -324,6 +324,14 @@ pub(crate) fn hooks(app: &AppHandle) -> Arc<dyn SiteHooks> {
|
|||
}
|
||||
|
||||
/// The app's config ([`run_app`] must be running).
|
||||
/// The document-start script that gives a new site tab the current string packs (none when the
|
||||
/// shell never applied any, or the app has no store). Part of the normal page layers, so safe mode
|
||||
/// leaves it out.
|
||||
fn strings_layer(app: &AppHandle) -> Option<String> {
|
||||
let stored = app.try_state::<crate::store::Store>()?.strings().delivery()?;
|
||||
Some(crate::store::delivery_script(config(app).site.hosts, &stored, false))
|
||||
}
|
||||
|
||||
pub fn config(app: &AppHandle) -> AppConfig {
|
||||
host_state(app).config
|
||||
}
|
||||
|
|
@ -1011,7 +1019,7 @@ fn tab_builder(app: &AppHandle, hooks: &Arc<dyn SiteHooks>, tab: &NewTab, url: U
|
|||
}
|
||||
// Safe mode: the safe set (the tab bridge) instead of the app's page layers.
|
||||
// The string packs' delivery goes first, before the page runtime reads it (not in safe mode).
|
||||
let layers = || crate::store_commands::strings_init_script(app).into_iter().chain(hooks.init_scripts(app, tab)).collect::<Vec<_>>();
|
||||
let layers = || strings_layer(app).into_iter().chain(hooks.init_scripts(app, tab)).collect::<Vec<_>>();
|
||||
for script in crate::safe::layer(crate::safe::active(), layers, || hooks.safe_init_scripts(app, tab)) {
|
||||
builder = builder.initialization_script(script);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ mod tests {
|
|||
let host = include_str!("host.rs");
|
||||
// Document-start scripts: the safe set instead of the app's.
|
||||
// (the normal layers are the string packs' delivery and then the app's own scripts).
|
||||
assert!(app.contains("let layers = || crate::store_commands::strings_init_script(app).into_iter().chain(hooks.init_scripts(app, tab)).collect::<Vec<_>>();"));
|
||||
assert!(app.contains("let layers = || strings_layer(app).into_iter().chain(hooks.init_scripts(app, tab)).collect::<Vec<_>>();"));
|
||||
assert!(app.contains("crate::safe::layer(crate::safe::active(), layers, || hooks.safe_init_scripts(app, tab))"));
|
||||
// The default safe set is the tab bridge alone.
|
||||
let default = &app[app.find("fn safe_init_scripts").expect("the hook")..];
|
||||
|
|
|
|||
|
|
@ -183,13 +183,6 @@ pub(crate) async fn strings_apply(webview: Webview, app: AppHandle, delivery: Op
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// The document-start script that gives a new site tab the current string packs (none when the
|
||||
/// shell never applied any). Part of the normal page layers, so safe mode leaves it out.
|
||||
pub(crate) fn strings_init_script(app: &AppHandle) -> Option<String> {
|
||||
let stored = app.try_state::<Store>()?.strings().delivery()?;
|
||||
Some(delivery_script(crate::app::config(app).site.hosts, &stored, false))
|
||||
}
|
||||
|
||||
/// The store's commands ([`crate::commands::STORE`]).
|
||||
pub(crate) fn handler() -> impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static {
|
||||
tauri::generate_handler![
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue