5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 13:13:16 +08:00
wails/v3/internal/runtime/runtime_production_desktop_windows.js
2023-08-27 15:54:01 +10:00

2 lines
9.1 KiB
JavaScript

(()=>{var me=Object.defineProperty;var C=(e,t)=>{for(var n in t)me(e,n,{get:t[n],enumerable:!0})};var y={};C(y,{SetText:()=>xe,Text:()=>ve});var j=window.location.origin+"/wails/runtime",s={Call:0,Clipboard:1,Application:2,Events:3,ContextMenu:4,Dialog:5,Window:6,Screens:7,System:8};function we(e,t,n){let i=new URL(j);e&&i.searchParams.append("method",e);let o={headers:{}};return t&&(o.headers["x-wails-window-name"]=t),n&&(n["wails-method-id"]&&(o.headers["x-wails-method-id"]=n["wails-method-id"],delete n["wails-method-id"]),i.searchParams.append("args",JSON.stringify(n))),new Promise((l,d)=>{fetch(i,o).then(r=>{if(r.ok)return r.headers.get("Content-Type")&&r.headers.get("Content-Type").indexOf("application/json")!==-1?r.json():r.text();d(Error(r.statusText))}).then(r=>l(r)).catch(r=>d(r))})}function F(e,t){return function(n,i=null){return we(e+"."+n,t,i)}}function pe(e,t,n,i){let o=new URL(j);o.searchParams.append("object",e),o.searchParams.append("method",t);let l={headers:{}};return n&&(l.headers["x-wails-window-name"]=n),i&&(i["wails-method-id"]&&(l.headers["x-wails-method-id"]=i["wails-method-id"],delete i["wails-method-id"]),o.searchParams.append("args",JSON.stringify(i))),new Promise((d,r)=>{fetch(o,l).then(a=>{if(a.ok)return a.headers.get("Content-Type")&&a.headers.get("Content-Type").indexOf("application/json")!==-1?a.json():a.text();r(Error(a.statusText))}).then(a=>d(a)).catch(a=>r(a))})}function u(e,t){return function(n,i=null){return pe(e,n,t,i)}}var G=u(s.Clipboard),he=0,ge=1;function xe(e){G(he,{text:e})}function ve(){return G(ge)}var k={};C(k,{Hide:()=>Ce,Quit:()=>be,Show:()=>We});var R=u(s.Application),O={Hide:0,Show:1,Quit:2};function Ce(){R(O.Hide)}function We(){R(O.Show)}function be(){R(O.Quit)}var z={};C(z,{GetAll:()=>Ee,GetCurrent:()=>Re,GetPrimary:()=>ye});var L=u(s.Screens),Se=0,Me=1,De=2;function Ee(){return L(Se)}function ye(){return L(Me)}function Re(){return L(De)}var P={};C(P,{IsDarkMode:()=>Le});var Oe=u(s.System),ke=0;function Le(){return Oe(ke)}var ze="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var W=(e=21)=>{let t="",n=e;for(;n--;)t+=ze[Math.random()*64|0];return t};var Pe=F("call"),m=new Map;function Te(){let e;do e=W();while(m.has(e));return e}function U(e,t,n){let i=m.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),m.delete(e))}function B(e,t){let n=m.get(e);n&&(n.reject(t),m.delete(e))}function Z(e,t){return new Promise((n,i)=>{let o=Te();t=t||{},t["call-id"]=o,m.set(o,{resolve:n,reject:i}),Pe(e,t).catch(l=>{i(l),m.delete(o)})})}function Y(e){return Z("Call",e)}function Q(e,t,...n){return Z("Call",{packageName:"wails-plugins",structName:e,methodName:t,args:n})}var Ne=0,Ae=1,Ie=2,He=3,je=4,Fe=5,Ge=6,Ue=7,Be=8,Ze=9,Ye=10,Qe=11,Xe=12,Ve=13,Je=14,qe=15,_e=16,Ke=17,$e=18,et=19,tt=20,nt=21,it=22,ot=23,lt=24,rt=25,at=26,st=27,ut=28,dt=29;function X(e){let t=u(s.Window,e);return{Center:()=>void t(Ne),SetTitle:n=>void t(Ae,{title:n}),Fullscreen:()=>void t(Ie),UnFullscreen:()=>void t(He),SetSize:(n,i)=>t(je,{width:n,height:i}),Size:()=>t(Fe),SetMaxSize:(n,i)=>void t(Ge,{width:n,height:i}),SetMinSize:(n,i)=>void t(Ue,{width:n,height:i}),SetAlwaysOnTop:n=>void t(Be,{alwaysOnTop:n}),SetRelativePosition:(n,i)=>t(Ze,{x:n,y:i}),RelativePosition:()=>t(Ye),Screen:()=>t(Qe),Hide:()=>void t(Xe),Maximise:()=>void t(Ve),Show:()=>void t(et),Close:()=>void t(tt),ToggleMaximise:()=>void t(qe),UnMaximise:()=>void t(Je),Minimise:()=>void t(_e),UnMinimise:()=>void t(Ke),Restore:()=>void t($e),SetBackgroundColour:(n,i,o,l)=>void t(nt,{r:n,g:i,b:o,a:l}),SetResizable:n=>void t(it,{resizable:n}),Width:()=>t(ot),Height:()=>t(lt),ZoomIn:()=>void t(rt),ZoomOut:()=>void t(at),ZoomReset:()=>void t(st),GetZoomLevel:()=>t(ut),SetZoomLevel:n=>void t(dt,{zoomLevel:n})}}var ct=u(s.Events),ft=0,T=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))}},b=class{constructor(t,n=null){this.name=t,this.data=n}},c=new Map;function S(e,t,n){let i=c.get(e)||[],o=new T(e,t,n);return i.push(o),c.set(e,i),()=>mt(o)}function V(e,t){return S(e,t,-1)}function J(e,t){return S(e,t,1)}function mt(e){let t=e.eventName,n=c.get(t).filter(i=>i!==e);n.length===0?c.delete(t):c.set(t,n)}function q(e){let t=c.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?c.delete(e.name):c.set(e.name,t))}}function _(e,...t){[e,...t].forEach(i=>{c.delete(i)})}function K(){c.clear()}function M(e){ct(ft,e)}var wt=u(s.Dialog),pt=0,ht=1,gt=2,xt=3,vt=4,Ct=5,w=new Map;function Wt(){let e;do e=W();while(w.has(e));return e}function $(e,t,n){let i=w.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),w.delete(e))}function ee(e,t){let n=w.get(e);n&&(n.reject(t),w.delete(e))}function h(e,t){return new Promise((n,i)=>{let o=Wt();t=t||{},t["dialog-id"]=o,w.set(o,{resolve:n,reject:i}),wt(e,t).catch(l=>{i(l),w.delete(o)})})}function te(e){return h(pt,e)}function ne(e){return h(ht,e)}function ie(e){return h(gt,e)}function x(e){return h(xt,e)}function oe(e){return h(vt,e)}function le(e){return h(Ct,e)}var bt=u(s.ContextMenu),St=0;function Mt(e,t,n,i){bt(St,{id:e,x:t,y:n,data:i})}function re(){window.addEventListener("contextmenu",Dt)}function Dt(e){let t=e.target,n=window.getComputedStyle(t).getPropertyValue("--custom-contextmenu");if(n=n?n.trim():"",n){e.preventDefault();let i=window.getComputedStyle(t).getPropertyValue("--custom-contextmenu-data");Mt(n,e.clientX,e.clientY,i);return}Et(e)}function Et(e){let t=e.target;switch(window.getComputedStyle(t).getPropertyValue("--default-contextmenu").trim()){case"show":return;case"hide":e.preventDefault();return;default:if(t.isContentEditable)return;let o=window.getSelection(),l=o.toString().length>0;if(l)for(let d=0;d<o.rangeCount;d++){let a=o.getRangeAt(d).getClientRects();for(let p=0;p<a.length;p++){let g=a[p];if(document.elementFromPoint(g.left,g.top)===t)return}}if((t.tagName==="INPUT"||t.tagName==="TEXTAREA")&&(l||!t.readOnly&&!t.disabled))return;e.preventDefault()}}function ae(e,t=null){let n=new b(e,t);M(n)}function yt(){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){x({Title:"Confirm",Message:i,Detached:!1,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(d){d!=="No"&&ae(n)});return}ae(n)};t.removeEventListener(o,l),t.addEventListener(o,l)})}function se(e){wails.Window[e]===void 0&&console.log("Window method "+e+" not found"),wails.Window[e]()}function Rt(){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){x({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(d){d!=="No"&&se(n)});return}se(n)};t.removeEventListener(o,l),t.addEventListener(o,l)})}function N(){yt(),Rt()}var A=function(e){chrome.webview.postMessage(e)};var ue=new Map;function de(e){let t=new Map;for(let[n,i]of Object.entries(e))typeof i=="object"&&i!==null?t.set(n,de(i)):t.set(n,i);return t}fetch("/wails/flags").then(e=>{e.json().then(t=>{ue=de(t)})});function Ot(e){let t=e.split("."),n=ue;for(let i of t)if(n instanceof Map?n=n.get(i):n=n[i],n===void 0)break;return n}function D(e){return Ot(e)}var v=!1;function kt(e){let t=window.getComputedStyle(e.target).getPropertyValue("--webkit-app-region");return t&&(t=t.trim()),t!=="drag"||e.buttons!==1?!1:e.detail===1}function ce(){window.addEventListener("mousedown",zt),window.addEventListener("mousemove",Tt),window.addEventListener("mouseup",Pt)}var E=null;function Lt(e){return E?(A("resize:"+E),!0):!1}function zt(e){if(!Lt())if(kt(e)){if(e.offsetX>e.target.clientWidth||e.offsetY>e.target.clientHeight)return;v=!0}else v=!1}function Pt(e){(e.buttons!==void 0?e.buttons:e.which)>0&&I()}function I(){document.body.style.cursor="default",v=!1}function f(e){document.documentElement.style.cursor=e||Nt,E=e}function Tt(e){if(v){v=!1,(e.buttons!==void 0?e.buttons:e.which)>0&&A("drag");return}At(e)}var Nt="auto";function At(e){let t=D("system.resizeHandleHeight")||5,n=D("system.resizeHandleWidth")||5,i=D("resizeCornerExtra")||3,o=window.outerWidth-e.clientX<n,l=e.clientX<n,d=e.clientY<t,r=window.outerHeight-e.clientY<t,a=window.outerWidth-e.clientX<n+i,p=e.clientX<n+i,g=e.clientY<t+i,H=window.outerHeight-e.clientY<t+i;!l&&!o&&!d&&!r&&E!==void 0?f():a&&H?f("se-resize"):p&&H?f("sw-resize"):p&&g?f("nw-resize"):g&&a?f("ne-resize"):l?f("w-resize"):d?f("n-resize"):r?f("s-resize"):o&&f("e-resize")}window.wails={...fe(null),Capabilities:{}};fetch("/wails/capabilities").then(e=>{e.json().then(t=>{window.wails.Capabilities=t})});window._wails={dialogCallback:$,dialogErrorCallback:ee,dispatchWailsEvent:q,callCallback:U,callErrorCallback:B,endDrag:I};function fe(e){return{Clipboard:{...y},Application:{...k,GetWindowByName(t){return fe(t)}},System:P,Screens:z,Call:Y,Plugin:Q,WML:{Reload:N},Dialog:{Info:te,Warning:ne,Error:ie,Question:x,OpenFile:oe,SaveFile:le},Events:{Emit:M,On:V,Once:J,OnMultiple:S,Off:_,OffAll:K},Window:X(e)}}re();ce();document.addEventListener("DOMContentLoaded",function(e){N()});})();