5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 03:51:18 +08:00

Support application calls

This commit is contained in:
Lea Anthony 2023-02-04 19:49:30 +11:00
parent f26756be9c
commit 3bd6c34ae6
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
13 changed files with 232 additions and 77 deletions

View File

@ -0,0 +1,3 @@
# README
After updating any files in this directory, you must run `wails task build-runtime` to regenerate the compiled JS.

View File

@ -0,0 +1,27 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 9 */
import {newRuntimeCaller} from "./runtime";
let call = newRuntimeCaller("application");
export function Hide() {
return call("Hide");
}
export function Show() {
return call("Show");
}
export function Quit() {
return call("Quit");
}

View File

@ -9,11 +9,13 @@ The electron alternative for Go
*/
/* jshint esversion: 9 */
import {Info, Warning, Error, Question, OpenFile, SaveFile, dialogCallback, dialogErrorCallback, } from "./dialogs";
import {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs";
import * as Clipboard from './clipboard';
import * as Application from './application';
import {newWindow} from "./window";
import {dispatchCustomEvent, Emit, On, Off, OffAll, Once, OnMultiple} from "./events";
import {dispatchCustomEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./events";
// Internal wails endpoints
window.wails = {
@ -32,6 +34,9 @@ export function newRuntime(id) {
Clipboard: {
...Clipboard
},
Application: {
...Application
},
Dialog: {
Info,
Warning,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{var z=Object.defineProperty;var P=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})};var W=window.location.origin+"/wails/runtime";function p(t,e){let n=new URL(W);return n.searchParams.append("method",t),n.searchParams.append("args",JSON.stringify(e)),new Promise((i,r)=>{fetch(n).then(o=>{if(o.ok)return o.headers.get("content-type")&&o.headers.get("content-type").indexOf("application/json")!==-1?o.json():o.text();r(Error(o.statusText))}).then(o=>i(o)).catch(o=>r(o))})}function a(t,e){return!e||e===-1?function(n,i){return i=i||{},p(t+"."+n,i)}:function(n,i){return i=i||{},i.windowID=e,p(t+"."+n,i)}}var y="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var d=(t=21)=>{let e="",n=t;for(;n--;)e+=y[Math.random()*64|0];return e};var A=a("dialog"),u=new Map;function D(){let t;do t=d();while(u.has(t));return t}function x(t,e,n){let i=u.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),u.delete(t))}function h(t,e){let n=u.get(t);n&&(n.reject(e),u.delete(t))}function s(t,e){return new Promise((n,i)=>{let r=D();e=e||{},e["dialog-id"]=r,u.set(r,{resolve:n,reject:i}),A(t,e).catch(o=>{i(o),u.delete(r)})})}function w(t){return s("Info",t)}function S(t){return s("Warning",t)}function g(t){return s("Error",t)}function C(t){return s("Question",t)}function M(t){return s("OpenFile",t)}function O(t){return s("SaveFile",t)}var f={};P(f,{SetText:()=>I,Text:()=>B});var b=a("clipboard");function I(t){return b("SetText",{text:t})}function B(){return b("Text")}function v(t){let e=a("window",t);return{Center:()=>e("Center"),SetTitle:n=>e("SetTitle",{title:n}),Fullscreen:()=>e("Fullscreen"),UnFullscreen:()=>e("UnFullscreen"),SetSize:(n,i)=>e("SetSize",{width:n,height:i}),Size:()=>e("Size"),SetMaxSize:(n,i)=>e("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>e("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>e("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>e("SetPosition",{x:n,y:i}),Position:()=>e("Position"),Screen:()=>e("Screen"),Hide:()=>e("Hide"),Maximise:()=>e("Maximise"),Show:()=>e("Show"),ToggleMaximise:()=>e("ToggleMaximise"),UnMaximise:()=>e("UnMaximise"),Minimise:()=>e("Minimise"),UnMinimise:()=>e("UnMinimise"),SetBackgroundColour:(n,i,r,o)=>e("SetBackgroundColour",{r:n,g:i,b:r,a:o})}}var L=a("events"),m=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=r=>(n(r),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var l=new Map;function c(t,e,n){let i=l.get(t)||[],r=new m(t,e,n);return i.push(r),l.set(t,i),()=>N(r)}function E(t,e){return c(t,e,-1)}function T(t,e){return c(t,e,1)}function N(t){let e=t.eventName,n=l.get(e).filter(i=>i!==t);n.length===0?l.delete(e):l.set(e,n)}function k(t){console.log("dispatching event: ",{event:t});let e=l.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?l.delete(t.name):l.set(t.name,e))}}function R(t,...e){[t,...e].forEach(i=>{l.delete(i)})}function F(){l.clear()}function U(t){L("Emit",t)}window.wails={...Q(-1)};window._wails={dialogCallback:x,dialogErrorCallback:h,dispatchCustomEvent:k};function Q(t){return{Clipboard:{...f},Dialog:{Info:w,Warning:S,Error:g,Question:C,OpenFile:M,SaveFile:O},Events:{Emit:U,On:E,Once:T,OnMultiple:c,Off:R,OffAll:F},Window:v(t)}}console.log("Wails v3.0.0 Debug Mode Enabled");})();
(()=>{var W=Object.defineProperty;var x=(t,e)=>{for(var n in e)W(t,n,{get:e[n],enumerable:!0})};var y=window.location.origin+"/wails/runtime";function h(t,e){let n=new URL(y);return n.searchParams.append("method",t),n.searchParams.append("args",JSON.stringify(e)),new Promise((i,r)=>{fetch(n).then(o=>{if(o.ok)return o.headers.get("content-type")&&o.headers.get("content-type").indexOf("application/json")!==-1?o.json():o.text();r(Error(o.statusText))}).then(o=>i(o)).catch(o=>r(o))})}function l(t,e){return!e||e===-1?function(n,i){return i=i||{},h(t+"."+n,i)}:function(n,i){return i=i||{},i.windowID=e,h(t+"."+n,i)}}var D="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var w=(t=21)=>{let e="",n=t;for(;n--;)e+=D[Math.random()*64|0];return e};var I=l("dialog"),u=new Map;function Q(){let t;do t=w();while(u.has(t));return t}function S(t,e,n){let i=u.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),u.delete(t))}function g(t,e){let n=u.get(t);n&&(n.reject(e),u.delete(t))}function c(t,e){return new Promise((n,i)=>{let r=Q();e=e||{},e["dialog-id"]=r,u.set(r,{resolve:n,reject:i}),I(t,e).catch(o=>{i(o),u.delete(r)})})}function C(t){return c("Info",t)}function M(t){return c("Warning",t)}function O(t){return c("Error",t)}function b(t){return c("Question",t)}function v(t){return c("OpenFile",t)}function E(t){return c("SaveFile",t)}var f={};x(f,{SetText:()=>H,Text:()=>B});var T=l("clipboard");function H(t){return T("SetText",{text:t})}function B(){return T("Text")}var p={};x(p,{Hide:()=>L,Quit:()=>J,Show:()=>N});var m=l("application");function L(){return m("Hide")}function N(){return m("Show")}function J(){return m("Quit")}function k(t){let e=l("window",t);return{Center:()=>e("Center"),SetTitle:n=>e("SetTitle",{title:n}),Fullscreen:()=>e("Fullscreen"),UnFullscreen:()=>e("UnFullscreen"),SetSize:(n,i)=>e("SetSize",{width:n,height:i}),Size:()=>e("Size"),SetMaxSize:(n,i)=>e("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>e("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>e("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>e("SetPosition",{x:n,y:i}),Position:()=>e("Position"),Screen:()=>e("Screen"),Hide:()=>e("Hide"),Maximise:()=>e("Maximise"),Show:()=>e("Show"),ToggleMaximise:()=>e("ToggleMaximise"),UnMaximise:()=>e("UnMaximise"),Minimise:()=>e("Minimise"),UnMinimise:()=>e("UnMinimise"),SetBackgroundColour:(n,i,r,o)=>e("SetBackgroundColour",{r:n,g:i,b:r,a:o})}}var G=l("events"),d=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=r=>(n(r),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var a=new Map;function s(t,e,n){let i=a.get(t)||[],r=new d(t,e,n);return i.push(r),a.set(t,i),()=>_(r)}function R(t,e){return s(t,e,-1)}function F(t,e){return s(t,e,1)}function _(t){let e=t.eventName,n=a.get(e).filter(i=>i!==t);n.length===0?a.delete(e):a.set(e,n)}function U(t){console.log("dispatching event: ",{event:t});let e=a.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?a.delete(t.name):a.set(t.name,e))}}function z(t,...e){[t,...e].forEach(i=>{a.delete(i)})}function A(){a.clear()}function P(t){G("Emit",t)}window.wails={...j(-1)};window._wails={dialogCallback:S,dialogErrorCallback:g,dispatchCustomEvent:U};function j(t){return{Clipboard:{...f},Application:{...p},Dialog:{Info:C,Warning:M,Error:O,Question:b,OpenFile:v,SaveFile:E},Events:{Emit:P,On:R,Once:F,OnMultiple:s,Off:z,OffAll:A},Window:k(t)}}console.log("Wails v3.0.0 Debug Mode Enabled");})();

View File

@ -1 +1 @@
(()=>{var z=Object.defineProperty;var P=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})};var W=window.location.origin+"/wails/runtime";function p(t,e){let n=new URL(W);return n.searchParams.append("method",t),n.searchParams.append("args",JSON.stringify(e)),new Promise((i,r)=>{fetch(n).then(o=>{if(o.ok)return o.headers.get("content-type")&&o.headers.get("content-type").indexOf("application/json")!==-1?o.json():o.text();r(Error(o.statusText))}).then(o=>i(o)).catch(o=>r(o))})}function a(t,e){return!e||e===-1?function(n,i){return i=i||{},p(t+"."+n,i)}:function(n,i){return i=i||{},i.windowID=e,p(t+"."+n,i)}}var y="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var d=(t=21)=>{let e="",n=t;for(;n--;)e+=y[Math.random()*64|0];return e};var A=a("dialog"),u=new Map;function D(){let t;do t=d();while(u.has(t));return t}function x(t,e,n){let i=u.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),u.delete(t))}function h(t,e){let n=u.get(t);n&&(n.reject(e),u.delete(t))}function s(t,e){return new Promise((n,i)=>{let r=D();e=e||{},e["dialog-id"]=r,u.set(r,{resolve:n,reject:i}),A(t,e).catch(o=>{i(o),u.delete(r)})})}function w(t){return s("Info",t)}function S(t){return s("Warning",t)}function g(t){return s("Error",t)}function C(t){return s("Question",t)}function M(t){return s("OpenFile",t)}function O(t){return s("SaveFile",t)}var f={};P(f,{SetText:()=>I,Text:()=>B});var b=a("clipboard");function I(t){return b("SetText",{text:t})}function B(){return b("Text")}function v(t){let e=a("window",t);return{Center:()=>e("Center"),SetTitle:n=>e("SetTitle",{title:n}),Fullscreen:()=>e("Fullscreen"),UnFullscreen:()=>e("UnFullscreen"),SetSize:(n,i)=>e("SetSize",{width:n,height:i}),Size:()=>e("Size"),SetMaxSize:(n,i)=>e("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>e("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>e("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>e("SetPosition",{x:n,y:i}),Position:()=>e("Position"),Screen:()=>e("Screen"),Hide:()=>e("Hide"),Maximise:()=>e("Maximise"),Show:()=>e("Show"),ToggleMaximise:()=>e("ToggleMaximise"),UnMaximise:()=>e("UnMaximise"),Minimise:()=>e("Minimise"),UnMinimise:()=>e("UnMinimise"),SetBackgroundColour:(n,i,r,o)=>e("SetBackgroundColour",{r:n,g:i,b:r,a:o})}}var L=a("events"),m=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=r=>(n(r),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var l=new Map;function c(t,e,n){let i=l.get(t)||[],r=new m(t,e,n);return i.push(r),l.set(t,i),()=>N(r)}function E(t,e){return c(t,e,-1)}function T(t,e){return c(t,e,1)}function N(t){let e=t.eventName,n=l.get(e).filter(i=>i!==t);n.length===0?l.delete(e):l.set(e,n)}function k(t){console.log("dispatching event: ",{event:t});let e=l.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?l.delete(t.name):l.set(t.name,e))}}function R(t,...e){[t,...e].forEach(i=>{l.delete(i)})}function F(){l.clear()}function U(t){L("Emit",t)}window.wails={...Q(-1)};window._wails={dialogCallback:x,dialogErrorCallback:h,dispatchCustomEvent:k};function Q(t){return{Clipboard:{...f},Dialog:{Info:w,Warning:S,Error:g,Question:C,OpenFile:M,SaveFile:O},Events:{Emit:U,On:E,Once:T,OnMultiple:c,Off:R,OffAll:F},Window:v(t)}}console.log("Wails v3.0.0 Debug Mode Enabled");})();
(()=>{var W=Object.defineProperty;var x=(t,e)=>{for(var n in e)W(t,n,{get:e[n],enumerable:!0})};var y=window.location.origin+"/wails/runtime";function h(t,e){let n=new URL(y);return n.searchParams.append("method",t),n.searchParams.append("args",JSON.stringify(e)),new Promise((i,r)=>{fetch(n).then(o=>{if(o.ok)return o.headers.get("content-type")&&o.headers.get("content-type").indexOf("application/json")!==-1?o.json():o.text();r(Error(o.statusText))}).then(o=>i(o)).catch(o=>r(o))})}function l(t,e){return!e||e===-1?function(n,i){return i=i||{},h(t+"."+n,i)}:function(n,i){return i=i||{},i.windowID=e,h(t+"."+n,i)}}var D="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var w=(t=21)=>{let e="",n=t;for(;n--;)e+=D[Math.random()*64|0];return e};var I=l("dialog"),u=new Map;function Q(){let t;do t=w();while(u.has(t));return t}function S(t,e,n){let i=u.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),u.delete(t))}function g(t,e){let n=u.get(t);n&&(n.reject(e),u.delete(t))}function c(t,e){return new Promise((n,i)=>{let r=Q();e=e||{},e["dialog-id"]=r,u.set(r,{resolve:n,reject:i}),I(t,e).catch(o=>{i(o),u.delete(r)})})}function C(t){return c("Info",t)}function M(t){return c("Warning",t)}function O(t){return c("Error",t)}function b(t){return c("Question",t)}function v(t){return c("OpenFile",t)}function E(t){return c("SaveFile",t)}var f={};x(f,{SetText:()=>H,Text:()=>B});var T=l("clipboard");function H(t){return T("SetText",{text:t})}function B(){return T("Text")}var p={};x(p,{Hide:()=>L,Quit:()=>J,Show:()=>N});var m=l("application");function L(){return m("Hide")}function N(){return m("Show")}function J(){return m("Quit")}function k(t){let e=l("window",t);return{Center:()=>e("Center"),SetTitle:n=>e("SetTitle",{title:n}),Fullscreen:()=>e("Fullscreen"),UnFullscreen:()=>e("UnFullscreen"),SetSize:(n,i)=>e("SetSize",{width:n,height:i}),Size:()=>e("Size"),SetMaxSize:(n,i)=>e("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>e("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>e("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>e("SetPosition",{x:n,y:i}),Position:()=>e("Position"),Screen:()=>e("Screen"),Hide:()=>e("Hide"),Maximise:()=>e("Maximise"),Show:()=>e("Show"),ToggleMaximise:()=>e("ToggleMaximise"),UnMaximise:()=>e("UnMaximise"),Minimise:()=>e("Minimise"),UnMinimise:()=>e("UnMinimise"),SetBackgroundColour:(n,i,r,o)=>e("SetBackgroundColour",{r:n,g:i,b:r,a:o})}}var G=l("events"),d=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=r=>(n(r),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var a=new Map;function s(t,e,n){let i=a.get(t)||[],r=new d(t,e,n);return i.push(r),a.set(t,i),()=>_(r)}function R(t,e){return s(t,e,-1)}function F(t,e){return s(t,e,1)}function _(t){let e=t.eventName,n=a.get(e).filter(i=>i!==t);n.length===0?a.delete(e):a.set(e,n)}function U(t){console.log("dispatching event: ",{event:t});let e=a.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?a.delete(t.name):a.set(t.name,e))}}function z(t,...e){[t,...e].forEach(i=>{a.delete(i)})}function A(){a.clear()}function P(t){G("Emit",t)}window.wails={...j(-1)};window._wails={dialogCallback:S,dialogErrorCallback:g,dispatchCustomEvent:U};function j(t){return{Clipboard:{...f},Application:{...p},Dialog:{Info:C,Warning:M,Error:O,Question:b,OpenFile:v,SaveFile:E},Events:{Emit:P,On:R,Once:F,OnMultiple:s,Off:z,OffAll:A},Window:k(t)}}console.log("Wails v3.0.0 Debug Mode Enabled");})();

View File

@ -1 +1 @@
(()=>{var z=Object.defineProperty;var P=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})};var W=window.location.origin+"/wails/runtime";function p(t,e){let n=new URL(W);return n.searchParams.append("method",t),n.searchParams.append("args",JSON.stringify(e)),new Promise((i,r)=>{fetch(n).then(o=>{if(o.ok)return o.headers.get("content-type")&&o.headers.get("content-type").indexOf("application/json")!==-1?o.json():o.text();r(Error(o.statusText))}).then(o=>i(o)).catch(o=>r(o))})}function a(t,e){return!e||e===-1?function(n,i){return i=i||{},p(t+"."+n,i)}:function(n,i){return i=i||{},i.windowID=e,p(t+"."+n,i)}}var y="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var d=(t=21)=>{let e="",n=t;for(;n--;)e+=y[Math.random()*64|0];return e};var A=a("dialog"),u=new Map;function D(){let t;do t=d();while(u.has(t));return t}function x(t,e,n){let i=u.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),u.delete(t))}function h(t,e){let n=u.get(t);n&&(n.reject(e),u.delete(t))}function s(t,e){return new Promise((n,i)=>{let r=D();e=e||{},e["dialog-id"]=r,u.set(r,{resolve:n,reject:i}),A(t,e).catch(o=>{i(o),u.delete(r)})})}function w(t){return s("Info",t)}function S(t){return s("Warning",t)}function g(t){return s("Error",t)}function C(t){return s("Question",t)}function M(t){return s("OpenFile",t)}function O(t){return s("SaveFile",t)}var f={};P(f,{SetText:()=>I,Text:()=>B});var b=a("clipboard");function I(t){return b("SetText",{text:t})}function B(){return b("Text")}function v(t){let e=a("window",t);return{Center:()=>e("Center"),SetTitle:n=>e("SetTitle",{title:n}),Fullscreen:()=>e("Fullscreen"),UnFullscreen:()=>e("UnFullscreen"),SetSize:(n,i)=>e("SetSize",{width:n,height:i}),Size:()=>e("Size"),SetMaxSize:(n,i)=>e("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>e("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>e("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>e("SetPosition",{x:n,y:i}),Position:()=>e("Position"),Screen:()=>e("Screen"),Hide:()=>e("Hide"),Maximise:()=>e("Maximise"),Show:()=>e("Show"),ToggleMaximise:()=>e("ToggleMaximise"),UnMaximise:()=>e("UnMaximise"),Minimise:()=>e("Minimise"),UnMinimise:()=>e("UnMinimise"),SetBackgroundColour:(n,i,r,o)=>e("SetBackgroundColour",{r:n,g:i,b:r,a:o})}}var L=a("events"),m=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=r=>(n(r),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var l=new Map;function c(t,e,n){let i=l.get(t)||[],r=new m(t,e,n);return i.push(r),l.set(t,i),()=>N(r)}function E(t,e){return c(t,e,-1)}function T(t,e){return c(t,e,1)}function N(t){let e=t.eventName,n=l.get(e).filter(i=>i!==t);n.length===0?l.delete(e):l.set(e,n)}function k(t){console.log("dispatching event: ",{event:t});let e=l.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?l.delete(t.name):l.set(t.name,e))}}function R(t,...e){[t,...e].forEach(i=>{l.delete(i)})}function F(){l.clear()}function U(t){L("Emit",t)}window.wails={...Q(-1)};window._wails={dialogCallback:x,dialogErrorCallback:h,dispatchCustomEvent:k};function Q(t){return{Clipboard:{...f},Dialog:{Info:w,Warning:S,Error:g,Question:C,OpenFile:M,SaveFile:O},Events:{Emit:U,On:E,Once:T,OnMultiple:c,Off:R,OffAll:F},Window:v(t)}}console.log("Wails v3.0.0 Debug Mode Enabled");})();
(()=>{var W=Object.defineProperty;var x=(t,e)=>{for(var n in e)W(t,n,{get:e[n],enumerable:!0})};var y=window.location.origin+"/wails/runtime";function h(t,e){let n=new URL(y);return n.searchParams.append("method",t),n.searchParams.append("args",JSON.stringify(e)),new Promise((i,r)=>{fetch(n).then(o=>{if(o.ok)return o.headers.get("content-type")&&o.headers.get("content-type").indexOf("application/json")!==-1?o.json():o.text();r(Error(o.statusText))}).then(o=>i(o)).catch(o=>r(o))})}function l(t,e){return!e||e===-1?function(n,i){return i=i||{},h(t+"."+n,i)}:function(n,i){return i=i||{},i.windowID=e,h(t+"."+n,i)}}var D="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var w=(t=21)=>{let e="",n=t;for(;n--;)e+=D[Math.random()*64|0];return e};var I=l("dialog"),u=new Map;function Q(){let t;do t=w();while(u.has(t));return t}function S(t,e,n){let i=u.get(t);i&&(n?i.resolve(JSON.parse(e)):i.resolve(e),u.delete(t))}function g(t,e){let n=u.get(t);n&&(n.reject(e),u.delete(t))}function c(t,e){return new Promise((n,i)=>{let r=Q();e=e||{},e["dialog-id"]=r,u.set(r,{resolve:n,reject:i}),I(t,e).catch(o=>{i(o),u.delete(r)})})}function C(t){return c("Info",t)}function M(t){return c("Warning",t)}function O(t){return c("Error",t)}function b(t){return c("Question",t)}function v(t){return c("OpenFile",t)}function E(t){return c("SaveFile",t)}var f={};x(f,{SetText:()=>H,Text:()=>B});var T=l("clipboard");function H(t){return T("SetText",{text:t})}function B(){return T("Text")}var p={};x(p,{Hide:()=>L,Quit:()=>J,Show:()=>N});var m=l("application");function L(){return m("Hide")}function N(){return m("Show")}function J(){return m("Quit")}function k(t){let e=l("window",t);return{Center:()=>e("Center"),SetTitle:n=>e("SetTitle",{title:n}),Fullscreen:()=>e("Fullscreen"),UnFullscreen:()=>e("UnFullscreen"),SetSize:(n,i)=>e("SetSize",{width:n,height:i}),Size:()=>e("Size"),SetMaxSize:(n,i)=>e("SetMaxSize",{width:n,height:i}),SetMinSize:(n,i)=>e("SetMinSize",{width:n,height:i}),SetAlwaysOnTop:n=>e("SetAlwaysOnTop",{alwaysOnTop:n}),SetPosition:(n,i)=>e("SetPosition",{x:n,y:i}),Position:()=>e("Position"),Screen:()=>e("Screen"),Hide:()=>e("Hide"),Maximise:()=>e("Maximise"),Show:()=>e("Show"),ToggleMaximise:()=>e("ToggleMaximise"),UnMaximise:()=>e("UnMaximise"),Minimise:()=>e("Minimise"),UnMinimise:()=>e("UnMinimise"),SetBackgroundColour:(n,i,r,o)=>e("SetBackgroundColour",{r:n,g:i,b:r,a:o})}}var G=l("events"),d=class{constructor(e,n,i){this.eventName=e,this.maxCallbacks=i||-1,this.Callback=r=>(n(r),this.maxCallbacks===-1?!1:(this.maxCallbacks-=1,this.maxCallbacks===0))}};var a=new Map;function s(t,e,n){let i=a.get(t)||[],r=new d(t,e,n);return i.push(r),a.set(t,i),()=>_(r)}function R(t,e){return s(t,e,-1)}function F(t,e){return s(t,e,1)}function _(t){let e=t.eventName,n=a.get(e).filter(i=>i!==t);n.length===0?a.delete(e):a.set(e,n)}function U(t){console.log("dispatching event: ",{event:t});let e=a.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?a.delete(t.name):a.set(t.name,e))}}function z(t,...e){[t,...e].forEach(i=>{a.delete(i)})}function A(){a.clear()}function P(t){G("Emit",t)}window.wails={...j(-1)};window._wails={dialogCallback:S,dialogErrorCallback:g,dispatchCustomEvent:U};function j(t){return{Clipboard:{...f},Application:{...p},Dialog:{Info:C,Warning:M,Error:O,Question:b,OpenFile:v,SaveFile:E},Events:{Emit:P,On:R,Once:F,OnMultiple:s,Off:z,OffAll:A},Window:k(t)}}console.log("Wails v3.0.0 Debug Mode Enabled");})();

View File

@ -58,6 +58,8 @@ type platformApp interface {
setIcon(icon []byte)
on(id uint)
dispatchOnMainThread(id uint)
hide()
show()
}
// Messages sent from javascript get routed here
@ -417,3 +419,15 @@ func (a *App) dispatchEventToWindows(event *CustomEvent) {
window.dispatchCustomEvent(event)
}
}
func (a *App) Hide() {
if a.impl != nil {
a.impl.hide()
}
}
func (a *App) Show() {
if a.impl != nil {
a.impl.show()
}
}

View File

@ -113,6 +113,16 @@ static void setApplicationIcon(void *icon, int length) {
});
}
// Hide the application
static void hide(void) {
[NSApp hide:nil];
}
// Show the application
static void show(void) {
[NSApp unhide:nil];
}
*/
import "C"
import (
@ -127,6 +137,14 @@ type macosApp struct {
parent *App
}
func (m *macosApp) hide() {
C.hide()
}
func (m *macosApp) show() {
C.show()
}
func (m *macosApp) on(eventID uint) {
C.registerListener(C.uint(eventID))
}

View File

@ -63,6 +63,8 @@ func (m *MessageProcessor) HandleRuntimeCall(rw http.ResponseWriter, r *http.Req
m.processDialogMethod(method, rw, r, targetWindow, params)
case "events":
m.processEventsMethod(method, rw, r, targetWindow, params)
case "application":
m.processApplicationMethod(method, rw, r, targetWindow, params)
default:
m.httpError(rw, "Unknown runtime call: %s", object)
}

View File

@ -0,0 +1,23 @@
package application
import (
"net/http"
)
func (m *MessageProcessor) processApplicationMethod(method string, rw http.ResponseWriter, r *http.Request, window *WebviewWindow, params QueryParams) {
switch method {
case "Quit":
globalApplication.Quit()
m.ok(rw)
case "Hide":
globalApplication.Hide()
m.ok(rw)
case "Show":
globalApplication.Show()
m.ok(rw)
default:
m.httpError(rw, "Unknown event method: %s", method)
}
}