From a04ea2f38294d5a3987578283badc8eec87a7752 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 19 Mar 2024 15:03:20 -0300 Subject: [PATCH] refactor: only inject API IIFE script when withGlobalTauri is true (#1071) * refactor: only inject API IIFE script when withGlobalTauri is true * fmt * update tauri --- .changes/global-api-script-refactor.md | 32 +++++++++++++++++++ .../src-tauri/gen/schemas/mobile-schema.json | 8 ++--- plugins/authenticator/{src => }/api-iife.js | 0 plugins/authenticator/build.rs | 4 ++- plugins/authenticator/src/lib.rs | 1 - plugins/autostart/{src => }/api-iife.js | 0 plugins/autostart/build.rs | 4 ++- plugins/autostart/src/lib.rs | 1 - plugins/barcode-scanner/{src => }/api-iife.js | 0 plugins/barcode-scanner/build.rs | 1 + plugins/biometric/{src => }/api-iife.js | 0 plugins/biometric/build.rs | 1 + plugins/biometric/src/lib.rs | 1 - plugins/cli/{src => }/api-iife.js | 0 plugins/cli/build.rs | 4 ++- plugins/cli/src/lib.rs | 1 - .../clipboard-manager/{src => }/api-iife.js | 0 plugins/clipboard-manager/build.rs | 1 + plugins/clipboard-manager/src/lib.rs | 1 - plugins/deep-link/{src => }/api-iife.js | 0 plugins/deep-link/build.rs | 1 + plugins/deep-link/src/lib.rs | 1 - plugins/dialog/{src => }/api-iife.js | 0 plugins/dialog/build.rs | 1 + plugins/dialog/src/lib.rs | 8 +---- plugins/fs/{src => }/api-iife.js | 0 plugins/fs/build.rs | 1 + plugins/fs/src/lib.rs | 1 - plugins/global-shortcut/{src => }/api-iife.js | 0 plugins/global-shortcut/build.rs | 4 ++- plugins/global-shortcut/src/lib.rs | 1 - plugins/http/{src => }/api-iife.js | 0 plugins/http/build.rs | 1 + plugins/http/src/lib.rs | 1 - plugins/log/{src => }/api-iife.js | 0 plugins/log/build.rs | 5 ++- plugins/log/src/lib.rs | 1 - plugins/nfc/{src => }/api-iife.js | 0 plugins/nfc/build.rs | 1 + plugins/nfc/src/lib.rs | 1 - plugins/notification/{src => }/api-iife.js | 0 plugins/notification/build.rs | 1 + plugins/notification/src/lib.rs | 4 +-- plugins/os/{src => }/api-iife.js | 0 plugins/os/build.rs | 4 ++- plugins/os/src/init.js | 2 -- plugins/os/src/lib.rs | 3 -- plugins/positioner/{src => }/api-iife.js | 0 plugins/positioner/build.rs | 4 ++- plugins/positioner/src/lib.rs | 5 ++- plugins/process/{src => }/api-iife.js | 0 plugins/process/build.rs | 4 ++- plugins/process/src/lib.rs | 1 - plugins/shell/{src => }/api-iife.js | 0 plugins/shell/build.rs | 1 + plugins/shell/src/lib.rs | 5 +-- plugins/sql/{src => }/api-iife.js | 0 plugins/sql/build.rs | 4 ++- plugins/sql/src/plugin.rs | 1 - plugins/store/{src => }/api-iife.js | 0 plugins/store/build.rs | 1 + plugins/store/src/lib.rs | 1 - plugins/stronghold/{src => }/api-iife.js | 0 plugins/stronghold/build.rs | 4 ++- plugins/stronghold/src/lib.rs | 24 +++++++------- plugins/updater/{src => }/api-iife.js | 0 plugins/updater/build.rs | 4 ++- plugins/updater/src/lib.rs | 1 - plugins/upload/{src => }/api-iife.js | 0 plugins/upload/build.rs | 4 ++- plugins/upload/src/lib.rs | 1 - plugins/websocket/{src => }/api-iife.js | 0 plugins/websocket/build.rs | 4 ++- plugins/websocket/src/lib.rs | 1 - plugins/window-state/{src => }/api-iife.js | 0 plugins/window-state/build.rs | 4 ++- plugins/window-state/src/lib.rs | 1 - shared/rollup.config.js | 2 +- shared/template/build.rs | 1 + shared/template/src/lib.rs | 1 - 80 files changed, 108 insertions(+), 73 deletions(-) create mode 100644 .changes/global-api-script-refactor.md rename plugins/authenticator/{src => }/api-iife.js (100%) rename plugins/autostart/{src => }/api-iife.js (100%) rename plugins/barcode-scanner/{src => }/api-iife.js (100%) rename plugins/biometric/{src => }/api-iife.js (100%) rename plugins/cli/{src => }/api-iife.js (100%) rename plugins/clipboard-manager/{src => }/api-iife.js (100%) rename plugins/deep-link/{src => }/api-iife.js (100%) rename plugins/dialog/{src => }/api-iife.js (100%) rename plugins/fs/{src => }/api-iife.js (100%) rename plugins/global-shortcut/{src => }/api-iife.js (100%) rename plugins/http/{src => }/api-iife.js (100%) rename plugins/log/{src => }/api-iife.js (100%) rename plugins/nfc/{src => }/api-iife.js (100%) rename plugins/notification/{src => }/api-iife.js (100%) rename plugins/os/{src => }/api-iife.js (100%) rename plugins/positioner/{src => }/api-iife.js (100%) rename plugins/process/{src => }/api-iife.js (100%) rename plugins/shell/{src => }/api-iife.js (100%) rename plugins/sql/{src => }/api-iife.js (100%) rename plugins/store/{src => }/api-iife.js (100%) rename plugins/stronghold/{src => }/api-iife.js (100%) rename plugins/updater/{src => }/api-iife.js (100%) rename plugins/upload/{src => }/api-iife.js (100%) rename plugins/websocket/{src => }/api-iife.js (100%) rename plugins/window-state/{src => }/api-iife.js (100%) diff --git a/.changes/global-api-script-refactor.md b/.changes/global-api-script-refactor.md new file mode 100644 index 000000000..40f2427e7 --- /dev/null +++ b/.changes/global-api-script-refactor.md @@ -0,0 +1,32 @@ +--- +"authenticator": patch +"autostart": patch +"barcode-scanner": patch +"biometric": patch +"cli": patch +"clipboard-manager": patch +"deep-link": patch +"dialog": patch +"fs": patch +"global-shortcut": patch +"http": patch +"localhost": patch +"log-plugin": patch +"nfc": patch +"notification": patch +"os": patch +"persisted-scope": patch +"positioner": patch +"process": patch +"shell": patch +"single-instance": patch +"sql": patch +"store": patch +"stronghold": patch +"updater": patch +"upload": patch +"websocket": patch +"window-state": patch +--- + +The global API script is now only added to the binary when the `withGlobalTauri` config is true. \ No newline at end of file diff --git a/examples/api/src-tauri/gen/schemas/mobile-schema.json b/examples/api/src-tauri/gen/schemas/mobile-schema.json index 29d8bf4ea..7a3179c34 100644 --- a/examples/api/src-tauri/gen/schemas/mobile-schema.json +++ b/examples/api/src-tauri/gen/schemas/mobile-schema.json @@ -2363,7 +2363,7 @@ "type": "object", "required": [ "args", - "command", + "cmd", "name", "sidecar" ], @@ -2376,7 +2376,7 @@ } ] }, - "command": { + "cmd": { "description": "The command name. It can start with a variable that resolves to a system base directory. The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`, `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`, `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`, `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.", "type": "string" }, @@ -2398,7 +2398,7 @@ "type": "object", "required": [ "args", - "command", + "cmd", "name", "sidecar" ], @@ -2411,7 +2411,7 @@ } ] }, - "command": { + "cmd": { "description": "The command name. It can start with a variable that resolves to a system base directory. The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`, `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`, `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$APP`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`, `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.", "type": "string" }, diff --git a/plugins/authenticator/src/api-iife.js b/plugins/authenticator/api-iife.js similarity index 100% rename from plugins/authenticator/src/api-iife.js rename to plugins/authenticator/api-iife.js diff --git a/plugins/authenticator/build.rs b/plugins/authenticator/build.rs index 993df57a9..8b4c860e3 100644 --- a/plugins/authenticator/build.rs +++ b/plugins/authenticator/build.rs @@ -11,5 +11,7 @@ const COMMANDS: &[&str] = &[ ]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/authenticator/src/lib.rs b/plugins/authenticator/src/lib.rs index b9979b7ff..0e3e9f057 100644 --- a/plugins/authenticator/src/lib.rs +++ b/plugins/authenticator/src/lib.rs @@ -78,7 +78,6 @@ fn verify_signature( pub fn init() -> TauriPlugin { PluginBuilder::new("authenticator") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ init_auth, register, diff --git a/plugins/autostart/src/api-iife.js b/plugins/autostart/api-iife.js similarity index 100% rename from plugins/autostart/src/api-iife.js rename to plugins/autostart/api-iife.js diff --git a/plugins/autostart/build.rs b/plugins/autostart/build.rs index 2b27eff07..1460469b5 100644 --- a/plugins/autostart/build.rs +++ b/plugins/autostart/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/autostart/src/lib.rs b/plugins/autostart/src/lib.rs index b4338208c..264185a95 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -107,7 +107,6 @@ pub fn init( args: Option>, ) -> TauriPlugin { Builder::new("autostart") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![enable, disable, is_enabled]) .setup(move |app, _api| { let mut builder = AutoLaunchBuilder::new(); diff --git a/plugins/barcode-scanner/src/api-iife.js b/plugins/barcode-scanner/api-iife.js similarity index 100% rename from plugins/barcode-scanner/src/api-iife.js rename to plugins/barcode-scanner/api-iife.js diff --git a/plugins/barcode-scanner/build.rs b/plugins/barcode-scanner/build.rs index 9239a4046..6326c23da 100644 --- a/plugins/barcode-scanner/build.rs +++ b/plugins/barcode-scanner/build.rs @@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[ fn main() { if let Err(error) = tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .try_build() diff --git a/plugins/biometric/src/api-iife.js b/plugins/biometric/api-iife.js similarity index 100% rename from plugins/biometric/src/api-iife.js rename to plugins/biometric/api-iife.js diff --git a/plugins/biometric/build.rs b/plugins/biometric/build.rs index 3df01ac9e..8099044f8 100644 --- a/plugins/biometric/build.rs +++ b/plugins/biometric/build.rs @@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["authenticate", "status"]; fn main() { tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .build(); diff --git a/plugins/biometric/src/lib.rs b/plugins/biometric/src/lib.rs index 8b0d472db..4f7ffd1ee 100644 --- a/plugins/biometric/src/lib.rs +++ b/plugins/biometric/src/lib.rs @@ -59,7 +59,6 @@ impl> crate::BiometricExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin { Builder::new("biometric") - .js_init_script(include_str!("api-iife.js").to_string()) .setup(|app, api| { #[cfg(target_os = "android")] let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BiometricPlugin")?; diff --git a/plugins/cli/src/api-iife.js b/plugins/cli/api-iife.js similarity index 100% rename from plugins/cli/src/api-iife.js rename to plugins/cli/api-iife.js diff --git a/plugins/cli/build.rs b/plugins/cli/build.rs index 15ff656f8..50d888497 100644 --- a/plugins/cli/build.rs +++ b/plugins/cli/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["cli_matches"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/cli/src/lib.rs b/plugins/cli/src/lib.rs index c666874c9..0e65409ef 100644 --- a/plugins/cli/src/lib.rs +++ b/plugins/cli/src/lib.rs @@ -51,7 +51,6 @@ fn cli_matches(_app: AppHandle, cli: State<'_, Cli>) -> Result pub fn init() -> TauriPlugin { Builder::new("cli") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![cli_matches]) .setup(|app, api| { app.manage(Cli(api)); diff --git a/plugins/clipboard-manager/src/api-iife.js b/plugins/clipboard-manager/api-iife.js similarity index 100% rename from plugins/clipboard-manager/src/api-iife.js rename to plugins/clipboard-manager/api-iife.js diff --git a/plugins/clipboard-manager/build.rs b/plugins/clipboard-manager/build.rs index 1921a072e..133aa421a 100644 --- a/plugins/clipboard-manager/build.rs +++ b/plugins/clipboard-manager/build.rs @@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[ fn main() { if let Err(error) = tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .try_build() diff --git a/plugins/clipboard-manager/src/lib.rs b/plugins/clipboard-manager/src/lib.rs index 10ee516ef..573da1b3e 100644 --- a/plugins/clipboard-manager/src/lib.rs +++ b/plugins/clipboard-manager/src/lib.rs @@ -48,7 +48,6 @@ impl> crate::ClipboardExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin { Builder::new("clipboard-manager") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ commands::write_text, commands::read_text, diff --git a/plugins/deep-link/src/api-iife.js b/plugins/deep-link/api-iife.js similarity index 100% rename from plugins/deep-link/src/api-iife.js rename to plugins/deep-link/api-iife.js diff --git a/plugins/deep-link/build.rs b/plugins/deep-link/build.rs index bffa4675a..4e66abe65 100644 --- a/plugins/deep-link/build.rs +++ b/plugins/deep-link/build.rs @@ -33,6 +33,7 @@ fn intent_filter(domain: &AssociatedDomain) -> String { fn main() { if let Err(error) = tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .try_build() { diff --git a/plugins/deep-link/src/lib.rs b/plugins/deep-link/src/lib.rs index 5fa4b9075..7dde3dd36 100644 --- a/plugins/deep-link/src/lib.rs +++ b/plugins/deep-link/src/lib.rs @@ -128,7 +128,6 @@ impl> crate::DeepLinkExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin> { Builder::new("deep-link") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![commands::get_current]) .setup(|app, api| { app.manage(init_deep_link(app, api)?); diff --git a/plugins/dialog/src/api-iife.js b/plugins/dialog/api-iife.js similarity index 100% rename from plugins/dialog/src/api-iife.js rename to plugins/dialog/api-iife.js diff --git a/plugins/dialog/build.rs b/plugins/dialog/build.rs index d692f66d7..89592ce1c 100644 --- a/plugins/dialog/build.rs +++ b/plugins/dialog/build.rs @@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["open", "save", "message", "ask", "confirm"]; fn main() { if let Err(error) = tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .try_build() diff --git a/plugins/dialog/src/lib.rs b/plugins/dialog/src/lib.rs index 0e9aa9dbd..7f58168cf 100644 --- a/plugins/dialog/src/lib.rs +++ b/plugins/dialog/src/lib.rs @@ -84,13 +84,7 @@ pub fn init() -> TauriPlugin { // Dialogs are implemented natively on Android #[cfg(not(target_os = "android"))] { - let mut init_script = include_str!("init-iife.js").to_string(); - init_script.push_str(include_str!("api-iife.js")); - builder = builder.js_init_script(init_script); - } - #[cfg(target_os = "android")] - { - builder = builder.js_init_script(include_str!("api-iife.js").to_string()); + builder = builder.js_init_script(include_str!("init-iife.js").to_string()); } builder diff --git a/plugins/fs/src/api-iife.js b/plugins/fs/api-iife.js similarity index 100% rename from plugins/fs/src/api-iife.js rename to plugins/fs/api-iife.js diff --git a/plugins/fs/build.rs b/plugins/fs/build.rs index dcfefd294..056c0e61d 100644 --- a/plugins/fs/build.rs +++ b/plugins/fs/build.rs @@ -162,6 +162,7 @@ permissions = [ } tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .global_scope_schema(schemars::schema_for!(scope::Entry)) .build(); } diff --git a/plugins/fs/src/lib.rs b/plugins/fs/src/lib.rs index 2c8843ffd..c4568808a 100644 --- a/plugins/fs/src/lib.rs +++ b/plugins/fs/src/lib.rs @@ -69,7 +69,6 @@ impl ScopeObject for scope::Entry { pub fn init() -> TauriPlugin> { PluginBuilder::>::new("fs") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ commands::create, commands::open, diff --git a/plugins/global-shortcut/src/api-iife.js b/plugins/global-shortcut/api-iife.js similarity index 100% rename from plugins/global-shortcut/src/api-iife.js rename to plugins/global-shortcut/api-iife.js diff --git a/plugins/global-shortcut/build.rs b/plugins/global-shortcut/build.rs index 8c5c71dfd..cc5ade7d2 100644 --- a/plugins/global-shortcut/build.rs +++ b/plugins/global-shortcut/build.rs @@ -11,5 +11,7 @@ const COMMANDS: &[&str] = &[ ]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/global-shortcut/src/lib.rs b/plugins/global-shortcut/src/lib.rs index b1f3b83ec..6680c78d4 100644 --- a/plugins/global-shortcut/src/lib.rs +++ b/plugins/global-shortcut/src/lib.rs @@ -353,7 +353,6 @@ impl Builder { let handler = self.handler; let shortcuts = self.shortcuts; PluginBuilder::new("global-shortcut") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ register, register_all, diff --git a/plugins/http/src/api-iife.js b/plugins/http/api-iife.js similarity index 100% rename from plugins/http/src/api-iife.js rename to plugins/http/api-iife.js diff --git a/plugins/http/build.rs b/plugins/http/build.rs index 7811cffc1..13a44c2cc 100644 --- a/plugins/http/build.rs +++ b/plugins/http/build.rs @@ -68,6 +68,7 @@ impl From for scope::Entry { fn main() { tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .global_scope_schema(schemars::schema_for!(ScopeEntry)) .build(); } diff --git a/plugins/http/src/lib.rs b/plugins/http/src/lib.rs index e4aa7ba1e..9e6e39082 100644 --- a/plugins/http/src/lib.rs +++ b/plugins/http/src/lib.rs @@ -35,7 +35,6 @@ impl> HttpExt for T { pub fn init() -> TauriPlugin { Builder::::new("http") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ commands::fetch, commands::fetch_cancel, diff --git a/plugins/log/src/api-iife.js b/plugins/log/api-iife.js similarity index 100% rename from plugins/log/src/api-iife.js rename to plugins/log/api-iife.js diff --git a/plugins/log/build.rs b/plugins/log/build.rs index f413529a1..5969c1e97 100644 --- a/plugins/log/build.rs +++ b/plugins/log/build.rs @@ -5,5 +5,8 @@ const COMMANDS: &[&str] = &["log"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).ios_path("ios").build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .ios_path("ios") + .build(); } diff --git a/plugins/log/src/lib.rs b/plugins/log/src/lib.rs index 5f564b2d9..2cf190065 100644 --- a/plugins/log/src/lib.rs +++ b/plugins/log/src/lib.rs @@ -396,7 +396,6 @@ impl Builder { pub fn build(mut self) -> TauriPlugin { plugin::Builder::new("log") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![log]) .setup(move |app_handle, _api| { let app_name = &app_handle.package_info().name; diff --git a/plugins/nfc/src/api-iife.js b/plugins/nfc/api-iife.js similarity index 100% rename from plugins/nfc/src/api-iife.js rename to plugins/nfc/api-iife.js diff --git a/plugins/nfc/build.rs b/plugins/nfc/build.rs index 1d2343712..725512d0c 100644 --- a/plugins/nfc/build.rs +++ b/plugins/nfc/build.rs @@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["is_available", "write", "scan"]; fn main() { tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .build(); diff --git a/plugins/nfc/src/lib.rs b/plugins/nfc/src/lib.rs index 28d5160d4..2e3dc9dd9 100644 --- a/plugins/nfc/src/lib.rs +++ b/plugins/nfc/src/lib.rs @@ -71,7 +71,6 @@ impl> crate::NfcExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin { Builder::new("nfc") - .js_init_script(include_str!("api-iife.js").to_string()) .setup(|app, api| { #[cfg(target_os = "android")] let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "NfcPlugin")?; diff --git a/plugins/notification/src/api-iife.js b/plugins/notification/api-iife.js similarity index 100% rename from plugins/notification/src/api-iife.js rename to plugins/notification/api-iife.js diff --git a/plugins/notification/build.rs b/plugins/notification/build.rs index 26d1f96e9..916d0f10a 100644 --- a/plugins/notification/build.rs +++ b/plugins/notification/build.rs @@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["notify", "request_permission", "is_permission_grant fn main() { if let Err(error) = tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .try_build() diff --git a/plugins/notification/src/lib.rs b/plugins/notification/src/lib.rs index 408a0f790..37d9d6da3 100644 --- a/plugins/notification/src/lib.rs +++ b/plugins/notification/src/lib.rs @@ -224,15 +224,13 @@ impl> crate::NotificationExt for T { /// Initializes the plugin. pub fn init() -> TauriPlugin { - let mut init_script = include_str!("init-iife.js").to_string(); - init_script.push_str(include_str!("api-iife.js")); Builder::new("notification") .invoke_handler(tauri::generate_handler![ commands::notify, commands::request_permission, commands::is_permission_granted ]) - .js_init_script(init_script) + .js_init_script(include_str!("init-iife.js").to_string()) .setup(|app, api| { #[cfg(mobile)] let notification = mobile::init(app, api)?; diff --git a/plugins/os/src/api-iife.js b/plugins/os/api-iife.js similarity index 100% rename from plugins/os/src/api-iife.js rename to plugins/os/api-iife.js diff --git a/plugins/os/build.rs b/plugins/os/build.rs index 91dca73ef..f108f9656 100644 --- a/plugins/os/build.rs +++ b/plugins/os/build.rs @@ -14,5 +14,7 @@ const COMMANDS: &[&str] = &[ ]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/os/src/init.js b/plugins/os/src/init.js index a26d35aaf..5d2f3d1cf 100644 --- a/plugins/os/src/init.js +++ b/plugins/os/src/init.js @@ -8,5 +8,3 @@ Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", { eol: __TEMPLATE_eol__, }, }); - -__RAW_global_os_api__; diff --git a/plugins/os/src/lib.rs b/plugins/os/src/lib.rs index fab629d59..3297f4fc3 100644 --- a/plugins/os/src/lib.rs +++ b/plugins/os/src/lib.rs @@ -103,14 +103,11 @@ pub fn hostname() -> String { #[derive(Template)] #[default_template("./init.js")] struct InitJavascript { - #[raw] - global_os_api: &'static str, eol: &'static str, } pub fn init() -> TauriPlugin { let init_js = InitJavascript { - global_os_api: include_str!("api-iife.js"), #[cfg(windows)] eol: "\r\n", #[cfg(not(windows))] diff --git a/plugins/positioner/src/api-iife.js b/plugins/positioner/api-iife.js similarity index 100% rename from plugins/positioner/src/api-iife.js rename to plugins/positioner/api-iife.js diff --git a/plugins/positioner/build.rs b/plugins/positioner/build.rs index 1fc5acfb8..52d333761 100644 --- a/plugins/positioner/build.rs +++ b/plugins/positioner/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["move_window"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/positioner/src/lib.rs b/plugins/positioner/src/lib.rs index 6c5b735e7..3db88bf26 100644 --- a/plugins/positioner/src/lib.rs +++ b/plugins/positioner/src/lib.rs @@ -57,9 +57,8 @@ async fn move_window(window: tauri::Window, position: Position) - /// The Tauri plugin that exposes [`WindowExt::move_window`] to the webview. pub fn init() -> TauriPlugin { - let plugin = plugin::Builder::new("positioner") - .js_init_script(include_str!("api-iife.js").to_string()) - .invoke_handler(tauri::generate_handler![move_window]); + let plugin = + plugin::Builder::new("positioner").invoke_handler(tauri::generate_handler![move_window]); #[cfg(feature = "tray-icon")] let plugin = plugin.setup(|app_handle, _api| { diff --git a/plugins/process/src/api-iife.js b/plugins/process/api-iife.js similarity index 100% rename from plugins/process/src/api-iife.js rename to plugins/process/api-iife.js diff --git a/plugins/process/build.rs b/plugins/process/build.rs index e9d6cfda1..e412b34eb 100644 --- a/plugins/process/build.rs +++ b/plugins/process/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["exit", "restart"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/process/src/lib.rs b/plugins/process/src/lib.rs index 2de829140..e0e948fc8 100644 --- a/plugins/process/src/lib.rs +++ b/plugins/process/src/lib.rs @@ -20,7 +20,6 @@ mod commands; pub fn init() -> TauriPlugin { Builder::new("process") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![commands::exit, commands::restart]) .build() } diff --git a/plugins/shell/src/api-iife.js b/plugins/shell/api-iife.js similarity index 100% rename from plugins/shell/src/api-iife.js rename to plugins/shell/api-iife.js diff --git a/plugins/shell/build.rs b/plugins/shell/build.rs index f3ff751de..6814fbbc7 100644 --- a/plugins/shell/build.rs +++ b/plugins/shell/build.rs @@ -9,6 +9,7 @@ const COMMANDS: &[&str] = &["execute", "stdin_write", "kill", "open"]; fn main() { tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .global_scope_schema(schemars::schema_for!(scope_entry::Entry)) .build(); } diff --git a/plugins/shell/src/lib.rs b/plugins/shell/src/lib.rs index b01f3e30c..012d9e96e 100644 --- a/plugins/shell/src/lib.rs +++ b/plugins/shell/src/lib.rs @@ -77,11 +77,8 @@ impl> ShellExt for T { } pub fn init() -> TauriPlugin> { - let mut init_script = include_str!("init-iife.js").to_string(); - init_script.push_str(include_str!("api-iife.js")); - Builder::>::new("shell") - .js_init_script(init_script) + .js_init_script(include_str!("init-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ commands::execute, commands::stdin_write, diff --git a/plugins/sql/src/api-iife.js b/plugins/sql/api-iife.js similarity index 100% rename from plugins/sql/src/api-iife.js rename to plugins/sql/api-iife.js diff --git a/plugins/sql/build.rs b/plugins/sql/build.rs index e74fdb42e..fbbca422c 100644 --- a/plugins/sql/build.rs +++ b/plugins/sql/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["load", "execute", "select", "close"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/sql/src/plugin.rs b/plugins/sql/src/plugin.rs index f2a952799..59fdf024d 100644 --- a/plugins/sql/src/plugin.rs +++ b/plugins/sql/src/plugin.rs @@ -288,7 +288,6 @@ impl Builder { pub fn build(mut self) -> TauriPlugin> { PluginBuilder::>::new("sql") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![load, execute, select, close]) .setup(|app, api| { let config = api.config().clone().unwrap_or_default(); diff --git a/plugins/store/src/api-iife.js b/plugins/store/api-iife.js similarity index 100% rename from plugins/store/src/api-iife.js rename to plugins/store/api-iife.js diff --git a/plugins/store/build.rs b/plugins/store/build.rs index 140b4a85b..d9bac3bfe 100644 --- a/plugins/store/build.rs +++ b/plugins/store/build.rs @@ -9,6 +9,7 @@ const COMMANDS: &[&str] = &[ fn main() { tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .build(); diff --git a/plugins/store/src/lib.rs b/plugins/store/src/lib.rs index 2b923fdee..f7c9eb0d3 100644 --- a/plugins/store/src/lib.rs +++ b/plugins/store/src/lib.rs @@ -315,7 +315,6 @@ impl Builder { /// ``` pub fn build(mut self) -> TauriPlugin { plugin::Builder::new("store") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ set, get, has, delete, clear, reset, keys, values, length, entries, load, save ]) diff --git a/plugins/stronghold/src/api-iife.js b/plugins/stronghold/api-iife.js similarity index 100% rename from plugins/stronghold/src/api-iife.js rename to plugins/stronghold/api-iife.js diff --git a/plugins/stronghold/build.rs b/plugins/stronghold/build.rs index 05404a1be..e9550e252 100644 --- a/plugins/stronghold/build.rs +++ b/plugins/stronghold/build.rs @@ -17,5 +17,7 @@ const COMMANDS: &[&str] = &[ ]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/stronghold/src/lib.rs b/plugins/stronghold/src/lib.rs index 9c09decdc..fe4b91fbc 100644 --- a/plugins/stronghold/src/lib.rs +++ b/plugins/stronghold/src/lib.rs @@ -456,19 +456,17 @@ impl Builder { pub fn build(self) -> TauriPlugin { let password_hash_function = self.password_hash_function; - let plugin_builder = PluginBuilder::new("stronghold") - .js_init_script(include_str!("api-iife.js").to_string()) - .setup(move |app, _api| { - app.manage(StrongholdCollection::default()); - app.manage(PasswordHashFunction(match password_hash_function { - #[cfg(feature = "kdf")] - PasswordHashFunctionKind::Argon2(path) => { - Box::new(move |p| kdf::KeyDerivation::argon2(p, &path)) - } - PasswordHashFunctionKind::Custom(f) => f, - })); - Ok(()) - }); + let plugin_builder = PluginBuilder::new("stronghold").setup(move |app, _api| { + app.manage(StrongholdCollection::default()); + app.manage(PasswordHashFunction(match password_hash_function { + #[cfg(feature = "kdf")] + PasswordHashFunctionKind::Argon2(path) => { + Box::new(move |p| kdf::KeyDerivation::argon2(p, &path)) + } + PasswordHashFunctionKind::Custom(f) => f, + })); + Ok(()) + }); Builder::invoke_stronghold_handlers_and_build(plugin_builder) } diff --git a/plugins/updater/src/api-iife.js b/plugins/updater/api-iife.js similarity index 100% rename from plugins/updater/src/api-iife.js rename to plugins/updater/api-iife.js diff --git a/plugins/updater/build.rs b/plugins/updater/build.rs index 6ba1a7d91..8e3c3859e 100644 --- a/plugins/updater/build.rs +++ b/plugins/updater/build.rs @@ -5,7 +5,9 @@ const COMMANDS: &[&str] = &["check", "download_and_install"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); let mobile = target_os == "ios" || target_os == "android"; diff --git a/plugins/updater/src/lib.rs b/plugins/updater/src/lib.rs index 37198150d..7c0c9a89b 100644 --- a/plugins/updater/src/lib.rs +++ b/plugins/updater/src/lib.rs @@ -166,7 +166,6 @@ impl Builder { let target = self.target; let installer_args = self.installer_args; PluginBuilder::::new("updater") - .js_init_script(include_str!("api-iife.js").to_string()) .setup(move |app, api| { let mut config = api.config().clone(); if let Some(pubkey) = pubkey { diff --git a/plugins/upload/src/api-iife.js b/plugins/upload/api-iife.js similarity index 100% rename from plugins/upload/src/api-iife.js rename to plugins/upload/api-iife.js diff --git a/plugins/upload/build.rs b/plugins/upload/build.rs index bfdf48b9c..96b5a90a5 100644 --- a/plugins/upload/build.rs +++ b/plugins/upload/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["download", "upload"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/upload/src/lib.rs b/plugins/upload/src/lib.rs index 12106d802..bf63d1e1b 100644 --- a/plugins/upload/src/lib.rs +++ b/plugins/upload/src/lib.rs @@ -130,7 +130,6 @@ fn file_to_body(channel: Channel, file: File) -> reqwest::Body { pub fn init() -> TauriPlugin { PluginBuilder::new("upload") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![download, upload]) .build() } diff --git a/plugins/websocket/src/api-iife.js b/plugins/websocket/api-iife.js similarity index 100% rename from plugins/websocket/src/api-iife.js rename to plugins/websocket/api-iife.js diff --git a/plugins/websocket/build.rs b/plugins/websocket/build.rs index b7bf848cb..deadb78f4 100644 --- a/plugins/websocket/build.rs +++ b/plugins/websocket/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["connect", "send"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/websocket/src/lib.rs b/plugins/websocket/src/lib.rs index f4a95b8e1..8697c676c 100644 --- a/plugins/websocket/src/lib.rs +++ b/plugins/websocket/src/lib.rs @@ -200,7 +200,6 @@ async fn send( pub fn init() -> TauriPlugin { PluginBuilder::new("websocket") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![connect, send]) .setup(|app, _api| { app.manage(ConnectionManager::default()); diff --git a/plugins/window-state/src/api-iife.js b/plugins/window-state/api-iife.js similarity index 100% rename from plugins/window-state/src/api-iife.js rename to plugins/window-state/api-iife.js diff --git a/plugins/window-state/build.rs b/plugins/window-state/build.rs index 9d9a160a3..5940f6802 100644 --- a/plugins/window-state/build.rs +++ b/plugins/window-state/build.rs @@ -5,5 +5,7 @@ const COMMANDS: &[&str] = &["save_window_state", "restore_window_state"]; fn main() { - tauri_plugin::Builder::new(COMMANDS).build(); + tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") + .build(); } diff --git a/plugins/window-state/src/lib.rs b/plugins/window-state/src/lib.rs index 16ad75e58..ed9f10cfe 100644 --- a/plugins/window-state/src/lib.rs +++ b/plugins/window-state/src/lib.rs @@ -319,7 +319,6 @@ impl Builder { pub fn build(self) -> TauriPlugin { let flags = self.state_flags; PluginBuilder::new("window-state") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![ cmd::save_window_state, cmd::restore_state diff --git a/shared/rollup.config.js b/shared/rollup.config.js index c44e7fd11..3b8741c16 100644 --- a/shared/rollup.config.js +++ b/shared/rollup.config.js @@ -73,7 +73,7 @@ export function createConfig(options = {}) { banner: "if ('__TAURI__' in window) {", // the last `}` closes the if in the banner footer: `Object.defineProperty(window.__TAURI__, '${pluginJsName}', { value: ${iifeVarName} }) }`, - file: "src/api-iife.js", + file: "api-iife.js", }, // and var is not guaranteed to assign to the global `window` object so we make sure to assign it plugins: [typescript(), terser(), nodeResolve()], diff --git a/shared/template/build.rs b/shared/template/build.rs index 121f3b740..415deddc4 100644 --- a/shared/template/build.rs +++ b/shared/template/build.rs @@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["execute"]; fn main() { if let Err(error) = tauri_plugin::Builder::new(COMMANDS) + .global_api_script_path("./api-iife.js") .android_path("android") .ios_path("ios") .run() diff --git a/shared/template/src/lib.rs b/shared/template/src/lib.rs index 3e0f76181..77861b7f0 100644 --- a/shared/template/src/lib.rs +++ b/shared/template/src/lib.rs @@ -39,7 +39,6 @@ impl> crate::{{ plugin_name_pascal_case }}Ext for T /// Initializes the plugin. pub fn init() -> TauriPlugin { Builder::new("{{ plugin_name }}") - .js_init_script(include_str!("api-iife.js").to_string()) .invoke_handler(tauri::generate_handler![commands::execute]) .setup(|app, api| { #[cfg(mobile)]