5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 05:50:54 +08:00
wails/v2/internal/frontend/runtime/runtime_prod_desktop.js
Lea Anthony b6dee773c5
Attempted fix for both drag and doubleclick (#1704)
* Attempted fix for both drag and doubleclick

* Shameful hack for windows doubleclick events

* Handle end of drag

* Remove dbClickInterval
2022-08-08 17:27:23 +10:00

2 lines
6.4 KiB
JavaScript

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