|
@@ -22,6 +22,7 @@ use tauri_utils::html::{
|
|
|
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node, NodeRef,
|
|
|
};
|
|
|
use tauri_utils::platform::Target;
|
|
|
+use tauri_utils::plugin::GLOBAL_API_SCRIPT_FILE_LIST_PATH;
|
|
|
use tauri_utils::tokens::{map_lit, str_lit};
|
|
|
|
|
|
use crate::embedded_assets::{AssetOptions, CspHashes, EmbeddedAssets, EmbeddedAssetsError};
|
|
@@ -456,6 +457,36 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
|
|
let resolved = Resolved::resolve(&acl, capabilities, target).expect("failed to resolve ACL");
|
|
|
let runtime_authority = quote!(#root::ipc::RuntimeAuthority::new(#acl_tokens, #resolved));
|
|
|
|
|
|
+ let plugin_global_api_script_file_list_path = out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH);
|
|
|
+ let plugin_global_api_script =
|
|
|
+ if config.app.with_global_tauri && plugin_global_api_script_file_list_path.exists() {
|
|
|
+ let file_list_str = std::fs::read_to_string(plugin_global_api_script_file_list_path)
|
|
|
+ .expect("failed to read plugin global API script paths");
|
|
|
+ let file_list = serde_json::from_str::<Vec<PathBuf>>(&file_list_str)
|
|
|
+ .expect("failed to parse plugin global API script paths");
|
|
|
+
|
|
|
+ let mut plugins = Vec::new();
|
|
|
+ for path in file_list {
|
|
|
+ plugins.push(std::fs::read_to_string(&path).unwrap_or_else(|e| {
|
|
|
+ panic!(
|
|
|
+ "failed to read plugin global API script {}: {e}",
|
|
|
+ path.display()
|
|
|
+ )
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ Some(plugins)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ };
|
|
|
+
|
|
|
+ let plugin_global_api_script = if let Some(scripts) = plugin_global_api_script {
|
|
|
+ let scripts = scripts.into_iter().map(|s| quote!(#s));
|
|
|
+ quote!(::std::option::Option::Some(&[#(#scripts),*]))
|
|
|
+ } else {
|
|
|
+ quote!(::std::option::Option::None)
|
|
|
+ };
|
|
|
+
|
|
|
Ok(quote!({
|
|
|
#[allow(unused_mut, clippy::let_and_return)]
|
|
|
let mut context = #root::Context::new(
|
|
@@ -466,7 +497,8 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
|
|
#package_info,
|
|
|
#info_plist,
|
|
|
#pattern,
|
|
|
- #runtime_authority
|
|
|
+ #runtime_authority,
|
|
|
+ #plugin_global_api_script
|
|
|
);
|
|
|
#with_tray_icon_code
|
|
|
context
|