5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-07 00:51:49 +08:00
wails/v3/internal/runtime/runtime_production_desktop_linux.js
2023-09-28 12:14:54 -05:00

2 lines
8.0 KiB
JavaScript

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