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

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
package/package.json CHANGED
@@ -1,17 +1,38 @@
1
- {
2
- "name": "@wailsio/runtime",
3
- "version": "3.0.0-alpha.6",
4
- "description": "Wails Runtime",
5
- "main": "index.js",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/wailsapp/wails.git"
9
- },
10
- "author": "The Wails Team",
11
- "license": "MIT",
12
- "bugs": {
13
- "url": "https://github.com/wailsapp/wails/issues"
14
- },
15
- "homepage": "https://wails.io",
16
- "private": false
17
- }
1
+ {
2
+ "name": "@wailsio/runtime",
3
+ "type": "module",
4
+ "version": "3.0.0-alpha.61",
5
+ "description": "Wails Runtime",
6
+ "types": "types/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./types/index.d.ts",
10
+ "require": "./src/index.js",
11
+ "import": "./src/index.js"
12
+ }
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/wailsapp/wails.git"
17
+ },
18
+ "scripts": {
19
+ "prebuild:types": "rimraf ./types",
20
+ "build:types": "npx -p typescript tsc src/index.js --declaration --allowJs --emitDeclarationOnly --outDir types",
21
+ "postbuild:types": "task generate:events",
22
+ "build:docs": "npx typedoc ./src/index.js",
23
+ "build:docs:md": "npx typedoc ./src/index.js"
24
+ },
25
+ "author": "The Wails Team",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/wailsapp/wails/issues"
29
+ },
30
+ "homepage": "https://wails.io",
31
+ "private": false,
32
+ "devDependencies": {
33
+ "rimraf": "^5.0.5",
34
+ "typedoc": "^0.25.7",
35
+ "typedoc-plugin-markdown": "^3.17.1",
36
+ "typescript": "^5.3.3"
37
+ }
38
+ }
@@ -1,46 +1,46 @@
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 { newRuntimeCallerWithID, objectNames } from "./runtime";
14
- const call = newRuntimeCallerWithID(objectNames.Application);
15
-
16
- const HideMethod = 0;
17
- const ShowMethod = 1;
18
- const QuitMethod = 2;
19
-
20
- /**
21
- * Hides a certain method by calling the HideMethod function.
22
- *
23
- * @return {Promise<void>}
24
- *
25
- */
26
- export function Hide() {
27
- return call(HideMethod);
28
- }
29
-
30
- /**
31
- * Calls the ShowMethod and returns the result.
32
- *
33
- * @return {Promise<void>}
34
- */
35
- export function Show() {
36
- return call(ShowMethod);
37
- }
38
-
39
- /**
40
- * Calls the QuitMethod to terminate the program.
41
- *
42
- * @return {Promise<void>}
43
- */
44
- export function Quit() {
45
- return call(QuitMethod);
46
- }
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 { newRuntimeCallerWithID, objectNames } from "./runtime";
14
+ const call = newRuntimeCallerWithID(objectNames.Application, '');
15
+
16
+ const HideMethod = 0;
17
+ const ShowMethod = 1;
18
+ const QuitMethod = 2;
19
+
20
+ /**
21
+ * Hides a certain method by calling the HideMethod function.
22
+ *
23
+ * @return {Promise<void>}
24
+ *
25
+ */
26
+ export function Hide() {
27
+ return call(HideMethod);
28
+ }
29
+
30
+ /**
31
+ * Calls the ShowMethod and returns the result.
32
+ *
33
+ * @return {Promise<void>}
34
+ */
35
+ export function Show() {
36
+ return call(ShowMethod);
37
+ }
38
+
39
+ /**
40
+ * Calls the QuitMethod to terminate the program.
41
+ *
42
+ * @return {Promise<void>}
43
+ */
44
+ export function Quit() {
45
+ return call(QuitMethod);
46
+ }
@@ -1,24 +1,24 @@
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 {newRuntimeCallerWithID, objectNames} from "./runtime";
13
-
14
- const call = newRuntimeCallerWithID(objectNames.Browser, '');
15
- const BrowserOpenURL = 0;
16
-
17
- /**
18
- * Open a browser window to the given URL
19
- * @param {string} url - The URL to open
20
- * @returns {Promise<string>}
21
- */
22
- export function OpenURL(url) {
23
- return call(BrowserOpenURL, {url});
24
- }
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 {newRuntimeCallerWithID, objectNames} from "./runtime";
13
+
14
+ const call = newRuntimeCallerWithID(objectNames.Browser, '');
15
+ const BrowserOpenURL = 0;
16
+
17
+ /**
18
+ * Open a browser window to the given URL
19
+ * @param {string} url - The URL to open
20
+ * @returns {Promise<string>}
21
+ */
22
+ export function OpenURL(url) {
23
+ return call(BrowserOpenURL, {url});
24
+ }
package/src/calls.js ADDED
@@ -0,0 +1,221 @@
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 { newRuntimeCallerWithID, objectNames } from "./runtime";
13
+ import { nanoid } from './nanoid.js';
14
+
15
+ // Setup
16
+ window._wails = window._wails || {};
17
+ window._wails.callResultHandler = resultHandler;
18
+ window._wails.callErrorHandler = errorHandler;
19
+
20
+
21
+ const CallBinding = 0;
22
+ const call = newRuntimeCallerWithID(objectNames.Call, '');
23
+ const cancelCall = newRuntimeCallerWithID(objectNames.CancelCall, '');
24
+ let callResponses = new Map();
25
+
26
+ /**
27
+ * Generates a unique ID using the nanoid library.
28
+ *
29
+ * @return {string} - A unique ID that does not exist in the callResponses set.
30
+ */
31
+ function generateID() {
32
+ let result;
33
+ do {
34
+ result = nanoid();
35
+ } while (callResponses.has(result));
36
+ return result;
37
+ }
38
+
39
+ /**
40
+ * Handles the result of a call request.
41
+ *
42
+ * @param {string} id - The id of the request to handle the result for.
43
+ * @param {string} data - The result data of the request.
44
+ * @param {boolean} isJSON - Indicates whether the data is JSON or not.
45
+ *
46
+ * @return {undefined} - This method does not return any value.
47
+ */
48
+ function resultHandler(id, data, isJSON) {
49
+ const promiseHandler = getAndDeleteResponse(id);
50
+ if (promiseHandler) {
51
+ if (!data) {
52
+ promiseHandler.resolve();
53
+ } else if (!isJSON) {
54
+ promiseHandler.resolve(data);
55
+ } else {
56
+ try {
57
+ promiseHandler.resolve(JSON.parse(data));
58
+ } catch (err) {
59
+ promiseHandler.reject(new TypeError("could not parse result: " + err.message, { cause: err }));
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Handles the error from a call request.
67
+ *
68
+ * @param {string} id - The id of the promise handler.
69
+ * @param {string} data - The error data to reject the promise handler with.
70
+ * @param {boolean} isJSON - Indicates whether the data is JSON or not.
71
+ *
72
+ * @return {void}
73
+ */
74
+ function errorHandler(id, data, isJSON) {
75
+ const promiseHandler = getAndDeleteResponse(id);
76
+ if (promiseHandler) {
77
+ if (!isJSON) {
78
+ promiseHandler.reject(new Error(data));
79
+ } else {
80
+ let error;
81
+ try {
82
+ error = JSON.parse(data);
83
+ } catch (err) {
84
+ promiseHandler.reject(new TypeError("could not parse error: " + err.message, { cause: err }));
85
+ return;
86
+ }
87
+
88
+ let options = {};
89
+ if (error.cause) {
90
+ options.cause = error.cause;
91
+ }
92
+
93
+ let exception;
94
+ switch (error.kind) {
95
+ case "ReferenceError":
96
+ exception = new ReferenceError(error.message, options);
97
+ break;
98
+ case "TypeError":
99
+ exception = new TypeError(error.message, options);
100
+ break;
101
+ case "RuntimeError":
102
+ exception = new RuntimeError(error.message, options);
103
+ break;
104
+ default:
105
+ exception = new Error(error.message, options);
106
+ break;
107
+ }
108
+
109
+ promiseHandler.reject(exception);
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Retrieves and removes the response associated with the given ID from the callResponses map.
116
+ *
117
+ * @param {any} id - The ID of the response to be retrieved and removed.
118
+ *
119
+ * @returns {any} The response object associated with the given ID.
120
+ */
121
+ function getAndDeleteResponse(id) {
122
+ const response = callResponses.get(id);
123
+ callResponses.delete(id);
124
+ return response;
125
+ }
126
+
127
+ /**
128
+ * Collects all required information for a binding call.
129
+ *
130
+ * @typedef {Object} CallOptions
131
+ * @property {number} [methodID] - The numeric ID of the bound method to call.
132
+ * @property {string} [methodName] - The fully qualified name of the bound method to call.
133
+ * @property {any[]} args - Arguments to be passed into the bound method.
134
+ */
135
+
136
+ /**
137
+ * Exception class that will be thrown in case the bound method returns an error.
138
+ * The value of the {@link RuntimeError#name} property is "RuntimeError".
139
+ */
140
+ export class RuntimeError extends Error {
141
+ /**
142
+ * Constructs a new RuntimeError instance.
143
+ *
144
+ * @param {string} message - The error message.
145
+ * @param {any[]} args - Optional arguments for the Error constructor.
146
+ */
147
+ constructor(message, ...args) {
148
+ super(message, ...args);
149
+ this.name = "RuntimeError";
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Call a bound method according to the given call options.
155
+ *
156
+ * In case of failure, the returned promise will reject with an exception
157
+ * among ReferenceError (unknown method), TypeError (wrong argument count or type),
158
+ * {@link RuntimeError} (method returned an error), or other (network or internal errors).
159
+ * The exception might have a "cause" field with the value returned
160
+ * by the application- or service-level error marshaling functions.
161
+ *
162
+ * @param {CallOptions} options - A method call descriptor.
163
+ * @returns {Promise<any>} - The result of the call.
164
+ */
165
+ export function Call(options) {
166
+ const id = generateID();
167
+ const doCancel = () => { return cancelCall(type, {"call-id": id}) };
168
+ let queuedCancel = false, callRunning = false;
169
+ let p = new Promise((resolve, reject) => {
170
+ options["call-id"] = id;
171
+ callResponses.set(id, { resolve, reject });
172
+ call(CallBinding, options).then((_) => {
173
+ callRunning = true;
174
+ if (queuedCancel) {
175
+ return doCancel();
176
+ }
177
+ }).catch((error) => {
178
+ reject(error);
179
+ callResponses.delete(id);
180
+ });
181
+ });
182
+ p.cancel = () => {
183
+ if (callRunning) {
184
+ return doCancel();
185
+ } else {
186
+ queuedCancel = true;
187
+ }
188
+ };
189
+
190
+ return p;
191
+ }
192
+
193
+ /**
194
+ * Calls a bound method by name with the specified arguments.
195
+ * See {@link Call} for details.
196
+ *
197
+ * @param {string} methodName - The name of the method in the format 'package.struct.method'.
198
+ * @param {any[]} args - The arguments to pass to the method.
199
+ * @returns {Promise<any>} The result of the method call.
200
+ */
201
+ export function ByName(methodName, ...args) {
202
+ return Call({
203
+ methodName,
204
+ args
205
+ });
206
+ }
207
+
208
+ /**
209
+ * Calls a method by its numeric ID with the specified arguments.
210
+ * See {@link Call} for details.
211
+ *
212
+ * @param {number} methodID - The ID of the method to call.
213
+ * @param {any[]} args - The arguments to pass to the method.
214
+ * @return {Promise<any>} - The result of the method call.
215
+ */
216
+ export function ByID(methodID, ...args) {
217
+ return Call({
218
+ methodID,
219
+ args
220
+ });
221
+ }
@@ -1,35 +1,35 @@
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 {newRuntimeCallerWithID, objectNames} from "./runtime";
14
-
15
- const call = newRuntimeCallerWithID(objectNames.Clipboard, '');
16
- const ClipboardSetText = 0;
17
- const ClipboardText = 1;
18
-
19
- /**
20
- * Sets the text to the Clipboard.
21
- *
22
- * @param {string} text - The text to be set to the Clipboard.
23
- * @return {Promise} - A Promise that resolves when the operation is successful.
24
- */
25
- export function SetText(text) {
26
- return call(ClipboardSetText, {text});
27
- }
28
-
29
- /**
30
- * Get the Clipboard text
31
- * @returns {Promise<string>} A promise that resolves with the text from the Clipboard.
32
- */
33
- export function Text() {
34
- return call(ClipboardText);
35
- }
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 {newRuntimeCallerWithID, objectNames} from "./runtime";
14
+
15
+ const call = newRuntimeCallerWithID(objectNames.Clipboard, '');
16
+ const ClipboardSetText = 0;
17
+ const ClipboardText = 1;
18
+
19
+ /**
20
+ * Sets the text to the Clipboard.
21
+ *
22
+ * @param {string} text - The text to be set to the Clipboard.
23
+ * @return {Promise} - A Promise that resolves when the operation is successful.
24
+ */
25
+ export function SetText(text) {
26
+ return call(ClipboardSetText, {text});
27
+ }
28
+
29
+ /**
30
+ * Get the Clipboard text
31
+ * @returns {Promise<string>} A promise that resolves with the text from the Clipboard.
32
+ */
33
+ export function Text() {
34
+ return call(ClipboardText);
35
+ }