Skip to content

Commit

Permalink
refactor: only inject API IIFE script when withGlobalTauri is true (t…
Browse files Browse the repository at this point in the history
…auri-apps#1071)

* refactor: only inject API IIFE script when withGlobalTauri is true

* fmt

* update tauri
  • Loading branch information
lucasfernog authored Mar 19, 2024
1 parent 9dec960 commit a04ea2f
Show file tree
Hide file tree
Showing 80 changed files with 108 additions and 73 deletions.
32 changes: 32 additions & 0 deletions .changes/global-api-script-refactor.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 4 additions & 4 deletions examples/api/src-tauri/gen/schemas/mobile-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@
"type": "object",
"required": [
"args",
"command",
"cmd",
"name",
"sidecar"
],
Expand All @@ -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"
},
Expand All @@ -2398,7 +2398,7 @@
"type": "object",
"required": [
"args",
"command",
"cmd",
"name",
"sidecar"
],
Expand All @@ -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"
},
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/authenticator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/authenticator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ fn verify_signature(

pub fn init<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("authenticator")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![
init_auth,
register,
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/autostart/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/autostart/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub fn init<R: Runtime>(
args: Option<Vec<&'static str>>,
) -> TauriPlugin<R> {
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();
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/barcode-scanner/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/biometric/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion plugins/biometric/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl<R: Runtime, T: Manager<R>> crate::BiometricExt<R> for T {
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
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")?;
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ fn cli_matches<R: Runtime>(_app: AppHandle<R>, cli: State<'_, Cli<R>>) -> Result

pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
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));
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/clipboard-manager/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion plugins/clipboard-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl<R: Runtime, T: Manager<R>> crate::ClipboardExt<R> for T {
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
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,
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/deep-link/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
1 change: 0 additions & 1 deletion plugins/deep-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl<R: Runtime, T: Manager<R>> crate::DeepLinkExt<R> for T {
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
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)?);
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/dialog/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 1 addition & 7 deletions plugins/dialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
// 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
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/fs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl ScopeObject for scope::Entry {

pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
PluginBuilder::<R, Option<config::Config>>::new("fs")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![
commands::create,
commands::open,
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/global-shortcut/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/global-shortcut/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ impl<R: Runtime> Builder<R> {
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,
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/http/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl From<ScopeEntry> 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();
}
1 change: 0 additions & 1 deletion plugins/http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl<R: Runtime, T: Manager<R>> HttpExt<R> for T {

pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::<R>::new("http")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![
commands::fetch,
commands::fetch_cancel,
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion plugins/log/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ impl Builder {

pub fn build<R: Runtime>(mut self) -> TauriPlugin<R> {
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;
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/nfc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion plugins/nfc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ impl<R: Runtime, T: Manager<R>> crate::NfcExt<R> for T {
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
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")?;
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/notification/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions plugins/notification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,13 @@ impl<R: Runtime, T: Manager<R>> crate::NotificationExt<R> for T {

/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
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)?;
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/os/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 0 additions & 2 deletions plugins/os/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
eol: __TEMPLATE_eol__,
},
});

__RAW_global_os_api__;
3 changes: 0 additions & 3 deletions plugins/os/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: Runtime>() -> TauriPlugin<R> {
let init_js = InitJavascript {
global_os_api: include_str!("api-iife.js"),
#[cfg(windows)]
eol: "\r\n",
#[cfg(not(windows))]
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/positioner/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 2 additions & 3 deletions plugins/positioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ async fn move_window<R: Runtime>(window: tauri::Window<R>, position: Position) -

/// The Tauri plugin that exposes [`WindowExt::move_window`] to the webview.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
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| {
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion plugins/process/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 0 additions & 1 deletion plugins/process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod commands;

pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("process")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![commands::exit, commands::restart])
.build()
}
File renamed without changes.
1 change: 1 addition & 0 deletions plugins/shell/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 1 addition & 4 deletions plugins/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
}

pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
let mut init_script = include_str!("init-iife.js").to_string();
init_script.push_str(include_str!("api-iife.js"));

Builder::<R, Option<config::Config>>::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,
Expand Down
File renamed without changes.
Loading

0 comments on commit a04ea2f

Please sign in to comment.