mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-23 19:52:31 +03:00
feat: add Builder::append_invoke_initialization_script
(#10295)
* Allow to append a custom initialization script * docs: add doc for `Builder::append_invoke_initialization_script` * Update core/tauri/src/app.rs * Update core/tauri/src/app.rs * add change file * fix signature * fix doc test * doc fmt --------- Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
This commit is contained in:
parent
ed04cc3d36
commit
30c7685eb8
5
.changes/append_invoke_initialization_script.md
Normal file
5
.changes/append_invoke_initialization_script.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch:enhance
|
||||
---
|
||||
|
||||
Added `Builder::append_invoke_initialization_script`.
|
@ -1328,6 +1328,53 @@ impl<R: Runtime> Builder<R> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Append a custom initialization script.
|
||||
///
|
||||
/// Allow to append custom initialization script instend of replacing entire invoke system.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let custom_script = r#"
|
||||
/// // A custom call system bridge build on top of tauri invoke system.
|
||||
/// async function invoke(cmd, args = {}) {
|
||||
/// if (!args) args = {};
|
||||
///
|
||||
/// let prefix = "";
|
||||
///
|
||||
/// if (args?.__module) {
|
||||
/// prefix = `plugin:hybridcall.${args.__module}|`;
|
||||
/// }
|
||||
///
|
||||
/// const command = `${prefix}tauri_${cmd}`;
|
||||
///
|
||||
/// const invoke = window.__TAURI_INTERNALS__.invoke;
|
||||
///
|
||||
/// return invoke(command, args).then(result => {
|
||||
/// if (window.build.debug) {
|
||||
/// console.log(`call: ${command}`);
|
||||
/// console.log(`args: ${JSON.stringify(args)}`);
|
||||
/// console.log(`return: ${JSON.stringify(result)}`);
|
||||
/// }
|
||||
///
|
||||
/// return result;
|
||||
/// });
|
||||
/// }
|
||||
/// "#;
|
||||
///
|
||||
/// tauri::Builder::default()
|
||||
/// .append_invoke_initialization_script(custom_script);
|
||||
/// ```
|
||||
pub fn append_invoke_initialization_script(
|
||||
mut self,
|
||||
initialization_script: impl AsRef<str>,
|
||||
) -> Self {
|
||||
self
|
||||
.invoke_initialization_script
|
||||
.push_str(initialization_script.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
/// Defines the setup hook.
|
||||
///
|
||||
/// # Examples
|
||||
|
Loading…
Reference in New Issue
Block a user