mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(plugins): inject API on window.__TAURI__ (#383)
This commit is contained in:
committed by
GitHub
parent
3c8577bc9a
commit
b131bc8f7c
@@ -8,7 +8,11 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application version.
|
||||
@@ -21,7 +25,7 @@ import { invoke } from "@tauri-apps/api/tauri";
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function getVersion(): Promise<string> {
|
||||
return invoke("plugin:app|version");
|
||||
return window.__TAURI_INVOKE__("plugin:app|version");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +39,7 @@ async function getVersion(): Promise<string> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function getName(): Promise<string> {
|
||||
return invoke("plugin:app|name");
|
||||
return window.__TAURI_INVOKE__("plugin:app|name");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +54,7 @@ async function getName(): Promise<string> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function getTauriVersion(): Promise<string> {
|
||||
return invoke("plugin:app|tauri_version");
|
||||
return window.__TAURI_INVOKE__("plugin:app|tauri_version");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +69,7 @@ async function getTauriVersion(): Promise<string> {
|
||||
* @since 1.2.0
|
||||
*/
|
||||
async function show(): Promise<void> {
|
||||
return invoke("plugin:app|show");
|
||||
return window.__TAURI_INVOKE__("plugin:app|show");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +84,7 @@ async function show(): Promise<void> {
|
||||
* @since 1.2.0
|
||||
*/
|
||||
async function hide(): Promise<void> {
|
||||
return invoke("plugin:app|hide");
|
||||
return window.__TAURI_INVOKE__("plugin:app|hide");
|
||||
}
|
||||
|
||||
export { getName, getVersion, getTauriVersion, show, hide };
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_APP__=function(_){"use strict";return _.getName=async function(){return window.__TAURI_INVOKE__("plugin:app|name")},_.getTauriVersion=async function(){return window.__TAURI_INVOKE__("plugin:app|tauri_version")},_.getVersion=async function(){return window.__TAURI_INVOKE__("plugin:app|version")},_.hide=async function(){return window.__TAURI_INVOKE__("plugin:app|hide")},_.show=async function(){return window.__TAURI_INVOKE__("plugin:app|show")},_}({});Object.defineProperty(window.__TAURI__,"app",{value:__TAURI_APP__})}
|
||||
@@ -11,6 +11,7 @@ mod commands;
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("app")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::version,
|
||||
commands::name,
|
||||
|
||||
Reference in New Issue
Block a user