Fix invoke calls in dialog & shell init scripts (#675)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>pull/677/head
parent
5c137365c6
commit
beb6b139eb
@ -0,0 +1,6 @@
|
||||
---
|
||||
"shell": patch
|
||||
"dialog": patch
|
||||
---
|
||||
|
||||
Fix invoke usage.
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
"window-state-js": patch
|
||||
---
|
||||
|
||||
Fix usage of no longer available `__TAURI_METADATA__` API.
|
@ -0,0 +1 @@
|
||||
!function(){"use strict";var e=Object.defineProperty,n=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},t=(e,t,r)=>(n(e,t,"read from private field"),r?r.call(e):t.get(e));function r(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}((n,t)=>{for(var r in t)e(n,r,{get:t[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>a,addPluginListener:()=>o,convertFileSrc:()=>c,invoke:()=>l,transformCallback:()=>r});var i,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,i,(()=>{})),this.id=r((e=>{t(this,i).call(this,e)}))}set onmessage(e){var t,r,s,a;s=e,n(t=this,r=i,"write to private field"),a?a.call(t,s):r.set(t,s)}get onmessage(){return t(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var a=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return l(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function o(e,n,t){let r=new s;return r.onmessage=t,l(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new a(e,n,r.id)))}async function l(e,n={},t){return window.__TAURI_INTERNALS__.invoke(e,n,t)}function c(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}window.alert=function(e){l("plugin:dialog|message",{message:e.toString()})},window.confirm=function(e){return l("plugin:dialog|confirm",{message:e.toString()})}}();
|
@ -0,0 +1,40 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/primitives";
|
||||
|
||||
// open <a href="..."> links with the API
|
||||
function openLinks() {
|
||||
document.querySelector("body")?.addEventListener("click", function (e) {
|
||||
let target = e.target as HTMLElement;
|
||||
while (target != null) {
|
||||
if (target.matches("a")) {
|
||||
const t = target as HTMLAnchorElement;
|
||||
if (
|
||||
t.href &&
|
||||
["http://", "https://", "mailto:", "tel:"].some((v) =>
|
||||
t.href.startsWith(v),
|
||||
) &&
|
||||
t.target === "_blank"
|
||||
) {
|
||||
invoke("plugin:shell|open", {
|
||||
path: t.href,
|
||||
});
|
||||
e.preventDefault();
|
||||
}
|
||||
break;
|
||||
}
|
||||
target = target.parentElement as HTMLElement;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
document.readyState === "complete" ||
|
||||
document.readyState === "interactive"
|
||||
) {
|
||||
openLinks();
|
||||
} else {
|
||||
window.addEventListener("DOMContentLoaded", openLinks, true);
|
||||
}
|
@ -0,0 +1 @@
|
||||
!function(){"use strict";var e=Object.defineProperty,t=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},n=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e));function r(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})({},{Channel:()=>i,PluginListener:()=>s,addPluginListener:()=>o,convertFileSrc:()=>c,invoke:()=>l,transformCallback:()=>r});var a,i=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)})(this,a,(()=>{})),this.id=r((e=>{n(this,a).call(this,e)}))}set onmessage(e){var n,r,i,s;i=e,t(n=this,r=a,"write to private field"),s?s.call(n,i):r.set(n,i)}get onmessage(){return n(this,a)}toJSON(){return`__CHANNEL__:${this.id}`}};a=new WeakMap;var s=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return l(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function o(e,t,n){let r=new i;return r.onmessage=n,l(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new s(e,t,r.id)))}async function l(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function c(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)}function h(){var e;null===(e=document.querySelector("body"))||void 0===e||e.addEventListener("click",(function(e){let t=e.target;for(;null!=t;){if(t.matches("a")){const n=t;n.href&&["http://","https://","mailto:","tel:"].some((e=>n.href.startsWith(e)))&&"_blank"===n.target&&(l("plugin:shell|open",{path:n.href}),e.preventDefault());break}t=t.parentElement}}))}"complete"===document.readyState||"interactive"===document.readyState?h():window.addEventListener("DOMContentLoaded",h,!0)}();
|
@ -1,39 +0,0 @@
|
||||
// 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"
|
||||
) {
|
||||
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);
|
||||
}
|
||||
})();
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue