@wailsio/runtime 3.0.0-alpha.9 → 3.0.0-alpha.95

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 (71) hide show
  1. package/dist/android.js +39 -0
  2. package/{src → dist}/application.js +32 -46
  3. package/dist/browser.js +20 -0
  4. package/dist/callable.js +144 -0
  5. package/dist/calls.js +114 -0
  6. package/dist/cancellable.js +792 -0
  7. package/dist/clipboard.js +30 -0
  8. package/dist/contextmenu.js +83 -0
  9. package/dist/create.js +99 -0
  10. package/dist/dialogs.js +69 -0
  11. package/dist/drag.js +268 -0
  12. package/dist/environment.js +17 -0
  13. package/dist/event_types.js +292 -0
  14. package/dist/events.js +119 -0
  15. package/dist/flags.js +23 -0
  16. package/dist/index.js +88 -0
  17. package/dist/ios.js +28 -0
  18. package/dist/listener.js +44 -0
  19. package/dist/nanoid.js +38 -0
  20. package/dist/plugins/vite.js +64 -0
  21. package/dist/runtime.js +198 -0
  22. package/dist/screens.js +58 -0
  23. package/dist/system.js +158 -0
  24. package/dist/updater.js +74 -0
  25. package/dist/utils.js +98 -0
  26. package/dist/window.js +734 -0
  27. package/dist/wml.js +179 -0
  28. package/package.json +71 -26
  29. package/types/android.d.ts +21 -0
  30. package/types/application.d.ts +3 -10
  31. package/types/browser.d.ts +4 -4
  32. package/types/callable.d.ts +3 -0
  33. package/types/calls.d.ts +52 -24
  34. package/types/cancellable.d.ts +433 -0
  35. package/types/clipboard.d.ts +6 -5
  36. package/types/contextmenu.d.ts +1 -1
  37. package/types/create.d.ts +36 -0
  38. package/types/dialogs.d.ts +132 -20
  39. package/types/drag.d.ts +1 -4
  40. package/types/environment.d.ts +8 -0
  41. package/types/event_types.d.ts +281 -0
  42. package/types/events.d.ts +70 -33
  43. package/types/flags.d.ts +3 -3
  44. package/types/index.d.ts +32 -48
  45. package/types/ios.d.ts +13 -0
  46. package/types/listener.d.ts +9 -0
  47. package/types/nanoid.d.ts +1 -0
  48. package/types/plugins/vite.d.ts +10 -0
  49. package/types/runtime.d.ts +61 -22
  50. package/types/screens.d.ts +64 -7
  51. package/types/system.d.ts +74 -39
  52. package/types/updater.d.ts +65 -0
  53. package/types/utils.d.ts +21 -0
  54. package/types/window.d.ts +327 -13
  55. package/types/wml.d.ts +5 -3
  56. package/src/browser.js +0 -24
  57. package/src/calls.js +0 -123
  58. package/src/clipboard.js +0 -35
  59. package/src/contextmenu.js +0 -98
  60. package/src/dialogs.js +0 -138
  61. package/src/drag.js +0 -125
  62. package/src/events.js +0 -134
  63. package/src/flags.js +0 -63
  64. package/src/index.d.ts +0 -136
  65. package/src/index.js +0 -58
  66. package/src/runtime.js +0 -122
  67. package/src/screens.js +0 -45
  68. package/src/system.js +0 -122
  69. package/src/window.js +0 -122
  70. package/src/wml.js +0 -151
  71. package/tsconfig.json +0 -20
@@ -0,0 +1,39 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ const call = newRuntimeCaller(objectNames.Android);
12
+ // Method IDs (must match messageprocessor_android.go)
13
+ const HapticsVibrate = 0;
14
+ const DeviceInfo = 1;
15
+ const ToastShow = 2;
16
+ export var Haptics;
17
+ (function (Haptics) {
18
+ /** Vibrate the device for the given duration in milliseconds. */
19
+ function Vibrate(durationMs = 100) {
20
+ return call(HapticsVibrate, { duration: durationMs });
21
+ }
22
+ Haptics.Vibrate = Vibrate;
23
+ })(Haptics || (Haptics = {}));
24
+ export var Device;
25
+ (function (Device) {
26
+ /** Return information about the Android device. */
27
+ function Info() {
28
+ return call(DeviceInfo);
29
+ }
30
+ Device.Info = Info;
31
+ })(Device || (Device = {}));
32
+ export var Toast;
33
+ (function (Toast) {
34
+ /** Show a short Android toast message. */
35
+ function Show(message) {
36
+ return call(ToastShow, { message });
37
+ }
38
+ Toast.Show = Show;
39
+ })(Toast || (Toast = {}));
@@ -1,46 +1,32 @@
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
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ const call = newRuntimeCaller(objectNames.Application);
12
+ const HideMethod = 0;
13
+ const ShowMethod = 1;
14
+ const QuitMethod = 2;
15
+ /**
16
+ * Hides a certain method by calling the HideMethod function.
17
+ */
18
+ export function Hide() {
19
+ return call(HideMethod);
20
+ }
21
+ /**
22
+ * Calls the ShowMethod and returns the result.
23
+ */
24
+ export function Show() {
25
+ return call(ShowMethod);
26
+ }
27
+ /**
28
+ * Calls the QuitMethod to terminate the program.
29
+ */
30
+ export function Quit() {
31
+ return call(QuitMethod);
32
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
11
+ const call = newRuntimeCaller(objectNames.Browser);
12
+ const BrowserOpenURL = 0;
13
+ /**
14
+ * Open a browser window to the given URL.
15
+ *
16
+ * @param url - The URL to open
17
+ */
18
+ export function OpenURL(url) {
19
+ return call(BrowserOpenURL, { url: url.toString() });
20
+ }
@@ -0,0 +1,144 @@
1
+ // Source: https://github.com/inspect-js/is-callable
2
+ // The MIT License (MIT)
3
+ //
4
+ // Copyright (c) 2015 Jordan Harband
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in all
14
+ // copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ // SOFTWARE.
23
+ var fnToStr = Function.prototype.toString;
24
+ var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply;
25
+ var badArrayLike;
26
+ var isCallableMarker;
27
+ if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') {
28
+ try {
29
+ badArrayLike = Object.defineProperty({}, 'length', {
30
+ get: function () {
31
+ throw isCallableMarker;
32
+ }
33
+ });
34
+ isCallableMarker = {};
35
+ // eslint-disable-next-line no-throw-literal
36
+ reflectApply(function () { throw 42; }, null, badArrayLike);
37
+ }
38
+ catch (_) {
39
+ if (_ !== isCallableMarker) {
40
+ reflectApply = null;
41
+ }
42
+ }
43
+ }
44
+ else {
45
+ reflectApply = null;
46
+ }
47
+ var constructorRegex = /^\s*class\b/;
48
+ var isES6ClassFn = function isES6ClassFunction(value) {
49
+ try {
50
+ var fnStr = fnToStr.call(value);
51
+ return constructorRegex.test(fnStr);
52
+ }
53
+ catch (e) {
54
+ return false; // not a function
55
+ }
56
+ };
57
+ var tryFunctionObject = function tryFunctionToStr(value) {
58
+ try {
59
+ if (isES6ClassFn(value)) {
60
+ return false;
61
+ }
62
+ fnToStr.call(value);
63
+ return true;
64
+ }
65
+ catch (e) {
66
+ return false;
67
+ }
68
+ };
69
+ var toStr = Object.prototype.toString;
70
+ var objectClass = '[object Object]';
71
+ var fnClass = '[object Function]';
72
+ var genClass = '[object GeneratorFunction]';
73
+ var ddaClass = '[object HTMLAllCollection]'; // IE 11
74
+ var ddaClass2 = '[object HTML document.all class]';
75
+ var ddaClass3 = '[object HTMLCollection]'; // IE 9-10
76
+ var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag`
77
+ var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing
78
+ var isDDA = function isDocumentDotAll() { return false; };
79
+ if (typeof document === 'object') {
80
+ // Firefox 3 canonicalizes DDA to undefined when it's not accessed directly
81
+ var all = document.all;
82
+ if (toStr.call(all) === toStr.call(document.all)) {
83
+ isDDA = function isDocumentDotAll(value) {
84
+ /* globals document: false */
85
+ // in IE 6-8, typeof document.all is "object" and it's truthy
86
+ if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) {
87
+ try {
88
+ var str = toStr.call(value);
89
+ return (str === ddaClass
90
+ || str === ddaClass2
91
+ || str === ddaClass3 // opera 12.16
92
+ || str === objectClass // IE 6-8
93
+ ) && value('') == null; // eslint-disable-line eqeqeq
94
+ }
95
+ catch (e) { /**/ }
96
+ }
97
+ return false;
98
+ };
99
+ }
100
+ }
101
+ function isCallableRefApply(value) {
102
+ if (isDDA(value)) {
103
+ return true;
104
+ }
105
+ if (!value) {
106
+ return false;
107
+ }
108
+ if (typeof value !== 'function' && typeof value !== 'object') {
109
+ return false;
110
+ }
111
+ try {
112
+ reflectApply(value, null, badArrayLike);
113
+ }
114
+ catch (e) {
115
+ if (e !== isCallableMarker) {
116
+ return false;
117
+ }
118
+ }
119
+ return !isES6ClassFn(value) && tryFunctionObject(value);
120
+ }
121
+ function isCallableNoRefApply(value) {
122
+ if (isDDA(value)) {
123
+ return true;
124
+ }
125
+ if (!value) {
126
+ return false;
127
+ }
128
+ if (typeof value !== 'function' && typeof value !== 'object') {
129
+ return false;
130
+ }
131
+ if (hasToStringTag) {
132
+ return tryFunctionObject(value);
133
+ }
134
+ if (isES6ClassFn(value)) {
135
+ return false;
136
+ }
137
+ var strClass = toStr.call(value);
138
+ if (strClass !== fnClass && strClass !== genClass && !(/^\[object HTML/).test(strClass)) {
139
+ return false;
140
+ }
141
+ return tryFunctionObject(value);
142
+ }
143
+ ;
144
+ export default reflectApply ? isCallableRefApply : isCallableNoRefApply;
package/dist/calls.js ADDED
@@ -0,0 +1,114 @@
1
+ /*
2
+ _ __ _ __
3
+ | | / /___ _(_) /____
4
+ | | /| / / __ `/ / / ___/
5
+ | |/ |/ / /_/ / / (__ )
6
+ |__/|__/\__,_/_/_/____/
7
+ The electron alternative for Go
8
+ (c) Lea Anthony 2019-present
9
+ */
10
+ import { CancellablePromise } from "./cancellable.js";
11
+ import { newRuntimeCaller, objectNames } from "./runtime.js";
12
+ import { nanoid } from "./nanoid.js";
13
+ // Setup
14
+ import { hasDOM } from "./environment.js";
15
+ if (hasDOM) {
16
+ window._wails = window._wails || {};
17
+ }
18
+ const call = newRuntimeCaller(objectNames.Call);
19
+ const cancelCall = newRuntimeCaller(objectNames.CancelCall);
20
+ const callResponses = new Map();
21
+ const CallBinding = 0;
22
+ const CancelMethod = 0;
23
+ /**
24
+ * Exception class that will be thrown in case the bound method returns an error.
25
+ * The value of the {@link RuntimeError#name} property is "RuntimeError".
26
+ */
27
+ export class RuntimeError extends Error {
28
+ /**
29
+ * Constructs a new RuntimeError instance.
30
+ * @param message - The error message.
31
+ * @param options - Options to be forwarded to the Error constructor.
32
+ */
33
+ constructor(message, options) {
34
+ super(message, options);
35
+ this.name = "RuntimeError";
36
+ }
37
+ }
38
+ /**
39
+ * Generates a unique ID using the nanoid library.
40
+ *
41
+ * @returns A unique ID that does not exist in the callResponses set.
42
+ */
43
+ function generateID() {
44
+ let result;
45
+ do {
46
+ result = nanoid();
47
+ } while (callResponses.has(result));
48
+ return result;
49
+ }
50
+ /**
51
+ * Call a bound method according to the given call options.
52
+ *
53
+ * In case of failure, the returned promise will reject with an exception
54
+ * among ReferenceError (unknown method), TypeError (wrong argument count or type),
55
+ * {@link RuntimeError} (method returned an error), or other (network or internal errors).
56
+ * The exception might have a "cause" field with the value returned
57
+ * by the application- or service-level error marshaling functions.
58
+ *
59
+ * @param options - A method call descriptor.
60
+ * @returns The result of the call.
61
+ */
62
+ export function Call(options) {
63
+ const id = generateID();
64
+ const result = CancellablePromise.withResolvers();
65
+ callResponses.set(id, { resolve: result.resolve, reject: result.reject });
66
+ const request = call(CallBinding, Object.assign({ "call-id": id }, options));
67
+ let running = true;
68
+ request.then((res) => {
69
+ running = false;
70
+ callResponses.delete(id);
71
+ result.resolve(res);
72
+ }, (err) => {
73
+ running = false;
74
+ callResponses.delete(id);
75
+ result.reject(err);
76
+ });
77
+ const cancel = () => {
78
+ callResponses.delete(id);
79
+ return cancelCall(CancelMethod, { "call-id": id }).catch((err) => {
80
+ console.error("Error while requesting binding call cancellation:", err);
81
+ });
82
+ };
83
+ result.oncancelled = () => {
84
+ if (running) {
85
+ return cancel();
86
+ }
87
+ else {
88
+ return request.then(cancel);
89
+ }
90
+ };
91
+ return result.promise;
92
+ }
93
+ /**
94
+ * Calls a bound method by name with the specified arguments.
95
+ * See {@link Call} for details.
96
+ *
97
+ * @param methodName - The name of the method in the format 'package.struct.method'.
98
+ * @param args - The arguments to pass to the method.
99
+ * @returns The result of the method call.
100
+ */
101
+ export function ByName(methodName, ...args) {
102
+ return Call({ methodName, args });
103
+ }
104
+ /**
105
+ * Calls a method by its numeric ID with the specified arguments.
106
+ * See {@link Call} for details.
107
+ *
108
+ * @param methodID - The ID of the method to call.
109
+ * @param args - The arguments to pass to the method.
110
+ * @return The result of the method call.
111
+ */
112
+ export function ByID(methodID, ...args) {
113
+ return Call({ methodID, args });
114
+ }