mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-05 19:59:43 +08:00
2 lines
8.4 KiB
JavaScript
2 lines
8.4 KiB
JavaScript
(()=>{var se=Object.defineProperty;var g=(t,e)=>{for(var n in e)se(t,n,{get:e[n],enumerable:!0})};var S={};g(S,{SetText:()=>me,Text:()=>we});var T=window.location.origin+"/wails/runtime",r={Call:0,Clipboard:1,Application:2,Events:3,ContextMenu:4,Dialog:5,Window:6,Screens:7,System:8};function ue(t,e,n){let i=new URL(T);t&&i.searchParams.append("method",t);let o={headers:{}};return e&&(o.headers["x-wails-window-name"]=e),n&&(n["wails-method-id"]&&(o.headers["x-wails-method-id"]=n["wails-method-id"],delete n["wails-method-id"]),i.searchParams.append("args",JSON.stringify(n))),new Promise((l,d)=>{fetch(i,o).then(s=>{if(s.ok)return s.headers.get("Content-Type")&&s.headers.get("Content-Type").indexOf("application/json")!==-1?s.json():s.text();d(Error(s.statusText))}).then(s=>l(s)).catch(s=>d(s))})}function N(t,e){return function(n,i=null){return ue(t+"."+n,e,i)}}function de(t,e,n,i){let o=new URL(T);o.searchParams.append("object",t),o.searchParams.append("method",e);let l={headers:{}};return n&&(l.headers["x-wails-window-name"]=n),i&&(i["wails-method-id"]&&(l.headers["x-wails-method-id"]=i["wails-method-id"],delete i["wails-method-id"]),o.searchParams.append("args",JSON.stringify(i))),new Promise((d,s)=>{fetch(o,l).then(u=>{if(u.ok)return u.headers.get("Content-Type")&&u.headers.get("Content-Type").indexOf("application/json")!==-1?u.json():u.text();s(Error(u.statusText))}).then(u=>d(u)).catch(u=>s(u))})}function a(t,e){return function(n,i=null){return de(t,n,e,i)}}var A=a(r.Clipboard),ce=0,fe=1;function me(t){A(ce,{text:t})}function we(){return A(fe)}var E={};g(E,{Hide:()=>pe,Quit:()=>ge,Show:()=>he});var M=a(r.Application),D={Hide:0,Show:1,Quit:2};function pe(){M(D.Hide)}function he(){M(D.Show)}function ge(){M(D.Quit)}var R={};g(R,{GetAll:()=>We,GetCurrent:()=>Se,GetPrimary:()=>be});var y=a(r.Screens),xe=0,ve=1,Ce=2;function We(){return y(xe)}function be(){return y(ve)}function Se(){return y(Ce)}var O={};g(O,{IsDarkMode:()=>Ee});var Me=a(r.System),De=0;function Ee(){return Me(De)}var ye="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var x=(t=21)=>{let e="",n=t;for(;n--;)e+=ye[Math.random()*64|0];return e};var Re=N("call"),f=new Map;function Oe(){let t;do t=x();while(f.has(t));return t}function I(t,e,n){let i=f.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),f.delete(t))}function H(t,e){let n=f.get(t);n&&(n.reject(e),f.delete(t))}function j(t,e){return new Promise((n,i)=>{let o=Oe();e=e||{},e["call-id"]=o,f.set(o,{resolve:n,reject:i}),Re(t,e).catch(l=>{i(l),f.delete(o)})})}function F(t){return j("Call",t)}function G(t,e,...n){return j("Call",{packageName:"wails-plugins",structName:t,methodName:e,args:n})}var ke=0,ze=1,Le=2,Pe=3,Te=4,Ne=5,Ae=6,Ie=7,He=8,je=9,Fe=10,Ge=11,Ue=12,Be=13,Ze=14,Ye=15,Qe=16,Xe=17,Ve=18,Je=19,qe=20,_e=21,Ke=22,$e=23,et=24,tt=25,nt=26,it=27,ot=28,lt=29;function U(t){let e=a(r.Window,t);return{Center:()=>void e(ke),SetTitle:n=>void e(ze,{title:n}),Fullscreen:()=>void e(Le),UnFullscreen:()=>void e(Pe),SetSize:(n,i)=>e(Te,{width:n,height:i}),Size:()=>e(Ne),SetMaxSize:(n,i)=>void e(Ae,{width:n,height:i}),SetMinSize:(n,i)=>void e(Ie,{width:n,height:i}),SetAlwaysOnTop:n=>void e(He,{alwaysOnTop:n}),SetRelativePosition:(n,i)=>e(je,{x:n,y:i}),RelativePosition:()=>e(Fe),Screen:()=>e(Ge),Hide:()=>void e(Ue),Maximise:()=>void e(Be),Show:()=>void e(Je),Close:()=>void e(qe),ToggleMaximise:()=>void e(Ye),UnMaximise:()=>void e(Ze),Minimise:()=>void e(Qe),UnMinimise:()=>void e(Xe),Restore:()=>void e(Ve),SetBackgroundColour:(n,i,o,l)=>void e(_e,{r:n,g:i,b:o,a:l}),SetResizable:n=>void e(Ke,{resizable:n}),Width:()=>e($e),Height:()=>e(et),ZoomIn:()=>void e(tt),ZoomOut:()=>void e(nt),ZoomReset:()=>void e(it),GetZoomLevel:()=>e(ot),SetZoomLevel:n=>void e(lt,{zoomLevel:n})}}var rt=a(r.Events),at=0,k=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=o=>(n(o),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}},v=class{constructor(e,n=null){this.name=e,this.data=n}},c=new Map;function C(t,e,n){let i=c.get(t)||[],o=new k(t,e,n);return i.push(o),c.set(t,i),()=>st(o)}function B(t,e){return C(t,e,-1)}function Z(t,e){return C(t,e,1)}function st(t){let e=t.eventName,n=c.get(e).filter(i=>i!==t);n.length===0?c.delete(e):c.set(e,n)}function Y(t){let e=c.get(t.name);if(e){let n=[];e.forEach(i=>{i.Callback(t)&&n.push(i)}),n.length>0&&(e=e.filter(i=>!n.includes(i)),e.length===0?c.delete(t.name):c.set(t.name,e))}}function Q(t,...e){[t,...e].forEach(i=>{c.delete(i)})}function X(){c.clear()}function W(t){rt(at,t)}var ut=a(r.Dialog),dt=0,ct=1,ft=2,mt=3,wt=4,pt=5,m=new Map;function ht(){let t;do t=x();while(m.has(t));return t}function V(t,e,n){let i=m.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),m.delete(t))}function J(t,e){let n=m.get(t);n&&(n.reject(e),m.delete(t))}function w(t,e){return new Promise((n,i)=>{let o=ht();e=e||{},e["dialog-id"]=o,m.set(o,{resolve:n,reject:i}),ut(t,e).catch(l=>{i(l),m.delete(o)})})}function q(t){return w(dt,t)}function _(t){return w(ct,t)}function K(t){return w(ft,t)}function p(t){return w(mt,t)}function $(t){return w(wt,t)}function ee(t){return w(pt,t)}var gt=a(r.ContextMenu),xt=0;function vt(t,e,n,i){gt(xt,{id:t,x:e,y:n,data:i})}function te(){window.addEventListener("contextmenu",Ct)}function Ct(t){let e=t.target,n=window.getComputedStyle(e).getPropertyValue("--custom-contextmenu");if(n=n?n.trim():"",n){t.preventDefault();let i=window.getComputedStyle(e).getPropertyValue("--custom-contextmenu-data");vt(n,t.clientX,t.clientY,i);return}Wt(t)}function Wt(t){let e=t.target;switch(window.getComputedStyle(e).getPropertyValue("--default-contextmenu").trim()){case"show":return;case"hide":t.preventDefault();return;default:if(e.isContentEditable)return;let o=window.getSelection(),l=o.toString().length>0;if(l)for(let d=0;d<o.rangeCount;d++){let u=o.getRangeAt(d).getClientRects();for(let b=0;b<u.length;b++){let P=u[b];if(document.elementFromPoint(P.left,P.top)===e)return}}if((e.tagName==="INPUT"||e.tagName==="TEXTAREA")&&(l||!e.readOnly&&!e.disabled))return;t.preventDefault()}}function ne(t,e=null){let n=new v(t,e);W(n)}function bt(){document.querySelectorAll("[data-wml-event]").forEach(function(e){let n=e.getAttribute("data-wml-event"),i=e.getAttribute("data-wml-confirm"),o=e.getAttribute("data-wml-trigger")||"click",l=function(){if(i){p({Title:"Confirm",Message:i,Detached:!1,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(d){d!=="No"&&ne(n)});return}ne(n)};e.removeEventListener(o,l),e.addEventListener(o,l)})}function ie(t){wails.Window[t]===void 0&&console.log("Window method "+t+" not found"),wails.Window[t]()}function St(){document.querySelectorAll("[data-wml-window]").forEach(function(e){let n=e.getAttribute("data-wml-window"),i=e.getAttribute("data-wml-confirm"),o=e.getAttribute("data-wml-trigger")||"click",l=function(){if(i){p({Title:"Confirm",Message:i,Buttons:[{Label:"Yes"},{Label:"No",IsDefault:!0}]}).then(function(d){d!=="No"&&ie(n)});return}ie(n)};e.removeEventListener(o,l),e.addEventListener(o,l)})}function z(){bt(),St()}var oe=function(t){webkit.messageHandlers.external.postMessage(t)};var Mt=new Map;function le(t){let e=new Map;for(let[n,i]of Object.entries(t))typeof i=="object"&&i!==null?e.set(n,le(i)):e.set(n,i);return e}fetch("/wails/flags").then(t=>{t.json().then(e=>{Mt=le(e)})});var h=!1;function Dt(t){let e=window.getComputedStyle(t.target).getPropertyValue("--webkit-app-region");return e&&(e=e.trim()),e!=="drag"||t.buttons!==1?!1:t.detail===1}function re(){window.addEventListener("mousedown",Et),window.addEventListener("mousemove",Rt),window.addEventListener("mouseup",yt)}function Et(t){if(Dt(t)){if(t.offsetX>t.target.clientWidth||t.offsetY>t.target.clientHeight)return;h=!0}else h=!1}function yt(t){(t.buttons!==void 0?t.buttons:t.which)>0&&L()}function L(){document.body.style.cursor="default",h=!1}function Rt(t){if(h){h=!1,(t.buttons!==void 0?t.buttons:t.which)>0&&oe("drag");return}}window.wails={...ae(null),Capabilities:{}};fetch("/wails/capabilities").then(t=>{t.json().then(e=>{window.wails.Capabilities=e})});window._wails={dialogCallback:V,dialogErrorCallback:J,dispatchWailsEvent:Y,callCallback:I,callErrorCallback:H,endDrag:L};function ae(t){return{Clipboard:{...S},Application:{...E,GetWindowByName(e){return ae(e)}},System:O,Screens:R,Call:F,Plugin:G,WML:{Reload:z},Dialog:{Info:q,Warning:_,Error:K,Question:p,OpenFile:$,SaveFile:ee},Events:{Emit:W,On:B,Once:Z,OnMultiple:C,Off:Q,OffAll:X},Window:U(t)}}te();re();document.addEventListener("DOMContentLoaded",function(t){z()});})();
|