@wailsio/runtime 3.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/application.js +46 -0
- package/browser.js +24 -0
- package/calls.js +123 -0
- package/clipboard.js +35 -0
- package/contextmenu.js +96 -0
- package/dialogs.js +138 -0
- package/drag.js +125 -0
- package/events.js +134 -0
- package/flags.js +63 -0
- package/index.js +56 -0
- package/package.json +17 -0
- package/runtime.js +122 -0
- package/screens.js +45 -0
- package/system.js +118 -0
- package/types.d.ts +130 -0
- package/window.js +122 -0
- package/wml.js +148 -0
package/window.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* jshint esversion: 9 */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import("../api/types").Size} Size
|
|
15
|
+
* @typedef {import("../api/types").Position} Position
|
|
16
|
+
* @typedef {import("../api/types").Screen} Screen
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
20
|
+
|
|
21
|
+
const center = 0;
|
|
22
|
+
const setTitle = 1;
|
|
23
|
+
const fullscreen = 2;
|
|
24
|
+
const unFullscreen = 3;
|
|
25
|
+
const setSize = 4;
|
|
26
|
+
const size = 5;
|
|
27
|
+
const setMaxSize = 6;
|
|
28
|
+
const setMinSize = 7;
|
|
29
|
+
const setAlwaysOnTop = 8;
|
|
30
|
+
const setRelativePosition = 9;
|
|
31
|
+
const relativePosition = 10;
|
|
32
|
+
const screen = 11;
|
|
33
|
+
const hide = 12;
|
|
34
|
+
const maximise = 13;
|
|
35
|
+
const unMaximise = 14;
|
|
36
|
+
const toggleMaximise = 15;
|
|
37
|
+
const minimise = 16;
|
|
38
|
+
const unMinimise = 17;
|
|
39
|
+
const restore = 18;
|
|
40
|
+
const show = 19;
|
|
41
|
+
const close = 20;
|
|
42
|
+
const setBackgroundColour = 21;
|
|
43
|
+
const setResizable = 22;
|
|
44
|
+
const width = 23;
|
|
45
|
+
const height = 24;
|
|
46
|
+
const zoomIn = 25;
|
|
47
|
+
const zoomOut = 26;
|
|
48
|
+
const zoomReset = 27;
|
|
49
|
+
const getZoomLevel = 28;
|
|
50
|
+
const setZoomLevel = 29;
|
|
51
|
+
|
|
52
|
+
const thisWindow = newRuntimeCallerWithID(objectNames.Window, '');
|
|
53
|
+
|
|
54
|
+
function createWindow(call) {
|
|
55
|
+
return {
|
|
56
|
+
Get: (windowName) => createWindow(newRuntimeCallerWithID(objectNames.Window, windowName)),
|
|
57
|
+
Center: () => call(center),
|
|
58
|
+
SetTitle: (title) => call(setTitle, {title}),
|
|
59
|
+
Fullscreen: () => call(fullscreen),
|
|
60
|
+
UnFullscreen: () => call(unFullscreen),
|
|
61
|
+
SetSize: (width, height) => call(setSize, {width, height}),
|
|
62
|
+
Size: () => call(size),
|
|
63
|
+
SetMaxSize: (width, height) => call(setMaxSize, {width, height}),
|
|
64
|
+
SetMinSize: (width, height) => call(setMinSize, {width, height}),
|
|
65
|
+
SetAlwaysOnTop: (onTop) => call(setAlwaysOnTop, {alwaysOnTop: onTop}),
|
|
66
|
+
SetRelativePosition: (x, y) => call(setRelativePosition, {x, y}),
|
|
67
|
+
RelativePosition: () => call(relativePosition),
|
|
68
|
+
Screen: () => call(screen),
|
|
69
|
+
Hide: () => call(hide),
|
|
70
|
+
Maximise: () => call(maximise),
|
|
71
|
+
UnMaximise: () => call(unMaximise),
|
|
72
|
+
ToggleMaximise: () => call(toggleMaximise),
|
|
73
|
+
Minimise: () => call(minimise),
|
|
74
|
+
UnMinimise: () => call(unMinimise),
|
|
75
|
+
Restore: () => call(restore),
|
|
76
|
+
Show: () => call(show),
|
|
77
|
+
Close: () => call(close),
|
|
78
|
+
SetBackgroundColour: (r, g, b, a) => call(setBackgroundColour, {r, g, b, a}),
|
|
79
|
+
SetResizable: (resizable) => call(setResizable, {resizable}),
|
|
80
|
+
Width: () => call(width),
|
|
81
|
+
Height: () => call(height),
|
|
82
|
+
ZoomIn: () => call(zoomIn),
|
|
83
|
+
ZoomOut: () => call(zoomOut),
|
|
84
|
+
ZoomReset: () => call(zoomReset),
|
|
85
|
+
GetZoomLevel: () => call(getZoomLevel),
|
|
86
|
+
SetZoomLevel: (zoomLevel) => call(setZoomLevel, {zoomLevel}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets the specified window.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} windowName - The name of the window to get.
|
|
94
|
+
* @return {Object} - The specified window object.
|
|
95
|
+
*/
|
|
96
|
+
export function Get(windowName) {
|
|
97
|
+
return createWindow(newRuntimeCallerWithID(objectNames.Window, windowName));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns a map of all methods in the current window.
|
|
102
|
+
* @returns {Map} - A map of window methods.
|
|
103
|
+
*/
|
|
104
|
+
export function WindowMethods(targetWindow) {
|
|
105
|
+
// Create a new map to store methods
|
|
106
|
+
let result = new Map();
|
|
107
|
+
|
|
108
|
+
// Iterate over all properties of the window object
|
|
109
|
+
for (let method in targetWindow) {
|
|
110
|
+
// Check if the property is indeed a method (function)
|
|
111
|
+
if(typeof targetWindow[method] === 'function') {
|
|
112
|
+
// Add the method to the map
|
|
113
|
+
result.set(method, targetWindow[method]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
// Return the map of window methods
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
export default {
|
|
121
|
+
...Get('')
|
|
122
|
+
}
|
package/wml.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
|
|
2
|
+
import {Emit, WailsEvent} from "./events";
|
|
3
|
+
import {Question} from "./dialogs";
|
|
4
|
+
import {WindowMethods, Get} from "./window";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sends an event with the given name and optional data.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} eventName - The name of the event to send.
|
|
10
|
+
* @param {any} [data=null] - Optional data to send along with the event.
|
|
11
|
+
*
|
|
12
|
+
* @return {void}
|
|
13
|
+
*/
|
|
14
|
+
function sendEvent(eventName, data=null) {
|
|
15
|
+
let event = new WailsEvent(eventName, data);
|
|
16
|
+
Emit(event);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Adds event listeners to elements with `wml-event` attribute.
|
|
21
|
+
*
|
|
22
|
+
* @return {void}
|
|
23
|
+
*/
|
|
24
|
+
function addWMLEventListeners() {
|
|
25
|
+
const elements = document.querySelectorAll('[wml-event]');
|
|
26
|
+
elements.forEach(function (element) {
|
|
27
|
+
const eventType = element.getAttribute('wml-event');
|
|
28
|
+
const confirm = element.getAttribute('wml-confirm');
|
|
29
|
+
const trigger = element.getAttribute('wml-trigger') || "click";
|
|
30
|
+
|
|
31
|
+
let callback = function () {
|
|
32
|
+
if (confirm) {
|
|
33
|
+
Question({Title: "Confirm", Message:confirm, Detached: false, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
|
|
34
|
+
if (result !== "No") {
|
|
35
|
+
sendEvent(eventType);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
sendEvent(eventType);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Remove existing listeners
|
|
44
|
+
element.removeEventListener(trigger, callback);
|
|
45
|
+
|
|
46
|
+
// Add new listener
|
|
47
|
+
element.addEventListener(trigger, callback);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Calls a method on the window object.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} method - The name of the method to call on the window object.
|
|
55
|
+
*
|
|
56
|
+
* @return {void}
|
|
57
|
+
*/
|
|
58
|
+
function callWindowMethod(method) {
|
|
59
|
+
// TODO: Make this a parameter!
|
|
60
|
+
let windowName = '';
|
|
61
|
+
let targetWindow = Get('');
|
|
62
|
+
let methodMap = WindowMethods(targetWindow);
|
|
63
|
+
if (!methodMap.has(method)) {
|
|
64
|
+
console.log("Window method " + method + " not found");
|
|
65
|
+
}
|
|
66
|
+
methodMap.get(method)();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Adds window listeners for elements with the 'wml-window' attribute.
|
|
71
|
+
* Removes any existing listeners before adding new ones.
|
|
72
|
+
*
|
|
73
|
+
* @return {void}
|
|
74
|
+
*/
|
|
75
|
+
function addWMLWindowListeners() {
|
|
76
|
+
const elements = document.querySelectorAll('[wml-window]');
|
|
77
|
+
elements.forEach(function (element) {
|
|
78
|
+
const windowMethod = element.getAttribute('wml-window');
|
|
79
|
+
const confirm = element.getAttribute('wml-confirm');
|
|
80
|
+
const trigger = element.getAttribute('wml-trigger') || "click";
|
|
81
|
+
|
|
82
|
+
let callback = function () {
|
|
83
|
+
if (confirm) {
|
|
84
|
+
Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
|
|
85
|
+
if (result !== "No") {
|
|
86
|
+
callWindowMethod(windowMethod);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
callWindowMethod(windowMethod);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Remove existing listeners
|
|
95
|
+
element.removeEventListener(trigger, callback);
|
|
96
|
+
|
|
97
|
+
// Add new listener
|
|
98
|
+
element.addEventListener(trigger, callback);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Adds a listener to elements with the 'wml-openurl' attribute.
|
|
104
|
+
* When the specified trigger event is fired on any of these elements,
|
|
105
|
+
* the listener will open the URL specified by the 'wml-openurl' attribute.
|
|
106
|
+
* If a 'wml-confirm' attribute is provided, a confirmation dialog will be displayed,
|
|
107
|
+
* and the URL will only be opened if the user confirms.
|
|
108
|
+
*
|
|
109
|
+
* @return {void}
|
|
110
|
+
*/
|
|
111
|
+
function addWMLOpenBrowserListener() {
|
|
112
|
+
const elements = document.querySelectorAll('[wml-openurl]');
|
|
113
|
+
elements.forEach(function (element) {
|
|
114
|
+
const url = element.getAttribute('wml-openurl');
|
|
115
|
+
const confirm = element.getAttribute('wml-confirm');
|
|
116
|
+
const trigger = element.getAttribute('wml-trigger') || "click";
|
|
117
|
+
|
|
118
|
+
let callback = function () {
|
|
119
|
+
if (confirm) {
|
|
120
|
+
Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
|
|
121
|
+
if (result !== "No") {
|
|
122
|
+
void wails.Browser.OpenURL(url);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
void wails.Browser.OpenURL(url);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Remove existing listeners
|
|
131
|
+
element.removeEventListener(trigger, callback);
|
|
132
|
+
|
|
133
|
+
// Add new listener
|
|
134
|
+
element.addEventListener(trigger, callback);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Reloads the WML page by adding necessary event listeners and browser listeners.
|
|
140
|
+
*
|
|
141
|
+
* @return {void}
|
|
142
|
+
*/
|
|
143
|
+
export function reloadWML() {
|
|
144
|
+
console.log("Reloading WML");
|
|
145
|
+
addWMLEventListeners();
|
|
146
|
+
addWMLWindowListeners();
|
|
147
|
+
addWMLOpenBrowserListener();
|
|
148
|
+
}
|