chore: remove hotkey.js script and replace var with const (#7343)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir 2023-07-12 14:44:26 +03:00 committed by GitHub
parent a2be88a21d
commit 71a0240166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 72 deletions

View File

@ -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

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,36 @@
// 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__('tauri', {
__tauriModule: 'Window',
message: {
cmd: 'manage',
data: {
cmd: {
type: '__toggleDevtools'
}
}
}
});
}
});
}
if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
toggleDevtoolsHotkey();
} else {
window.addEventListener("DOMContentLoaded", toggleDevtoolsHotkey, true);
}
})();

View File

@ -778,30 +778,7 @@ impl<R: Runtime> WindowManager<R> {
};
#[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 = "";

View File

@ -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('<img src="' + src + '"></img>')
}
)

View File

@ -14,17 +14,17 @@
<div id="response"></div>
<script>
var WebviewWindow = window.__TAURI__.window.WebviewWindow
var appWindow = window.__TAURI__.window.appWindow
var windowLabel = appWindow.label
var windowLabelContainer = document.getElementById('window-label')
const WebviewWindow = window.__TAURI__.window.WebviewWindow
const appWindow = window.__TAURI__.window.appWindow
const windowLabel = appWindow.label
const windowLabelContainer = document.getElementById('window-label')
windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'
var container = document.getElementById('container')
const container = document.getElementById('container')
function createWindowMessageBtn(label) {
var tauriWindow = WebviewWindow.getByLabel(label)
var button = document.createElement('button')
const tauriWindow = WebviewWindow.getByLabel(label)
const button = document.createElement('button')
button.innerText = 'Send message to ' + label
button.addEventListener('click', function () {
tauriWindow.emit('clicked', 'message from ' + windowLabel)
@ -33,6 +33,7 @@
}
// global listener
const responseContainer = document.getElementById('response')
window.__TAURI__.event.listen('clicked', function (event) {
responseContainer.innerHTML +=
'Got ' + JSON.stringify(event) + ' on global listener\n\n'
@ -41,17 +42,16 @@
createWindowMessageBtn(event.payload.label)
})
var responseContainer = document.getElementById('response')
// listener tied to this window
appWindow.listen('clicked', function (event) {
responseContainer.innerText +=
'Got ' + JSON.stringify(event) + ' on window listener\n\n'
})
var createWindowButton = document.createElement('button')
const createWindowButton = document.createElement('button')
createWindowButton.innerHTML = 'Create window'
createWindowButton.addEventListener('click', function () {
var webviewWindow = new WebviewWindow(
const webviewWindow = new WebviewWindow(
Math.random().toString().replace('.', ''),
{
tabbingIdentifier: windowLabel
@ -66,7 +66,7 @@
})
container.appendChild(createWindowButton)
var globalMessageButton = document.createElement('button')
const globalMessageButton = document.createElement('button')
globalMessageButton.innerHTML = 'Send global message'
globalMessageButton.addEventListener('click', function () {
// emit to all windows
@ -74,9 +74,9 @@
})
container.appendChild(globalMessageButton)
var allWindows = window.__TAURI__.window.getAll()
for (var index in allWindows) {
var label = allWindows[index].label
const allWindows = window.__TAURI__.window.getAll()
for (const index in allWindows) {
const label = allWindows[index].label
if (label === windowLabel) {
continue
}

View File

@ -14,15 +14,15 @@
<div id="response"></div>
<script>
var WebviewWindow = window.__TAURI__.window.WebviewWindow
var thisTauriWindow = window.__TAURI__.window.getCurrent()
var windowLabel = thisTauriWindow.label
var windowLabelContainer = document.getElementById('window-label')
const WebviewWindow = window.__TAURI__.window.WebviewWindow
const thisTauriWindow = window.__TAURI__.window.getCurrent()
const windowLabel = thisTauriWindow.label
const windowLabelContainer = document.getElementById('window-label')
windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'
var container = document.getElementById('container')
const container = document.getElementById('container')
var responseContainer = document.getElementById('response')
const responseContainer = document.getElementById('response')
function runCommand(commandName, args, optional) {
window.__TAURI__
.invoke(commandName, args)
@ -37,9 +37,9 @@
responseContainer.innerText += 'Got window-created event\n\n'
})
var createWindowButton = document.createElement('button')
var windowId = Math.random().toString().replace('.', '')
var windowNumber = 1
const createWindowButton = document.createElement('button')
const windowId = Math.random().toString().replace('.', '')
const windowNumber = 1
createWindowButton.innerHTML = 'Create child window ' + windowNumber
createWindowButton.addEventListener('click', function () {
runCommand('create_child_window', {

View File

@ -23,10 +23,10 @@
}
function testFs(dir) {
var contents = 'TAURI E2E TEST FILE'
var commandSuffix = dir ? 'WithDir' : ''
const contents = 'TAURI E2E TEST FILE'
const commandSuffix = dir ? 'WithDir' : ''
var options = {
const options = {
dir: dir || null
}

View File

@ -5,21 +5,21 @@
// taken from https://github.com/thedodd/trunk/blob/5c799dc35f1f1d8f8d3d30c8723cbb761a9b6a08/src/autoreload.js
;(function () {
var url = 'ws:' + '//' + window.location.host + '/_tauri-cli/ws'
var poll_interval = 5000
var reload_upon_connect = () => {
const url = 'ws:' + '//' + window.location.host + '/_tauri-cli/ws'
const poll_interval = 5000
const reload_upon_connect = () => {
window.setTimeout(() => {
// when we successfully reconnect, we'll force a
// reload (since we presumably lost connection to
// trunk due to it being killed, so it will have
// rebuilt on restart)
var ws = new WebSocket(url)
const ws = new WebSocket(url)
ws.onopen = () => window.location.reload()
ws.onclose = reload_upon_connect
}, poll_interval)
}
var ws = new WebSocket(url)
const ws = new WebSocket(url)
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data)
if (msg.reload) {