@wailsio/runtime 3.0.0-alpha.20 → 3.0.0-alpha.21
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/docs/{functions/Window.Size.html → assets/icons.js} +15 -2
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +4 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +2 -1
- package/docs/classes/Events.WailsEvent.html +4 -4
- package/docs/functions/Application.Hide.html +2 -2
- package/docs/functions/Application.Quit.html +2 -2
- package/docs/functions/Application.Show.html +2 -2
- package/docs/functions/Browser.OpenURL.html +3 -3
- package/docs/functions/Call.ByID.html +4 -4
- package/docs/functions/Call.ByName.html +4 -4
- package/docs/functions/Call.Call.html +3 -3
- package/docs/functions/Call.Plugin.html +5 -5
- package/docs/functions/Clipboard.SetText.html +3 -3
- package/docs/functions/Clipboard.Text.html +2 -2
- package/docs/functions/Dialogs.Error.html +2 -2
- package/docs/functions/Dialogs.Info.html +2 -2
- package/docs/functions/Dialogs.OpenFile.html +2 -2
- package/docs/functions/Dialogs.Question.html +2 -2
- package/docs/functions/Dialogs.SaveFile.html +2 -2
- package/docs/functions/Dialogs.Warning.html +2 -2
- package/docs/functions/Events.Emit.html +3 -3
- package/docs/functions/Events.Off.html +4 -4
- package/docs/functions/Events.OffAll.html +2 -2
- package/docs/functions/Events.On.html +4 -4
- package/docs/functions/Events.OnMultiple.html +5 -5
- package/docs/functions/Events.Once.html +4 -4
- package/docs/functions/Events.setup.html +1 -1
- package/docs/functions/Flags.GetFlag.html +3 -3
- package/docs/functions/Screens.GetAll.html +3 -3
- package/docs/functions/Screens.GetCurrent.html +3 -3
- package/docs/functions/Screens.GetPrimary.html +3 -3
- package/docs/functions/System.Capabilities.html +2 -2
- package/docs/functions/System.Environment.html +2 -2
- package/docs/functions/System.IsAMD64.html +2 -2
- package/docs/functions/System.IsARM.html +2 -2
- package/docs/functions/System.IsARM64.html +2 -2
- package/docs/functions/System.IsDarkMode.html +2 -2
- package/docs/functions/System.IsDebug.html +1 -1
- package/docs/functions/System.IsLinux.html +2 -2
- package/docs/functions/System.IsMac.html +2 -2
- package/docs/functions/System.IsWindows.html +2 -2
- package/docs/functions/System.invoke.html +1 -1
- package/docs/functions/WML.Enable.html +2 -0
- package/docs/functions/WML.Reload.html +2 -2
- package/docs/index.html +2 -2
- package/docs/interfaces/Dialogs.Button.html +7 -7
- package/docs/interfaces/Dialogs.FileFilter.html +5 -5
- package/docs/interfaces/Dialogs.MessageDialogOptions.html +9 -9
- package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +33 -33
- package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +35 -35
- package/docs/interfaces/Screens.Position.html +5 -5
- package/docs/interfaces/Screens.Rect.html +9 -9
- package/docs/interfaces/Screens.Screen.html +19 -19
- package/docs/interfaces/Screens.Size.html +5 -5
- package/docs/interfaces/System.EnvironmentInfo.html +11 -5
- package/docs/interfaces/System.OSInfo.html +9 -0
- package/docs/modules/Application.html +4 -4
- package/docs/modules/Browser.html +2 -2
- package/docs/modules/Call.html +5 -5
- package/docs/modules/Clipboard.html +3 -3
- package/docs/modules/Dialogs.html +12 -12
- package/docs/modules/Events.html +10 -10
- package/docs/modules/Flags.html +2 -2
- package/docs/modules/Screens.html +8 -9
- package/docs/modules/System.html +14 -13
- package/docs/modules/WML.html +3 -2
- package/docs/modules.html +12 -12
- package/docs/variables/Events.Types.html +1 -1
- package/docs/variables/Window.html +2 -0
- package/package.json +31 -31
- package/src/application.js +46 -46
- package/src/browser.js +24 -24
- package/src/calls.js +180 -161
- package/src/clipboard.js +35 -35
- package/src/contextmenu.js +97 -97
- package/src/dialogs.js +200 -200
- package/src/drag.js +119 -125
- package/src/event_types.js +5 -0
- package/src/events.js +140 -140
- package/src/flags.js +25 -25
- package/src/index.js +46 -95
- package/src/runtime.js +123 -122
- package/src/screens.js +77 -83
- package/src/system.js +128 -117
- package/src/utils.js +86 -0
- package/src/window.js +638 -316
- package/src/wml.js +250 -171
- package/tsconfig.json +19 -19
- package/types/event_types.d.ts +5 -0
- package/types/events.d.ts +5 -0
- package/types/index.d.ts +2 -2
- package/types/runtime.d.ts +1 -0
- package/types/screens.d.ts +1 -5
- package/types/system.d.ts +44 -4
- package/types/utils.d.ts +14 -0
- package/types/window.d.ts +400 -133
- package/types/wml.d.ts +6 -0
- package/docs/functions/Window.Center.html +0 -2
- package/docs/functions/Window.Close.html +0 -2
- package/docs/functions/Window.Fullscreen.html +0 -2
- package/docs/functions/Window.Get.html +0 -6
- package/docs/functions/Window.GetZoomLevel.html +0 -2
- package/docs/functions/Window.Height.html +0 -2
- package/docs/functions/Window.Hide.html +0 -2
- package/docs/functions/Window.Maximise.html +0 -2
- package/docs/functions/Window.Minimise.html +0 -2
- package/docs/functions/Window.RelativePosition.html +0 -2
- package/docs/functions/Window.Restore.html +0 -2
- package/docs/functions/Window.Screen-1.html +0 -2
- package/docs/functions/Window.SetAlwaysOnTop.html +0 -3
- package/docs/functions/Window.SetBackgroundColour.html +0 -6
- package/docs/functions/Window.SetMaxSize.html +0 -4
- package/docs/functions/Window.SetMinSize.html +0 -4
- package/docs/functions/Window.SetRelativePosition.html +0 -4
- package/docs/functions/Window.SetResizable.html +0 -3
- package/docs/functions/Window.SetSize.html +0 -4
- package/docs/functions/Window.SetTitle.html +0 -3
- package/docs/functions/Window.SetZoomLevel.html +0 -3
- package/docs/functions/Window.Show.html +0 -2
- package/docs/functions/Window.ToggleMaximise.html +0 -2
- package/docs/functions/Window.UnMaximise.html +0 -2
- package/docs/functions/Window.UnMinimise.html +0 -2
- package/docs/functions/Window.Width.html +0 -2
- package/docs/functions/Window.ZoomIn.html +0 -2
- package/docs/functions/Window.ZoomOut.html +0 -2
- package/docs/functions/Window.ZoomReset.html +0 -2
- package/docs/modules/Window.html +0 -32
- package/docs/types/Screens.Rotation.html +0 -2
- package/src/log.js +0 -13
package/src/drag.js
CHANGED
|
@@ -1,125 +1,119 @@
|
|
|
1
|
-
/*
|
|
2
|
-
_ __ _ __
|
|
3
|
-
| | / /___ _(_) /____
|
|
4
|
-
| | /| / / __ `/ / / ___/
|
|
5
|
-
| |/ |/ / /_/ / / (__ )
|
|
6
|
-
|__/|__/\__,_/_/_/____/
|
|
7
|
-
The electron alternative for Go
|
|
8
|
-
(c) Lea Anthony 2019-present
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
window.
|
|
21
|
-
|
|
22
|
-
window.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if(
|
|
49
|
-
invoke(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
let
|
|
103
|
-
let
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
else if (
|
|
118
|
-
else if (
|
|
119
|
-
|
|
120
|
-
else if (topCorner && rightCorner) setResize("ne-resize");
|
|
121
|
-
else if (leftBorder) setResize("w-resize");
|
|
122
|
-
else if (topBorder) setResize("n-resize");
|
|
123
|
-
else if (bottomBorder) setResize("s-resize");
|
|
124
|
-
else if (rightBorder) setResize("e-resize");
|
|
125
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
/* jshint esversion: 9 */
|
|
11
|
+
import {invoke, IsWindows} from "./system";
|
|
12
|
+
import {GetFlag} from "./flags";
|
|
13
|
+
|
|
14
|
+
// Setup
|
|
15
|
+
let shouldDrag = false;
|
|
16
|
+
let resizable = false;
|
|
17
|
+
let resizeEdge = null;
|
|
18
|
+
let defaultCursor = "auto";
|
|
19
|
+
|
|
20
|
+
window._wails = window._wails || {};
|
|
21
|
+
|
|
22
|
+
window._wails.setResizable = function(value) {
|
|
23
|
+
resizable = value;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
window._wails.endDrag = function() {
|
|
27
|
+
document.body.style.cursor = 'default';
|
|
28
|
+
shouldDrag = false;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
window.addEventListener('mousedown', onMouseDown);
|
|
32
|
+
window.addEventListener('mousemove', onMouseMove);
|
|
33
|
+
window.addEventListener('mouseup', onMouseUp);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function dragTest(e) {
|
|
37
|
+
let val = window.getComputedStyle(e.target).getPropertyValue("--wails-draggable");
|
|
38
|
+
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
|
39
|
+
if (!val || val === "" || val.trim() !== "drag" || mousePressed === 0) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return e.detail === 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function onMouseDown(e) {
|
|
46
|
+
|
|
47
|
+
// Check for resizing
|
|
48
|
+
if (resizeEdge) {
|
|
49
|
+
invoke("resize:" + resizeEdge);
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (dragTest(e)) {
|
|
55
|
+
// This checks for clicks on the scroll bar
|
|
56
|
+
if (e.offsetX > e.target.clientWidth || e.offsetY > e.target.clientHeight) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
shouldDrag = true;
|
|
60
|
+
} else {
|
|
61
|
+
shouldDrag = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function onMouseUp() {
|
|
66
|
+
shouldDrag = false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function setResize(cursor) {
|
|
70
|
+
document.documentElement.style.cursor = cursor || defaultCursor;
|
|
71
|
+
resizeEdge = cursor;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function onMouseMove(e) {
|
|
75
|
+
if (shouldDrag) {
|
|
76
|
+
shouldDrag = false;
|
|
77
|
+
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
|
78
|
+
if (mousePressed > 0) {
|
|
79
|
+
invoke("drag");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!resizable || !IsWindows()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (defaultCursor == null) {
|
|
87
|
+
defaultCursor = document.documentElement.style.cursor;
|
|
88
|
+
}
|
|
89
|
+
let resizeHandleHeight = GetFlag("system.resizeHandleHeight") || 5;
|
|
90
|
+
let resizeHandleWidth = GetFlag("system.resizeHandleWidth") || 5;
|
|
91
|
+
|
|
92
|
+
// Extra pixels for the corner areas
|
|
93
|
+
let cornerExtra = GetFlag("resizeCornerExtra") || 10;
|
|
94
|
+
|
|
95
|
+
let rightBorder = window.outerWidth - e.clientX < resizeHandleWidth;
|
|
96
|
+
let leftBorder = e.clientX < resizeHandleWidth;
|
|
97
|
+
let topBorder = e.clientY < resizeHandleHeight;
|
|
98
|
+
let bottomBorder = window.outerHeight - e.clientY < resizeHandleHeight;
|
|
99
|
+
|
|
100
|
+
// Adjust for corners
|
|
101
|
+
let rightCorner = window.outerWidth - e.clientX < (resizeHandleWidth + cornerExtra);
|
|
102
|
+
let leftCorner = e.clientX < (resizeHandleWidth + cornerExtra);
|
|
103
|
+
let topCorner = e.clientY < (resizeHandleHeight + cornerExtra);
|
|
104
|
+
let bottomCorner = window.outerHeight - e.clientY < (resizeHandleHeight + cornerExtra);
|
|
105
|
+
|
|
106
|
+
// If we aren't on an edge, but were, reset the cursor to default
|
|
107
|
+
if (!leftBorder && !rightBorder && !topBorder && !bottomBorder && resizeEdge !== undefined) {
|
|
108
|
+
setResize();
|
|
109
|
+
}
|
|
110
|
+
// Adjusted for corner areas
|
|
111
|
+
else if (rightCorner && bottomCorner) setResize("se-resize");
|
|
112
|
+
else if (leftCorner && bottomCorner) setResize("sw-resize");
|
|
113
|
+
else if (leftCorner && topCorner) setResize("nw-resize");
|
|
114
|
+
else if (topCorner && rightCorner) setResize("ne-resize");
|
|
115
|
+
else if (leftBorder) setResize("w-resize");
|
|
116
|
+
else if (topBorder) setResize("n-resize");
|
|
117
|
+
else if (bottomBorder) setResize("s-resize");
|
|
118
|
+
else if (rightBorder) setResize("e-resize");
|
|
119
|
+
}
|
package/src/event_types.js
CHANGED
|
@@ -155,6 +155,11 @@ export const EventTypes = {
|
|
|
155
155
|
},
|
|
156
156
|
Linux: {
|
|
157
157
|
SystemThemeChanged: "linux:SystemThemeChanged",
|
|
158
|
+
WindowLoadChanged: "linux:WindowLoadChanged",
|
|
159
|
+
WindowDeleteEvent: "linux:WindowDeleteEvent",
|
|
160
|
+
WindowFocusIn: "linux:WindowFocusIn",
|
|
161
|
+
WindowFocusOut: "linux:WindowFocusOut",
|
|
162
|
+
ApplicationStartup: "linux:ApplicationStartup",
|
|
158
163
|
},
|
|
159
164
|
Common: {
|
|
160
165
|
ApplicationStarted: "common:ApplicationStarted",
|
package/src/events.js
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
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("./types").WailsEvent} WailsEvent
|
|
15
|
-
*/
|
|
16
|
-
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
17
|
-
|
|
18
|
-
import {EventTypes} from "./event_types";
|
|
19
|
-
export const Types = EventTypes;
|
|
20
|
-
|
|
21
|
-
// Setup
|
|
22
|
-
window._wails = window._wails || {};
|
|
23
|
-
window._wails.dispatchWailsEvent = dispatchWailsEvent;
|
|
24
|
-
|
|
25
|
-
const call = newRuntimeCallerWithID(objectNames.Events, '');
|
|
26
|
-
const EmitMethod = 0;
|
|
27
|
-
const eventListeners = new Map();
|
|
28
|
-
|
|
29
|
-
class Listener {
|
|
30
|
-
constructor(eventName, callback, maxCallbacks) {
|
|
31
|
-
this.eventName = eventName;
|
|
32
|
-
this.maxCallbacks = maxCallbacks || -1;
|
|
33
|
-
this.Callback = (data) => {
|
|
34
|
-
callback(data);
|
|
35
|
-
if (this.maxCallbacks === -1) return false;
|
|
36
|
-
this.maxCallbacks -= 1;
|
|
37
|
-
return this.maxCallbacks === 0;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class WailsEvent {
|
|
43
|
-
constructor(name, data = null) {
|
|
44
|
-
this.name = name;
|
|
45
|
-
this.data = data;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function setup() {
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function dispatchWailsEvent(event) {
|
|
53
|
-
let listeners = eventListeners.get(event.name);
|
|
54
|
-
if (listeners) {
|
|
55
|
-
let toRemove = listeners.filter(listener => {
|
|
56
|
-
let remove = listener.Callback(event);
|
|
57
|
-
if (remove) return true;
|
|
58
|
-
});
|
|
59
|
-
if (toRemove.length > 0) {
|
|
60
|
-
listeners = listeners.filter(l => !toRemove.includes(l));
|
|
61
|
-
if (listeners.length === 0) eventListeners.delete(event.name);
|
|
62
|
-
else eventListeners.set(event.name, listeners);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Register a callback function to be called multiple times for a specific event.
|
|
69
|
-
*
|
|
70
|
-
* @param {string} eventName - The name of the event to register the callback for.
|
|
71
|
-
* @param {function} callback - The callback function to be called when the event is triggered.
|
|
72
|
-
* @param {number} maxCallbacks - The maximum number of times the callback can be called for the event. Once the maximum number is reached, the callback will no longer be called.
|
|
73
|
-
*
|
|
74
|
-
@return {function} - A function that, when called, will unregister the callback from the event.
|
|
75
|
-
*/
|
|
76
|
-
export function OnMultiple(eventName, callback, maxCallbacks) {
|
|
77
|
-
let listeners = eventListeners.get(eventName) || [];
|
|
78
|
-
const thisListener = new Listener(eventName, callback, maxCallbacks);
|
|
79
|
-
listeners.push(thisListener);
|
|
80
|
-
eventListeners.set(eventName, listeners);
|
|
81
|
-
return () => listenerOff(thisListener);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Registers a callback function to be executed when the specified event occurs.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} eventName - The name of the event.
|
|
88
|
-
* @param {function} callback - The callback function to be executed. It takes no parameters.
|
|
89
|
-
* @return {function} - A function that, when called, will unregister the callback from the event. */
|
|
90
|
-
export function On(eventName, callback) { return OnMultiple(eventName, callback, -1); }
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Registers a callback function to be executed only once for the specified event.
|
|
94
|
-
*
|
|
95
|
-
* @param {string} eventName - The name of the event.
|
|
96
|
-
* @param {function} callback - The function to be executed when the event occurs.
|
|
97
|
-
* @return {function} - A function that, when called, will unregister the callback from the event.
|
|
98
|
-
*/
|
|
99
|
-
export function Once(eventName, callback) { return OnMultiple(eventName, callback, 1); }
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Removes the specified listener from the event listeners collection.
|
|
103
|
-
* If all listeners for the event are removed, the event key is deleted from the collection.
|
|
104
|
-
*
|
|
105
|
-
* @param {Object} listener - The listener to be removed.
|
|
106
|
-
*/
|
|
107
|
-
function listenerOff(listener) {
|
|
108
|
-
const eventName = listener.eventName;
|
|
109
|
-
let listeners = eventListeners.get(eventName).filter(l => l !== listener);
|
|
110
|
-
if (listeners.length === 0) eventListeners.delete(eventName);
|
|
111
|
-
else eventListeners.set(eventName, listeners);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Removes event listeners for the specified event names.
|
|
117
|
-
*
|
|
118
|
-
* @param {string} eventName - The name of the event to remove listeners for.
|
|
119
|
-
* @param {...string} additionalEventNames - Additional event names to remove listeners for.
|
|
120
|
-
* @return {undefined}
|
|
121
|
-
*/
|
|
122
|
-
export function Off(eventName, ...additionalEventNames) {
|
|
123
|
-
let eventsToRemove = [eventName, ...additionalEventNames];
|
|
124
|
-
eventsToRemove.forEach(eventName => eventListeners.delete(eventName));
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Removes all event listeners.
|
|
128
|
-
*
|
|
129
|
-
* @function OffAll
|
|
130
|
-
* @returns {void}
|
|
131
|
-
*/
|
|
132
|
-
export function OffAll() { eventListeners.clear(); }
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Emits an event using the given event name.
|
|
136
|
-
*
|
|
137
|
-
* @param {WailsEvent} event - The name of the event to emit.
|
|
138
|
-
* @returns {any} - The result of the emitted event.
|
|
139
|
-
*/
|
|
140
|
-
export function Emit(event) { return call(EmitMethod, event); }
|
|
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("./types").WailsEvent} WailsEvent
|
|
15
|
+
*/
|
|
16
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
17
|
+
|
|
18
|
+
import {EventTypes} from "./event_types";
|
|
19
|
+
export const Types = EventTypes;
|
|
20
|
+
|
|
21
|
+
// Setup
|
|
22
|
+
window._wails = window._wails || {};
|
|
23
|
+
window._wails.dispatchWailsEvent = dispatchWailsEvent;
|
|
24
|
+
|
|
25
|
+
const call = newRuntimeCallerWithID(objectNames.Events, '');
|
|
26
|
+
const EmitMethod = 0;
|
|
27
|
+
const eventListeners = new Map();
|
|
28
|
+
|
|
29
|
+
class Listener {
|
|
30
|
+
constructor(eventName, callback, maxCallbacks) {
|
|
31
|
+
this.eventName = eventName;
|
|
32
|
+
this.maxCallbacks = maxCallbacks || -1;
|
|
33
|
+
this.Callback = (data) => {
|
|
34
|
+
callback(data);
|
|
35
|
+
if (this.maxCallbacks === -1) return false;
|
|
36
|
+
this.maxCallbacks -= 1;
|
|
37
|
+
return this.maxCallbacks === 0;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class WailsEvent {
|
|
43
|
+
constructor(name, data = null) {
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.data = data;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function setup() {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function dispatchWailsEvent(event) {
|
|
53
|
+
let listeners = eventListeners.get(event.name);
|
|
54
|
+
if (listeners) {
|
|
55
|
+
let toRemove = listeners.filter(listener => {
|
|
56
|
+
let remove = listener.Callback(event);
|
|
57
|
+
if (remove) return true;
|
|
58
|
+
});
|
|
59
|
+
if (toRemove.length > 0) {
|
|
60
|
+
listeners = listeners.filter(l => !toRemove.includes(l));
|
|
61
|
+
if (listeners.length === 0) eventListeners.delete(event.name);
|
|
62
|
+
else eventListeners.set(event.name, listeners);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Register a callback function to be called multiple times for a specific event.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} eventName - The name of the event to register the callback for.
|
|
71
|
+
* @param {function} callback - The callback function to be called when the event is triggered.
|
|
72
|
+
* @param {number} maxCallbacks - The maximum number of times the callback can be called for the event. Once the maximum number is reached, the callback will no longer be called.
|
|
73
|
+
*
|
|
74
|
+
@return {function} - A function that, when called, will unregister the callback from the event.
|
|
75
|
+
*/
|
|
76
|
+
export function OnMultiple(eventName, callback, maxCallbacks) {
|
|
77
|
+
let listeners = eventListeners.get(eventName) || [];
|
|
78
|
+
const thisListener = new Listener(eventName, callback, maxCallbacks);
|
|
79
|
+
listeners.push(thisListener);
|
|
80
|
+
eventListeners.set(eventName, listeners);
|
|
81
|
+
return () => listenerOff(thisListener);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Registers a callback function to be executed when the specified event occurs.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} eventName - The name of the event.
|
|
88
|
+
* @param {function} callback - The callback function to be executed. It takes no parameters.
|
|
89
|
+
* @return {function} - A function that, when called, will unregister the callback from the event. */
|
|
90
|
+
export function On(eventName, callback) { return OnMultiple(eventName, callback, -1); }
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Registers a callback function to be executed only once for the specified event.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} eventName - The name of the event.
|
|
96
|
+
* @param {function} callback - The function to be executed when the event occurs.
|
|
97
|
+
* @return {function} - A function that, when called, will unregister the callback from the event.
|
|
98
|
+
*/
|
|
99
|
+
export function Once(eventName, callback) { return OnMultiple(eventName, callback, 1); }
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Removes the specified listener from the event listeners collection.
|
|
103
|
+
* If all listeners for the event are removed, the event key is deleted from the collection.
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} listener - The listener to be removed.
|
|
106
|
+
*/
|
|
107
|
+
function listenerOff(listener) {
|
|
108
|
+
const eventName = listener.eventName;
|
|
109
|
+
let listeners = eventListeners.get(eventName).filter(l => l !== listener);
|
|
110
|
+
if (listeners.length === 0) eventListeners.delete(eventName);
|
|
111
|
+
else eventListeners.set(eventName, listeners);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Removes event listeners for the specified event names.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} eventName - The name of the event to remove listeners for.
|
|
119
|
+
* @param {...string} additionalEventNames - Additional event names to remove listeners for.
|
|
120
|
+
* @return {undefined}
|
|
121
|
+
*/
|
|
122
|
+
export function Off(eventName, ...additionalEventNames) {
|
|
123
|
+
let eventsToRemove = [eventName, ...additionalEventNames];
|
|
124
|
+
eventsToRemove.forEach(eventName => eventListeners.delete(eventName));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Removes all event listeners.
|
|
128
|
+
*
|
|
129
|
+
* @function OffAll
|
|
130
|
+
* @returns {void}
|
|
131
|
+
*/
|
|
132
|
+
export function OffAll() { eventListeners.clear(); }
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Emits an event using the given event name.
|
|
136
|
+
*
|
|
137
|
+
* @param {WailsEvent} event - The name of the event to emit.
|
|
138
|
+
* @returns {any} - The result of the emitted event.
|
|
139
|
+
*/
|
|
140
|
+
export function Emit(event) { return call(EmitMethod, event); }
|
package/src/flags.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
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
|
-
* Retrieves the value associated with the specified key from the flag map.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} keyString - The key to retrieve the value for.
|
|
17
|
-
* @return {*} - The value associated with the specified key.
|
|
18
|
-
*/
|
|
19
|
-
export function GetFlag(keyString) {
|
|
20
|
-
try {
|
|
21
|
-
return window._wails.flags[keyString];
|
|
22
|
-
} catch (e) {
|
|
23
|
-
throw new Error("Unable to retrieve flag '" + keyString + "': " + e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
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
|
+
* Retrieves the value associated with the specified key from the flag map.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} keyString - The key to retrieve the value for.
|
|
17
|
+
* @return {*} - The value associated with the specified key.
|
|
18
|
+
*/
|
|
19
|
+
export function GetFlag(keyString) {
|
|
20
|
+
try {
|
|
21
|
+
return window._wails.flags[keyString];
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw new Error("Unable to retrieve flag '" + keyString + "': " + e);
|
|
24
|
+
}
|
|
25
|
+
}
|