@wailsio/runtime 3.0.0-alpha.19 → 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.
Files changed (132) hide show
  1. package/docs/{functions/Window.Size.html → assets/icons.js} +15 -2
  2. package/docs/assets/icons.svg +1 -0
  3. package/docs/assets/main.js +4 -4
  4. package/docs/assets/navigation.js +1 -1
  5. package/docs/assets/search.js +1 -1
  6. package/docs/assets/style.css +2 -1
  7. package/docs/classes/Events.WailsEvent.html +4 -4
  8. package/docs/functions/Application.Hide.html +2 -2
  9. package/docs/functions/Application.Quit.html +2 -2
  10. package/docs/functions/Application.Show.html +2 -2
  11. package/docs/functions/Browser.OpenURL.html +3 -3
  12. package/docs/functions/Call.ByID.html +4 -4
  13. package/docs/functions/Call.ByName.html +4 -4
  14. package/docs/functions/Call.Call.html +3 -3
  15. package/docs/functions/Call.Plugin.html +5 -5
  16. package/docs/functions/Clipboard.SetText.html +3 -3
  17. package/docs/functions/Clipboard.Text.html +2 -2
  18. package/docs/functions/Dialogs.Error.html +2 -2
  19. package/docs/functions/Dialogs.Info.html +2 -2
  20. package/docs/functions/Dialogs.OpenFile.html +2 -2
  21. package/docs/functions/Dialogs.Question.html +2 -2
  22. package/docs/functions/Dialogs.SaveFile.html +2 -2
  23. package/docs/functions/Dialogs.Warning.html +2 -2
  24. package/docs/functions/Events.Emit.html +3 -3
  25. package/docs/functions/Events.Off.html +4 -4
  26. package/docs/functions/Events.OffAll.html +2 -2
  27. package/docs/functions/Events.On.html +4 -4
  28. package/docs/functions/Events.OnMultiple.html +5 -5
  29. package/docs/functions/Events.Once.html +4 -4
  30. package/docs/functions/Events.setup.html +1 -1
  31. package/docs/functions/Flags.GetFlag.html +3 -3
  32. package/docs/functions/Screens.GetAll.html +3 -3
  33. package/docs/functions/Screens.GetCurrent.html +3 -3
  34. package/docs/functions/Screens.GetPrimary.html +3 -3
  35. package/docs/functions/System.Capabilities.html +2 -2
  36. package/docs/functions/System.Environment.html +2 -2
  37. package/docs/functions/System.IsAMD64.html +2 -2
  38. package/docs/functions/System.IsARM.html +2 -2
  39. package/docs/functions/System.IsARM64.html +2 -2
  40. package/docs/functions/System.IsDarkMode.html +2 -2
  41. package/docs/functions/System.IsDebug.html +1 -1
  42. package/docs/functions/System.IsLinux.html +2 -2
  43. package/docs/functions/System.IsMac.html +2 -2
  44. package/docs/functions/System.IsWindows.html +2 -2
  45. package/docs/functions/System.invoke.html +1 -1
  46. package/docs/functions/WML.Enable.html +2 -0
  47. package/docs/functions/WML.Reload.html +2 -2
  48. package/docs/index.html +2 -2
  49. package/docs/interfaces/Dialogs.Button.html +7 -7
  50. package/docs/interfaces/Dialogs.FileFilter.html +5 -5
  51. package/docs/interfaces/Dialogs.MessageDialogOptions.html +9 -9
  52. package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +33 -33
  53. package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +35 -35
  54. package/docs/interfaces/Screens.Position.html +5 -5
  55. package/docs/interfaces/Screens.Rect.html +9 -9
  56. package/docs/interfaces/Screens.Screen.html +19 -19
  57. package/docs/interfaces/Screens.Size.html +5 -5
  58. package/docs/interfaces/System.EnvironmentInfo.html +11 -5
  59. package/docs/interfaces/System.OSInfo.html +9 -0
  60. package/docs/modules/Application.html +4 -4
  61. package/docs/modules/Browser.html +2 -2
  62. package/docs/modules/Call.html +5 -5
  63. package/docs/modules/Clipboard.html +3 -3
  64. package/docs/modules/Dialogs.html +12 -12
  65. package/docs/modules/Events.html +10 -10
  66. package/docs/modules/Flags.html +2 -2
  67. package/docs/modules/Screens.html +8 -9
  68. package/docs/modules/System.html +14 -13
  69. package/docs/modules/WML.html +3 -2
  70. package/docs/modules.html +12 -12
  71. package/docs/variables/Events.Types.html +1 -1
  72. package/docs/variables/Window.html +2 -0
  73. package/package.json +31 -31
  74. package/src/application.js +46 -46
  75. package/src/browser.js +24 -24
  76. package/src/calls.js +180 -161
  77. package/src/clipboard.js +35 -35
  78. package/src/contextmenu.js +97 -97
  79. package/src/dialogs.js +200 -200
  80. package/src/drag.js +119 -124
  81. package/src/event_types.js +5 -0
  82. package/src/events.js +140 -140
  83. package/src/flags.js +25 -25
  84. package/src/index.js +46 -93
  85. package/src/runtime.js +123 -122
  86. package/src/screens.js +77 -83
  87. package/src/system.js +128 -117
  88. package/src/utils.js +86 -0
  89. package/src/window.js +638 -316
  90. package/src/wml.js +250 -171
  91. package/tsconfig.json +19 -19
  92. package/types/event_types.d.ts +5 -0
  93. package/types/events.d.ts +5 -0
  94. package/types/index.d.ts +2 -2
  95. package/types/runtime.d.ts +1 -0
  96. package/types/screens.d.ts +1 -5
  97. package/types/system.d.ts +44 -4
  98. package/types/utils.d.ts +14 -0
  99. package/types/window.d.ts +400 -133
  100. package/types/wml.d.ts +6 -0
  101. package/docs/functions/Window.Center.html +0 -2
  102. package/docs/functions/Window.Close.html +0 -2
  103. package/docs/functions/Window.Fullscreen.html +0 -2
  104. package/docs/functions/Window.Get.html +0 -6
  105. package/docs/functions/Window.GetZoomLevel.html +0 -2
  106. package/docs/functions/Window.Height.html +0 -2
  107. package/docs/functions/Window.Hide.html +0 -2
  108. package/docs/functions/Window.Maximise.html +0 -2
  109. package/docs/functions/Window.Minimise.html +0 -2
  110. package/docs/functions/Window.RelativePosition.html +0 -2
  111. package/docs/functions/Window.Restore.html +0 -2
  112. package/docs/functions/Window.Screen-1.html +0 -2
  113. package/docs/functions/Window.SetAlwaysOnTop.html +0 -3
  114. package/docs/functions/Window.SetBackgroundColour.html +0 -6
  115. package/docs/functions/Window.SetMaxSize.html +0 -4
  116. package/docs/functions/Window.SetMinSize.html +0 -4
  117. package/docs/functions/Window.SetRelativePosition.html +0 -4
  118. package/docs/functions/Window.SetResizable.html +0 -3
  119. package/docs/functions/Window.SetSize.html +0 -4
  120. package/docs/functions/Window.SetTitle.html +0 -3
  121. package/docs/functions/Window.SetZoomLevel.html +0 -3
  122. package/docs/functions/Window.Show.html +0 -2
  123. package/docs/functions/Window.ToggleMaximise.html +0 -2
  124. package/docs/functions/Window.UnMaximise.html +0 -2
  125. package/docs/functions/Window.UnMinimise.html +0 -2
  126. package/docs/functions/Window.Width.html +0 -2
  127. package/docs/functions/Window.ZoomIn.html +0 -2
  128. package/docs/functions/Window.ZoomOut.html +0 -2
  129. package/docs/functions/Window.ZoomReset.html +0 -2
  130. package/docs/modules/Window.html +0 -32
  131. package/docs/types/Screens.Rotation.html +0 -2
  132. package/src/log.js +0 -13
package/src/drag.js CHANGED
@@ -1,124 +1,119 @@
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
- import {invoke, IsWindows} from "./system";
14
- import {GetFlag} from "./flags";
15
-
16
- // Setup
17
- window._wails = window._wails || {};
18
- window._wails.setResizable = setResizable;
19
- window._wails.endDrag = endDrag;
20
- window.addEventListener('mousedown', onMouseDown);
21
- window.addEventListener('mousemove', onMouseMove);
22
- window.addEventListener('mouseup', onMouseUp);
23
-
24
- let shouldDrag = false;
25
- let resizeEdge = null;
26
- let resizable = false;
27
- let defaultCursor = "auto";
28
-
29
- function dragTest(e) {
30
- let val = window.getComputedStyle(e.target).getPropertyValue("--webkit-app-region");
31
- if (!val || val === "" || val.trim() !== "drag" || e.buttons !== 1) {
32
- return false;
33
- }
34
- return e.detail === 1;
35
- }
36
-
37
- function setResizable(value) {
38
- resizable = value;
39
- }
40
-
41
- function endDrag() {
42
- document.body.style.cursor = 'default';
43
- shouldDrag = false;
44
- }
45
-
46
- function testResize() {
47
- if( resizeEdge ) {
48
- invoke(`resize:${resizeEdge}`);
49
- return true
50
- }
51
- return false;
52
- }
53
-
54
- function onMouseDown(e) {
55
- if(IsWindows() && testResize() || dragTest(e)) {
56
- shouldDrag = !!isValidDrag(e);
57
- }
58
- }
59
-
60
- function isValidDrag(e) {
61
- // Ignore drag on scrollbars
62
- return !(e.offsetX > e.target.clientWidth || e.offsetY > e.target.clientHeight);
63
- }
64
-
65
- function onMouseUp(e) {
66
- let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
67
- if (mousePressed > 0) {
68
- endDrag();
69
- }
70
- }
71
-
72
- function setResize(cursor = defaultCursor) {
73
- document.documentElement.style.cursor = cursor;
74
- resizeEdge = cursor;
75
- }
76
-
77
- function onMouseMove(e) {
78
- shouldDrag = checkDrag(e);
79
- if (IsWindows() && resizable) {
80
- handleResize(e);
81
- }
82
- }
83
-
84
- function checkDrag(e) {
85
- let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
86
- if(shouldDrag && mousePressed > 0) {
87
- invoke("drag");
88
- return false;
89
- }
90
- return shouldDrag;
91
- }
92
-
93
- function handleResize(e) {
94
- let resizeHandleHeight = GetFlag("system.resizeHandleHeight") || 5;
95
- let resizeHandleWidth = GetFlag("system.resizeHandleWidth") || 5;
96
-
97
- // Extra pixels for the corner areas
98
- let cornerExtra = GetFlag("resizeCornerExtra") || 10;
99
-
100
- let rightBorder = window.outerWidth - e.clientX < resizeHandleWidth;
101
- let leftBorder = e.clientX < resizeHandleWidth;
102
- let topBorder = e.clientY < resizeHandleHeight;
103
- let bottomBorder = window.outerHeight - e.clientY < resizeHandleHeight;
104
-
105
- // Adjust for corners
106
- let rightCorner = window.outerWidth - e.clientX < (resizeHandleWidth + cornerExtra);
107
- let leftCorner = e.clientX < (resizeHandleWidth + cornerExtra);
108
- let topCorner = e.clientY < (resizeHandleHeight + cornerExtra);
109
- let bottomCorner = window.outerHeight - e.clientY < (resizeHandleHeight + cornerExtra);
110
-
111
- // If we aren't on an edge, but were, reset the cursor to default
112
- if (!leftBorder && !rightBorder && !topBorder && !bottomBorder && resizeEdge !== undefined) {
113
- setResize();
114
- }
115
- // Adjusted for corner areas
116
- else if (rightCorner && bottomCorner) setResize("se-resize");
117
- else if (leftCorner && bottomCorner) setResize("sw-resize");
118
- else if (leftCorner && topCorner) setResize("nw-resize");
119
- else if (topCorner && rightCorner) setResize("ne-resize");
120
- else if (leftBorder) setResize("w-resize");
121
- else if (topBorder) setResize("n-resize");
122
- else if (bottomBorder) setResize("s-resize");
123
- else if (rightBorder) setResize("e-resize");
124
- }
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
+ }
@@ -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
+ }