mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-31 13:39:36 +02:00
feat(plugins): inject API on window.__TAURI__ (#383)
This commit is contained in:
committed by
GitHub
parent
3c8577bc9a
commit
b131bc8f7c
@@ -7,7 +7,11 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits immediately with the given `exitCode`.
|
||||
@@ -23,7 +27,7 @@ import { invoke } from "@tauri-apps/api/tauri";
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function exit(code = 0): Promise<void> {
|
||||
return invoke("plugin:process|exit", { code });
|
||||
return window.__TAURI_INVOKE__("plugin:process|exit", { code });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +43,7 @@ async function exit(code = 0): Promise<void> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function relaunch(): Promise<void> {
|
||||
return invoke("plugin:process|restart");
|
||||
return window.__TAURI_INVOKE__("plugin:process|restart");
|
||||
}
|
||||
|
||||
export { exit, relaunch };
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_PROCESS__=function(_){"use strict";return _.exit=async function(_=0){return window.__TAURI_INVOKE__("plugin:process|exit",{code:_})},_.relaunch=async function(){return window.__TAURI_INVOKE__("plugin:process|restart")},_}({});Object.defineProperty(window.__TAURI__,"process",{value:__TAURI_PROCESS__})}
|
||||
@@ -11,6 +11,7 @@ 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user