5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 04:50:09 +08:00
wails/v3/internal/runtime/runtime_production_desktop_darwin.js

2 lines
8.0 KiB
JavaScript

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