5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 17:39:58 +08:00
wails/v2/internal/frontend/runtime/runtime_prod_desktop.js
2022-04-09 10:27:54 +10:00

2 lines
6.1 KiB
JavaScript

(()=>{var k=Object.defineProperty;var D=e=>k(e,"__esModule",{value:!0});var W=(e,n)=>{D(e);for(var o in n)k(e,o,{get:n[o],enumerable:!0})};var g={};W(g,{LogDebug:()=>B,LogError:()=>J,LogFatal:()=>G,LogInfo:()=>A,LogLevel:()=>U,LogPrint:()=>R,LogTrace:()=>C,LogWarning:()=>H,SetLogLevel:()=>M});function w(e,n){window.WailsInvoke("L"+e+n)}function C(e){w("T",e)}function R(e){w("P",e)}function B(e){w("D",e)}function A(e){w("I",e)}function H(e){w("W",e)}function J(e){w("E",e)}function G(e){w("F",e)}function M(e){w("S",e)}var U={TRACE:1,DEBUG:2,INFO:3,WARNING:4,ERROR:5};var m=class{constructor(n,o){o=o||-1,this.Callback=i=>(n.apply(null,i),o===-1?!1:(o-=1,o===0))}},s={};function c(e,n,o){s[e]=s[e]||[];let i=new m(n,o);s[e].push(i)}function b(e,n){c(e,n,-1)}function E(e,n){c(e,n,1)}function I(e){let n=e.name;if(s[n]){let o=s[n].slice();for(let i=0;i<s[n].length;i+=1){let t=s[n][i],r=e.data;t.Callback(r)&&o.splice(i,1)}s[n]=o}}function h(e){let n;try{n=JSON.parse(e)}catch(o){let i="Invalid JSON passed to Notify: "+e;throw new Error(i)}I(n)}function S(e){let n={name:e,data:[].slice.apply(arguments).slice(1)};I(n),window.WailsInvoke("EE"+JSON.stringify(n))}function y(e){delete s[e],window.WailsInvoke("EX"+e)}var d={};function F(){var e=new Uint32Array(1);return window.crypto.getRandomValues(e)[0]}function P(){return Math.random()*9007199254740991}var p;window.crypto?p=F:p=P;function f(e,n,o){return o==null&&(o=0),new Promise(function(i,t){var r;do r=e+"-"+p();while(d[r]);var a;o>0&&(a=setTimeout(function(){t(Error("Call to "+e+" timed out. Request ID: "+r))},o)),d[r]={timeoutHandle:a,reject:t,resolve:i};try{let u={name:e,args:n,callbackID:r};window.WailsInvoke("C"+JSON.stringify(u))}catch(u){console.error(u)}})}function T(e){let n;try{n=JSON.parse(e)}catch(t){let r=`Invalid JSON passed to callback: ${t.message}. Message: ${e}`;throw runtime.LogDebug(r),new Error(r)}let o=n.callbackid,i=d[o];if(!i){let t=`Callback '${o}' not registered!!!`;throw console.error(t),new Error(t)}clearTimeout(i.timeoutHandle),delete d[o],n.error?i.reject(n.error):i.resolve(n.result)}window.go={};function L(e){try{e=JSON.parse(e)}catch(n){console.error(n)}window.go=window.go||{},Object.keys(e).forEach(n=>{window.go[n]=window.go[n]||{},Object.keys(e[n]).forEach(o=>{window.go[n][o]=window.go[n][o]||{},Object.keys(e[n][o]).forEach(i=>{window.go[n][o][i]=function(){let t=0;function r(){let a=[].slice.call(arguments);return f([n,o,i].join("."),a,t)}return r.setTimeout=function(a){t=a},r.getTimeout=function(){return t},r}()})})})}var v={};W(v,{WindowCenter:()=>Q,WindowFullscreen:()=>q,WindowGetPosition:()=>oe,WindowGetSize:()=>K,WindowHide:()=>ie,WindowMaximise:()=>re,WindowMinimise:()=>we,WindowReload:()=>j,WindowSetDarkTheme:()=>$,WindowSetLightTheme:()=>Y,WindowSetMaxSize:()=>_,WindowSetMinSize:()=>ee,WindowSetPosition:()=>ne,WindowSetRGBA:()=>de,WindowSetSize:()=>Z,WindowSetSystemDefaultTheme:()=>X,WindowSetTitle:()=>V,WindowShow:()=>te,WindowToggleMaximise:()=>se,WindowUnfullscreen:()=>N,WindowUnmaximise:()=>le,WindowUnminimise:()=>ae});function j(){window.location.reload()}function X(){window.WailsInvoke("WASDT")}function Y(){window.WailsInvoke("WALT")}function $(){window.WailsInvoke("WADT")}function Q(){window.WailsInvoke("Wc")}function V(e){window.WailsInvoke("WT"+e)}function q(){window.WailsInvoke("WF")}function N(){window.WailsInvoke("Wf")}function Z(e,n){window.WailsInvoke("Ws:"+e+":"+n)}function K(){return f(":wails:WindowGetSize")}function _(e,n){window.WailsInvoke("WZ:"+e+":"+n)}function ee(e,n){window.WailsInvoke("Wz:"+e+":"+n)}function ne(e,n){window.WailsInvoke("Wp:"+e+":"+n)}function oe(){return f(":wails:WindowGetPos")}function ie(){window.WailsInvoke("WH")}function te(){window.WailsInvoke("WS")}function re(){window.WailsInvoke("WM")}function se(){window.WailsInvoke("Wt")}function le(){window.WailsInvoke("WU")}function we(){window.WailsInvoke("Wm")}function ae(){window.WailsInvoke("Wu")}function de(e,n,o,i){let t=JSON.stringify({r:e||0,g:n||0,b:o||0,a:i||255});window.WailsInvoke("Wr:"+t)}var x={};W(x,{BrowserOpenURL:()=>fe});function fe(e){window.WailsInvoke("BO:"+e)}function ce(){window.WailsInvoke("Q")}window.runtime={...g,...v,...x,EventsOn:b,EventsOnce:E,EventsOnMultiple:c,EventsEmit:S,EventsOff:y,Quit:ce};window.wails={Callback:T,EventsNotify:h,SetBindings:L,eventListeners:s,callbacks:d,flags:{disableScrollbarDrag:!1,disableWailsDefaultContextMenu:!1,enableResize:!1,defaultCursor:null,borderThickness:6,dbClickInterval:100}};window.wails.SetBindings(window.wailsbindings);delete window.wails.SetBindings;var O,z=0;window.addEventListener("mousedown",e=>{if(window.wails.flags.resizeEdge){window.WailsInvoke("resize:"+window.wails.flags.resizeEdge),e.preventDefault();return}let n=e.target;for(;n!=null&&!n.hasAttribute("data-wails-no-drag");){if(n.hasAttribute("data-wails-drag")){if(window.wails.flags.disableScrollbarDrag&&(e.offsetX>e.target.clientWidth||e.offsetY>e.target.clientHeight))break;if(new Date().getTime()-z<window.wails.flags.dbClickInterval){clearTimeout(O);break}O=setTimeout(function(){window.WailsInvoke("drag")},window.wails.flags.dbClickInterval),z=new Date().getTime(),e.preventDefault();break}n=n.parentElement}});function l(e){document.body.style.cursor=e||window.wails.flags.defaultCursor,window.wails.flags.resizeEdge=e}window.addEventListener("mousemove",function(e){if(!window.wails.flags.enableResize)return;window.wails.flags.defaultCursor==null&&(window.wails.flags.defaultCursor=document.body.style.cursor),window.outerWidth-e.clientX<window.wails.flags.borderThickness&&window.outerHeight-e.clientY<window.wails.flags.borderThickness&&(document.body.style.cursor="se-resize");let n=window.outerWidth-e.clientX<window.wails.flags.borderThickness,o=e.clientX<window.wails.flags.borderThickness,i=e.clientY<window.wails.flags.borderThickness,t=window.outerHeight-e.clientY<window.wails.flags.borderThickness;!o&&!n&&!i&&!t&&window.wails.flags.resizeEdge!==void 0?l():n&&t?l("se-resize"):o&&t?l("sw-resize"):o&&i?l("nw-resize"):i&&n?l("ne-resize"):o?l("w-resize"):i?l("n-resize"):t?l("s-resize"):n&&l("e-resize")});window.addEventListener("contextmenu",function(e){window.wails.flags.disableWailsDefaultContextMenu&&e.preventDefault()});})();