5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 18:42:23 +08:00
wails/v2/internal/frontend/runtime/runtime_prod_desktop.js
Lea Anthony 29912785fa
Add Show() and Hide() to runtime to show/hide application (#1599)
* Add Show() and Hide() to runtime to show/hide application

* Fix devserver

* Update API docs
2022-07-20 20:59:49 +10:00

2 lines
6.5 KiB
JavaScript

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