@wailsio/runtime 3.0.0-alpha.6 → 3.0.0-alpha.60

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 (129) hide show
  1. package/docs/.nojekyll +1 -0
  2. package/docs/assets/highlight.css +22 -0
  3. package/docs/assets/icons.js +15 -0
  4. package/docs/assets/icons.svg +1 -0
  5. package/docs/assets/main.js +59 -0
  6. package/docs/assets/navigation.js +1 -0
  7. package/docs/assets/search.js +1 -0
  8. package/docs/assets/style.css +1415 -0
  9. package/docs/classes/Call.RuntimeError.html +11 -0
  10. package/docs/classes/Events.WailsEvent.html +4 -0
  11. package/docs/functions/Application.Hide.html +2 -0
  12. package/docs/functions/Application.Quit.html +2 -0
  13. package/docs/functions/Application.Show.html +2 -0
  14. package/docs/functions/Browser.OpenURL.html +3 -0
  15. package/docs/functions/Call.ByID.html +8 -0
  16. package/docs/functions/Call.ByName.html +6 -0
  17. package/docs/functions/Call.Call.html +11 -0
  18. package/docs/functions/Clipboard.SetText.html +6 -0
  19. package/docs/functions/Clipboard.Text.html +3 -0
  20. package/docs/functions/Create.Any.html +2 -0
  21. package/docs/functions/Create.Array.html +4 -0
  22. package/docs/functions/Create.ByteSlice.html +3 -0
  23. package/docs/functions/Create.Map.html +4 -0
  24. package/docs/functions/Create.Nullable.html +3 -0
  25. package/docs/functions/Create.Struct.html +3 -0
  26. package/docs/functions/Dialogs.Error.html +5 -0
  27. package/docs/functions/Dialogs.Info.html +5 -0
  28. package/docs/functions/Dialogs.OpenFile.html +3 -0
  29. package/docs/functions/Dialogs.Question.html +5 -0
  30. package/docs/functions/Dialogs.SaveFile.html +3 -0
  31. package/docs/functions/Dialogs.Warning.html +5 -0
  32. package/docs/functions/Events.Emit.html +6 -0
  33. package/docs/functions/Events.Off.html +4 -0
  34. package/docs/functions/Events.OffAll.html +3 -0
  35. package/docs/functions/Events.On.html +7 -0
  36. package/docs/functions/Events.OnMultiple.html +8 -0
  37. package/docs/functions/Events.Once.html +7 -0
  38. package/docs/functions/Events.setup.html +1 -0
  39. package/docs/functions/Flags.GetFlag.html +6 -0
  40. package/docs/functions/Screens.GetAll.html +3 -0
  41. package/docs/functions/Screens.GetCurrent.html +3 -0
  42. package/docs/functions/Screens.GetPrimary.html +3 -0
  43. package/docs/functions/System.Capabilities.html +4 -0
  44. package/docs/functions/System.Environment.html +5 -0
  45. package/docs/functions/System.IsAMD64.html +3 -0
  46. package/docs/functions/System.IsARM.html +3 -0
  47. package/docs/functions/System.IsARM64.html +5 -0
  48. package/docs/functions/System.IsDarkMode.html +5 -0
  49. package/docs/functions/System.IsDebug.html +1 -0
  50. package/docs/functions/System.IsLinux.html +3 -0
  51. package/docs/functions/System.IsMac.html +3 -0
  52. package/docs/functions/System.IsWindows.html +3 -0
  53. package/docs/functions/System.invoke.html +1 -0
  54. package/docs/functions/WML.Enable.html +2 -0
  55. package/docs/functions/WML.Reload.html +2 -0
  56. package/docs/functions/init.html +1 -0
  57. package/docs/index.html +5 -0
  58. package/docs/interfaces/Call.CallOptions.html +7 -0
  59. package/docs/interfaces/Dialogs.Button.html +7 -0
  60. package/docs/interfaces/Dialogs.FileFilter.html +5 -0
  61. package/docs/interfaces/Dialogs.MessageDialogOptions.html +9 -0
  62. package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +33 -0
  63. package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +35 -0
  64. package/docs/interfaces/Screens.Rect.html +9 -0
  65. package/docs/interfaces/Screens.Screen.html +25 -0
  66. package/docs/interfaces/Screens.Size.html +5 -0
  67. package/docs/interfaces/System.EnvironmentInfo.html +11 -0
  68. package/docs/interfaces/System.OSInfo.html +9 -0
  69. package/docs/modules/Application.html +4 -0
  70. package/docs/modules/Browser.html +2 -0
  71. package/docs/modules/Call.html +6 -0
  72. package/docs/modules/Clipboard.html +3 -0
  73. package/docs/modules/Create.html +7 -0
  74. package/docs/modules/Dialogs.html +12 -0
  75. package/docs/modules/Events.html +10 -0
  76. package/docs/modules/Flags.html +2 -0
  77. package/docs/modules/Screens.html +7 -0
  78. package/docs/modules/System.html +14 -0
  79. package/docs/modules/WML.html +3 -0
  80. package/docs/modules.html +14 -0
  81. package/docs/variables/Events.Types.html +1 -0
  82. package/docs/variables/Window.html +2 -0
  83. package/package.json +38 -17
  84. package/{application.js → src/application.js} +46 -46
  85. package/{browser.js → src/browser.js} +24 -24
  86. package/src/calls.js +221 -0
  87. package/{clipboard.js → src/clipboard.js} +35 -35
  88. package/{contextmenu.js → src/contextmenu.js} +97 -98
  89. package/src/create.js +125 -0
  90. package/src/dialogs.js +200 -0
  91. package/{drag.js → src/drag.js} +119 -125
  92. package/src/event_types.js +219 -0
  93. package/{events.js → src/events.js} +140 -134
  94. package/src/flags.js +25 -0
  95. package/src/index.js +60 -0
  96. package/src/nanoid.js +42 -0
  97. package/src/runtime.js +92 -0
  98. package/src/screens.js +71 -0
  99. package/{system.js → src/system.js} +143 -122
  100. package/src/utils.js +86 -0
  101. package/src/window.js +638 -0
  102. package/src/wml.js +250 -0
  103. package/tsconfig.json +20 -0
  104. package/types/application.d.ts +19 -0
  105. package/types/browser.d.ts +6 -0
  106. package/types/calls.d.ts +69 -0
  107. package/types/clipboard.d.ts +12 -0
  108. package/types/create.d.ts +52 -0
  109. package/types/dialogs.d.ts +184 -0
  110. package/types/event_types.d.ts +219 -0
  111. package/types/events.d.ts +271 -0
  112. package/types/flags.d.ts +7 -0
  113. package/types/index.d.ts +14 -0
  114. package/types/nanoid.d.ts +1 -0
  115. package/types/runtime.d.ts +30 -0
  116. package/types/screens.d.ts +94 -0
  117. package/types/system.d.ts +112 -0
  118. package/types/utils.d.ts +14 -0
  119. package/types/window.d.ts +407 -0
  120. package/types/wml.d.ts +12 -0
  121. package/calls.js +0 -123
  122. package/dialogs.js +0 -138
  123. package/flags.js +0 -63
  124. package/index.js +0 -56
  125. package/runtime.js +0 -122
  126. package/screens.js +0 -45
  127. package/types.d.ts +0 -130
  128. package/window.js +0 -122
  129. package/wml.js +0 -149
@@ -1,134 +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
- const call = newRuntimeCallerWithID(objectNames.Events, '');
19
- const EmitMethod = 0;
20
- const eventListeners = new Map();
21
-
22
- class Listener {
23
- constructor(eventName, callback, maxCallbacks) {
24
- this.eventName = eventName;
25
- this.maxCallbacks = maxCallbacks || -1;
26
- this.Callback = (data) => {
27
- callback(data);
28
- if (this.maxCallbacks === -1) return false;
29
- this.maxCallbacks -= 1;
30
- return this.maxCallbacks === 0;
31
- };
32
- }
33
- }
34
-
35
- export class WailsEvent {
36
- constructor(name, data = null) {
37
- this.name = name;
38
- this.data = data;
39
- }
40
- }
41
-
42
-
43
- window._wails = window._wails || {};
44
- window._wails.dispatchWailsEvent = dispatchWailsEvent;
45
-
46
- export function dispatchWailsEvent(event) {
47
- let listeners = eventListeners.get(event.name);
48
- if (listeners) {
49
- let toRemove = listeners.filter(listener => {
50
- let remove = listener.Callback(event);
51
- if (remove) return true;
52
- });
53
- if (toRemove.length > 0) {
54
- listeners = listeners.filter(l => !toRemove.includes(l));
55
- if (listeners.length === 0) eventListeners.delete(event.name);
56
- else eventListeners.set(event.name, listeners);
57
- }
58
- }
59
- }
60
-
61
- /**
62
- * Register a callback function to be called multiple times for a specific event.
63
- *
64
- * @param {string} eventName - The name of the event to register the callback for.
65
- * @param {function} callback - The callback function to be called when the event is triggered.
66
- * @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.
67
- *
68
- @return {function} - A function that, when called, will unregister the callback from the event.
69
- */
70
- export function OnMultiple(eventName, callback, maxCallbacks) {
71
- let listeners = eventListeners.get(eventName) || [];
72
- const thisListener = new Listener(eventName, callback, maxCallbacks);
73
- listeners.push(thisListener);
74
- eventListeners.set(eventName, listeners);
75
- return () => listenerOff(thisListener);
76
- }
77
-
78
- /**
79
- * Registers a callback function to be executed when the specified event occurs.
80
- *
81
- * @param {string} eventName - The name of the event.
82
- * @param {function} callback - The callback function to be executed. It takes no parameters.
83
- * @return {function} - A function that, when called, will unregister the callback from the event. */
84
- export function On(eventName, callback) { return OnMultiple(eventName, callback, -1); }
85
-
86
- /**
87
- * Registers a callback function to be executed only once for the specified event.
88
- *
89
- * @param {string} eventName - The name of the event.
90
- * @param {function} callback - The function to be executed when the event occurs.
91
- * @return {void@return {function} - A function that, when called, will unregister the callback from the event.
92
- */
93
- export function Once(eventName, callback) { return OnMultiple(eventName, callback, 1); }
94
-
95
- /**
96
- * Removes the specified listener from the event listeners collection.
97
- * If all listeners for the event are removed, the event key is deleted from the collection.
98
- *
99
- * @param {Object} listener - The listener to be removed.
100
- */
101
- function listenerOff(listener) {
102
- const eventName = listener.eventName;
103
- let listeners = eventListeners.get(eventName).filter(l => l !== listener);
104
- if (listeners.length === 0) eventListeners.delete(eventName);
105
- else eventListeners.set(eventName, listeners);
106
- }
107
-
108
-
109
- /**
110
- * Removes event listeners for the specified event names.
111
- *
112
- * @param {string} eventName - The name of the event to remove listeners for.
113
- * @param {...string} additionalEventNames - Additional event names to remove listeners for.
114
- * @return {undefined}
115
- */
116
- export function Off(eventName, ...additionalEventNames) {
117
- let eventsToRemove = [eventName, ...additionalEventNames];
118
- eventsToRemove.forEach(eventName => eventListeners.delete(eventName));
119
- }
120
- /**
121
- * Removes all event listeners.
122
- *
123
- * @function OffAll
124
- * @returns {void}
125
- */
126
- export function OffAll() { eventListeners.clear(); }
127
-
128
- /**
129
- * Emits an event using the given event name.
130
- *
131
- * @param {WailsEvent} event - The name of the event to emit.
132
- * @returns {any} - The result of the emitted event.
133
- */
134
- 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 ADDED
@@ -0,0 +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
+ }
package/src/index.js ADDED
@@ -0,0 +1,60 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+
11
+ // Setup
12
+ window._wails = window._wails || {};
13
+
14
+ import "./contextmenu";
15
+ import "./drag";
16
+
17
+ // Re-export public API
18
+ import * as Application from "./application";
19
+ import * as Browser from "./browser";
20
+ import * as Call from "./calls";
21
+ import * as Clipboard from "./clipboard";
22
+ import * as Create from "./create";
23
+ import * as Dialogs from "./dialogs";
24
+ import * as Events from "./events";
25
+ import * as Flags from "./flags";
26
+ import * as Screens from "./screens";
27
+ import * as System from "./system";
28
+ import Window from "./window";
29
+ import * as WML from "./wml";
30
+
31
+ export {
32
+ Application,
33
+ Browser,
34
+ Call,
35
+ Clipboard,
36
+ Create,
37
+ Dialogs,
38
+ Events,
39
+ Flags,
40
+ Screens,
41
+ System,
42
+ Window,
43
+ WML
44
+ };
45
+
46
+ let initialised = false;
47
+ export function init() {
48
+ window._wails.invoke = System.invoke;
49
+ System.invoke("wails:runtime:ready");
50
+ initialised = true;
51
+ }
52
+
53
+ window.addEventListener("load", () => {
54
+ if (!initialised) {
55
+ init();
56
+ }
57
+ });
58
+
59
+ // Notify backend
60
+
package/src/nanoid.js ADDED
@@ -0,0 +1,42 @@
1
+ // Source: https://github.com/ai/nanoid
2
+
3
+ // The MIT License (MIT)
4
+ //
5
+ // Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ // this software and associated documentation files (the "Software"), to deal in
9
+ // the Software without restriction, including without limitation the rights to
10
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ // the Software, and to permit persons to whom the Software is furnished to do so,
12
+ // subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ // This alphabet uses `A-Za-z0-9_-` symbols.
25
+ // The order of characters is optimized for better gzip and brotli compression.
26
+ // References to the same file (works both for gzip and brotli):
27
+ // `'use`, `andom`, and `rict'`
28
+ // References to the brotli default dictionary:
29
+ // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
30
+ let urlAlphabet =
31
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
32
+
33
+ export let nanoid = (size = 21) => {
34
+ let id = ''
35
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
36
+ let i = size | 0
37
+ while (i--) {
38
+ // `| 0` is more compact and faster than `Math.floor()`.
39
+ id += urlAlphabet[(Math.random() * 64) | 0]
40
+ }
41
+ return id
42
+ }
package/src/runtime.js ADDED
@@ -0,0 +1,92 @@
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
+ import { nanoid } from './nanoid.js';
13
+
14
+ const runtimeURL = window.location.origin + "/wails/runtime";
15
+
16
+ // Object Names
17
+ export const objectNames = {
18
+ Call: 0,
19
+ Clipboard: 1,
20
+ Application: 2,
21
+ Events: 3,
22
+ ContextMenu: 4,
23
+ Dialog: 5,
24
+ Window: 6,
25
+ Screens: 7,
26
+ System: 8,
27
+ Browser: 9,
28
+ CancelCall: 10,
29
+ }
30
+ export let clientId = nanoid();
31
+
32
+ /**
33
+ * Creates a runtime caller function that invokes a specified method on a given object within a specified window context.
34
+ *
35
+ * @param {Object} object - The object on which the method is to be invoked.
36
+ * @param {string} windowName - The name of the window context in which the method should be called.
37
+ * @returns {Function} A runtime caller function that takes the method name and optionally arguments and invokes the method within the specified window context.
38
+ */
39
+ export function newRuntimeCaller(object, windowName) {
40
+ return function (method, args=null) {
41
+ return runtimeCall(object + "." + method, windowName, args);
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Creates a new runtime caller with specified ID.
47
+ *
48
+ * @param {number} object - The object to invoke the method on.
49
+ * @param {string} windowName - The name of the window.
50
+ * @return {Function} - The new runtime caller function.
51
+ */
52
+ export function newRuntimeCallerWithID(object, windowName) {
53
+ return function (method, args=null) {
54
+ return runtimeCallWithID(object, method, windowName, args);
55
+ };
56
+ }
57
+
58
+
59
+ function runtimeCall(method, windowName, args) {
60
+ return runtimeCallWithID(null, method, windowName, args);
61
+ }
62
+
63
+ async function runtimeCallWithID(objectID, method, windowName, args) {
64
+ let url = new URL(runtimeURL);
65
+ if (objectID != null) {
66
+ url.searchParams.append("object", objectID);
67
+ }
68
+ if (method != null) {
69
+ url.searchParams.append("method", method);
70
+ }
71
+ let fetchOptions = {
72
+ headers: {},
73
+ };
74
+ if (windowName) {
75
+ fetchOptions.headers["x-wails-window-name"] = windowName;
76
+ }
77
+ if (args) {
78
+ url.searchParams.append("args", JSON.stringify(args));
79
+ }
80
+ fetchOptions.headers["x-wails-client-id"] = clientId;
81
+
82
+ let response = await fetch(url, fetchOptions);
83
+ if (!response.ok) {
84
+ throw new Error(await response.text());
85
+ }
86
+
87
+ if (response.headers.get("Content-Type") && response.headers.get("Content-Type").indexOf("application/json") !== -1) {
88
+ return response.json();
89
+ } else {
90
+ return response.text();
91
+ }
92
+ }
package/src/screens.js ADDED
@@ -0,0 +1,71 @@
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 {Object} Size
15
+ * @property {number} Width - The width.
16
+ * @property {number} Height - The height.
17
+ */
18
+
19
+ /**
20
+ * @typedef {Object} Rect
21
+ * @property {number} X - The X coordinate of the origin.
22
+ * @property {number} Y - The Y coordinate of the origin.
23
+ * @property {number} Width - The width of the rectangle.
24
+ * @property {number} Height - The height of the rectangle.
25
+ */
26
+
27
+ /**
28
+ * @typedef {Object} Screen
29
+ * @property {string} ID - Unique identifier for the screen.
30
+ * @property {string} Name - Human readable name of the screen.
31
+ * @property {number} ScaleFactor - The scale factor of the screen (DPI/96). 1 = standard DPI, 2 = HiDPI (Retina), etc.
32
+ * @property {number} X - The X coordinate of the screen.
33
+ * @property {number} Y - The Y coordinate of the screen.
34
+ * @property {Size} Size - Contains the width and height of the screen.
35
+ * @property {Rect} Bounds - Contains the bounds of the screen in terms of X, Y, Width, and Height.
36
+ * @property {Rect} PhysicalBounds - Contains the physical bounds of the screen in terms of X, Y, Width, and Height (before scaling).
37
+ * @property {Rect} WorkArea - Contains the area of the screen that is actually usable (excluding taskbar and other system UI).
38
+ * @property {Rect} PhysicalWorkArea - Contains the physical WorkArea of the screen (before scaling).
39
+ * @property {boolean} IsPrimary - True if this is the primary monitor selected by the user in the operating system.
40
+ * @property {number} Rotation - The rotation of the screen.
41
+ */
42
+
43
+ import { newRuntimeCallerWithID, objectNames } from "./runtime";
44
+ const call = newRuntimeCallerWithID(objectNames.Screens, "");
45
+
46
+ const getAll = 0;
47
+ const getPrimary = 1;
48
+ const getCurrent = 2;
49
+
50
+ /**
51
+ * Gets all screens.
52
+ * @returns {Promise<Screen[]>} A promise that resolves to an array of Screen objects.
53
+ */
54
+ export function GetAll() {
55
+ return call(getAll);
56
+ }
57
+ /**
58
+ * Gets the primary screen.
59
+ * @returns {Promise<Screen>} A promise that resolves to the primary screen.
60
+ */
61
+ export function GetPrimary() {
62
+ return call(getPrimary);
63
+ }
64
+ /**
65
+ * Gets the current active screen.
66
+ *
67
+ * @returns {Promise<Screen>} A promise that resolves with the current active screen.
68
+ */
69
+ export function GetCurrent() {
70
+ return call(getCurrent);
71
+ }