Fix invoke calls in dialog & shell init scripts (#675)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Mo
2023-10-22 16:39:40 +03:30
committed by GitHub
parent 5c137365c6
commit beb6b139eb
14 changed files with 112 additions and 66 deletions
+1
View File
@@ -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)}();
-39
View File
@@ -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);
}
})();
+1 -1
View File
@@ -78,7 +78,7 @@ impl<R: Runtime, T: Manager<R>> ShellExt<R> for T {
}
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<Config>> {
let mut init_script = include_str!("init.js").to_string();
let mut init_script = include_str!("init-iife.js").to_string();
init_script.push_str(include_str!("api-iife.js"));
Builder::<R, Option<Config>>::new("shell")