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

2 lines
7.0 KiB
JavaScript

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