5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 07:21:32 +08:00

Support Screens API

This commit is contained in:
Lea Anthony 2023-02-15 18:56:41 +11:00
parent 045a830fbc
commit a5e10557c5
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
16 changed files with 347 additions and 119 deletions

View File

@ -6,7 +6,6 @@ Informal and incomplete list of things needed in v3.
- [ ] Generate Bindings - [ ] Generate Bindings
- [ ] Generate TS Models - [ ] Generate TS Models
- [ ] Port NSIS creation
- [ ] Dev Mode - [ ] Dev Mode
- [ ] Generate Info.Plist from `info.json` - [ ] Generate Info.Plist from `info.json`
@ -16,11 +15,11 @@ Informal and incomplete list of things needed in v3.
## Runtime ## Runtime
- [x] Pass window ID with window calls in JS - [x] Pass window ID with window calls in JS
- [ ] Implement alias for `window` in JS - [x] Implement alias for `window` in JS
- [ ] Implement runtime dispatcher - [x] Implement runtime dispatcher
- [ ] Log - [x] Log
- [x] Same Window - [x] Same Window
- [x] Other Window - [ ] Other Window
- [x] Dialogs - [x] Dialogs
- [x] Info - [x] Info
- [x] Warning - [x] Warning
@ -29,9 +28,9 @@ Informal and incomplete list of things needed in v3.
- [x] OpenFile - [x] OpenFile
- [x] SaveFile - [x] SaveFile
- [x] Events - [x] Events
- [ ] Screens - [x] Screens
- [x] Clipboard - [x] Clipboard
- [ ] Application - [x] Application
- [ ] Create `.d.ts` file - [ ] Create `.d.ts` file
## Templates ## Templates

View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Screens Demo</title>
<style>
body {
padding-top: 75px;
margin: 0 auto;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
text-align: -webkit-center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif
}
article {
padding: 1em;
}
.monitor {
width: 300px;
height: 150px;
overflow-y: scroll;
border: solid 1em #333;
border-radius: .5em;
background: lightblue;
}
.monitor::-webkit-scrollbar {
width: 15px;
}
.monitor::-webkit-scrollbar-thumb {
background: #666;
}
::-webkit-scrollbar-track {
background-color: #888;
}
.center {
text-align: -webkit-center;
}
</style>
</head>
<body>
<script>
let monitors = wails.Screens.GetAll();
monitors.then((result) => {
console.log({result})
let html = "";
for (let i = 0; i < result.length; i++) {
html += "<article class='center'><div class='monitor'><div style='padding:5px;'>";
let hidpi = result[i].scale === 2 ? " (HiDPI)" : "";
html += "<h3 class='center'>"+result[i].name+"</h3>";
html += "<h4 class='center'>"+hidpi+"</h4>";
html += "<h4 class='center'>"+result[i].size.width+"x"+result[i].size.height+"</h4>";
html += "</div></div></article>";
}
document.body.innerHTML = html;
})
</script>
</body>
</html>

View File

@ -0,0 +1,43 @@
package main
import (
"embed"
_ "embed"
"log"
"github.com/wailsapp/wails/v3/pkg/application"
)
//go:embed assets/*
var assets embed.FS
func main() {
app := application.New(application.Options{
Name: "Screen Demo",
Description: "A demo of the Screen API",
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{
Title: "Screen Demo",
Width: 800,
Height: 600,
Assets: application.AssetOptions{
FS: assets,
},
Mac: application.MacWindow{
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInsetUnified,
InvisibleTitleBarHeight: 50,
},
})
err := app.Run()
if err != nil {
log.Fatal(err.Error())
}
}

View File

@ -13,6 +13,7 @@ The electron alternative for Go
import * as Clipboard from './clipboard'; import * as Clipboard from './clipboard';
import * as Application from './application'; import * as Application from './application';
import * as Log from './log'; import * as Log from './log';
import * as Screens from './screens';
import {newWindow} from "./window"; import {newWindow} from "./window";
import {dispatchCustomEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./events"; import {dispatchCustomEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./events";
@ -40,6 +41,7 @@ export function newRuntime(id) {
...Application ...Application
}, },
Log, Log,
Screens,
Dialog: { Dialog: {
Info, Info,
Warning, Warning,

View File

@ -23,7 +23,7 @@ function runtimeCall(method, args) {
.then(response => { .then(response => {
if (response.ok) { if (response.ok) {
// check content type // check content type
if (response.headers.get("content-type") && response.headers.get("content-type").indexOf("application/json") !== -1) { if (response.headers.get("Content-Type") && response.headers.get("Content-Type").indexOf("application/json") !== -1) {
return response.json(); return response.json();
} else { } else {
return response.text(); return response.text();

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("screens");
export function GetAll() {
return call("GetAll");
}
export function GetPrimary() {
return call("GetPrimary");
}
export function GetCurrent() {
return call("GetCurrent");
}

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

View File

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

View File

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

View File

@ -69,6 +69,8 @@ func (m *MessageProcessor) HandleRuntimeCall(rw http.ResponseWriter, r *http.Req
m.processLogMethod(method, rw, r, targetWindow, params) m.processLogMethod(method, rw, r, targetWindow, params)
case "contextmenu": case "contextmenu":
m.processContextMenuMethod(method, rw, r, targetWindow, params) m.processContextMenuMethod(method, rw, r, targetWindow, params)
case "screens":
m.processScreensMethod(method, rw, r, targetWindow, params)
default: default:
m.httpError(rw, "Unknown runtime call: %s", object) m.httpError(rw, "Unknown runtime call: %s", object)
} }
@ -88,6 +90,7 @@ func (m *MessageProcessor) Info(message string, args ...any) {
} }
func (m *MessageProcessor) json(rw http.ResponseWriter, data any) { func (m *MessageProcessor) json(rw http.ResponseWriter, data any) {
rw.Header().Set("Content-Type", "application/json")
// convert data to json // convert data to json
var jsonPayload = []byte("{}") var jsonPayload = []byte("{}")
var err error var err error
@ -103,7 +106,6 @@ func (m *MessageProcessor) json(rw http.ResponseWriter, data any) {
m.Error("Unable to write json payload. Please report this to the Wails team! Error: %s", err) m.Error("Unable to write json payload. Please report this to the Wails team! Error: %s", err)
return return
} }
rw.Header().Set("Content-Type", "application/json")
m.ok(rw) m.ok(rw)
} }
@ -114,7 +116,7 @@ func (m *MessageProcessor) text(rw http.ResponseWriter, data string) {
return return
} }
rw.Header().Set("Content-Type", "text/plain") rw.Header().Set("Content-Type", "text/plain")
m.ok(rw) rw.WriteHeader(http.StatusOK)
} }
func (m *MessageProcessor) ok(rw http.ResponseWriter) { func (m *MessageProcessor) ok(rw http.ResponseWriter) {

View File

@ -0,0 +1,35 @@
package application
import (
"net/http"
)
func (m *MessageProcessor) processScreensMethod(method string, rw http.ResponseWriter, _ *http.Request, _ *WebviewWindow, _ QueryParams) {
switch method {
case "GetAll":
screens, err := globalApplication.GetScreens()
if err != nil {
m.Error("GetAll: %s", err.Error())
return
}
m.json(rw, screens)
case "GetPrimary":
screen, err := globalApplication.GetPrimaryScreen()
if err != nil {
m.Error("GetPrimary: %s", err.Error())
return
}
m.json(rw, screen)
case "GetCurrent":
screen, err := globalApplication.CurrentWindow().GetScreen()
if err != nil {
m.Error("GetCurrent: %s", err.Error())
return
}
m.json(rw, screen)
default:
m.httpError(rw, "Unknown clipboard method: %s", method)
}
}

View File

@ -1,26 +1,26 @@
package application package application
type Screen struct { type Screen struct {
ID string // A unique identifier for the display ID string `json:"id,omitempty"` // A unique identifier for the display
Name string // The name of the display Name string `json:"name,omitempty"` // The name of the display
Scale float32 // The scale factor of the display Scale float32 `json:"scale,omitempty"` // The scale factor of the display
X int // The x-coordinate of the top-left corner of the rectangle X int `json:"x,omitempty"` // The x-coordinate of the top-left corner of the rectangle
Y int // The y-coordinate of the top-left corner of the rectangle Y int `json:"y,omitempty"` // The y-coordinate of the top-left corner of the rectangle
Size Size // The size of the display Size Size `json:"size"` // The size of the display
Bounds Rect // The bounds of the display Bounds Rect `json:"bounds"` // The bounds of the display
WorkArea Rect // The work area of the display WorkArea Rect `json:"work_area"` // The work area of the display
IsPrimary bool // Whether this is the primary display IsPrimary bool `json:"is_primary,omitempty"` // Whether this is the primary display
Rotation float32 // The rotation of the display Rotation float32 `json:"rotation,omitempty"` // The rotation of the display
} }
type Rect struct { type Rect struct {
X int X int `json:"x,omitempty"`
Y int Y int `json:"y,omitempty"`
Width int Width int `json:"width,omitempty"`
Height int Height int `json:"height,omitempty"`
} }
type Size struct { type Size struct {
Width int Width int `json:"width,omitempty"`
Height int Height int `json:"height,omitempty"`
} }

View File

@ -212,12 +212,9 @@ void windowSetResizable(void* nsWindow, bool resizable) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
WebviewWindow* window = (WebviewWindow*)nsWindow; WebviewWindow* window = (WebviewWindow*)nsWindow;
if (resizable) { if (resizable) {
printf("Setting resizable to true\n");
NSWindowStyleMask styleMask = [window styleMask] | NSWindowStyleMaskResizable; NSWindowStyleMask styleMask = [window styleMask] | NSWindowStyleMaskResizable;
[window setStyleMask:styleMask]; [window setStyleMask:styleMask];
} else { } else {
printf("Setting resizable to false\n");
NSWindowStyleMask styleMask = [window styleMask] & ~NSWindowStyleMaskResizable; NSWindowStyleMask styleMask = [window styleMask] & ~NSWindowStyleMaskResizable;
[window setStyleMask:styleMask]; [window setStyleMask:styleMask];
} }