diff --git a/plugins/shell/src/init.js b/plugins/shell/src/init.js index 295af57c..c43f7cdf 100644 --- a/plugins/shell/src/init.js +++ b/plugins/shell/src/init.js @@ -2,43 +2,39 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -// open links with the API -function __openLinks() { - document.querySelector('body').addEventListener( - 'click', - function (e) { - var target = e.target - while (target != null) { - if (target.matches('a')) { - if ( - target.href && - (['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) && - target.target === '_blank' - ) { - window.__TAURI_INVOKE__('plugin:shell|open', { - path: target.href - }) - e.preventDefault() +;(function () { + // open links with the API + function openLinks() { + document.querySelector('body').addEventListener( + 'click', + function (e) { + var target = e.target + while (target != null) { + if (target.matches('a')) { + if ( + target.href && + (['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) && + target.target === '_blank' + ) { + window.__TAURI_INVOKE__('plugin:shell|open', { + path: target.href + }) + e.preventDefault() + } + break } - break + target = target.parentElement } - target = target.parentElement } - } - ) -} + ) + } -if ( - document.readyState === 'complete' || - document.readyState === 'interactive' -) { - __openLinks() -} else { - window.addEventListener( - 'DOMContentLoaded', - function () { - __openLinks() - }, - true - ) -} \ No newline at end of file + if ( + document.readyState === 'complete' || + document.readyState === 'interactive' + ) { + openLinks() + } else { + window.addEventListener('DOMContentLoaded', openLinks, true) + } +})() diff --git a/plugins/window/src/lib.rs b/plugins/window/src/lib.rs index bead40bf..0f4c2dda 100644 --- a/plugins/window/src/lib.rs +++ b/plugins/window/src/lib.rs @@ -15,10 +15,7 @@ pub fn init() -> TauriPlugin { } init_js.push_str(include_str!("./scripts/drag.js")); #[cfg(any(debug_assertions, feature = "devtools"))] - { - init_js.push_str(include_str!("./scripts/hotkey.js")); - init_js.push_str(include_str!("./scripts/toggle-devtools.js")); - } + init_js.push_str(include_str!("./scripts/toggle-devtools.js")); Builder::new("window") .js_init_script(init_js) diff --git a/plugins/window/src/scripts/hotkey.js b/plugins/window/src/scripts/hotkey.js deleted file mode 100644 index 0bf6f6d7..00000000 --- a/plugins/window/src/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 { - window.__TAURI_INVOKE__('plugin:window|internal_toggle_devtools'); -}); +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +;(function () { + function toggleDevtoolsHotkey() { + const isHotkey = navigator.appVersion.includes('Mac') + ? event => 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__('plugin:window|internal_toggle_devtools'); + } + }) + } + + if ( + document.readyState === 'complete' || + document.readyState === 'interactive' + ) { + toggleDevtoolsHotkey() + } else { + window.addEventListener('DOMContentLoaded', toggleDevtoolsHotkey, true) + } +})()