fix example, fix linux, document

pull/2019/head
amrbashir 8 months ago
parent 5df1e4b384
commit b696024611
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

1
Cargo.lock generated

@ -6574,6 +6574,7 @@ dependencies = [
"tauri",
"tauri-plugin",
"thiserror 2.0.3",
"url",
"windows 0.58.0",
"zbus",
]

@ -32,7 +32,7 @@
function openPath() {
opener
.openPath(path, pathProgram === 'Default' ? undefined : urlProgram)
.openPath(path, pathProgram === 'Default' ? undefined : pathProgram)
.catch(onMessage)
}

@ -51,6 +51,7 @@ features = [
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies]
zbus = { workspace = true }
url = { workspace = true }
[target."cfg(target_os = \"macos\")".dependencies.objc2-app-kit]
version = "0.2"

@ -6,7 +6,19 @@ import { invoke } from '@tauri-apps/api/core'
// open <a href="..."> links with the API
window.addEventListener('click', function (evt) {
if (evt.defaultPrevented || evt.button !== 0 || evt.metaKey || evt.altKey)
console.log(evt.button)
// return early if
if (
// event was prevented
evt.defaultPrevented ||
// or not a left click or middle click
evt.button !== 0 ||
// or meta key pressed
evt.metaKey ||
// or al key pressed
evt.altKey
)
return
const a = evt
@ -15,20 +27,30 @@ window.addEventListener('click', function (evt) {
| HTMLAnchorElement
| undefined
// return early if
if (
// not tirggered from <a> element
!a ||
// or doesn't have a href
!a.href ||
// only open if supposed to be open in a new tab
!(a.target === '_blank' || evt.ctrlKey || evt.shiftKey)
// or not supposed to be open in a new tab
!(
a.target === '_blank' ||
// or ctrl key pressed
evt.ctrlKey ||
// or shift key pressed
evt.shiftKey
)
)
return
const url = new URL(a.href)
// return early if
if (
// only open if not same origin
// same origin (internal navigation)
url.origin === window.location.origin ||
// only open default protocols
// not default protocols
['http:', 'https:', 'mailto:', 'tel:'].every((p) => url.protocol !== p)
)
return
@ -36,6 +58,6 @@ window.addEventListener('click', function (evt) {
evt.preventDefault()
void invoke('plugin:opener|open_url', {
path: url
url
})
})

@ -1 +1 @@
!function(){"use strict";"function"==typeof SuppressedError&&SuppressedError,window.addEventListener("click",(function(e){if(e.defaultPrevented||0!==e.button||e.metaKey||e.altKey)return;const t=e.composedPath().find((e=>e instanceof Node&&"A"===e.nodeName.toUpperCase()));if(!t||!t.href||"_blank"!==t.target&&!e.ctrlKey&&!e.shiftKey)return;const n=new URL(t.href);n.origin===window.location.origin||["http:","https:","mailto:","tel:"].every((e=>n.protocol!==e))||(e.preventDefault(),async function(e,t={},n){window.__TAURI_INTERNALS__.invoke(e,t,n)}("plugin:opener|open_url",{path:n}))}))}();
!function(){"use strict";"function"==typeof SuppressedError&&SuppressedError,window.addEventListener("click",(function(e){if(console.log(e.button),e.defaultPrevented||0!==e.button||e.metaKey||e.altKey)return;const t=e.composedPath().find((e=>e instanceof Node&&"A"===e.nodeName.toUpperCase()));if(!t||!t.href||"_blank"!==t.target&&!e.ctrlKey&&!e.shiftKey)return;const n=new URL(t.href);n.origin===window.location.origin||["http:","https:","mailto:","tel:"].every((e=>n.protocol!==e))||(e.preventDefault(),async function(e,t={},n){window.__TAURI_INTERNALS__.invoke(e,t,n)}("plugin:opener|open_url",{url:n}))}))}();

Loading…
Cancel
Save