Skip to content

Commit a04ea2f

Browse files
authored
refactor: only inject API IIFE script when withGlobalTauri is true (#1071)
* refactor: only inject API IIFE script when withGlobalTauri is true * fmt * update tauri
1 parent 9dec960 commit a04ea2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+108
-73
lines changed
Lines changed: 32 additions & 0 deletions

examples/api/src-tauri/gen/schemas/mobile-schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@
23632363
"type": "object",
23642364
"required": [
23652365
"args",
2366-
"command",
2366+
"cmd",
23672367
"name",
23682368
"sidecar"
23692369
],
@@ -2376,7 +2376,7 @@
23762376
}
23772377
]
23782378
},
2379-
"command": {
2379+
"cmd": {
23802380
"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`.",
23812381
"type": "string"
23822382
},
@@ -2398,7 +2398,7 @@
23982398
"type": "object",
23992399
"required": [
24002400
"args",
2401-
"command",
2401+
"cmd",
24022402
"name",
24032403
"sidecar"
24042404
],
@@ -2411,7 +2411,7 @@
24112411
}
24122412
]
24132413
},
2414-
"command": {
2414+
"cmd": {
24152415
"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`.",
24162416
"type": "string"
24172417
},

plugins/authenticator/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ const COMMANDS: &[&str] = &[
1111
];
1212

1313
fn main() {
14-
tauri_plugin::Builder::new(COMMANDS).build();
14+
tauri_plugin::Builder::new(COMMANDS)
15+
.global_api_script_path("./api-iife.js")
16+
.build();
1517
}

plugins/authenticator/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ fn verify_signature(
7878

7979
pub fn init<R: Runtime>() -> TauriPlugin<R> {
8080
PluginBuilder::new("authenticator")
81-
.js_init_script(include_str!("api-iife.js").to_string())
8281
.invoke_handler(tauri::generate_handler![
8382
init_auth,
8483
register,
File renamed without changes.

plugins/autostart/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"];
66

77
fn main() {
8-
tauri_plugin::Builder::new(COMMANDS).build();
8+
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
10+
.build();
911
}

plugins/autostart/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ pub fn init<R: Runtime>(
107107
args: Option<Vec<&'static str>>,
108108
) -> TauriPlugin<R> {
109109
Builder::new("autostart")
110-
.js_init_script(include_str!("api-iife.js").to_string())
111110
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
112111
.setup(move |app, _api| {
113112
let mut builder = AutoLaunchBuilder::new();

plugins/barcode-scanner/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[
1313

1414
fn main() {
1515
if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
16+
.global_api_script_path("./api-iife.js")
1617
.android_path("android")
1718
.ios_path("ios")
1819
.try_build()
File renamed without changes.

plugins/biometric/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["authenticate", "status"];
66

77
fn main() {
88
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
910
.android_path("android")
1011
.ios_path("ios")
1112
.build();

plugins/biometric/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl<R: Runtime, T: Manager<R>> crate::BiometricExt<R> for T {
5959
/// Initializes the plugin.
6060
pub fn init<R: Runtime>() -> TauriPlugin<R> {
6161
Builder::new("biometric")
62-
.js_init_script(include_str!("api-iife.js").to_string())
6362
.setup(|app, api| {
6463
#[cfg(target_os = "android")]
6564
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BiometricPlugin")?;
File renamed without changes.

plugins/cli/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
const COMMANDS: &[&str] = &["cli_matches"];
66

77
fn main() {
8-
tauri_plugin::Builder::new(COMMANDS).build();
8+
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
10+
.build();
911
}

plugins/cli/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ fn cli_matches<R: Runtime>(_app: AppHandle<R>, cli: State<'_, Cli<R>>) -> Result
5151

5252
pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
5353
Builder::new("cli")
54-
.js_init_script(include_str!("api-iife.js").to_string())
5554
.invoke_handler(tauri::generate_handler![cli_matches])
5655
.setup(|app, api| {
5756
app.manage(Cli(api));

plugins/clipboard-manager/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[
1313

1414
fn main() {
1515
if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
16+
.global_api_script_path("./api-iife.js")
1617
.android_path("android")
1718
.ios_path("ios")
1819
.try_build()

plugins/clipboard-manager/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ impl<R: Runtime, T: Manager<R>> crate::ClipboardExt<R> for T {
4848
/// Initializes the plugin.
4949
pub fn init<R: Runtime>() -> TauriPlugin<R> {
5050
Builder::new("clipboard-manager")
51-
.js_init_script(include_str!("api-iife.js").to_string())
5251
.invoke_handler(tauri::generate_handler![
5352
commands::write_text,
5453
commands::read_text,
File renamed without changes.

plugins/deep-link/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn intent_filter(domain: &AssociatedDomain) -> String {
3333

3434
fn main() {
3535
if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
36+
.global_api_script_path("./api-iife.js")
3637
.android_path("android")
3738
.try_build()
3839
{

plugins/deep-link/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ impl<R: Runtime, T: Manager<R>> crate::DeepLinkExt<R> for T {
128128
/// Initializes the plugin.
129129
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
130130
Builder::new("deep-link")
131-
.js_init_script(include_str!("api-iife.js").to_string())
132131
.invoke_handler(tauri::generate_handler![commands::get_current])
133132
.setup(|app, api| {
134133
app.manage(init_deep_link(app, api)?);
File renamed without changes.

plugins/dialog/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["open", "save", "message", "ask", "confirm"];
66

77
fn main() {
88
if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
910
.android_path("android")
1011
.ios_path("ios")
1112
.try_build()

plugins/dialog/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
8484
// Dialogs are implemented natively on Android
8585
#[cfg(not(target_os = "android"))]
8686
{
87-
let mut init_script = include_str!("init-iife.js").to_string();
88-
init_script.push_str(include_str!("api-iife.js"));
89-
builder = builder.js_init_script(init_script);
90-
}
91-
#[cfg(target_os = "android")]
92-
{
93-
builder = builder.js_init_script(include_str!("api-iife.js").to_string());
87+
builder = builder.js_init_script(include_str!("init-iife.js").to_string());
9488
}
9589

9690
builder
File renamed without changes.

plugins/fs/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ permissions = [
162162
}
163163

164164
tauri_plugin::Builder::new(COMMANDS)
165+
.global_api_script_path("./api-iife.js")
165166
.global_scope_schema(schemars::schema_for!(scope::Entry))
166167
.build();
167168
}

plugins/fs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ impl ScopeObject for scope::Entry {
6969

7070
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
7171
PluginBuilder::<R, Option<config::Config>>::new("fs")
72-
.js_init_script(include_str!("api-iife.js").to_string())
7372
.invoke_handler(tauri::generate_handler![
7473
commands::create,
7574
commands::open,

plugins/global-shortcut/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ const COMMANDS: &[&str] = &[
1111
];
1212

1313
fn main() {
14-
tauri_plugin::Builder::new(COMMANDS).build();
14+
tauri_plugin::Builder::new(COMMANDS)
15+
.global_api_script_path("./api-iife.js")
16+
.build();
1517
}

plugins/global-shortcut/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ impl<R: Runtime> Builder<R> {
353353
let handler = self.handler;
354354
let shortcuts = self.shortcuts;
355355
PluginBuilder::new("global-shortcut")
356-
.js_init_script(include_str!("api-iife.js").to_string())
357356
.invoke_handler(tauri::generate_handler![
358357
register,
359358
register_all,
File renamed without changes.

plugins/http/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl From<ScopeEntry> for scope::Entry {
6868

6969
fn main() {
7070
tauri_plugin::Builder::new(COMMANDS)
71+
.global_api_script_path("./api-iife.js")
7172
.global_scope_schema(schemars::schema_for!(ScopeEntry))
7273
.build();
7374
}

plugins/http/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ impl<R: Runtime, T: Manager<R>> HttpExt<R> for T {
3535

3636
pub fn init<R: Runtime>() -> TauriPlugin<R> {
3737
Builder::<R>::new("http")
38-
.js_init_script(include_str!("api-iife.js").to_string())
3938
.invoke_handler(tauri::generate_handler![
4039
commands::fetch,
4140
commands::fetch_cancel,
File renamed without changes.

plugins/log/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
const COMMANDS: &[&str] = &["log"];
66

77
fn main() {
8-
tauri_plugin::Builder::new(COMMANDS).ios_path("ios").build();
8+
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
10+
.ios_path("ios")
11+
.build();
912
}

plugins/log/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ impl Builder {
396396

397397
pub fn build<R: Runtime>(mut self) -> TauriPlugin<R> {
398398
plugin::Builder::new("log")
399-
.js_init_script(include_str!("api-iife.js").to_string())
400399
.invoke_handler(tauri::generate_handler![log])
401400
.setup(move |app_handle, _api| {
402401
let app_name = &app_handle.package_info().name;
File renamed without changes.

plugins/nfc/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["is_available", "write", "scan"];
66

77
fn main() {
88
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
910
.android_path("android")
1011
.ios_path("ios")
1112
.build();

plugins/nfc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ impl<R: Runtime, T: Manager<R>> crate::NfcExt<R> for T {
7171
/// Initializes the plugin.
7272
pub fn init<R: Runtime>() -> TauriPlugin<R> {
7373
Builder::new("nfc")
74-
.js_init_script(include_str!("api-iife.js").to_string())
7574
.setup(|app, api| {
7675
#[cfg(target_os = "android")]
7776
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "NfcPlugin")?;

plugins/notification/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["notify", "request_permission", "is_permission_grant
66

77
fn main() {
88
if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
910
.android_path("android")
1011
.ios_path("ios")
1112
.try_build()

plugins/notification/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,13 @@ impl<R: Runtime, T: Manager<R>> crate::NotificationExt<R> for T {
224224

225225
/// Initializes the plugin.
226226
pub fn init<R: Runtime>() -> TauriPlugin<R> {
227-
let mut init_script = include_str!("init-iife.js").to_string();
228-
init_script.push_str(include_str!("api-iife.js"));
229227
Builder::new("notification")
230228
.invoke_handler(tauri::generate_handler![
231229
commands::notify,
232230
commands::request_permission,
233231
commands::is_permission_granted
234232
])
235-
.js_init_script(init_script)
233+
.js_init_script(include_str!("init-iife.js").to_string())
236234
.setup(|app, api| {
237235
#[cfg(mobile)]
238236
let notification = mobile::init(app, api)?;
File renamed without changes.

plugins/os/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ const COMMANDS: &[&str] = &[
1414
];
1515

1616
fn main() {
17-
tauri_plugin::Builder::new(COMMANDS).build();
17+
tauri_plugin::Builder::new(COMMANDS)
18+
.global_api_script_path("./api-iife.js")
19+
.build();
1820
}

plugins/os/src/init.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
88
eol: __TEMPLATE_eol__,
99
},
1010
});
11-
12-
__RAW_global_os_api__;

plugins/os/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,11 @@ pub fn hostname() -> String {
103103
#[derive(Template)]
104104
#[default_template("./init.js")]
105105
struct InitJavascript {
106-
#[raw]
107-
global_os_api: &'static str,
108106
eol: &'static str,
109107
}
110108

111109
pub fn init<R: Runtime>() -> TauriPlugin<R> {
112110
let init_js = InitJavascript {
113-
global_os_api: include_str!("api-iife.js"),
114111
#[cfg(windows)]
115112
eol: "\r\n",
116113
#[cfg(not(windows))]
File renamed without changes.

plugins/positioner/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
const COMMANDS: &[&str] = &["move_window"];
66

77
fn main() {
8-
tauri_plugin::Builder::new(COMMANDS).build();
8+
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
10+
.build();
911
}

plugins/positioner/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ async fn move_window<R: Runtime>(window: tauri::Window<R>, position: Position) -
5757

5858
/// The Tauri plugin that exposes [`WindowExt::move_window`] to the webview.
5959
pub fn init<R: Runtime>() -> TauriPlugin<R> {
60-
let plugin = plugin::Builder::new("positioner")
61-
.js_init_script(include_str!("api-iife.js").to_string())
62-
.invoke_handler(tauri::generate_handler![move_window]);
60+
let plugin =
61+
plugin::Builder::new("positioner").invoke_handler(tauri::generate_handler![move_window]);
6362

6463
#[cfg(feature = "tray-icon")]
6564
let plugin = plugin.setup(|app_handle, _api| {
File renamed without changes.

plugins/process/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
const COMMANDS: &[&str] = &["exit", "restart"];
66

77
fn main() {
8-
tauri_plugin::Builder::new(COMMANDS).build();
8+
tauri_plugin::Builder::new(COMMANDS)
9+
.global_api_script_path("./api-iife.js")
10+
.build();
911
}

plugins/process/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod commands;
2020

2121
pub fn init<R: Runtime>() -> TauriPlugin<R> {
2222
Builder::new("process")
23-
.js_init_script(include_str!("api-iife.js").to_string())
2423
.invoke_handler(tauri::generate_handler![commands::exit, commands::restart])
2524
.build()
2625
}
File renamed without changes.

plugins/shell/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const COMMANDS: &[&str] = &["execute", "stdin_write", "kill", "open"];
99

1010
fn main() {
1111
tauri_plugin::Builder::new(COMMANDS)
12+
.global_api_script_path("./api-iife.js")
1213
.global_scope_schema(schemars::schema_for!(scope_entry::Entry))
1314
.build();
1415
}

plugins/shell/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
7777
}
7878

7979
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
80-
let mut init_script = include_str!("init-iife.js").to_string();
81-
init_script.push_str(include_str!("api-iife.js"));
82-
8380
Builder::<R, Option<config::Config>>::new("shell")
84-
.js_init_script(init_script)
81+
.js_init_script(include_str!("init-iife.js").to_string())
8582
.invoke_handler(tauri::generate_handler![
8683
commands::execute,
8784
commands::stdin_write,
File renamed without changes.

0 commit comments

Comments
 (0)