refactor: only inject API IIFE script when withGlobalTauri is true (#1071)

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

* fmt

* update tauri
pull/1096/head
Lucas Fernandes Nogueira 1 year ago committed by GitHub
parent 9dec9605ed
commit a04ea2f382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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.

@ -2363,7 +2363,7 @@
"type": "object", "type": "object",
"required": [ "required": [
"args", "args",
"command", "cmd",
"name", "name",
"sidecar" "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`.", "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" "type": "string"
}, },
@ -2398,7 +2398,7 @@
"type": "object", "type": "object",
"required": [ "required": [
"args", "args",
"command", "cmd",
"name", "name",
"sidecar" "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`.", "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" "type": "string"
}, },

@ -11,5 +11,7 @@ const COMMANDS: &[&str] = &[
]; ];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -78,7 +78,6 @@ fn verify_signature(
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("authenticator") PluginBuilder::new("authenticator")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
init_auth, init_auth,
register, register,

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"]; const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -107,7 +107,6 @@ pub fn init<R: Runtime>(
args: Option<Vec<&'static str>>, args: Option<Vec<&'static str>>,
) -> TauriPlugin<R> { ) -> TauriPlugin<R> {
Builder::new("autostart") Builder::new("autostart")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled]) .invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
.setup(move |app, _api| { .setup(move |app, _api| {
let mut builder = AutoLaunchBuilder::new(); let mut builder = AutoLaunchBuilder::new();

@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[
fn main() { fn main() {
if let Err(error) = tauri_plugin::Builder::new(COMMANDS) if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.try_build() .try_build()

@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["authenticate", "status"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.build(); .build();

@ -59,7 +59,6 @@ impl<R: Runtime, T: Manager<R>> crate::BiometricExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("biometric") Builder::new("biometric")
.js_init_script(include_str!("api-iife.js").to_string())
.setup(|app, api| { .setup(|app, api| {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BiometricPlugin")?; let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BiometricPlugin")?;

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["cli_matches"]; const COMMANDS: &[&str] = &["cli_matches"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -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> { pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
Builder::new("cli") Builder::new("cli")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![cli_matches]) .invoke_handler(tauri::generate_handler![cli_matches])
.setup(|app, api| { .setup(|app, api| {
app.manage(Cli(api)); app.manage(Cli(api));

@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[
fn main() { fn main() {
if let Err(error) = tauri_plugin::Builder::new(COMMANDS) if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.try_build() .try_build()

@ -48,7 +48,6 @@ impl<R: Runtime, T: Manager<R>> crate::ClipboardExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("clipboard-manager") Builder::new("clipboard-manager")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::write_text, commands::write_text,
commands::read_text, commands::read_text,

@ -33,6 +33,7 @@ fn intent_filter(domain: &AssociatedDomain) -> String {
fn main() { fn main() {
if let Err(error) = tauri_plugin::Builder::new(COMMANDS) if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.try_build() .try_build()
{ {

@ -128,7 +128,6 @@ impl<R: Runtime, T: Manager<R>> crate::DeepLinkExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> { pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
Builder::new("deep-link") Builder::new("deep-link")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![commands::get_current]) .invoke_handler(tauri::generate_handler![commands::get_current])
.setup(|app, api| { .setup(|app, api| {
app.manage(init_deep_link(app, api)?); app.manage(init_deep_link(app, api)?);

@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["open", "save", "message", "ask", "confirm"];
fn main() { fn main() {
if let Err(error) = tauri_plugin::Builder::new(COMMANDS) if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.try_build() .try_build()

@ -84,13 +84,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
// Dialogs are implemented natively on Android // Dialogs are implemented natively on Android
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
{ {
let mut init_script = include_str!("init-iife.js").to_string(); builder = builder.js_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

@ -162,6 +162,7 @@ permissions = [
} }
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.global_scope_schema(schemars::schema_for!(scope::Entry)) .global_scope_schema(schemars::schema_for!(scope::Entry))
.build(); .build();
} }

@ -69,7 +69,6 @@ impl ScopeObject for scope::Entry {
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> { pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
PluginBuilder::<R, Option<config::Config>>::new("fs") PluginBuilder::<R, Option<config::Config>>::new("fs")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::create, commands::create,
commands::open, commands::open,

@ -11,5 +11,7 @@ const COMMANDS: &[&str] = &[
]; ];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -353,7 +353,6 @@ impl<R: Runtime> Builder<R> {
let handler = self.handler; let handler = self.handler;
let shortcuts = self.shortcuts; let shortcuts = self.shortcuts;
PluginBuilder::new("global-shortcut") PluginBuilder::new("global-shortcut")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
register, register,
register_all, register_all,

@ -68,6 +68,7 @@ impl From<ScopeEntry> for scope::Entry {
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.global_scope_schema(schemars::schema_for!(ScopeEntry)) .global_scope_schema(schemars::schema_for!(ScopeEntry))
.build(); .build();
} }

@ -35,7 +35,6 @@ impl<R: Runtime, T: Manager<R>> HttpExt<R> for T {
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::<R>::new("http") Builder::<R>::new("http")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::fetch, commands::fetch,
commands::fetch_cancel, commands::fetch_cancel,

@ -5,5 +5,8 @@
const COMMANDS: &[&str] = &["log"]; const COMMANDS: &[&str] = &["log"];
fn main() { 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();
} }

@ -396,7 +396,6 @@ impl Builder {
pub fn build<R: Runtime>(mut self) -> TauriPlugin<R> { pub fn build<R: Runtime>(mut self) -> TauriPlugin<R> {
plugin::Builder::new("log") plugin::Builder::new("log")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![log]) .invoke_handler(tauri::generate_handler![log])
.setup(move |app_handle, _api| { .setup(move |app_handle, _api| {
let app_name = &app_handle.package_info().name; let app_name = &app_handle.package_info().name;

@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["is_available", "write", "scan"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.build(); .build();

@ -71,7 +71,6 @@ impl<R: Runtime, T: Manager<R>> crate::NfcExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("nfc") Builder::new("nfc")
.js_init_script(include_str!("api-iife.js").to_string())
.setup(|app, api| { .setup(|app, api| {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "NfcPlugin")?; let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "NfcPlugin")?;

@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["notify", "request_permission", "is_permission_grant
fn main() { fn main() {
if let Err(error) = tauri_plugin::Builder::new(COMMANDS) if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.try_build() .try_build()

@ -224,15 +224,13 @@ impl<R: Runtime, T: Manager<R>> crate::NotificationExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { 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") Builder::new("notification")
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::notify, commands::notify,
commands::request_permission, commands::request_permission,
commands::is_permission_granted commands::is_permission_granted
]) ])
.js_init_script(init_script) .js_init_script(include_str!("init-iife.js").to_string())
.setup(|app, api| { .setup(|app, api| {
#[cfg(mobile)] #[cfg(mobile)]
let notification = mobile::init(app, api)?; let notification = mobile::init(app, api)?;

@ -14,5 +14,7 @@ const COMMANDS: &[&str] = &[
]; ];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -8,5 +8,3 @@ Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
eol: __TEMPLATE_eol__, eol: __TEMPLATE_eol__,
}, },
}); });
__RAW_global_os_api__;

@ -103,14 +103,11 @@ pub fn hostname() -> String {
#[derive(Template)] #[derive(Template)]
#[default_template("./init.js")] #[default_template("./init.js")]
struct InitJavascript { struct InitJavascript {
#[raw]
global_os_api: &'static str,
eol: &'static str, eol: &'static str,
} }
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
let init_js = InitJavascript { let init_js = InitJavascript {
global_os_api: include_str!("api-iife.js"),
#[cfg(windows)] #[cfg(windows)]
eol: "\r\n", eol: "\r\n",
#[cfg(not(windows))] #[cfg(not(windows))]

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["move_window"]; const COMMANDS: &[&str] = &["move_window"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -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. /// The Tauri plugin that exposes [`WindowExt::move_window`] to the webview.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
let plugin = plugin::Builder::new("positioner") let plugin =
.js_init_script(include_str!("api-iife.js").to_string()) plugin::Builder::new("positioner").invoke_handler(tauri::generate_handler![move_window]);
.invoke_handler(tauri::generate_handler![move_window]);
#[cfg(feature = "tray-icon")] #[cfg(feature = "tray-icon")]
let plugin = plugin.setup(|app_handle, _api| { let plugin = plugin.setup(|app_handle, _api| {

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["exit", "restart"]; const COMMANDS: &[&str] = &["exit", "restart"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -20,7 +20,6 @@ mod commands;
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("process") Builder::new("process")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![commands::exit, commands::restart]) .invoke_handler(tauri::generate_handler![commands::exit, commands::restart])
.build() .build()
} }

@ -9,6 +9,7 @@ const COMMANDS: &[&str] = &["execute", "stdin_write", "kill", "open"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.global_scope_schema(schemars::schema_for!(scope_entry::Entry)) .global_scope_schema(schemars::schema_for!(scope_entry::Entry))
.build(); .build();
} }

@ -77,11 +77,8 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
} }
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> { 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") 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![ .invoke_handler(tauri::generate_handler![
commands::execute, commands::execute,
commands::stdin_write, commands::stdin_write,

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["load", "execute", "select", "close"]; const COMMANDS: &[&str] = &["load", "execute", "select", "close"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -288,7 +288,6 @@ impl Builder {
pub fn build<R: Runtime>(mut self) -> TauriPlugin<R, Option<PluginConfig>> { pub fn build<R: Runtime>(mut self) -> TauriPlugin<R, Option<PluginConfig>> {
PluginBuilder::<R, Option<PluginConfig>>::new("sql") PluginBuilder::<R, Option<PluginConfig>>::new("sql")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![load, execute, select, close]) .invoke_handler(tauri::generate_handler![load, execute, select, close])
.setup(|app, api| { .setup(|app, api| {
let config = api.config().clone().unwrap_or_default(); let config = api.config().clone().unwrap_or_default();

@ -9,6 +9,7 @@ const COMMANDS: &[&str] = &[
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.build(); .build();

@ -315,7 +315,6 @@ impl<R: Runtime> Builder<R> {
/// ``` /// ```
pub fn build(mut self) -> TauriPlugin<R> { pub fn build(mut self) -> TauriPlugin<R> {
plugin::Builder::new("store") plugin::Builder::new("store")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
set, get, has, delete, clear, reset, keys, values, length, entries, load, save set, get, has, delete, clear, reset, keys, values, length, entries, load, save
]) ])

@ -17,5 +17,7 @@ const COMMANDS: &[&str] = &[
]; ];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -456,9 +456,7 @@ impl Builder {
pub fn build<R: Runtime>(self) -> TauriPlugin<R> { pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
let password_hash_function = self.password_hash_function; let password_hash_function = self.password_hash_function;
let plugin_builder = PluginBuilder::new("stronghold") let plugin_builder = PluginBuilder::new("stronghold").setup(move |app, _api| {
.js_init_script(include_str!("api-iife.js").to_string())
.setup(move |app, _api| {
app.manage(StrongholdCollection::default()); app.manage(StrongholdCollection::default());
app.manage(PasswordHashFunction(match password_hash_function { app.manage(PasswordHashFunction(match password_hash_function {
#[cfg(feature = "kdf")] #[cfg(feature = "kdf")]

@ -5,7 +5,9 @@
const COMMANDS: &[&str] = &["check", "download_and_install"]; const COMMANDS: &[&str] = &["check", "download_and_install"];
fn main() { 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 target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android"; let mobile = target_os == "ios" || target_os == "android";

@ -166,7 +166,6 @@ impl Builder {
let target = self.target; let target = self.target;
let installer_args = self.installer_args; let installer_args = self.installer_args;
PluginBuilder::<R, Config>::new("updater") PluginBuilder::<R, Config>::new("updater")
.js_init_script(include_str!("api-iife.js").to_string())
.setup(move |app, api| { .setup(move |app, api| {
let mut config = api.config().clone(); let mut config = api.config().clone();
if let Some(pubkey) = pubkey { if let Some(pubkey) = pubkey {

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["download", "upload"]; const COMMANDS: &[&str] = &["download", "upload"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -130,7 +130,6 @@ fn file_to_body(channel: Channel, file: File) -> reqwest::Body {
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("upload") PluginBuilder::new("upload")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![download, upload]) .invoke_handler(tauri::generate_handler![download, upload])
.build() .build()
} }

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["connect", "send"]; const COMMANDS: &[&str] = &["connect", "send"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -200,7 +200,6 @@ async fn send(
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("websocket") PluginBuilder::new("websocket")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![connect, send]) .invoke_handler(tauri::generate_handler![connect, send])
.setup(|app, _api| { .setup(|app, _api| {
app.manage(ConnectionManager::default()); app.manage(ConnectionManager::default());

@ -5,5 +5,7 @@
const COMMANDS: &[&str] = &["save_window_state", "restore_window_state"]; const COMMANDS: &[&str] = &["save_window_state", "restore_window_state"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS).build(); tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.build();
} }

@ -319,7 +319,6 @@ impl Builder {
pub fn build<R: Runtime>(self) -> TauriPlugin<R> { pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
let flags = self.state_flags; let flags = self.state_flags;
PluginBuilder::new("window-state") PluginBuilder::new("window-state")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
cmd::save_window_state, cmd::save_window_state,
cmd::restore_state cmd::restore_state

@ -73,7 +73,7 @@ export function createConfig(options = {}) {
banner: "if ('__TAURI__' in window) {", banner: "if ('__TAURI__' in window) {",
// the last `}` closes the if in the banner // the last `}` closes the if in the banner
footer: `Object.defineProperty(window.__TAURI__, '${pluginJsName}', { value: ${iifeVarName} }) }`, 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 // and var is not guaranteed to assign to the global `window` object so we make sure to assign it
plugins: [typescript(), terser(), nodeResolve()], plugins: [typescript(), terser(), nodeResolve()],

@ -6,6 +6,7 @@ const COMMANDS: &[&str] = &["execute"];
fn main() { fn main() {
if let Err(error) = tauri_plugin::Builder::new(COMMANDS) if let Err(error) = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.run() .run()

@ -39,7 +39,6 @@ impl<R: Runtime, T: Manager<R>> crate::{{ plugin_name_pascal_case }}Ext<R> for T
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("{{ plugin_name }}") Builder::new("{{ plugin_name }}")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![commands::execute]) .invoke_handler(tauri::generate_handler![commands::execute])
.setup(|app, api| { .setup(|app, api| {
#[cfg(mobile)] #[cfg(mobile)]

Loading…
Cancel
Save