mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-16 19:30:27 +03:00
fix(core): run plugin init script in a separate context (#9571)
This commit is contained in:
parent
6d5a396ae9
commit
eff778b8f0
5
.changes/plugin-init-script-context.md
Normal file
5
.changes/plugin-init-script-context.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch:enhance
|
||||
---
|
||||
|
||||
Run each plugin initialization script on its own context so they do not interfere with each other or the Tauri init script.
|
@ -14,6 +14,4 @@
|
||||
__RAW_event_initialization_script__
|
||||
|
||||
__RAW_bundle_script__
|
||||
|
||||
__RAW_plugin_initialization_script__
|
||||
})()
|
||||
|
@ -133,7 +133,7 @@ impl<R: Runtime> WebviewManager<R> {
|
||||
let app_manager = manager.manager();
|
||||
|
||||
let is_init_global = app_manager.config.app.with_global_tauri;
|
||||
let plugin_init = app_manager
|
||||
let plugin_init_scripts = app_manager
|
||||
.plugins
|
||||
.lock()
|
||||
.expect("poisoned plugin store")
|
||||
@ -199,10 +199,13 @@ impl<R: Runtime> WebviewManager<R> {
|
||||
app_manager,
|
||||
&ipc_init.into_string(),
|
||||
&pattern_init.into_string(),
|
||||
&plugin_init,
|
||||
is_init_global,
|
||||
)?);
|
||||
|
||||
for plugin_init_script in plugin_init_scripts {
|
||||
webview_attributes = webview_attributes.initialization_script(&plugin_init_script);
|
||||
}
|
||||
|
||||
#[cfg(feature = "isolation")]
|
||||
if let crate::Pattern::Isolation { schema, .. } = &*app_manager.pattern {
|
||||
webview_attributes = webview_attributes.initialization_script(
|
||||
@ -345,7 +348,6 @@ impl<R: Runtime> WebviewManager<R> {
|
||||
app_manager: &AppManager<R>,
|
||||
ipc_script: &str,
|
||||
pattern_script: &str,
|
||||
plugin_initialization_script: &str,
|
||||
with_global_tauri: bool,
|
||||
) -> crate::Result<String> {
|
||||
#[derive(Template)]
|
||||
@ -362,8 +364,6 @@ impl<R: Runtime> WebviewManager<R> {
|
||||
#[raw]
|
||||
event_initialization_script: &'a str,
|
||||
#[raw]
|
||||
plugin_initialization_script: &'a str,
|
||||
#[raw]
|
||||
freeze_prototype: &'a str,
|
||||
}
|
||||
|
||||
@ -398,7 +398,6 @@ impl<R: Runtime> WebviewManager<R> {
|
||||
app_manager.listeners().function_name(),
|
||||
app_manager.listeners().listeners_object_name(),
|
||||
),
|
||||
plugin_initialization_script,
|
||||
freeze_prototype,
|
||||
}
|
||||
.render_default(&Default::default())
|
||||
|
@ -783,14 +783,13 @@ impl<R: Runtime> PluginStore<R> {
|
||||
}
|
||||
|
||||
/// Generates an initialization script from all plugins in the store.
|
||||
pub(crate) fn initialization_script(&self) -> String {
|
||||
pub(crate) fn initialization_script(&self) -> Vec<String> {
|
||||
self
|
||||
.store
|
||||
.iter()
|
||||
.filter_map(|p| p.initialization_script())
|
||||
.fold(String::new(), |acc, script| {
|
||||
format!("{acc}\n(function () {{ {script} }})();")
|
||||
})
|
||||
.map(|script| format!("(function () {{ {script} }})();"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Runs the created hook for all plugins in the store.
|
||||
|
Loading…
Reference in New Issue
Block a user