feat: add init scripts (#361)

This commit is contained in:
Lucas Fernandes Nogueira
2023-05-17 18:25:56 -03:00
committed by GitHub
parent d87b569643
commit 7ae7167fbe
13 changed files with 140 additions and 13 deletions
+40
View File
@@ -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)
}
})()
+1
View File
@@ -64,6 +64,7 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
Builder::<R, Option<Config>>::new("shell")
.js_init_script(include_str!("init.js").to_string())
.invoke_handler(tauri::generate_handler![
commands::execute,
commands::stdin_write,