5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 07:31:15 +08:00
wails/v3/internal/runtime/runtime_production_desktop_windows.js
2023-05-30 16:33:33 +08:00

2 lines
6.6 KiB
JavaScript

(()=>{var te=Object.defineProperty;var w=(e,t)=>{for(var n in t)te(e,n,{get:t[n],enumerable:!0})};var C={};w(C,{SetText:()=>ie,Text:()=>re});var ne=window.location.origin+"/wails/runtime";function oe(e,t,n){let o=new URL(ne);o.searchParams.append("method",e),n&&o.searchParams.append("args",JSON.stringify(n));let i={headers:{}};return t&&(i.headers["x-wails-window-name"]=t),new Promise((l,f)=>{fetch(o,i).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,o=null){return oe(e+"."+n,t,o)}}var W=r("clipboard");function ie(e){W("SetText",{text:e})}function re(){return W("Text")}var M={};w(M,{Hide:()=>le,Quit:()=>ue,Show:()=>ae});var b=r("application");function le(){b("Hide")}function ae(){b("Show")}function ue(){b("Quit")}var S={};w(S,{Log:()=>ce});var se=r("log");function ce(e){return se("Log",e)}var L={};w(L,{GetAll:()=>fe,GetCurrent:()=>me,GetPrimary:()=>de});var E=r("screens");function fe(){return E("GetAll")}function de(){return E("GetPrimary")}function me(){return E("GetCurrent")}var pe="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var g=(e=21)=>{let t="",n=e;for(;n--;)t+=pe[Math.random()*64|0];return t};var we=r("call"),s=new Map;function ge(){let e;do e=g();while(s.has(e));return e}function y(e,t,n){let o=s.get(e);o&&(n?o.resolve(JSON.parse(t)):o.resolve(t),s.delete(e))}function A(e,t){let n=s.get(e);n&&(n.reject(t),s.delete(e))}function T(e,t){return new Promise((n,o)=>{let i=ge();t=t||{},t["call-id"]=i,s.set(i,{resolve:n,reject:o}),we(e,t).catch(l=>{o(l),s.delete(i)})})}function R(e){return T("Call",e)}function P(e,t,...n){return T("Call",{packageName:"wails-plugins",structName:e,methodName:t,args:n})}function D(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,o)=>t("SetSize",{width:n,height:o}),Size:()=>t("Size"),SetMaxSize:(n,o)=>void t("SetMaxSize",{width:n,height:o}),SetMinSize:(n,o)=>void t("SetMinSize",{width:n,height:o}),SetAlwaysOnTop:n=>void t("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,o)=>t("SetPosition",{x:n,y:o}),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,o,i,l)=>void t("SetBackgroundColour",{r:n,g:o,b:i,a:l})}}var xe=r("events"),k=class{constructor(t,n,o){this.eventName=t,this.maxCallbacks=o||-1,this.Callback=i=>(n(i),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}},x=class{constructor(t,n=null){this.name=t,this.data=n}},u=new Map;function v(e,t,n){let o=u.get(e)||[],i=new k(e,t,n);return o.push(i),u.set(e,o),()=>ve(i)}function N(e,t){return v(e,t,-1)}function F(e,t){return v(e,t,1)}function ve(e){let t=e.eventName,n=u.get(t).filter(o=>o!==e);n.length===0?u.delete(t):u.set(t,n)}function U(e){console.log("dispatching event: ",{event:e});let t=u.get(e.name);if(t){let n=[];t.forEach(o=>{o.Callback(e)&&n.push(o)}),n.length>0&&(t=t.filter(o=>!n.includes(o)),t.length===0?u.delete(e.name):u.set(e.name,t))}}function z(e,...t){[e,...t].forEach(o=>{u.delete(o)})}function G(){u.clear()}function h(e){xe("Emit",e)}var he=r("dialog"),c=new Map;function Ce(){let e;do e=g();while(c.has(e));return e}function I(e,t,n){let o=c.get(e);o&&(n?o.resolve(JSON.parse(t)):o.resolve(t),c.delete(e))}function B(e,t){let n=c.get(e);n&&(n.reject(t),c.delete(e))}function d(e,t){return new Promise((n,o)=>{let i=Ce();t=t||{},t["dialog-id"]=i,c.set(i,{resolve:n,reject:o}),he(e,t).catch(l=>{o(l),c.delete(i)})})}function H(e){return d("Info",e)}function Q(e){return d("Warning",e)}function Y(e){return d("Error",e)}function m(e){return d("Question",e)}function J(e){return d("OpenFile",e)}function q(e){return d("SaveFile",e)}var be=r("contextmenu");function Me(e,t,n,o){return be("OpenContextMenu",{id:e,x:t,y:n,data:o})}function j(e){e?window.addEventListener("contextmenu",X):window.removeEventListener("contextmenu",X)}function X(e){V(e.target,e)}function V(e,t){let n=e.getAttribute("data-contextmenu");if(n)t.preventDefault(),Me(n,t.clientX,t.clientY,e.getAttribute("data-contextmenu-data"));else{let o=e.parentElement;o&&V(o,t)}}function _(e,t=null){let n=new x(e,t);h(n)}function Se(){document.querySelectorAll("[data-wml-event]").forEach(function(t){let n=t.getAttribute("data-wml-event"),o=t.getAttribute("data-wml-confirm"),i=t.getAttribute("data-wml-trigger")||"click",l=function(){if(o){m({Title:"Confirm",Message:o,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(f){f!=="No"&&_(n)});return}_(n)};t.removeEventListener(i,l),t.addEventListener(i,l)})}function K(e){wails.Window[e]===void 0&&console.log("Window method "+e+" not found"),wails.Window[e]()}function Ee(){document.querySelectorAll("[data-wml-window]").forEach(function(t){let n=t.getAttribute("data-wml-window"),o=t.getAttribute("data-wml-confirm"),i=t.getAttribute("data-wml-trigger")||"click",l=function(){if(o){m({Title:"Confirm",Message:o,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(f){f!=="No"&&K(n)});return}K(n)};t.removeEventListener(i,l),t.addEventListener(i,l)})}function O(){Se(),Ee()}var Z=chrome.webview.postMessage;var p=!1;function Le(e){let t=window.getComputedStyle(e.target).getPropertyValue("--wails-draggable");return t&&(t=t.trim()),t!=="drag"||e.buttons!==1?!1:e.detail===1}function $(){window.addEventListener("mousedown",ke),window.addEventListener("mousemove",We),window.addEventListener("mouseup",Oe)}function ke(e){if(Le(e)){if(e.offsetX>e.target.clientWidth||e.offsetY>e.target.clientHeight)return;p=!0}else p=!1}function Oe(e){document.body.style.cursor=window.wails.previousCursor||"auto",p=!1}function We(e){if(p&&(p=!1,(e.buttons!==void 0?e.buttons:e.which)>0)){window.wails.previousCursor=document.body.style.cursor,document.body.style.cursor="grab",Z("drag");return}}window.wails={...ee(null)};window._wails={dialogCallback:I,dialogErrorCallback:B,dispatchWailsEvent:U,callCallback:y,callErrorCallback:A};function ee(e){return{Clipboard:{...C},Application:{...M,GetWindowByName(t){return ee(t)}},Log:S,Screens:L,Call:R,Plugin:P,WML:{Reload:O},Dialog:{Info:H,Warning:Q,Error:Y,Question:m,OpenFile:J,SaveFile:q},Events:{Emit:h,On:N,Once:F,OnMultiple:v,Off:z,OffAll:G},Window:D(e)}}console.log("Wails v3.0.0 Debug Mode Enabled");j(!0);$();document.addEventListener("DOMContentLoaded",function(e){O()});})();