@wailsio/runtime 3.0.0-alpha.17 → 3.0.0-alpha.18

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 (119) hide show
  1. package/docs/.nojekyll +1 -0
  2. package/docs/assets/highlight.css +22 -0
  3. package/docs/assets/main.js +59 -0
  4. package/docs/assets/navigation.js +1 -0
  5. package/docs/assets/search.js +1 -0
  6. package/docs/assets/style.css +1414 -0
  7. package/docs/classes/Events.WailsEvent.html +4 -0
  8. package/docs/functions/Application.Hide.html +2 -0
  9. package/docs/functions/Application.Quit.html +2 -0
  10. package/docs/functions/Application.Show.html +2 -0
  11. package/docs/functions/Browser.OpenURL.html +3 -0
  12. package/docs/functions/Call.ByID.html +7 -0
  13. package/docs/functions/Call.ByName.html +6 -0
  14. package/docs/functions/Call.Call.html +6 -0
  15. package/docs/functions/Call.Plugin.html +8 -0
  16. package/docs/functions/Clipboard.SetText.html +6 -0
  17. package/docs/functions/Clipboard.Text.html +3 -0
  18. package/docs/functions/Dialogs.Error.html +5 -0
  19. package/docs/functions/Dialogs.Info.html +5 -0
  20. package/docs/functions/Dialogs.OpenFile.html +3 -0
  21. package/docs/functions/Dialogs.Question.html +5 -0
  22. package/docs/functions/Dialogs.SaveFile.html +3 -0
  23. package/docs/functions/Dialogs.Warning.html +5 -0
  24. package/docs/functions/Events.Emit.html +6 -0
  25. package/docs/functions/Events.Off.html +4 -0
  26. package/docs/functions/Events.OffAll.html +3 -0
  27. package/docs/functions/Events.On.html +7 -0
  28. package/docs/functions/Events.OnMultiple.html +8 -0
  29. package/docs/functions/Events.Once.html +7 -0
  30. package/docs/functions/Events.setup.html +1 -0
  31. package/docs/functions/Flags.GetFlag.html +6 -0
  32. package/docs/functions/Screens.GetAll.html +3 -0
  33. package/docs/functions/Screens.GetCurrent.html +3 -0
  34. package/docs/functions/Screens.GetPrimary.html +3 -0
  35. package/docs/functions/System.Capabilities.html +4 -0
  36. package/docs/functions/System.Environment.html +5 -0
  37. package/docs/functions/System.IsAMD64.html +3 -0
  38. package/docs/functions/System.IsARM.html +3 -0
  39. package/docs/functions/System.IsARM64.html +5 -0
  40. package/docs/functions/System.IsDarkMode.html +5 -0
  41. package/docs/functions/System.IsDebug.html +1 -0
  42. package/docs/functions/System.IsLinux.html +3 -0
  43. package/docs/functions/System.IsMac.html +3 -0
  44. package/docs/functions/System.IsWindows.html +3 -0
  45. package/docs/functions/System.invoke.html +1 -0
  46. package/docs/functions/WML.Reload.html +2 -0
  47. package/docs/functions/Window.Center.html +2 -0
  48. package/docs/functions/Window.Close.html +2 -0
  49. package/docs/functions/Window.Fullscreen.html +2 -0
  50. package/docs/functions/Window.Get.html +6 -0
  51. package/docs/functions/Window.GetZoomLevel.html +2 -0
  52. package/docs/functions/Window.Height.html +2 -0
  53. package/docs/functions/Window.Hide.html +2 -0
  54. package/docs/functions/Window.Maximise.html +2 -0
  55. package/docs/functions/Window.Minimise.html +2 -0
  56. package/docs/functions/Window.RelativePosition.html +2 -0
  57. package/docs/functions/Window.Restore.html +2 -0
  58. package/docs/functions/Window.Screen-1.html +2 -0
  59. package/docs/functions/Window.SetAlwaysOnTop.html +3 -0
  60. package/docs/functions/Window.SetBackgroundColour.html +6 -0
  61. package/docs/functions/Window.SetMaxSize.html +4 -0
  62. package/docs/functions/Window.SetMinSize.html +4 -0
  63. package/docs/functions/Window.SetRelativePosition.html +4 -0
  64. package/docs/functions/Window.SetResizable.html +3 -0
  65. package/docs/functions/Window.SetSize.html +4 -0
  66. package/docs/functions/Window.SetTitle.html +3 -0
  67. package/docs/functions/Window.SetZoomLevel.html +3 -0
  68. package/docs/functions/Window.Show.html +2 -0
  69. package/docs/functions/Window.Size.html +2 -0
  70. package/docs/functions/Window.ToggleMaximise.html +2 -0
  71. package/docs/functions/Window.UnMaximise.html +2 -0
  72. package/docs/functions/Window.UnMinimise.html +2 -0
  73. package/docs/functions/Window.Width.html +2 -0
  74. package/docs/functions/Window.ZoomIn.html +2 -0
  75. package/docs/functions/Window.ZoomOut.html +2 -0
  76. package/docs/functions/Window.ZoomReset.html +2 -0
  77. package/docs/index.html +5 -0
  78. package/docs/interfaces/Dialogs.Button.html +7 -0
  79. package/docs/interfaces/Dialogs.FileFilter.html +5 -0
  80. package/docs/interfaces/Dialogs.MessageDialogOptions.html +9 -0
  81. package/docs/interfaces/Dialogs.OpenFileDialogOptions.html +33 -0
  82. package/docs/interfaces/Dialogs.SaveFileDialogOptions.html +35 -0
  83. package/docs/interfaces/Screens.Position.html +5 -0
  84. package/docs/interfaces/Screens.Rect.html +9 -0
  85. package/docs/interfaces/Screens.Screen.html +19 -0
  86. package/docs/interfaces/Screens.Size.html +5 -0
  87. package/docs/interfaces/System.EnvironmentInfo.html +5 -0
  88. package/docs/modules/Application.html +4 -0
  89. package/docs/modules/Browser.html +2 -0
  90. package/docs/modules/Call.html +5 -0
  91. package/docs/modules/Clipboard.html +3 -0
  92. package/docs/modules/Dialogs.html +12 -0
  93. package/docs/modules/Events.html +10 -0
  94. package/docs/modules/Flags.html +2 -0
  95. package/docs/modules/Screens.html +9 -0
  96. package/docs/modules/System.html +13 -0
  97. package/docs/modules/WML.html +2 -0
  98. package/docs/modules/Window.html +32 -0
  99. package/docs/modules.html +12 -0
  100. package/docs/types/Screens.Rotation.html +2 -0
  101. package/docs/variables/Events.Types.html +1 -0
  102. package/package.json +1 -1
  103. package/src/calls.js +6 -4
  104. package/src/contextmenu.js +3 -4
  105. package/src/dialogs.js +5 -4
  106. package/src/drag.js +11 -12
  107. package/src/event_types.js +1 -0
  108. package/src/events.js +5 -13
  109. package/src/flags.js +5 -43
  110. package/src/index.js +21 -8
  111. package/src/log.js +13 -0
  112. package/src/system.js +17 -22
  113. package/src/wml.js +4 -1
  114. package/tsconfig.json +1 -1
  115. package/types/event_types.d.ts +1 -0
  116. package/types/events.d.ts +11 -25
  117. package/types/system.d.ts +1 -1
  118. package/types/contextmenu.d.ts +0 -1
  119. package/types/drag.d.ts +0 -4
package/src/drag.js CHANGED
@@ -13,15 +13,20 @@ The electron alternative for Go
13
13
  import {invoke, IsWindows} from "./system";
14
14
  import {GetFlag} from "./flags";
15
15
 
16
+ // Setup
17
+ window._wails = window._wails || {};
18
+ window._wails.setResizable = setResizable;
19
+ window._wails.endDrag = endDrag;
20
+ window.addEventListener('mousedown', onMouseDown);
21
+ window.addEventListener('mousemove', onMouseMove);
22
+ window.addEventListener('mouseup', onMouseUp);
23
+
16
24
  let shouldDrag = false;
17
25
  let resizeEdge = null;
18
26
  let resizable = false;
19
27
  let defaultCursor = "auto";
20
- window._wails = window._wails || {};
21
- window._wails.setResizable = setResizable;
22
- window._wails.endDrag = endDrag;
23
28
 
24
- export function dragTest(e) {
29
+ function dragTest(e) {
25
30
  let val = window.getComputedStyle(e.target).getPropertyValue("--webkit-app-region");
26
31
  if (!val || val === "" || val.trim() !== "drag" || e.buttons !== 1) {
27
32
  return false;
@@ -29,17 +34,11 @@ export function dragTest(e) {
29
34
  return e.detail === 1;
30
35
  }
31
36
 
32
- export function setupDrag() {
33
- window.addEventListener('mousedown', onMouseDown);
34
- window.addEventListener('mousemove', onMouseMove);
35
- window.addEventListener('mouseup', onMouseUp);
36
- }
37
-
38
- export function setResizable(value) {
37
+ function setResizable(value) {
39
38
  resizable = value;
40
39
  }
41
40
 
42
- export function endDrag() {
41
+ function endDrag() {
43
42
  document.body.style.cursor = 'default';
44
43
  shouldDrag = false;
45
44
  }
@@ -176,6 +176,7 @@ export const EventTypes = {
176
176
  WindowHide: "common:WindowHide",
177
177
  WindowDPIChanged: "common:WindowDPIChanged",
178
178
  WindowFilesDropped: "common:WindowFilesDropped",
179
+ WindowRuntimeReady: "common:WindowRuntimeReady",
179
180
  ThemeChanged: "common:ThemeChanged",
180
181
  },
181
182
  };
package/src/events.js CHANGED
@@ -18,6 +18,10 @@ import {newRuntimeCallerWithID, objectNames} from "./runtime";
18
18
  import {EventTypes} from "./event_types";
19
19
  export const Types = EventTypes;
20
20
 
21
+ // Setup
22
+ window._wails = window._wails || {};
23
+ window._wails.dispatchWailsEvent = dispatchWailsEvent;
24
+
21
25
  const call = newRuntimeCallerWithID(objectNames.Events, '');
22
26
  const EmitMethod = 0;
23
27
  const eventListeners = new Map();
@@ -42,19 +46,7 @@ export class WailsEvent {
42
46
  }
43
47
  }
44
48
 
45
- /**
46
- * Sets up event callbacks for Wails.
47
- *
48
- * @function setupEventCallbacks
49
- *
50
- * @description This method is responsible for setting up event callbacks for Wails. It checks if the global object `_wails` exists on the `window` object, and if not, initializes it
51
- *. It then assigns the `dispatchWailsEvent` function as a property on the `_wails` object.
52
- *
53
- * @returns {undefined} Returns nothing.
54
- */
55
- export function setupEventCallbacks() {
56
- window._wails = window._wails || {};
57
- window._wails.dispatchWailsEvent = dispatchWailsEvent;
49
+ export function setup() {
58
50
  }
59
51
 
60
52
  function dispatchWailsEvent(event) {
package/src/flags.js CHANGED
@@ -10,48 +10,6 @@ The electron alternative for Go
10
10
 
11
11
  /* jshint esversion: 9 */
12
12
 
13
- let flags = new Map();
14
-
15
- function convertToMap(obj) {
16
- const map = new Map();
17
-
18
- for (const [key, value] of Object.entries(obj)) {
19
- if (typeof value === 'object' && value !== null) {
20
- map.set(key, convertToMap(value)); // Recursively convert nested object
21
- } else {
22
- map.set(key, value);
23
- }
24
- }
25
-
26
- return map;
27
- }
28
-
29
- fetch("/wails/flags").then((response) => {
30
- response.json().then((data) => {
31
- flags = convertToMap(data);
32
- });
33
- });
34
-
35
-
36
- function getValueFromMap(keyString) {
37
- const keys = keyString.split('.');
38
- let value = flags;
39
-
40
- for (const key of keys) {
41
- if (value instanceof Map) {
42
- value = value.get(key);
43
- } else {
44
- value = value[key];
45
- }
46
-
47
- if (value === undefined) {
48
- break;
49
- }
50
- }
51
-
52
- return value;
53
- }
54
-
55
13
  /**
56
14
  * Retrieves the value associated with the specified key from the flag map.
57
15
  *
@@ -59,5 +17,9 @@ function getValueFromMap(keyString) {
59
17
  * @return {*} - The value associated with the specified key.
60
18
  */
61
19
  export function GetFlag(keyString) {
62
- return getValueFromMap(keyString);
20
+ try {
21
+ return window._wails.flags[keyString];
22
+ } catch (e) {
23
+ throw new Error("Unable to retrieve flag '" + keyString + "': " + e);
24
+ }
63
25
  }
package/src/index.js CHANGED
@@ -8,9 +8,9 @@ The electron alternative for Go
8
8
  (c) Lea Anthony 2019-present
9
9
  */
10
10
 
11
- import {setupContextMenus} from "./contextmenu";
12
- import {setupDrag} from "./drag";
13
- import {ByID, ByName, Plugin} from "./calls";
11
+ // Setup
12
+ window.wails = window.wails || {};
13
+ window._wails = window._wails || {};
14
14
 
15
15
  import * as Application from "./application";
16
16
  import * as Browser from "./browser";
@@ -23,7 +23,8 @@ import * as WML from './wml';
23
23
  import * as Events from "./events";
24
24
  import * as Dialogs from "./dialogs";
25
25
  import * as Call from "./calls";
26
- import {setupEventCallbacks} from "./events";
26
+ import {invoke} from "./system";
27
+
27
28
 
28
29
  export { Application, Browser, Call, Clipboard, Dialogs, Events, Flags, Screens, System, Window, WML};
29
30
 
@@ -59,7 +60,22 @@ export { Application, Browser, Call, Clipboard, Dialogs, Events, Flags, Screens,
59
60
 
60
61
  ***/
61
62
 
62
- let isReady = false
63
+ window.wails = {
64
+ Application,
65
+ Browser,
66
+ Call,
67
+ Clipboard,
68
+ Dialogs,
69
+ Events,
70
+ Flags,
71
+ Screens,
72
+ System,
73
+ Window,
74
+ WML,
75
+ };
76
+ invoke('wails:runtime:ready');
77
+
78
+ let isReady = false;
63
79
  document.addEventListener('DOMContentLoaded', function() {
64
80
  isReady = true
65
81
  })
@@ -73,8 +89,5 @@ function whenReady(fn) {
73
89
  }
74
90
 
75
91
  whenReady(() => {
76
- setupContextMenus();
77
- setupDrag();
78
- setupEventCallbacks();
79
92
  WML.Reload();
80
93
  });
package/src/log.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Logs a message to the console with custom formatting.
3
+ * @param {string} message - The message to be logged.
4
+ * @return {void}
5
+ */
6
+ export function debugLog(message) {
7
+ // eslint-disable-next-line
8
+ console.log(
9
+ '%c wails3 %c ' + message + ' ',
10
+ 'background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem',
11
+ 'background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem'
12
+ );
13
+ }
package/src/system.js CHANGED
@@ -15,6 +15,13 @@ let call = newRuntimeCallerWithID(objectNames.System, '');
15
15
  const systemIsDarkMode = 0;
16
16
  const environment = 1;
17
17
 
18
+ export function invoke(msg) {
19
+ if(window.chrome) {
20
+ return window.chrome.webview.postMessage(msg);
21
+ }
22
+ return window.webkit.messageHandlers.external.postMessage(msg);
23
+ }
24
+
18
25
  /**
19
26
  * @function
20
27
  * Retrieves the system dark mode status.
@@ -24,7 +31,6 @@ export function IsDarkMode() {
24
31
  return call(systemIsDarkMode);
25
32
  }
26
33
 
27
-
28
34
  /**
29
35
  * Fetches the capabilities of the application from the server.
30
36
  *
@@ -32,7 +38,7 @@ export function IsDarkMode() {
32
38
  * @function Capabilities
33
39
  * @returns {Promise<Object>} A promise that resolves to an object containing the capabilities.
34
40
  */
35
- export async function Capabilities() {
41
+ export function Capabilities() {
36
42
  let response = fetch("/wails/capabilities");
37
43
  return response.json();
38
44
  }
@@ -52,25 +58,13 @@ export function Environment() {
52
58
  return call(environment);
53
59
  }
54
60
 
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
61
  /**
68
62
  * Checks if the current operating system is Windows.
69
63
  *
70
64
  * @return {boolean} True if the operating system is Windows, otherwise false.
71
65
  */
72
66
  export function IsWindows() {
73
- return environmentCache.OS === "windows";
67
+ return window._wails.environment.OS === "windows";
74
68
  }
75
69
 
76
70
  /**
@@ -79,7 +73,7 @@ export function IsWindows() {
79
73
  * @returns {boolean} Returns true if the current operating system is Linux, false otherwise.
80
74
  */
81
75
  export function IsLinux() {
82
- return environmentCache.OS === "linux";
76
+ return window._wails.environment.OS === "linux";
83
77
  }
84
78
 
85
79
  /**
@@ -88,7 +82,7 @@ export function IsLinux() {
88
82
  * @returns {boolean} True if the environment is macOS, false otherwise.
89
83
  */
90
84
  export function IsMac() {
91
- return environmentCache.OS === "darwin";
85
+ return window._wails.environment.OS === "darwin";
92
86
  }
93
87
 
94
88
  /**
@@ -96,7 +90,7 @@ export function IsMac() {
96
90
  * @returns {boolean} True if the current environment architecture is AMD64, false otherwise.
97
91
  */
98
92
  export function IsAMD64() {
99
- return environmentCache.Arch === "amd64";
93
+ return window._wails.environment.Arch === "amd64";
100
94
  }
101
95
 
102
96
  /**
@@ -105,7 +99,7 @@ export function IsAMD64() {
105
99
  * @returns {boolean} True if the current architecture is ARM, false otherwise.
106
100
  */
107
101
  export function IsARM() {
108
- return environmentCache.Arch === "arm";
102
+ return window._wails.environment.Arch === "arm";
109
103
  }
110
104
 
111
105
  /**
@@ -114,9 +108,10 @@ export function IsARM() {
114
108
  * @returns {boolean} - Returns true if the environment is ARM64 architecture, otherwise returns false.
115
109
  */
116
110
  export function IsARM64() {
117
- return environmentCache.Arch === "arm64";
111
+ return window._wails.environment.Arch === "arm64";
118
112
  }
119
113
 
120
114
  export function IsDebug() {
121
- return environmentCache.Debug === true;
122
- }
115
+ return window._wails.environment.Debug === true;
116
+ }
117
+
package/src/wml.js CHANGED
@@ -3,6 +3,7 @@ import {Emit, WailsEvent} from "./events";
3
3
  import {Question} from "./dialogs";
4
4
  import {Get} from "./window";
5
5
  import {OpenURL} from "./browser";
6
+ import {debugLog} from "./log";
6
7
 
7
8
  /**
8
9
  * Sends an event with the given name and optional data.
@@ -144,7 +145,9 @@ function addWMLOpenBrowserListener() {
144
145
  * @return {void}
145
146
  */
146
147
  export function Reload() {
147
- console.log("Reloading WML");
148
+ if(DEBUG) {
149
+ debugLog("Reloading WML");
150
+ }
148
151
  addWMLEventListeners();
149
152
  addWMLWindowListeners();
150
153
  addWMLOpenBrowserListener();
package/tsconfig.json CHANGED
@@ -15,6 +15,6 @@
15
15
  "moduleResolution": "node",
16
16
  "outDir": "dist",
17
17
  "strict": true,
18
- "target": "es6"
18
+ "target": "es6",
19
19
  }
20
20
  }
@@ -176,6 +176,7 @@ export declare const EventTypes: {
176
176
  WindowHide: string,
177
177
  WindowDPIChanged: string,
178
178
  WindowFilesDropped: string,
179
+ WindowRuntimeReady: string,
179
180
  ThemeChanged: string,
180
181
  },
181
182
  };
package/types/events.d.ts CHANGED
@@ -1,14 +1,4 @@
1
- /**
2
- * Sets up event callbacks for Wails.
3
- *
4
- * @function setupEventCallbacks
5
- *
6
- * @description This method is responsible for setting up event callbacks for Wails. It checks if the global object `_wails` exists on the `window` object, and if not, initializes it
7
- *. It then assigns the `dispatchWailsEvent` function as a property on the `_wails` object.
8
- *
9
- * @returns {undefined} Returns nothing.
10
- */
11
- export function setupEventCallbacks(): undefined;
1
+ export function setup(): void;
12
2
  /**
13
3
  * Register a callback function to be called multiple times for a specific event.
14
4
  *
@@ -61,6 +51,9 @@ export const Types: {
61
51
  SystemThemeChanged: string;
62
52
  APMPowerStatusChange: string;
63
53
  APMSuspend: string;
54
+ /**
55
+ * @typedef {import("./types").WailsEvent} WailsEvent
56
+ */
64
57
  APMResumeAutomatic: string;
65
58
  APMResumeSuspend: string;
66
59
  APMPowerSettingChange: string;
@@ -117,7 +110,12 @@ export const Types: {
117
110
  WindowDidChangeEffectiveAppearance: string;
118
111
  WindowDidChangeOcclusionState: string;
119
112
  WindowDidChangeOrderingMode: string;
120
- WindowDidChangeScreen: string;
113
+ WindowDidChangeScreen: string; /**
114
+ * Removes the specified listener from the event listeners collection.
115
+ * If all listeners for the event are removed, the event key is deleted from the collection.
116
+ *
117
+ * @param {Object} listener - The listener to be removed.
118
+ */
121
119
  WindowDidChangeScreenParameters: string;
122
120
  WindowDidChangeScreenProfile: string;
123
121
  WindowDidChangeScreenSpace: string;
@@ -125,12 +123,6 @@ export const Types: {
125
123
  WindowDidChangeSharingType: string;
126
124
  WindowDidChangeSpace: string;
127
125
  WindowDidChangeSpaceOrderingMode: string;
128
- /**
129
- * Removes the specified listener from the event listeners collection.
130
- * If all listeners for the event are removed, the event key is deleted from the collection.
131
- *
132
- * @param {Object} listener - The listener to be removed.
133
- */
134
126
  WindowDidChangeTitle: string;
135
127
  WindowDidChangeToolbar: string;
136
128
  WindowDidChangeVisibility: string;
@@ -140,13 +132,6 @@ export const Types: {
140
132
  WindowDidEnterVersionBrowser: string;
141
133
  WindowDidExitFullScreen: string;
142
134
  WindowDidExitVersionBrowser: string;
143
- /**
144
- * Removes event listeners for the specified event names.
145
- *
146
- * @param {string} eventName - The name of the event to remove listeners for.
147
- * @param {...string} additionalEventNames - Additional event names to remove listeners for.
148
- * @return {undefined}
149
- */
150
135
  WindowDidExpose: string;
151
136
  WindowDidFocus: string;
152
137
  WindowDidMiniaturize: string;
@@ -246,6 +231,7 @@ export const Types: {
246
231
  WindowHide: string;
247
232
  WindowDPIChanged: string;
248
233
  WindowFilesDropped: string;
234
+ WindowRuntimeReady: string;
249
235
  ThemeChanged: string;
250
236
  };
251
237
  };
package/types/system.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export function invoke(msg: any): any;
1
2
  /**
2
3
  * @function
3
4
  * Retrieves the system dark mode status.
@@ -59,7 +60,6 @@ export function IsARM(): boolean;
59
60
  */
60
61
  export function IsARM64(): boolean;
61
62
  export function IsDebug(): boolean;
62
- export let invoke: any;
63
63
  export type EnvironmentInfo = {
64
64
  /**
65
65
  * - The operating system in use.
@@ -1 +0,0 @@
1
- export function setupContextMenus(): void;
package/types/drag.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export function dragTest(e: any): boolean;
2
- export function setupDrag(): void;
3
- export function setResizable(value: any): void;
4
- export function endDrag(): void;