@wailsio/runtime 3.0.0-alpha.7 → 3.0.0-alpha.72

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 (59) hide show
  1. package/{application.js → dist/application.js} +32 -46
  2. package/dist/browser.js +20 -0
  3. package/dist/callable.js +144 -0
  4. package/dist/calls.js +194 -0
  5. package/dist/cancellable.js +792 -0
  6. package/dist/clipboard.js +30 -0
  7. package/dist/contextmenu.js +80 -0
  8. package/dist/create.js +94 -0
  9. package/dist/dialogs.js +134 -0
  10. package/dist/drag.js +222 -0
  11. package/dist/event_types.js +232 -0
  12. package/dist/events.js +114 -0
  13. package/dist/flags.js +23 -0
  14. package/dist/index.js +42 -0
  15. package/dist/listener.js +44 -0
  16. package/dist/nanoid.js +38 -0
  17. package/dist/runtime.js +63 -0
  18. package/{screens.js → dist/screens.js} +38 -45
  19. package/dist/system.js +146 -0
  20. package/dist/utils.js +95 -0
  21. package/dist/window.js +570 -0
  22. package/dist/wml.js +179 -0
  23. package/package.json +62 -18
  24. package/types/application.d.ts +12 -0
  25. package/types/browser.d.ts +6 -0
  26. package/types/callable.d.ts +3 -0
  27. package/types/calls.d.ts +63 -0
  28. package/types/cancellable.d.ts +434 -0
  29. package/types/clipboard.d.ts +13 -0
  30. package/types/contextmenu.d.ts +1 -0
  31. package/types/create.d.ts +31 -0
  32. package/types/dialogs.d.ts +140 -0
  33. package/types/drag.d.ts +1 -0
  34. package/types/event_types.d.ts +221 -0
  35. package/types/events.d.ts +67 -0
  36. package/types/flags.d.ts +7 -0
  37. package/types/index.d.ts +16 -0
  38. package/types/listener.d.ts +9 -0
  39. package/types/nanoid.d.ts +1 -0
  40. package/types/runtime.d.ts +22 -0
  41. package/types/screens.d.ts +60 -0
  42. package/types/system.d.ts +92 -0
  43. package/types/utils.d.ts +21 -0
  44. package/types/window.d.ts +306 -0
  45. package/types/wml.d.ts +8 -0
  46. package/browser.js +0 -24
  47. package/calls.js +0 -123
  48. package/clipboard.js +0 -35
  49. package/contextmenu.js +0 -98
  50. package/dialogs.js +0 -138
  51. package/drag.js +0 -125
  52. package/events.js +0 -134
  53. package/flags.js +0 -63
  54. package/index.js +0 -56
  55. package/runtime.js +0 -122
  56. package/system.js +0 -122
  57. package/types.d.ts +0 -135
  58. package/window.js +0 -122
  59. package/wml.js +0 -151
package/system.js DELETED
@@ -1,122 +0,0 @@
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
- let call = newRuntimeCallerWithID(objectNames.System, '');
15
- const systemIsDarkMode = 0;
16
- const environment = 1;
17
-
18
- /**
19
- * @function
20
- * Retrieves the system dark mode status.
21
- * @returns {Promise<boolean>} - A promise that resolves to a boolean value indicating if the system is in dark mode.
22
- */
23
- export function IsDarkMode() {
24
- return call(systemIsDarkMode);
25
- }
26
-
27
-
28
- /**
29
- * Fetches the capabilities of the application from the server.
30
- *
31
- * @async
32
- * @function Capabilities
33
- * @returns {Promise<Object>} A promise that resolves to an object containing the capabilities.
34
- */
35
- export async function Capabilities() {
36
- let response = fetch("/wails/capabilities");
37
- return response.json();
38
- }
39
-
40
- /**
41
- * @typedef {object} EnvironmentInfo
42
- * @property {string} OS - The operating system in use.
43
- * @property {string} Arch - The architecture of the system.
44
- */
45
-
46
- /**
47
- * @function
48
- * Retrieves environment details.
49
- * @returns {Promise<EnvironmentInfo>} - A promise that resolves to an object containing OS and system architecture.
50
- */
51
- export function Environment() {
52
- return call(environment);
53
- }
54
-
55
- export let invoke = null;
56
- let environmentCache = null;
57
-
58
- Environment()
59
- .then(result => {
60
- environmentCache = result;
61
- invoke = IsWindows() ? window.chrome.webview.postMessage : window.webkit.messageHandlers.external.postMessage;
62
- })
63
- .catch(error => {
64
- console.error(`Error getting Environment: ${error}`);
65
- });
66
-
67
- /**
68
- * Checks if the current operating system is Windows.
69
- *
70
- * @return {boolean} True if the operating system is Windows, otherwise false.
71
- */
72
- export function IsWindows() {
73
- return environmentCache.OS === "windows";
74
- }
75
-
76
- /**
77
- * Checks if the current operating system is Linux.
78
- *
79
- * @returns {boolean} Returns true if the current operating system is Linux, false otherwise.
80
- */
81
- export function IsLinux() {
82
- return environmentCache.OS === "linux";
83
- }
84
-
85
- /**
86
- * Checks if the current environment is a macOS operating system.
87
- *
88
- * @returns {boolean} True if the environment is macOS, false otherwise.
89
- */
90
- export function IsMac() {
91
- return environmentCache.OS === "darwin";
92
- }
93
-
94
- /**
95
- * Checks if the current environment architecture is AMD64.
96
- * @returns {boolean} True if the current environment architecture is AMD64, false otherwise.
97
- */
98
- export function IsAMD64() {
99
- return environmentCache.Arch === "amd64";
100
- }
101
-
102
- /**
103
- * Checks if the current architecture is ARM.
104
- *
105
- * @returns {boolean} True if the current architecture is ARM, false otherwise.
106
- */
107
- export function IsARM() {
108
- return environmentCache.Arch === "arm";
109
- }
110
-
111
- /**
112
- * Checks if the current environment is ARM64 architecture.
113
- *
114
- * @returns {boolean} - Returns true if the environment is ARM64 architecture, otherwise returns false.
115
- */
116
- export function IsARM64() {
117
- return environmentCache.Arch === "arm64";
118
- }
119
-
120
- export function IsDebug() {
121
- return environmentCache.Debug === true;
122
- }
package/types.d.ts DELETED
@@ -1,135 +0,0 @@
1
-
2
- /**
3
- * Describes the properties of a Button object.
4
- */
5
- export interface Button {
6
- // Text that appears within the button.
7
- Label?: string;
8
- // True if the button should cancel an operation when clicked.
9
- IsCancel?: boolean;
10
- // True if the button should be the default action when the user presses enter.
11
- IsDefault?: boolean;
12
- }
13
-
14
- /**
15
- * Describes the properties of a FileFilter object.
16
- */
17
- export interface FileFilter {
18
- // Display name for the filter, it could be "Text Files", "Images" etc.
19
- DisplayName?: string;
20
- // Pattern to match for the filter, e.g. "*.txt;*.md" for text markdown files.
21
- Pattern?: string;
22
- }
23
-
24
- /**
25
- * Describes the properties of a Position object.
26
- */
27
- export interface Position {
28
- X: number;
29
- Y: number;
30
- }
31
-
32
- /**
33
- * Describes the properties of a Size object.
34
- * Extends the properties of Position.
35
- */
36
- export type Size = Position;
37
-
38
- /**
39
- * Describes the properties of a Rect object.
40
- * Extends the properties of Size.
41
- */
42
- export type Rect = Size & Position;
43
-
44
- /**
45
- * Describes the possible rotations a Screen can have.
46
- */
47
- export enum Rotation {
48
- Zero = 0,
49
- Ninety = 90,
50
- OneEighty = 180,
51
- TwoSeventy = 270
52
- }
53
-
54
- /**
55
- * Describes the properties of a Screen object.
56
- */
57
- export interface Screen {
58
- // Unique identifier for the screen.
59
- Id: string;
60
- // Human readable name of the screen.
61
- Name: string;
62
- // The resolution scale of the screen. 1 = standard resolution, 2 = high (Retina), etc.
63
- Scale: number;
64
- // Contains the X and Y coordinates of the screen's position.
65
- Position: Position;
66
- // Contains the width and height of the screen.
67
- Size: Size;
68
- // Contains the bounds of the screen in terms of X, Y, Width, and Height.
69
- Bounds: Rect;
70
- // Contains the area of the screen that is actually usable (excluding taskbar and other system UI).
71
- WorkArea: Rect;
72
- // True if this is the primary monitor selected by the user in the operating system.
73
- IsPrimary: boolean;
74
- // The rotation of the screen. Can be one of 0, 90, 180, 270 degrees.
75
- Rotation: Rotation;
76
- }
77
-
78
- /**
79
- * Describes the properties of a MessageDialogOptions object.
80
- */
81
- export interface MessageDialogOptions {
82
- // The title of the dialog window.
83
- Title?: string;
84
- // The main message to show in the dialog.
85
- Message?: string;
86
- // Array of button options to show in the dialog.
87
- Buttons?: Button[];
88
- // True if the dialog should appear detached from the main window (if applicable).
89
- Detached?: boolean;
90
- }
91
-
92
- /**
93
- * Describes the properties common to OpenFileDialogOptions and SaveFileDialogOptions objects.
94
- */
95
- export interface DialogOptions {
96
- CanChooseDirectories?: boolean;
97
- CanChooseFiles?: boolean;
98
- CanCreateDirectories?: boolean;
99
- ShowHiddenFiles?: boolean;
100
- ResolvesAliases?: boolean;
101
- AllowsMultipleSelection?: boolean;
102
- HideExtension?: boolean;
103
- CanSelectHiddenExtension?: boolean;
104
- TreatsFilePackagesAsDirectories?: boolean;
105
- AllowsOtherFiletypes?: boolean;
106
- Filters?: FileFilter[];
107
- Title?: string;
108
- Message?: string;
109
- ButtonText?: string;
110
- Directory?: string;
111
- Detached?: boolean;
112
- }
113
-
114
- /**
115
- * Describes properties unique to OpenFileDialogOptions.
116
- */
117
- export type OpenFileDialogOptions = DialogOptions;
118
-
119
- /**
120
- * Describes properties unique to SaveFileDialogOptions.
121
- */
122
- export type SaveFileDialogOptions = DialogOptions & {
123
- // Default filename to use for the save dialog.
124
- Filename?: string;
125
- };
126
-
127
- /**
128
- * Describes the properties of a WailsEvent object.
129
- */
130
- export interface WailsEvent {
131
- // The name of the event.
132
- Name: string;
133
- // Any data associated with the event.
134
- Data?: unknown;
135
- }
package/window.js DELETED
@@ -1,122 +0,0 @@
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("../api/types").Size} Size
15
- * @typedef {import("../api/types").Position} Position
16
- * @typedef {import("../api/types").Screen} Screen
17
- */
18
-
19
- import {newRuntimeCallerWithID, objectNames} from "./runtime";
20
-
21
- const center = 0;
22
- const setTitle = 1;
23
- const fullscreen = 2;
24
- const unFullscreen = 3;
25
- const setSize = 4;
26
- const size = 5;
27
- const setMaxSize = 6;
28
- const setMinSize = 7;
29
- const setAlwaysOnTop = 8;
30
- const setRelativePosition = 9;
31
- const relativePosition = 10;
32
- const screen = 11;
33
- const hide = 12;
34
- const maximise = 13;
35
- const unMaximise = 14;
36
- const toggleMaximise = 15;
37
- const minimise = 16;
38
- const unMinimise = 17;
39
- const restore = 18;
40
- const show = 19;
41
- const close = 20;
42
- const setBackgroundColour = 21;
43
- const setResizable = 22;
44
- const width = 23;
45
- const height = 24;
46
- const zoomIn = 25;
47
- const zoomOut = 26;
48
- const zoomReset = 27;
49
- const getZoomLevel = 28;
50
- const setZoomLevel = 29;
51
-
52
- const thisWindow = newRuntimeCallerWithID(objectNames.Window, '');
53
-
54
- function createWindow(call) {
55
- return {
56
- Get: (windowName) => createWindow(newRuntimeCallerWithID(objectNames.Window, windowName)),
57
- Center: () => call(center),
58
- SetTitle: (title) => call(setTitle, {title}),
59
- Fullscreen: () => call(fullscreen),
60
- UnFullscreen: () => call(unFullscreen),
61
- SetSize: (width, height) => call(setSize, {width, height}),
62
- Size: () => call(size),
63
- SetMaxSize: (width, height) => call(setMaxSize, {width, height}),
64
- SetMinSize: (width, height) => call(setMinSize, {width, height}),
65
- SetAlwaysOnTop: (onTop) => call(setAlwaysOnTop, {alwaysOnTop: onTop}),
66
- SetRelativePosition: (x, y) => call(setRelativePosition, {x, y}),
67
- RelativePosition: () => call(relativePosition),
68
- Screen: () => call(screen),
69
- Hide: () => call(hide),
70
- Maximise: () => call(maximise),
71
- UnMaximise: () => call(unMaximise),
72
- ToggleMaximise: () => call(toggleMaximise),
73
- Minimise: () => call(minimise),
74
- UnMinimise: () => call(unMinimise),
75
- Restore: () => call(restore),
76
- Show: () => call(show),
77
- Close: () => call(close),
78
- SetBackgroundColour: (r, g, b, a) => call(setBackgroundColour, {r, g, b, a}),
79
- SetResizable: (resizable) => call(setResizable, {resizable}),
80
- Width: () => call(width),
81
- Height: () => call(height),
82
- ZoomIn: () => call(zoomIn),
83
- ZoomOut: () => call(zoomOut),
84
- ZoomReset: () => call(zoomReset),
85
- GetZoomLevel: () => call(getZoomLevel),
86
- SetZoomLevel: (zoomLevel) => call(setZoomLevel, {zoomLevel}),
87
- };
88
- }
89
-
90
- /**
91
- * Gets the specified window.
92
- *
93
- * @param {string} windowName - The name of the window to get.
94
- * @return {Object} - The specified window object.
95
- */
96
- export function Get(windowName) {
97
- return createWindow(newRuntimeCallerWithID(objectNames.Window, windowName));
98
- }
99
-
100
- /**
101
- * Returns a map of all methods in the current window.
102
- * @returns {Map} - A map of window methods.
103
- */
104
- export function WindowMethods(targetWindow) {
105
- // Create a new map to store methods
106
- let result = new Map();
107
-
108
- // Iterate over all properties of the window object
109
- for (let method in targetWindow) {
110
- // Check if the property is indeed a method (function)
111
- if(typeof targetWindow[method] === 'function') {
112
- // Add the method to the map
113
- result.set(method, targetWindow[method]);
114
- }
115
-
116
- }
117
- // Return the map of window methods
118
- return result;
119
- }
120
- export default {
121
- ...Get('')
122
- }
package/wml.js DELETED
@@ -1,151 +0,0 @@
1
-
2
- import {Emit, WailsEvent} from "./events";
3
- import {Question} from "./dialogs";
4
- import {WindowMethods, Get} from "./window";
5
- import {OpenURL} from "./browser";
6
-
7
- /**
8
- * Sends an event with the given name and optional data.
9
- *
10
- * @param {string} eventName - The name of the event to send.
11
- * @param {any} [data=null] - Optional data to send along with the event.
12
- *
13
- * @return {void}
14
- */
15
- function sendEvent(eventName, data=null) {
16
- let event = new WailsEvent(eventName, data);
17
- Emit(event);
18
- }
19
-
20
- /**
21
- * Adds event listeners to elements with `wml-event` attribute.
22
- *
23
- * @return {void}
24
- */
25
- function addWMLEventListeners() {
26
- const elements = document.querySelectorAll('[wml-event]');
27
- elements.forEach(function (element) {
28
- const eventType = element.getAttribute('wml-event');
29
- const confirm = element.getAttribute('wml-confirm');
30
- const trigger = element.getAttribute('wml-trigger') || "click";
31
-
32
- let callback = function () {
33
- if (confirm) {
34
- Question({Title: "Confirm", Message:confirm, Detached: false, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
35
- if (result !== "No") {
36
- sendEvent(eventType);
37
- }
38
- });
39
- return;
40
- }
41
- sendEvent(eventType);
42
- };
43
-
44
- // Remove existing listeners
45
- element.removeEventListener(trigger, callback);
46
-
47
- // Add new listener
48
- element.addEventListener(trigger, callback);
49
- });
50
- }
51
-
52
-
53
- /**
54
- * Calls a method on a specified window.
55
- * @param {string} windowName - The name of the window to call the method on.
56
- * @param {string} method - The name of the method to call.
57
- */
58
- function callWindowMethod(windowName, method) {
59
- let targetWindow = Get(windowName);
60
- let methodMap = WindowMethods(targetWindow);
61
- if (!methodMap.has(method)) {
62
- console.log("Window method " + method + " not found");
63
- }
64
- try {
65
- methodMap.get(method)();
66
- } catch (e) {
67
- console.error("Error calling window method '" + method + "': " + e);
68
- }
69
- }
70
-
71
- /**
72
- * Adds window listeners for elements with the 'wml-window' attribute.
73
- * Removes any existing listeners before adding new ones.
74
- *
75
- * @return {void}
76
- */
77
- function addWMLWindowListeners() {
78
- const elements = document.querySelectorAll('[wml-window]');
79
- elements.forEach(function (element) {
80
- const windowMethod = element.getAttribute('wml-window');
81
- const confirm = element.getAttribute('wml-confirm');
82
- const trigger = element.getAttribute('wml-trigger') || 'click';
83
- const targetWindow = element.getAttribute('wml-target-window') || '';
84
-
85
- let callback = function () {
86
- if (confirm) {
87
- Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
88
- if (result !== "No") {
89
- callWindowMethod(targetWindow, windowMethod);
90
- }
91
- });
92
- return;
93
- }
94
- callWindowMethod(targetWindow, windowMethod);
95
- };
96
-
97
- // Remove existing listeners
98
- element.removeEventListener(trigger, callback);
99
-
100
- // Add new listener
101
- element.addEventListener(trigger, callback);
102
- });
103
- }
104
-
105
- /**
106
- * Adds a listener to elements with the 'wml-openurl' attribute.
107
- * When the specified trigger event is fired on any of these elements,
108
- * the listener will open the URL specified by the 'wml-openurl' attribute.
109
- * If a 'wml-confirm' attribute is provided, a confirmation dialog will be displayed,
110
- * and the URL will only be opened if the user confirms.
111
- *
112
- * @return {void}
113
- */
114
- function addWMLOpenBrowserListener() {
115
- const elements = document.querySelectorAll('[wml-openurl]');
116
- elements.forEach(function (element) {
117
- const url = element.getAttribute('wml-openurl');
118
- const confirm = element.getAttribute('wml-confirm');
119
- const trigger = element.getAttribute('wml-trigger') || "click";
120
-
121
- let callback = function () {
122
- if (confirm) {
123
- Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
124
- if (result !== "No") {
125
- void OpenURL(url);
126
- }
127
- });
128
- return;
129
- }
130
- void OpenURL(url);
131
- };
132
-
133
- // Remove existing listeners
134
- element.removeEventListener(trigger, callback);
135
-
136
- // Add new listener
137
- element.addEventListener(trigger, callback);
138
- });
139
- }
140
-
141
- /**
142
- * Reloads the WML page by adding necessary event listeners and browser listeners.
143
- *
144
- * @return {void}
145
- */
146
- export function reloadWML() {
147
- console.log("Reloading WML");
148
- addWMLEventListeners();
149
- addWMLWindowListeners();
150
- addWMLOpenBrowserListener();
151
- }