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)
This commit is contained in:
parent
2c7c143487
commit
b3dd6f7eea
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 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 {
|
pub fn config(app: &AppHandle) -> AppConfig {
|
||||||
host_state(app).config
|
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.
|
// 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).
|
// 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)) {
|
for script in crate::safe::layer(crate::safe::active(), layers, || hooks.safe_init_scripts(app, tab)) {
|
||||||
builder = builder.initialization_script(script);
|
builder = builder.initialization_script(script);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ mod tests {
|
||||||
let host = include_str!("host.rs");
|
let host = include_str!("host.rs");
|
||||||
// Document-start scripts: the safe set instead of the app's.
|
// 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).
|
// (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))"));
|
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.
|
// The default safe set is the tab bridge alone.
|
||||||
let default = &app[app.find("fn safe_init_scripts").expect("the hook")..];
|
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(())
|
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`]).
|
/// The store's commands ([`crate::commands::STORE`]).
|
||||||
pub(crate) fn handler() -> impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static {
|
pub(crate) fn handler() -> impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static {
|
||||||
tauri::generate_handler![
|
tauri::generate_handler![
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue