Skip to content

Commit 30c7685

Browse files
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 <[email protected]>
1 parent ed04cc3 commit 30c7685

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:enhance
3+
---
4+
5+
Added `Builder::append_invoke_initialization_script`.

core/tauri/src/app.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,53 @@ impl<R: Runtime> Builder<R> {
13281328
self
13291329
}
13301330

1331+
/// Append a custom initialization script.
1332+
///
1333+
/// Allow to append custom initialization script instend of replacing entire invoke system.
1334+
///
1335+
/// # Examples
1336+
///
1337+
/// ```
1338+
/// let custom_script = r#"
1339+
/// // A custom call system bridge build on top of tauri invoke system.
1340+
/// async function invoke(cmd, args = {}) {
1341+
/// if (!args) args = {};
1342+
///
1343+
/// let prefix = "";
1344+
///
1345+
/// if (args?.__module) {
1346+
/// prefix = `plugin:hybridcall.${args.__module}|`;
1347+
/// }
1348+
///
1349+
/// const command = `${prefix}tauri_${cmd}`;
1350+
///
1351+
/// const invoke = window.__TAURI_INTERNALS__.invoke;
1352+
///
1353+
/// return invoke(command, args).then(result => {
1354+
/// if (window.build.debug) {
1355+
/// console.log(`call: ${command}`);
1356+
/// console.log(`args: ${JSON.stringify(args)}`);
1357+
/// console.log(`return: ${JSON.stringify(result)}`);
1358+
/// }
1359+
///
1360+
/// return result;
1361+
/// });
1362+
/// }
1363+
/// "#;
1364+
///
1365+
/// tauri::Builder::default()
1366+
/// .append_invoke_initialization_script(custom_script);
1367+
/// ```
1368+
pub fn append_invoke_initialization_script(
1369+
mut self,
1370+
initialization_script: impl AsRef<str>,
1371+
) -> Self {
1372+
self
1373+
.invoke_initialization_script
1374+
.push_str(initialization_script.as_ref());
1375+
self
1376+
}
1377+
13311378
/// Defines the setup hook.
13321379
///
13331380
/// # Examples

0 commit comments

Comments
 (0)