mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-08 12:00:43 +08:00
2 lines
8.1 KiB
JavaScript
2 lines
8.1 KiB
JavaScript
(()=>{var ue=Object.defineProperty;var g=(e,t)=>{for(var n in t)ue(e,n,{get:t[n],enumerable:!0})};var S={};g(S,{SetText:()=>de,Text:()=>me});var ce=window.location.origin+"/wails/runtime";function fe(e,t,n){let i=new URL(ce);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((r,u)=>{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();u(Error(a.statusText))}).then(a=>r(a)).catch(a=>u(a))})}function l(e,t){return function(n,i=null){return fe(e+"."+n,t,i)}}var H=l("clipboard");function de(e){H("SetText",{text:e})}function me(){return H("Text")}var W={};g(W,{Hide:()=>pe,Quit:()=>ge,Show:()=>we});var E=l("application");function pe(){E("Hide")}function we(){E("Show")}function ge(){E("Quit")}var k={};g(k,{Log:()=>xe});var he=l("log");function xe(e){return he("Log",e)}var L={};g(L,{GetAll:()=>Ce,GetCurrent:()=>be,GetPrimary:()=>ve});var y=l("screens");function Ce(){return y("GetAll")}function ve(){return y("GetPrimary")}function be(){return y("GetCurrent")}var Me="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var h=(e=21)=>{let t="",n=e;for(;n--;)t+=Me[Math.random()*64|0];return t};var Se=l("call"),f=new Map;function Ee(){let e;do e=h();while(f.has(e));return e}function F(e,t,n){let i=f.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),f.delete(e))}function B(e,t){let n=f.get(e);n&&(n.reject(t),f.delete(e))}function G(e,t){return new Promise((n,i)=>{let o=Ee();t=t||{},t["call-id"]=o,f.set(o,{resolve:n,reject:i}),Se(e,t).catch(r=>{i(r),f.delete(o)})})}function I(e){return G("Call",e)}function U(e,t,...n){return G("Call",{packageName:"wails-plugins",structName:e,methodName:t,args:n})}function Y(e){let t=l("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,r)=>void t("SetBackgroundColour",{r:n,g:i,b:o,a:r})}}var We=l("events"),O=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))}},x=class{constructor(t,n=null){this.name=t,this.data=n}},s=new Map;function C(e,t,n){let i=s.get(e)||[],o=new O(e,t,n);return i.push(o),s.set(e,i),()=>ke(o)}function Q(e,t){return C(e,t,-1)}function X(e,t){return C(e,t,1)}function ke(e){let t=e.eventName,n=s.get(t).filter(i=>i!==e);n.length===0?s.delete(t):s.set(t,n)}function j(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 V(e,...t){[e,...t].forEach(i=>{s.delete(i)})}function J(){s.clear()}function v(e){We("Emit",e)}var ye=l("dialog"),d=new Map;function Le(){let e;do e=h();while(d.has(e));return e}function q(e,t,n){let i=d.get(e);i&&(n?i.resolve(JSON.parse(t)):i.resolve(t),d.delete(e))}function _(e,t){let n=d.get(e);n&&(n.reject(t),d.delete(e))}function m(e,t){return new Promise((n,i)=>{let o=Le();t=t||{},t["dialog-id"]=o,d.set(o,{resolve:n,reject:i}),ye(e,t).catch(r=>{i(r),d.delete(o)})})}function K(e){return m("Info",e)}function Z(e){return m("Warning",e)}function $(e){return m("Error",e)}function p(e){return m("Question",e)}function ee(e){return m("OpenFile",e)}function te(e){return m("SaveFile",e)}var Oe=l("contextmenu");function ze(e,t,n,i){Oe("OpenContextMenu",{id:e,x:t,y:n,data:i})}function ne(){window.addEventListener("contextmenu",Re)}function Re(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");ze(n,e.clientX,e.clientY,i);return}De(e)}function De(e){let t=e.target,n=window.getComputedStyle(t).getPropertyValue("--default-contextmenu");switch(n=n?n.trim():"",n){case"show":return;case"hide":e.preventDefault();return;default:let i=t.getAttribute("contentEditable");if(i&&i.toLowerCase()==="true")return;let o=window.getSelection();if(o&&o.toString().length>0)return;let r=t.tagName.toLowerCase();if(r==="input"||r==="textarea")return;e.preventDefault()}}function ie(e,t=null){let n=new x(e,t);v(n)}function Pe(){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",r=function(){if(i){p({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(u){u!=="No"&&ie(n)});return}ie(n)};t.removeEventListener(o,r),t.addEventListener(o,r)})}function oe(e){wails.Window[e]===void 0&&console.log("Window method "+e+" not found"),wails.Window[e]()}function Te(){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",r=function(){if(i){p({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(u){u!=="No"&&oe(n)});return}oe(n)};t.removeEventListener(o,r),t.addEventListener(o,r)})}function z(){Pe(),Te()}var R=function(e){chrome.webview.postMessage(e)};var re=new Map;function le(e){let t=new Map;for(let[n,i]of Object.entries(e))typeof i=="object"&&i!==null?t.set(n,le(i)):t.set(n,i);return t}fetch("/wails/flags").then(e=>{e.json().then(t=>{re=le(t)})});function Ae(e){let t=e.split("."),n=re;for(let i of t)if(n instanceof Map?n=n.get(i):n=n[i],n===void 0)break;return n}function b(e){return Ae(e)}var w=!1;function Ne(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 ae(){window.addEventListener("mousedown",Fe),window.addEventListener("mousemove",Ge),window.addEventListener("mouseup",Be)}var M=null;function He(e){return M?(R("resize:"+M),!0):!1}function Fe(e){if(!He())if(Ne(e)){if(e.offsetX>e.target.clientWidth||e.offsetY>e.target.clientHeight)return;w=!0}else w=!1}function Be(e){(e.buttons!==void 0?e.buttons:e.which)>0&&D()}function D(){document.body.style.cursor="default",w=!1}function c(e){document.documentElement.style.cursor=e||Ie,M=e}function Ge(e){if(w){w=!1,(e.buttons!==void 0?e.buttons:e.which)>0&&R("drag");return}Ue(e)}var Ie="auto";function Ue(e){let t=b("system.resizeHandleHeight")||5,n=b("system.resizeHandleWidth")||5,i=b("resizeCornerExtra")||3,o=window.outerWidth-e.clientX<n,r=e.clientX<n,u=e.clientY<t,a=window.outerHeight-e.clientY<t,P=window.outerWidth-e.clientX<n+i,T=e.clientX<n+i,A=e.clientY<t+i,N=window.outerHeight-e.clientY<t+i;!r&&!o&&!u&&!a&&M!==void 0?c():P&&N?c("se-resize"):T&&N?c("sw-resize"):T&&A?c("nw-resize"):A&&P?c("ne-resize"):r?c("w-resize"):u?c("n-resize"):a?c("s-resize"):o&&c("e-resize")}window.wails={...se(null),Capabilities:{}};fetch("/wails/capabilities").then(e=>{e.json().then(t=>{window.wails.Capabilities=t})});window._wails={dialogCallback:q,dialogErrorCallback:_,dispatchWailsEvent:j,callCallback:F,callErrorCallback:B,endDrag:D};function se(e){return{Clipboard:{...S},Application:{...W,GetWindowByName(t){return se(t)}},Log:k,Screens:L,Call:I,Plugin:U,WML:{Reload:z},Dialog:{Info:K,Warning:Z,Error:$,Question:p,OpenFile:ee,SaveFile:te},Events:{Emit:v,On:Q,Once:X,OnMultiple:C,Off:V,OffAll:J},Window:Y(e)}}console.log("Wails v3.0.0 Debug Mode Enabled");ne();ae();document.addEventListener("DOMContentLoaded",function(e){z()});})();
|