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

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 (3) hide show
  1. package/package.json +2 -1
  2. package/types.d.ts +100 -95
  3. package/wml.js +18 -15
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@wailsio/runtime",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.7",
4
4
  "description": "Wails Runtime",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "https://github.com/wailsapp/wails.git"
package/types.d.ts CHANGED
@@ -1,130 +1,135 @@
1
1
 
2
+ /**
3
+ * Describes the properties of a Button object.
4
+ */
2
5
  export interface Button {
3
- // The label of the button
6
+ // Text that appears within the button.
4
7
  Label?: string;
5
- // True if this button is the cancel button (selected when pressing escape)
8
+ // True if the button should cancel an operation when clicked.
6
9
  IsCancel?: boolean;
7
- // True if this button is the default button (selected when pressing enter)
10
+ // True if the button should be the default action when the user presses enter.
8
11
  IsDefault?: boolean;
9
12
  }
10
13
 
11
- interface MessageDialogOptions {
12
- // The title for the dialog
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.
13
83
  Title?: string;
14
- // The message to display
84
+ // The main message to show in the dialog.
15
85
  Message?: string;
16
- // The buttons to use on the dialog
86
+ // Array of button options to show in the dialog.
17
87
  Buttons?: Button[];
18
- // Whether the dialog is detached from the current window
88
+ // True if the dialog should appear detached from the main window (if applicable).
19
89
  Detached?: boolean;
20
90
  }
21
91
 
22
- export interface OpenFileDialogOptions {
23
- // Allows the user to be able to select directories
92
+ /**
93
+ * Describes the properties common to OpenFileDialogOptions and SaveFileDialogOptions objects.
94
+ */
95
+ export interface DialogOptions {
24
96
  CanChooseDirectories?: boolean;
25
- // Allows the user to be able to select files
26
97
  CanChooseFiles?: boolean;
27
- // Provide an option to create directories in the dialog
28
98
  CanCreateDirectories?: boolean;
29
- // Makes the dialog show hidden files
30
99
  ShowHiddenFiles?: boolean;
31
- // Whether the dialog should follow filesystem aliases
32
100
  ResolvesAliases?: boolean;
33
- // Allow the user to select multiple files or directories
34
101
  AllowsMultipleSelection?: boolean;
35
- // Hide the extension when showing the filename
36
102
  HideExtension?: boolean;
37
- // Allow the user to select files where the system hides their extensions
38
103
  CanSelectHiddenExtension?: boolean;
39
- // Treats file packages as directories, e.g. .app on macOS
40
104
  TreatsFilePackagesAsDirectories?: boolean;
41
- // Allows selection of filetypes not specified in the filters
42
105
  AllowsOtherFiletypes?: boolean;
43
- // The file filters to use in the dialog
44
106
  Filters?: FileFilter[];
45
- // The title of the dialog
46
107
  Title?: string;
47
- // The message to display
48
108
  Message?: string;
49
- // The label for the select button
50
109
  ButtonText?: string;
51
- // The default directory to open the dialog in
52
110
  Directory?: string;
53
- // Whether the dialog is detached from the current window
54
- Detached?: boolean;
55
- }
56
- export interface FileFilter {
57
- // The display name for the filter, e.g. "Text Files"
58
- DisplayName?: string;
59
- // The pattern to use for the filter, e.g. "*.txt;*.md"
60
- Pattern?: string;
61
- }
62
- export interface SaveFileDialogOptions {
63
- // Provide an option to create directories in the dialog
64
- CanCreateDirectories?: boolean;
65
- // Makes the dialog show hidden files
66
- ShowHiddenFiles?: boolean;
67
- // Allow the user to select files where the system hides their extensions
68
- CanSelectHiddenExtension?: boolean;
69
- // Allows selection of filetypes not specified in the filters
70
- AllowOtherFiletypes?: boolean;
71
- // Hide the extension when showing the filename
72
- HideExtension?: boolean;
73
- // Treats file packages as directories, e.g. .app on macOS
74
- TreatsFilePackagesAsDirectories?: boolean;
75
- // The message to show in the dialog
76
- Message?: string;
77
- // The default directory to open the dialog in
78
- Directory?: string;
79
- // The default filename to use in the dialog
80
- Filename?: string;
81
- // The label for the select button
82
- ButtonText?: string;
83
- // Whether the dialog is detached from the current window
84
111
  Detached?: boolean;
85
112
  }
86
113
 
87
- export interface Screen {
88
- // The screen ID
89
- Id: string;
90
- // The screen name
91
- Name: string;
92
- // The screen scale. 1 = standard resolution, 2: 2x retina, etc.
93
- Scale: number;
94
- // The X position of the screen
95
- X: number;
96
- // The Y position of the screen
97
- Y: number;
98
- // The width and height of the screen
99
- Size: Size;
100
- // The bounds of the screen
101
- Bounds: Rect;
102
- // The work area of the screen
103
- WorkArea: Rect;
104
- // True if this is the primary screen
105
- IsPrimary: boolean;
106
- // The rotation of the screen
107
- Rotation: number;
108
- }
109
- export interface Rect {
110
- X: number;
111
- Y: number;
112
- Width: number;
113
- Height: number;
114
- }
114
+ /**
115
+ * Describes properties unique to OpenFileDialogOptions.
116
+ */
117
+ export type OpenFileDialogOptions = DialogOptions;
115
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
+ */
116
130
  export interface WailsEvent {
117
- // The name of the event
131
+ // The name of the event.
118
132
  Name: string;
119
- // The data associated with the event
120
- Data?: any;
121
- }
122
-
123
- export interface Size {
124
- Width: number;
125
- Height: number;
126
- }
127
- export interface Position {
128
- X: number;
129
- Y: number;
133
+ // Any data associated with the event.
134
+ Data?: unknown;
130
135
  }
package/wml.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import {Emit, WailsEvent} from "./events";
3
3
  import {Question} from "./dialogs";
4
4
  import {WindowMethods, Get} from "./window";
5
+ import {OpenURL} from "./browser";
5
6
 
6
7
  /**
7
8
  * Sends an event with the given name and optional data.
@@ -48,22 +49,23 @@ function addWMLEventListeners() {
48
49
  });
49
50
  }
50
51
 
52
+
51
53
  /**
52
- * Calls a method on the window object.
53
- *
54
- * @param {string} method - The name of the method to call on the window object.
55
- *
56
- * @return {void}
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
57
  */
58
- function callWindowMethod(method) {
59
- // TODO: Make this a parameter!
60
- let windowName = '';
61
- let targetWindow = Get('');
58
+ function callWindowMethod(windowName, method) {
59
+ let targetWindow = Get(windowName);
62
60
  let methodMap = WindowMethods(targetWindow);
63
61
  if (!methodMap.has(method)) {
64
62
  console.log("Window method " + method + " not found");
65
63
  }
66
- methodMap.get(method)();
64
+ try {
65
+ methodMap.get(method)();
66
+ } catch (e) {
67
+ console.error("Error calling window method '" + method + "': " + e);
68
+ }
67
69
  }
68
70
 
69
71
  /**
@@ -77,18 +79,19 @@ function addWMLWindowListeners() {
77
79
  elements.forEach(function (element) {
78
80
  const windowMethod = element.getAttribute('wml-window');
79
81
  const confirm = element.getAttribute('wml-confirm');
80
- const trigger = element.getAttribute('wml-trigger') || "click";
82
+ const trigger = element.getAttribute('wml-trigger') || 'click';
83
+ const targetWindow = element.getAttribute('wml-target-window') || '';
81
84
 
82
85
  let callback = function () {
83
86
  if (confirm) {
84
87
  Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
85
88
  if (result !== "No") {
86
- callWindowMethod(windowMethod);
89
+ callWindowMethod(targetWindow, windowMethod);
87
90
  }
88
91
  });
89
92
  return;
90
93
  }
91
- callWindowMethod(windowMethod);
94
+ callWindowMethod(targetWindow, windowMethod);
92
95
  };
93
96
 
94
97
  // Remove existing listeners
@@ -119,12 +122,12 @@ function addWMLOpenBrowserListener() {
119
122
  if (confirm) {
120
123
  Question({Title: "Confirm", Message:confirm, Buttons:[{Label:"Yes"},{Label:"No", IsDefault:true}]}).then(function (result) {
121
124
  if (result !== "No") {
122
- void wails.Browser.OpenURL(url);
125
+ void OpenURL(url);
123
126
  }
124
127
  });
125
128
  return;
126
129
  }
127
- void wails.Browser.OpenURL(url);
130
+ void OpenURL(url);
128
131
  };
129
132
 
130
133
  // Remove existing listeners