From 6bfe7422ebbe955da757b863eb30e957406aea7b Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Fri, 13 Aug 2021 11:19:03 -0300 Subject: [PATCH] refactor(core): rename `__TAURI__._invoke` to `__TAURI_INVOKE__` (#2417) --- core/tauri/scripts/core.js | 70 ++++++++++++++++---------------------- core/tauri/src/manager.rs | 6 ++-- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/core/tauri/scripts/core.js b/core/tauri/scripts/core.js index 429d9a1e5..5e6aaf561 100644 --- a/core/tauri/scripts/core.js +++ b/core/tauri/scripts/core.js @@ -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', diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index bfc6c0203..192272d2d 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -429,10 +429,10 @@ impl WindowManager { {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 WindowManager { 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',