@wailsio/runtime 3.0.0-alpha.55 → 3.0.0-alpha.56

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 (81) hide show
  1. package/docs/assets/navigation.js +1 -1
  2. package/docs/assets/search.js +1 -1
  3. package/docs/classes/Call.RuntimeError.html +11 -0
  4. package/docs/classes/Events.WailsEvent.html +2 -2
  5. package/docs/functions/Application.Hide.html +1 -1
  6. package/docs/functions/Application.Quit.html +1 -1
  7. package/docs/functions/Application.Show.html +1 -1
  8. package/docs/functions/Browser.OpenURL.html +1 -1
  9. package/docs/functions/Call.ByID.html +4 -3
  10. package/docs/functions/Call.ByName.html +4 -4
  11. package/docs/functions/Call.Call.html +9 -4
  12. package/docs/functions/Clipboard.SetText.html +1 -1
  13. package/docs/functions/Clipboard.Text.html +1 -1
  14. package/docs/functions/Create.Any.html +1 -1
  15. package/docs/functions/Create.Array.html +1 -1
  16. package/docs/functions/Create.ByteSlice.html +1 -1
  17. package/docs/functions/Create.Map.html +1 -1
  18. package/docs/functions/Create.Nullable.html +1 -1
  19. package/docs/functions/Create.Struct.html +1 -1
  20. package/docs/functions/Dialogs.Error.html +1 -1
  21. package/docs/functions/Dialogs.Info.html +1 -1
  22. package/docs/functions/Dialogs.OpenFile.html +1 -1
  23. package/docs/functions/Dialogs.Question.html +1 -1
  24. package/docs/functions/Dialogs.SaveFile.html +1 -1
  25. package/docs/functions/Dialogs.Warning.html +1 -1
  26. package/docs/functions/Events.Emit.html +1 -1
  27. package/docs/functions/Events.Off.html +1 -1
  28. package/docs/functions/Events.OffAll.html +1 -1
  29. package/docs/functions/Events.On.html +1 -1
  30. package/docs/functions/Events.OnMultiple.html +1 -1
  31. package/docs/functions/Events.Once.html +1 -1
  32. package/docs/functions/Events.setup.html +1 -1
  33. package/docs/functions/Flags.GetFlag.html +1 -1
  34. package/docs/functions/Screens.GetAll.html +1 -1
  35. package/docs/functions/Screens.GetCurrent.html +1 -1
  36. package/docs/functions/Screens.GetPrimary.html +1 -1
  37. package/docs/functions/System.Capabilities.html +1 -1
  38. package/docs/functions/System.Environment.html +1 -1
  39. package/docs/functions/System.IsAMD64.html +1 -1
  40. package/docs/functions/System.IsARM.html +1 -1
  41. package/docs/functions/System.IsARM64.html +1 -1
  42. package/docs/functions/System.IsDarkMode.html +1 -1
  43. package/docs/functions/System.IsDebug.html +1 -1
  44. package/docs/functions/System.IsLinux.html +1 -1
  45. package/docs/functions/System.IsMac.html +1 -1
  46. package/docs/functions/System.IsWindows.html +1 -1
  47. package/docs/functions/System.invoke.html +1 -1
  48. package/docs/functions/WML.Enable.html +1 -1
  49. package/docs/functions/WML.Reload.html +1 -1
  50. package/docs/functions/init.html +1 -1
  51. package/docs/interfaces/Call.CallOptions.html +7 -0
  52. package/docs/interfaces/Dialogs.Button.html +4 -4
  53. package/docs/interfaces/Dialogs.FileFilter.html +3 -3
  54. package/docs/interfaces/Dialogs.MessageDialogOptions.html +5 -5
  55. package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +17 -17
  56. package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +18 -18
  57. package/docs/interfaces/Screens.Rect.html +5 -5
  58. package/docs/interfaces/Screens.Screen.html +13 -13
  59. package/docs/interfaces/Screens.Size.html +3 -3
  60. package/docs/interfaces/System.EnvironmentInfo.html +6 -6
  61. package/docs/interfaces/System.OSInfo.html +5 -5
  62. package/docs/modules/Application.html +1 -1
  63. package/docs/modules/Browser.html +1 -1
  64. package/docs/modules/Call.html +3 -2
  65. package/docs/modules/Clipboard.html +1 -1
  66. package/docs/modules/Create.html +1 -1
  67. package/docs/modules/Dialogs.html +1 -1
  68. package/docs/modules/Events.html +1 -1
  69. package/docs/modules/Flags.html +1 -1
  70. package/docs/modules/Screens.html +1 -1
  71. package/docs/modules/System.html +1 -1
  72. package/docs/modules/WML.html +1 -1
  73. package/docs/variables/Events.Types.html +1 -1
  74. package/docs/variables/Window.html +1 -1
  75. package/package.json +1 -1
  76. package/src/calls.js +103 -56
  77. package/src/dialogs.js +2 -2
  78. package/src/runtime.js +17 -48
  79. package/types/calls.d.ts +55 -19
  80. package/types/runtime.d.ts +2 -2
  81. package/docs/functions/Call.Plugin.html +0 -8
@@ -1,2 +1,2 @@
1
1
  <!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Window | @wailsio/runtime</title><meta name="description" content="Documentation for @wailsio/runtime"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@wailsio/runtime</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@wailsio/runtime</a></li><li><a href="Window.html">Window</a></li></ul><h1>Variable Window<code class="tsd-tag ts-flagConst">Const</code> </h1></div><div class="tsd-signature"><span class="tsd-kind-variable">Window</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Window</span><span class="tsd-signature-symbol"> = ...</span></div><div class="tsd-comment tsd-typography"><p>The window within which the script is running.</p>
2
- </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/wailsapp/wails/blob/b4c4cd8a/v3/internal/runtime/desktop/@wailsio/runtime/src/window.js#L636">window.js:636</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@wailsio/runtime</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><div class="tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div></body></html>
2
+ </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/wailsapp/wails/blob/29c0d150/v3/internal/runtime/desktop/@wailsio/runtime/src/window.js#L636">src/window.js:636</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@wailsio/runtime</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><div class="tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div></body></html>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wailsio/runtime",
3
3
  "type": "module",
4
- "version": "3.0.0-alpha.55",
4
+ "version": "3.0.0-alpha.56",
5
5
  "description": "Wails Runtime",
6
6
  "types": "types/index.d.ts",
7
7
  "exports": {
package/src/calls.js CHANGED
@@ -48,7 +48,17 @@ function generateID() {
48
48
  function resultHandler(id, data, isJSON) {
49
49
  const promiseHandler = getAndDeleteResponse(id);
50
50
  if (promiseHandler) {
51
- promiseHandler.resolve(isJSON ? JSON.parse(data) : data);
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
+ }
52
62
  }
53
63
  }
54
64
 
@@ -56,14 +66,48 @@ function resultHandler(id, data, isJSON) {
56
66
  * Handles the error from a call request.
57
67
  *
58
68
  * @param {string} id - The id of the promise handler.
59
- * @param {string} message - The error message to reject the promise handler with.
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.
60
71
  *
61
72
  * @return {void}
62
73
  */
63
- function errorHandler(id, message) {
74
+ function errorHandler(id, data, isJSON) {
64
75
  const promiseHandler = getAndDeleteResponse(id);
65
76
  if (promiseHandler) {
66
- promiseHandler.reject(message);
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
+ }
67
111
  }
68
112
  }
69
113
 
@@ -81,30 +125,59 @@ function getAndDeleteResponse(id) {
81
125
  }
82
126
 
83
127
  /**
84
- * Executes a call using the provided type and options.
128
+ * Collects all required information for a binding call.
85
129
  *
86
- * @param {string|number} type - The type of call to execute.
87
- * @param {Object} [options={}] - Additional options for the call.
88
- * @return {Promise} - A promise that will be resolved or rejected based on the result of the call. It also has a cancel method to cancel a long running request.
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.
89
134
  */
90
- function callBinding(type, options = {}) {
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) {
91
166
  const id = generateID();
92
167
  const doCancel = () => { return cancelCall(type, {"call-id": id}) };
93
168
  let queuedCancel = false, callRunning = false;
94
169
  let p = new Promise((resolve, reject) => {
95
170
  options["call-id"] = id;
96
171
  callResponses.set(id, { resolve, reject });
97
- call(type, options).
98
- then((_) => {
99
- callRunning = true;
100
- if (queuedCancel) {
101
- return doCancel();
102
- }
103
- }).
104
- catch((error) => {
105
- reject(error);
106
- callResponses.delete(id);
107
- });
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
+ });
108
181
  });
109
182
  p.cancel = () => {
110
183
  if (callRunning) {
@@ -118,57 +191,31 @@ function callBinding(type, options = {}) {
118
191
  }
119
192
 
120
193
  /**
121
- * Call method.
122
- *
123
- * @param {Object} options - The options for the method.
124
- * @returns {Object} - The result of the call.
125
- */
126
- export function Call(options) {
127
- return callBinding(CallBinding, options);
128
- }
129
-
130
- /**
131
- * Executes a method by name.
194
+ * Calls a bound method by name with the specified arguments.
195
+ * See {@link Call} for details.
132
196
  *
133
197
  * @param {string} methodName - The name of the method in the format 'package.struct.method'.
134
- * @param {...*} args - The arguments to pass to the method.
135
- * @throws {Error} If the name is not a string or is not in the correct format.
136
- * @returns {*} The result of the method execution.
198
+ * @param {any[]} args - The arguments to pass to the method.
199
+ * @returns {Promise<any>} The result of the method call.
137
200
  */
138
201
  export function ByName(methodName, ...args) {
139
- return callBinding(CallBinding, {
202
+ return Call({
140
203
  methodName,
141
204
  args
142
205
  });
143
206
  }
144
207
 
145
208
  /**
146
- * Calls a method by its ID with the specified arguments.
209
+ * Calls a method by its numeric ID with the specified arguments.
210
+ * See {@link Call} for details.
147
211
  *
148
212
  * @param {number} methodID - The ID of the method to call.
149
- * @param {...*} args - The arguments to pass to the method.
150
- * @return {*} - The result of the method call.
213
+ * @param {any[]} args - The arguments to pass to the method.
214
+ * @return {Promise<any>} - The result of the method call.
151
215
  */
152
216
  export function ByID(methodID, ...args) {
153
- return callBinding(CallBinding, {
217
+ return Call({
154
218
  methodID,
155
219
  args
156
220
  });
157
221
  }
158
-
159
- /**
160
- * Calls a method on a plugin.
161
- *
162
- * @param {string} pluginName - The name of the plugin.
163
- * @param {string} methodName - The name of the method to call.
164
- * @param {...*} args - The arguments to pass to the method.
165
- * @returns {*} - The result of the method call.
166
- */
167
- export function Plugin(pluginName, methodName, ...args) {
168
- return callBinding(CallBinding, {
169
- packageName: "wails-plugins",
170
- structName: pluginName,
171
- methodName,
172
- args
173
- });
174
- }
package/src/dialogs.js CHANGED
@@ -135,12 +135,12 @@ function dialog(type, options = {}) {
135
135
  function dialogResultCallback(id, data, isJSON) {
136
136
  let p = dialogResponses.get(id);
137
137
  if (p) {
138
+ dialogResponses.delete(id);
138
139
  if (isJSON) {
139
140
  p.resolve(JSON.parse(data));
140
141
  } else {
141
142
  p.resolve(data);
142
143
  }
143
- dialogResponses.delete(id);
144
144
  }
145
145
  }
146
146
 
@@ -155,8 +155,8 @@ function dialogResultCallback(id, data, isJSON) {
155
155
  function dialogErrorCallback(id, message) {
156
156
  let p = dialogResponses.get(id);
157
157
  if (p) {
158
- p.reject(message);
159
158
  dialogResponses.delete(id);
159
+ p.reject(new Error(message));
160
160
  }
161
161
  }
162
162
 
package/src/runtime.js CHANGED
@@ -45,7 +45,7 @@ export function newRuntimeCaller(object, windowName) {
45
45
  /**
46
46
  * Creates a new runtime caller with specified ID.
47
47
  *
48
- * @param {object} object - The object to invoke the method on.
48
+ * @param {number} object - The object to invoke the method on.
49
49
  * @param {string} windowName - The name of the window.
50
50
  * @return {Function} - The new runtime caller function.
51
51
  */
@@ -57,8 +57,15 @@ export function newRuntimeCallerWithID(object, windowName) {
57
57
 
58
58
 
59
59
  function runtimeCall(method, windowName, args) {
60
+ return runtimeCallWithID(null, method, windowName, args);
61
+ }
62
+
63
+ async function runtimeCallWithID(objectID, method, windowName, args) {
60
64
  let url = new URL(runtimeURL);
61
- if( method ) {
65
+ if (objectID != null) {
66
+ url.searchParams.append("object", objectID);
67
+ }
68
+ if (method != null) {
62
69
  url.searchParams.append("method", method);
63
70
  }
64
71
  let fetchOptions = {
@@ -72,52 +79,14 @@ function runtimeCall(method, windowName, args) {
72
79
  }
73
80
  fetchOptions.headers["x-wails-client-id"] = clientId;
74
81
 
75
- return new Promise((resolve, reject) => {
76
- fetch(url, fetchOptions)
77
- .then(response => {
78
- if (response.ok) {
79
- // check content type
80
- if (response.headers.get("Content-Type") && response.headers.get("Content-Type").indexOf("application/json") !== -1) {
81
- return response.json();
82
- } else {
83
- return response.text();
84
- }
85
- }
86
- reject(Error(response.statusText));
87
- })
88
- .then(data => resolve(data))
89
- .catch(error => reject(error));
90
- });
91
- }
92
-
93
- function runtimeCallWithID(objectID, method, windowName, args) {
94
- let url = new URL(runtimeURL);
95
- url.searchParams.append("object", objectID);
96
- url.searchParams.append("method", method);
97
- let fetchOptions = {
98
- headers: {},
99
- };
100
- if (windowName) {
101
- fetchOptions.headers["x-wails-window-name"] = windowName;
82
+ let response = await fetch(url, fetchOptions);
83
+ if (!response.ok) {
84
+ throw new Error(await response.text());
102
85
  }
103
- if (args) {
104
- url.searchParams.append("args", JSON.stringify(args));
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();
105
91
  }
106
- fetchOptions.headers["x-wails-client-id"] = clientId;
107
- return new Promise((resolve, reject) => {
108
- fetch(url, fetchOptions)
109
- .then(response => {
110
- if (response.ok) {
111
- // check content type
112
- if (response.headers.get("Content-Type") && response.headers.get("Content-Type").indexOf("application/json") !== -1) {
113
- return response.json();
114
- } else {
115
- return response.text();
116
- }
117
- }
118
- reject(Error(response.statusText));
119
- })
120
- .then(data => resolve(data))
121
- .catch(error => reject(error));
122
- });
123
92
  }
package/types/calls.d.ts CHANGED
@@ -1,33 +1,69 @@
1
1
  /**
2
- * Call method.
2
+ * Call a bound method according to the given call options.
3
3
  *
4
- * @param {Object} options - The options for the method.
5
- * @returns {Object} - The result of the call.
4
+ * In case of failure, the returned promise will reject with an exception
5
+ * among ReferenceError (unknown method), TypeError (wrong argument count or type),
6
+ * {@link RuntimeError} (method returned an error), or other (network or internal errors).
7
+ * The exception might have a "cause" field with the value returned
8
+ * by the application- or service-level error marshaling functions.
9
+ *
10
+ * @param {CallOptions} options - A method call descriptor.
11
+ * @returns {Promise<any>} - The result of the call.
6
12
  */
7
- export function Call(options: any): any;
13
+ export function Call(options: CallOptions): Promise<any>;
8
14
  /**
9
- * Executes a method by name.
15
+ * Calls a bound method by name with the specified arguments.
16
+ * See {@link Call} for details.
10
17
  *
11
18
  * @param {string} methodName - The name of the method in the format 'package.struct.method'.
12
- * @param {...*} args - The arguments to pass to the method.
13
- * @throws {Error} If the name is not a string or is not in the correct format.
14
- * @returns {*} The result of the method execution.
19
+ * @param {any[]} args - The arguments to pass to the method.
20
+ * @returns {Promise<any>} The result of the method call.
15
21
  */
16
- export function ByName(methodName: string, ...args: any[]): any;
22
+ export function ByName(methodName: string, ...args: any[]): Promise<any>;
17
23
  /**
18
- * Calls a method by its ID with the specified arguments.
24
+ * Calls a method by its numeric ID with the specified arguments.
25
+ * See {@link Call} for details.
19
26
  *
20
27
  * @param {number} methodID - The ID of the method to call.
21
- * @param {...*} args - The arguments to pass to the method.
22
- * @return {*} - The result of the method call.
28
+ * @param {any[]} args - The arguments to pass to the method.
29
+ * @return {Promise<any>} - The result of the method call.
23
30
  */
24
- export function ByID(methodID: number, ...args: any[]): any;
31
+ export function ByID(methodID: number, ...args: any[]): Promise<any>;
25
32
  /**
26
- * Calls a method on a plugin.
33
+ * Collects all required information for a binding call.
27
34
  *
28
- * @param {string} pluginName - The name of the plugin.
29
- * @param {string} methodName - The name of the method to call.
30
- * @param {...*} args - The arguments to pass to the method.
31
- * @returns {*} - The result of the method call.
35
+ * @typedef {Object} CallOptions
36
+ * @property {number} [methodID] - The numeric ID of the bound method to call.
37
+ * @property {string} [methodName] - The fully qualified name of the bound method to call.
38
+ * @property {any[]} args - Arguments to be passed into the bound method.
39
+ */
40
+ /**
41
+ * Exception class that will be thrown in case the bound method returns an error.
42
+ * The value of the {@link RuntimeError#name} property is "RuntimeError".
43
+ */
44
+ export class RuntimeError extends Error {
45
+ /**
46
+ * Constructs a new RuntimeError instance.
47
+ *
48
+ * @param {string} message - The error message.
49
+ * @param {any[]} args - Optional arguments for the Error constructor.
50
+ */
51
+ constructor(message: string, ...args: any[]);
52
+ }
53
+ /**
54
+ * Collects all required information for a binding call.
32
55
  */
33
- export function Plugin(pluginName: string, methodName: string, ...args: any[]): any;
56
+ export type CallOptions = {
57
+ /**
58
+ * - The numeric ID of the bound method to call.
59
+ */
60
+ methodID?: number;
61
+ /**
62
+ * - The fully qualified name of the bound method to call.
63
+ */
64
+ methodName?: string;
65
+ /**
66
+ * - Arguments to be passed into the bound method.
67
+ */
68
+ args: any[];
69
+ };
@@ -9,11 +9,11 @@ export function newRuntimeCaller(object: any, windowName: string): Function;
9
9
  /**
10
10
  * Creates a new runtime caller with specified ID.
11
11
  *
12
- * @param {object} object - The object to invoke the method on.
12
+ * @param {number} object - The object to invoke the method on.
13
13
  * @param {string} windowName - The name of the window.
14
14
  * @return {Function} - The new runtime caller function.
15
15
  */
16
- export function newRuntimeCallerWithID(object: object, windowName: string): Function;
16
+ export function newRuntimeCallerWithID(object: number, windowName: string): Function;
17
17
  export namespace objectNames {
18
18
  let Call: number;
19
19
  let Clipboard: number;
@@ -1,8 +0,0 @@
1
- <!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Plugin | @wailsio/runtime</title><meta name="description" content="Documentation for @wailsio/runtime"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@wailsio/runtime</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@wailsio/runtime</a></li><li><a href="../modules/Call.html">Call</a></li><li><a href="Call.Plugin.html">Plugin</a></li></ul><h1>Function Plugin</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="Plugin" class="tsd-anchor"></a><span class="tsd-kind-call-signature">Plugin</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">pluginName</span>, <span class="tsd-kind-parameter">methodName</span>, <span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">args</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><a href="#Plugin" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Calls a method on a plugin.</p>
2
- </div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">pluginName</span>: <span class="tsd-signature-type">string</span></span><div class="tsd-comment tsd-typography"><p>The name of the plugin.</p>
3
- </div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-kind-parameter">methodName</span>: <span class="tsd-signature-type">string</span></span><div class="tsd-comment tsd-typography"><p>The name of the method to call.</p>
4
- </div><div class="tsd-comment tsd-typography"></div></li><li><span><code class="tsd-tag ts-flagRest">Rest</code> <span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">args</span>: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></span><div class="tsd-comment tsd-typography"><p>The arguments to pass to the method.</p>
5
- </div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">any</span></h4><ul>
6
- <li>The result of the method call.</li>
7
- </ul>
8
- <div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/wailsapp/wails/blob/b4c4cd8a/v3/internal/runtime/desktop/@wailsio/runtime/src/calls.js#L167">calls.js:167</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@wailsio/runtime</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><div class="tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div></body></html>