mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-30 17:48:50 +02:00
feat(plugins): inject API on window.__TAURI__ (#383)
This commit is contained in:
@@ -2,16 +2,20 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
export async function isEnabled(): Promise<boolean> {
|
||||
return await invoke("plugin:autostart|is_enabled");
|
||||
return await window.__TAURI_INVOKE__("plugin:autostart|is_enabled");
|
||||
}
|
||||
|
||||
export async function enable(): Promise<void> {
|
||||
await invoke("plugin:autostart|enable");
|
||||
await window.__TAURI_INVOKE__("plugin:autostart|enable");
|
||||
}
|
||||
|
||||
export async function disable(): Promise<void> {
|
||||
await invoke("plugin:autostart|disable");
|
||||
await window.__TAURI_INVOKE__("plugin:autostart|disable");
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_AUTOSTART__=function(_){"use strict";return _.disable=async function(){await window.__TAURI_INVOKE__("plugin:autostart|disable")},_.enable=async function(){await window.__TAURI_INVOKE__("plugin:autostart|enable")},_.isEnabled=async function(){return await window.__TAURI_INVOKE__("plugin:autostart|is_enabled")},_}({});Object.defineProperty(window.__TAURI__,"autostart",{value:__TAURI_AUTOSTART__})}
|
||||
@@ -99,6 +99,7 @@ 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();
|
||||
|
||||
Reference in New Issue
Block a user