mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
refactor(core): rename __TAURI__._invoke to __TAURI_INVOKE__ (#2417)
This commit is contained in:
committed by
GitHub
parent
f81ebddfcc
commit
6bfe7422eb
@@ -10,7 +10,8 @@ if (!String.prototype.startsWith) {
|
||||
}
|
||||
}
|
||||
|
||||
;(function () {
|
||||
;
|
||||
(function () {
|
||||
function uid() {
|
||||
const length = new Int8Array(1)
|
||||
window.crypto.getRandomValues(length)
|
||||
@@ -92,7 +93,7 @@ if (!String.prototype.startsWith) {
|
||||
return identifier
|
||||
}
|
||||
|
||||
window.__TAURI__._invoke = function invoke(cmd, args = {}, key = null) {
|
||||
window.__TAURI_INVOKE__ = function invoke(cmd, args = {}, key = null) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var callback = window.__TAURI__.transformCallback(function (r) {
|
||||
resolve(r)
|
||||
@@ -114,8 +115,7 @@ if (!String.prototype.startsWith) {
|
||||
if (window.rpc) {
|
||||
window.rpc.notify(
|
||||
cmd,
|
||||
_objectSpread(
|
||||
{
|
||||
_objectSpread({
|
||||
callback: callback,
|
||||
error: error,
|
||||
__invokeKey: key || __TAURI_INVOKE_KEY__
|
||||
@@ -127,8 +127,7 @@ if (!String.prototype.startsWith) {
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
window.rpc.notify(
|
||||
cmd,
|
||||
_objectSpread(
|
||||
{
|
||||
_objectSpread({
|
||||
callback: callback,
|
||||
error: error,
|
||||
__invokeKey: key || __TAURI_INVOKE_KEY__
|
||||
@@ -156,9 +155,8 @@ if (!String.prototype.startsWith) {
|
||||
target.href.startsWith('http') &&
|
||||
target.target === '_blank'
|
||||
) {
|
||||
window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Shell',
|
||||
message: {
|
||||
cmd: 'open',
|
||||
@@ -197,9 +195,8 @@ if (!String.prototype.startsWith) {
|
||||
document.addEventListener('mousedown', (e) => {
|
||||
if (e.target.hasAttribute('data-tauri-drag-region') && e.buttons === 1) {
|
||||
// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
|
||||
window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Window',
|
||||
message: {
|
||||
cmd: 'manage',
|
||||
@@ -215,9 +212,8 @@ if (!String.prototype.startsWith) {
|
||||
}
|
||||
})
|
||||
|
||||
window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Event',
|
||||
message: {
|
||||
cmd: 'listen',
|
||||
@@ -225,7 +221,9 @@ if (!String.prototype.startsWith) {
|
||||
handler: window.__TAURI__.transformCallback(function (event) {
|
||||
if (event.payload) {
|
||||
var windowLabel = event.payload.label
|
||||
window.__TAURI__.__windows.push({ label: windowLabel })
|
||||
window.__TAURI__.__windows.push({
|
||||
label: windowLabel
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -240,9 +238,8 @@ if (!String.prototype.startsWith) {
|
||||
if (window.Notification.permission !== 'default') {
|
||||
return Promise.resolve(window.Notification.permission === 'granted')
|
||||
}
|
||||
return window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
return window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Notification',
|
||||
message: {
|
||||
cmd: 'isNotificationPermissionGranted'
|
||||
@@ -259,10 +256,8 @@ if (!String.prototype.startsWith) {
|
||||
}
|
||||
|
||||
function requestPermission() {
|
||||
return window.__TAURI__
|
||||
._invoke(
|
||||
'tauri',
|
||||
{
|
||||
return window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Notification',
|
||||
message: {
|
||||
cmd: 'requestNotificationPermission'
|
||||
@@ -283,18 +278,14 @@ if (!String.prototype.startsWith) {
|
||||
|
||||
isPermissionGranted().then(function (permission) {
|
||||
if (permission) {
|
||||
return window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
return window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Notification',
|
||||
message: {
|
||||
cmd: 'notification',
|
||||
options:
|
||||
typeof options === 'string'
|
||||
? {
|
||||
title: options
|
||||
}
|
||||
: options
|
||||
options: typeof options === 'string' ? {
|
||||
title: options
|
||||
} : options
|
||||
}
|
||||
},
|
||||
_KEY_VALUE_
|
||||
@@ -336,9 +327,8 @@ if (!String.prototype.startsWith) {
|
||||
})
|
||||
|
||||
window.alert = function (message) {
|
||||
window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Dialog',
|
||||
message: {
|
||||
cmd: 'messageDialog',
|
||||
@@ -350,9 +340,8 @@ if (!String.prototype.startsWith) {
|
||||
}
|
||||
|
||||
window.confirm = function (message) {
|
||||
return window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
return window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Dialog',
|
||||
message: {
|
||||
cmd: 'askDialog',
|
||||
@@ -366,9 +355,8 @@ if (!String.prototype.startsWith) {
|
||||
// window.print works on Linux/Windows; need to use the API on macOS
|
||||
if (navigator.userAgent.includes('Mac')) {
|
||||
window.print = function () {
|
||||
return window.__TAURI__._invoke(
|
||||
'tauri',
|
||||
{
|
||||
return window.__TAURI_INVOKE__(
|
||||
'tauri', {
|
||||
__tauriModule: 'Window',
|
||||
message: {
|
||||
cmd: 'manage',
|
||||
|
||||
@@ -429,10 +429,10 @@ impl<R: Runtime> WindowManager<R> {
|
||||
{core_script}
|
||||
{event_initialization_script}
|
||||
if (window.rpc) {{
|
||||
window.__TAURI__._invoke("__initialized", {{ url: window.location.href }}, {key})
|
||||
window.__TAURI_INVOKE__("__initialized", {{ url: window.location.href }}, {key})
|
||||
}} else {{
|
||||
window.addEventListener('DOMContentLoaded', function () {{
|
||||
window.__TAURI__._invoke("__initialized", {{ url: window.location.href }}, {key})
|
||||
window.__TAURI_INVOKE__("__initialized", {{ url: window.location.href }}, {key})
|
||||
}})
|
||||
}}
|
||||
{plugin_initialization_script}
|
||||
@@ -456,7 +456,7 @@ impl<R: Runtime> WindowManager<R> {
|
||||
const listeners = (window['{listeners}'] && window['{listeners}'][eventData.event]) || []
|
||||
|
||||
if (listeners.length > 0) {{
|
||||
window.__TAURI__._invoke('tauri', {{
|
||||
window.__TAURI_INVOKE__('tauri', {{
|
||||
__tauriModule: 'Internal',
|
||||
message: {{
|
||||
cmd: 'validateSalt',
|
||||
|
||||
Reference in New Issue
Block a user