feat: add init scripts (#361)
parent
d87b569643
commit
7ae7167fbe
@ -0,0 +1,15 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
window.alert = function (message) {
|
||||
window.__TAURI_INVOKE__('plugin:dialog|message', {
|
||||
message: message.toString()
|
||||
})
|
||||
}
|
||||
|
||||
window.confirm = function (message) {
|
||||
return window.__TAURI_INVOKE__('plugin:dialog|confirm', {
|
||||
message: message.toString()
|
||||
})
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
;(function () {
|
||||
// open <a href="..."> 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
|
||||
}
|
||||
target = target.parentElement
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (
|
||||
document.readyState === 'complete' ||
|
||||
document.readyState === 'interactive'
|
||||
) {
|
||||
openLinks()
|
||||
} else {
|
||||
window.addEventListener('DOMContentLoaded', openLinks, true)
|
||||
}
|
||||
})()
|
@ -0,0 +1,17 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
document.addEventListener('mousedown', (e) => {
|
||||
if (e.target.hasAttribute('data-tauri-drag-region') && e.buttons === 1) {
|
||||
// prevents text cursor
|
||||
e.preventDefault()
|
||||
// fix #2549: double click on drag region edge causes content to maximize without window sizing change
|
||||
// https://github.com/tauri-apps/tauri/issues/2549#issuecomment-1250036908
|
||||
e.stopImmediatePropagation()
|
||||
|
||||
// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
|
||||
const cmd = e.detail === 2 ? 'internal_toggle_maximize' : 'start_dragging'
|
||||
window.__TAURI_INVOKE__('plugin:window|' + cmd)
|
||||
}
|
||||
})
|
@ -0,0 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
window.print = function () {
|
||||
return window.__TAURI_INVOKE__('plugin:window|print')
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// 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)
|
||||
}
|
||||
})()
|
Loading…
Reference in new issue