5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 10:01:06 +08:00
wails/v3/internal/runtime/runtime_production_desktop_linux.js
Lea Anthony 4c75b288bb
Add BrowserOpenURL and BrowserOpenFile to App.
Better WML assets for demo
Fix dialog responses.
Add `wml-openurl`
Rename: data-wml -> wml
Fix Alpha Feedback URL
2023-10-11 20:23:59 +11:00

2 lines
8.5 KiB
JavaScript

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