From 71a02401664f19c17947b274d5472bddd228dd98 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 12 Jul 2023 14:44:26 +0300 Subject: [PATCH] chore: remove hotkey.js script and replace var with const (#7343) Co-authored-by: Lucas Nogueira --- core/tauri/scripts/core.js | 10 +++--- core/tauri/scripts/hotkey.js | 6 ---- core/tauri/scripts/toggle-devtools.js | 36 +++++++++++++++++++ core/tauri/src/manager.rs | 25 +------------ examples/api/src/views/Dialog.svelte | 12 +++---- examples/multiwindow/index.html | 28 +++++++-------- examples/parent-window/index.html | 18 +++++----- .../test/jest/fixtures/app/dist/index.html | 6 ++-- tooling/cli/src/helpers/auto-reload.js | 10 +++--- 9 files changed, 79 insertions(+), 72 deletions(-) delete mode 100644 core/tauri/scripts/hotkey.js create mode 100644 core/tauri/scripts/toggle-devtools.js diff --git a/core/tauri/scripts/core.js b/core/tauri/scripts/core.js index ad2196c17..9424b7504 100644 --- a/core/tauri/scripts/core.js +++ b/core/tauri/scripts/core.js @@ -17,8 +17,8 @@ callback, once ) { - var identifier = uid() - var prop = `_${identifier}` + const identifier = uid() + const prop = `_${identifier}` Object.defineProperty(window, prop, { value: (result) => { @@ -50,11 +50,11 @@ window.__TAURI_INVOKE__ = function invoke(cmd, args = {}) { return new Promise(function (resolve, reject) { - var callback = window.__TAURI__.transformCallback(function (r) { + const callback = window.__TAURI__.transformCallback(function (r) { resolve(r) delete window[`_${error}`] }, true) - var error = window.__TAURI__.transformCallback(function (e) { + const error = window.__TAURI__.transformCallback(function (e) { reject(e) delete window[`_${callback}`] }, true) @@ -211,7 +211,7 @@ } window.Notification = function (title, options) { - var opts = options || {} + const opts = options || {} sendNotification( Object.assign(opts, { title: title diff --git a/core/tauri/scripts/hotkey.js b/core/tauri/scripts/hotkey.js deleted file mode 100644 index 0bf6f6d73..000000000 --- a/core/tauri/scripts/hotkey.js +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2019-2023 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -/*! hotkeys-js v3.8.7 | MIT (c) 2021 kenny wong | http://jaywcjlove.github.io/hotkeys */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0 event.metaKey && event.altKey && event.key === "I" + : (event) => event.ctrlKey && event.shiftKey && event.key === "I"; + + document.addEventListener("keydown", (event) => { + if (isHotkey(event)) { + window.__TAURI_INVOKE__('tauri', { + __tauriModule: 'Window', + message: { + cmd: 'manage', + data: { + cmd: { + type: '__toggleDevtools' + } + } + } + }); + } + }); + } + + if ( + document.readyState === "complete" || + document.readyState === "interactive" + ) { + toggleDevtoolsHotkey(); + } else { + window.addEventListener("DOMContentLoaded", toggleDevtoolsHotkey, true); + } +})(); diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index a57e1cc05..7a574ab00 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -778,30 +778,7 @@ impl WindowManager { }; #[cfg(any(debug_assertions, feature = "devtools"))] - let hotkeys = &format!( - " - {}; - window.hotkeys('{}', () => {{ - window.__TAURI_INVOKE__('tauri', {{ - __tauriModule: 'Window', - message: {{ - cmd: 'manage', - data: {{ - cmd: {{ - type: '__toggleDevtools' - }} - }} - }} - }}); - }}); - ", - include_str!("../scripts/hotkey.js"), - if cfg!(target_os = "macos") { - "command+option+i" - } else { - "ctrl+shift+i" - } - ); + let hotkeys = include_str!("../scripts/toggle-devtools.js"); #[cfg(not(any(debug_assertions, feature = "devtools")))] let hotkeys = ""; diff --git a/examples/api/src/views/Dialog.svelte b/examples/api/src/views/Dialog.svelte index bdeca61ac..38f7e54ff 100644 --- a/examples/api/src/views/Dialog.svelte +++ b/examples/api/src/views/Dialog.svelte @@ -10,12 +10,12 @@ let directory = false function arrayBufferToBase64(buffer, callback) { - var blob = new Blob([buffer], { + const blob = new Blob([buffer], { type: 'application/octet-binary' }) - var reader = new FileReader() + const reader = new FileReader() reader.onload = function (evt) { - var dataurl = evt.target.result + const dataurl = evt.target.result callback(dataurl.substr(dataurl.indexOf(',') + 1)) } reader.readAsDataURL(blob) @@ -40,8 +40,8 @@ if (Array.isArray(res)) { onMessage(res) } else { - var pathToRead = res - var isFile = pathToRead.match(/\S+\.\S+$/g) + const pathToRead = res + const isFile = pathToRead.match(/\S+\.\S+$/g) readBinaryFile(pathToRead) .then(function (response) { if (isFile) { @@ -52,7 +52,7 @@ arrayBufferToBase64( new Uint8Array(response), function (base64) { - var src = 'data:image/png;base64,' + base64 + const src = 'data:image/png;base64,' + base64 insecureRenderHtml('') } ) diff --git a/examples/multiwindow/index.html b/examples/multiwindow/index.html index 3e89ee93a..d415b1ae3 100644 --- a/examples/multiwindow/index.html +++ b/examples/multiwindow/index.html @@ -14,17 +14,17 @@