mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 05:11:29 +08:00
2 lines
5.8 KiB
JavaScript
2 lines
5.8 KiB
JavaScript
(()=>{var V=Object.defineProperty;var p=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})};var h={};p(h,{SetText:()=>ee,Text:()=>te});var Z=window.location.origin+"/wails/runtime";function $(e,t,n){let i=new URL(Z);i.searchParams.append("method",e),n&&i.searchParams.append("args",JSON.stringify(n));let o={headers:{}};return t&&(o.headers["x-wails-window-name"]=t),new Promise((l,f)=>{fetch(i,o).then(a=>{if(a.ok)return a.headers.get("Content-Type")&&a.headers.get("Content-Type").indexOf("application/json")!==-1?a.json():a.text();f(Error(a.statusText))}).then(a=>l(a)).catch(a=>f(a))})}function r(e,t){return function(n,i=null){return $(e+"."+n,t,i)}}var O=r("clipboard");function ee(e){O("SetText",{text:e})}function te(){return O("Text")}var C={};p(C,{Hide:()=>ne,Quit:()=>oe,Show:()=>ie});var v=r("application");function ne(){v("Hide")}function ie(){v("Show")}function oe(){v("Quit")}var S={};p(S,{Log:()=>le});var re=r("log");function le(e){return re("Log",e)}var b={};p(b,{GetAll:()=>ae,GetCurrent:()=>ce,GetPrimary:()=>ue});var M=r("screens");function ae(){return M("GetAll")}function ue(){return M("GetPrimary")}function ce(){return M("GetCurrent")}var se="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var w=(e=21)=>{let t="",n=e;for(;n--;)t+=se[Math.random()*64|0];return t};var fe=r("call"),c=new Map;function de(){let e;do e=w();while(c.has(e));return e}function k(e,t,n){let i=c.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),c.delete(e))}function A(e,t){let n=c.get(e);n&&(n.reject(t),c.delete(e))}function R(e,t){return new Promise((n,i)=>{let o=de();t=t||{},t["call-id"]=o,c.set(o,{resolve:n,reject:i}),fe(e,t).catch(l=>{i(l),c.delete(o)})})}function T(e){return R("Call",e)}function W(e,t,...n){return R("Call",{packageName:"wails-plugins",structName:e,methodName:t,args:n})}function P(e){let t=r("window",e);return{Center:()=>void t("Center"),SetTitle:n=>void t("SetTitle",{title:n}),Fullscreen:()=>void t("Fullscreen"),UnFullscreen:()=>void t("UnFullscreen"),SetSize:(n,i)=>t("SetSize",{width:n,height:i}),Size:()=>t("Size"),SetMaxSize:(n,i)=>void t("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>void t("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>void t("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>t("SetPosition",{x:n,y:i}),Position:()=>t("Position"),Screen:()=>t("Screen"),Hide:()=>void t("Hide"),Maximise:()=>void t("Maximise"),Show:()=>void t("Show"),Close:()=>void t("Close"),ToggleMaximise:()=>void t("ToggleMaximise"),UnMaximise:()=>void t("UnMaximise"),Minimise:()=>void t("Minimise"),UnMinimise:()=>void t("UnMinimise"),SetBackgroundColour:(n,i,o,l)=>void t("SetBackgroundColour",{r:n,g:i,b:o,a:l})}}var me=r("events"),E=class{constructor(t,n,i){this.eventName=t,this.maxCallbacks=i||-1,this.Callback=o=>(n(o),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var u=new Map;function g(e,t,n){let i=u.get(e)||[],o=new E(e,t,n);return i.push(o),u.set(e,i),()=>pe(o)}function y(e,t){return g(e,t,-1)}function N(e,t){return g(e,t,1)}function pe(e){let t=e.eventName,n=u.get(t).filter(i=>i!==e);n.length===0?u.delete(t):u.set(t,n)}function F(e){console.log("dispatching event: ",{event:e});let t=u.get(e.name);if(t){let n=[];t.forEach(i=>{i.Callback(e)&&n.push(i)}),n.length>0&&(t=t.filter(i=>!n.includes(i)),t.length===0?u.delete(e.name):u.set(e.name,t))}}function D(e,...t){[e,...t].forEach(i=>{u.delete(i)})}function U(){u.clear()}function x(e){me("Emit",e)}var we=r("dialog"),s=new Map;function ge(){let e;do e=w();while(s.has(e));return e}function z(e,t,n){let i=s.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),s.delete(e))}function G(e,t){let n=s.get(e);n&&(n.reject(t),s.delete(e))}function d(e,t){return new Promise((n,i)=>{let o=ge();t=t||{},t["dialog-id"]=o,s.set(o,{resolve:n,reject:i}),we(e,t).catch(l=>{i(l),s.delete(o)})})}function B(e){return d("Info",e)}function I(e){return d("Warning",e)}function Q(e){return d("Error",e)}function m(e){return d("Question",e)}function H(e){return d("OpenFile",e)}function J(e){return d("SaveFile",e)}var xe=r("contextmenu");function he(e,t,n,i){return xe("OpenContextMenu",{id:e,x:t,y:n,data:i})}function q(e){e?window.addEventListener("contextmenu",Y):window.removeEventListener("contextmenu",Y)}function Y(e){j(e.target,e)}function j(e,t){let n=e.getAttribute("data-contextmenu");if(n)t.preventDefault(),he(n,t.clientX,t.clientY,e.getAttribute("data-contextmenu-data"));else{let i=e.parentElement;i&&j(i,t)}}function X(e){x(e)}function ve(){document.querySelectorAll("[data-wml-event]").forEach(function(t){let n=t.getAttribute("data-wml-event"),i=t.getAttribute("data-wml-confirm"),o=t.getAttribute("data-wml-trigger")||"click",l=function(){if(i){m({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(f){f!=="No"&&X(n)});return}X(n)};t.removeEventListener(o,l),t.addEventListener(o,l)})}function _(e){wails.Window[e]===void 0&&console.log("Window method "+e+" not found"),wails.Window[e]()}function Ce(){document.querySelectorAll("[data-wml-window]").forEach(function(t){let n=t.getAttribute("data-wml-window"),i=t.getAttribute("data-wml-confirm"),o=t.getAttribute("data-wml-trigger")||"click",l=function(){if(i){m({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(f){f!=="No"&&_(n)});return}_(n)};t.removeEventListener(o,l),t.addEventListener(o,l)})}function L(){ve(),Ce()}window.wails={...K(null)};window._wails={dialogCallback:z,dialogErrorCallback:G,dispatchCustomEvent:F,callCallback:k,callErrorCallback:A};function K(e){return{Clipboard:{...h},Application:{...C,GetWindowByName(t){return K(t)}},Log:S,Screens:b,Call:T,Plugin:W,WML:{Reload:L},Dialog:{Info:B,Warning:I,Error:Q,Question:m,OpenFile:H,SaveFile:J},Events:{Emit:x,On:y,Once:N,OnMultiple:g,Off:D,OffAll:U},Window:P(e)}}console.log("Wails v3.0.0 Debug Mode Enabled");q(!0);document.addEventListener("DOMContentLoaded",function(e){L()});})();
|