5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 02:09:38 +08:00
wails/v3/internal/runtime/runtime_production_desktop_windows.js
2023-08-27 16:59:18 +10:00

2 lines
8.5 KiB
JavaScript

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