@wailsio/runtime 3.0.0-alpha.10
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.
- package/package.json +26 -0
- package/src/application.js +46 -0
- package/src/browser.js +24 -0
- package/src/calls.js +123 -0
- package/src/clipboard.js +35 -0
- package/src/contextmenu.js +98 -0
- package/src/dialogs.js +138 -0
- package/src/drag.js +125 -0
- package/src/events.js +134 -0
- package/src/flags.js +63 -0
- package/src/index.d.ts +136 -0
- package/src/index.js +58 -0
- package/src/runtime.js +122 -0
- package/src/screens.js +45 -0
- package/src/system.js +122 -0
- package/src/window.js +122 -0
- package/src/wml.js +151 -0
- package/tsconfig.json +20 -0
- package/types/application.d.ts +19 -0
- package/types/browser.d.ts +6 -0
- package/types/calls.d.ts +35 -0
- package/types/clipboard.d.ts +12 -0
- package/types/contextmenu.d.ts +1 -0
- package/types/dialogs.d.ts +28 -0
- package/types/drag.d.ts +4 -0
- package/types/events.d.ts +53 -0
- package/types/flags.d.ts +7 -0
- package/types/index.d.ts +48 -0
- package/types/runtime.d.ts +29 -0
- package/types/screens.d.ts +17 -0
- package/types/system.d.ts +72 -0
- package/types/window.d.ts +17 -0
- package/types/wml.d.ts +6 -0
package/src/events.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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("./types").WailsEvent} WailsEvent
|
|
15
|
+
*/
|
|
16
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
17
|
+
|
|
18
|
+
const call = newRuntimeCallerWithID(objectNames.Events, '');
|
|
19
|
+
const EmitMethod = 0;
|
|
20
|
+
const eventListeners = new Map();
|
|
21
|
+
|
|
22
|
+
class Listener {
|
|
23
|
+
constructor(eventName, callback, maxCallbacks) {
|
|
24
|
+
this.eventName = eventName;
|
|
25
|
+
this.maxCallbacks = maxCallbacks || -1;
|
|
26
|
+
this.Callback = (data) => {
|
|
27
|
+
callback(data);
|
|
28
|
+
if (this.maxCallbacks === -1) return false;
|
|
29
|
+
this.maxCallbacks -= 1;
|
|
30
|
+
return this.maxCallbacks === 0;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class WailsEvent {
|
|
36
|
+
constructor(name, data = null) {
|
|
37
|
+
this.name = name;
|
|
38
|
+
this.data = data;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
window._wails = window._wails || {};
|
|
44
|
+
window._wails.dispatchWailsEvent = dispatchWailsEvent;
|
|
45
|
+
|
|
46
|
+
export function dispatchWailsEvent(event) {
|
|
47
|
+
let listeners = eventListeners.get(event.name);
|
|
48
|
+
if (listeners) {
|
|
49
|
+
let toRemove = listeners.filter(listener => {
|
|
50
|
+
let remove = listener.Callback(event);
|
|
51
|
+
if (remove) return true;
|
|
52
|
+
});
|
|
53
|
+
if (toRemove.length > 0) {
|
|
54
|
+
listeners = listeners.filter(l => !toRemove.includes(l));
|
|
55
|
+
if (listeners.length === 0) eventListeners.delete(event.name);
|
|
56
|
+
else eventListeners.set(event.name, listeners);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Register a callback function to be called multiple times for a specific event.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} eventName - The name of the event to register the callback for.
|
|
65
|
+
* @param {function} callback - The callback function to be called when the event is triggered.
|
|
66
|
+
* @param {number} maxCallbacks - The maximum number of times the callback can be called for the event. Once the maximum number is reached, the callback will no longer be called.
|
|
67
|
+
*
|
|
68
|
+
@return {function} - A function that, when called, will unregister the callback from the event.
|
|
69
|
+
*/
|
|
70
|
+
export function OnMultiple(eventName, callback, maxCallbacks) {
|
|
71
|
+
let listeners = eventListeners.get(eventName) || [];
|
|
72
|
+
const thisListener = new Listener(eventName, callback, maxCallbacks);
|
|
73
|
+
listeners.push(thisListener);
|
|
74
|
+
eventListeners.set(eventName, listeners);
|
|
75
|
+
return () => listenerOff(thisListener);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Registers a callback function to be executed when the specified event occurs.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} eventName - The name of the event.
|
|
82
|
+
* @param {function} callback - The callback function to be executed. It takes no parameters.
|
|
83
|
+
* @return {function} - A function that, when called, will unregister the callback from the event. */
|
|
84
|
+
export function On(eventName, callback) { return OnMultiple(eventName, callback, -1); }
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Registers a callback function to be executed only once for the specified event.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} eventName - The name of the event.
|
|
90
|
+
* @param {function} callback - The function to be executed when the event occurs.
|
|
91
|
+
* @return {void@return {function} - A function that, when called, will unregister the callback from the event.
|
|
92
|
+
*/
|
|
93
|
+
export function Once(eventName, callback) { return OnMultiple(eventName, callback, 1); }
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Removes the specified listener from the event listeners collection.
|
|
97
|
+
* If all listeners for the event are removed, the event key is deleted from the collection.
|
|
98
|
+
*
|
|
99
|
+
* @param {Object} listener - The listener to be removed.
|
|
100
|
+
*/
|
|
101
|
+
function listenerOff(listener) {
|
|
102
|
+
const eventName = listener.eventName;
|
|
103
|
+
let listeners = eventListeners.get(eventName).filter(l => l !== listener);
|
|
104
|
+
if (listeners.length === 0) eventListeners.delete(eventName);
|
|
105
|
+
else eventListeners.set(eventName, listeners);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Removes event listeners for the specified event names.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} eventName - The name of the event to remove listeners for.
|
|
113
|
+
* @param {...string} additionalEventNames - Additional event names to remove listeners for.
|
|
114
|
+
* @return {undefined}
|
|
115
|
+
*/
|
|
116
|
+
export function Off(eventName, ...additionalEventNames) {
|
|
117
|
+
let eventsToRemove = [eventName, ...additionalEventNames];
|
|
118
|
+
eventsToRemove.forEach(eventName => eventListeners.delete(eventName));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Removes all event listeners.
|
|
122
|
+
*
|
|
123
|
+
* @function OffAll
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
export function OffAll() { eventListeners.clear(); }
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Emits an event using the given event name.
|
|
130
|
+
*
|
|
131
|
+
* @param {WailsEvent} event - The name of the event to emit.
|
|
132
|
+
* @returns {any} - The result of the emitted event.
|
|
133
|
+
*/
|
|
134
|
+
export function Emit(event) { return call(EmitMethod, event); }
|
package/src/flags.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
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
|
+
/**
|
|
56
|
+
* Retrieves the value associated with the specified key from the flag map.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} keyString - The key to retrieve the value for.
|
|
59
|
+
* @return {*} - The value associated with the specified key.
|
|
60
|
+
*/
|
|
61
|
+
export function GetFlag(keyString) {
|
|
62
|
+
return getValueFromMap(keyString);
|
|
63
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
declare module '@wailsio/runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes the properties of a Button object.
|
|
5
|
+
*/
|
|
6
|
+
export interface Button {
|
|
7
|
+
// Text that appears within the button.
|
|
8
|
+
Label?: string;
|
|
9
|
+
// True if the button should cancel an operation when clicked.
|
|
10
|
+
IsCancel?: boolean;
|
|
11
|
+
// True if the button should be the default action when the user presses enter.
|
|
12
|
+
IsDefault?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Describes the properties of a FileFilter object.
|
|
17
|
+
*/
|
|
18
|
+
export interface FileFilter {
|
|
19
|
+
// Display name for the filter, it could be "Text Files", "Images" etc.
|
|
20
|
+
DisplayName?: string;
|
|
21
|
+
// Pattern to match for the filter, e.g. "*.txt;*.md" for text markdown files.
|
|
22
|
+
Pattern?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Describes the properties of a Position object.
|
|
27
|
+
*/
|
|
28
|
+
export interface Position {
|
|
29
|
+
X: number;
|
|
30
|
+
Y: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Describes the properties of a Size object.
|
|
35
|
+
* Extends the properties of Position.
|
|
36
|
+
*/
|
|
37
|
+
export type Size = Position;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Describes the properties of a Rect object.
|
|
41
|
+
* Extends the properties of Size.
|
|
42
|
+
*/
|
|
43
|
+
export type Rect = Size & Position;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Describes the possible rotations a Screen can have.
|
|
47
|
+
*/
|
|
48
|
+
export enum Rotation {
|
|
49
|
+
Zero = 0,
|
|
50
|
+
Ninety = 90,
|
|
51
|
+
OneEighty = 180,
|
|
52
|
+
TwoSeventy = 270
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Describes the properties of a Screen object.
|
|
57
|
+
*/
|
|
58
|
+
export interface Screen {
|
|
59
|
+
// Unique identifier for the screen.
|
|
60
|
+
Id: string;
|
|
61
|
+
// Human readable name of the screen.
|
|
62
|
+
Name: string;
|
|
63
|
+
// The resolution scale of the screen. 1 = standard resolution, 2 = high (Retina), etc.
|
|
64
|
+
Scale: number;
|
|
65
|
+
// Contains the X and Y coordinates of the screen's position.
|
|
66
|
+
Position: Position;
|
|
67
|
+
// Contains the width and height of the screen.
|
|
68
|
+
Size: Size;
|
|
69
|
+
// Contains the bounds of the screen in terms of X, Y, Width, and Height.
|
|
70
|
+
Bounds: Rect;
|
|
71
|
+
// Contains the area of the screen that is actually usable (excluding taskbar and other system UI).
|
|
72
|
+
WorkArea: Rect;
|
|
73
|
+
// True if this is the primary monitor selected by the user in the operating system.
|
|
74
|
+
IsPrimary: boolean;
|
|
75
|
+
// The rotation of the screen. Can be one of 0, 90, 180, 270 degrees.
|
|
76
|
+
Rotation: Rotation;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Describes the properties of a MessageDialogOptions object.
|
|
81
|
+
*/
|
|
82
|
+
export interface MessageDialogOptions {
|
|
83
|
+
// The title of the dialog window.
|
|
84
|
+
Title?: string;
|
|
85
|
+
// The main message to show in the dialog.
|
|
86
|
+
Message?: string;
|
|
87
|
+
// Array of button options to show in the dialog.
|
|
88
|
+
Buttons?: Button[];
|
|
89
|
+
// True if the dialog should appear detached from the main window (if applicable).
|
|
90
|
+
Detached?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Describes the properties common to OpenFileDialogOptions and SaveFileDialogOptions objects.
|
|
95
|
+
*/
|
|
96
|
+
export interface DialogOptions {
|
|
97
|
+
CanChooseDirectories?: boolean;
|
|
98
|
+
CanChooseFiles?: boolean;
|
|
99
|
+
CanCreateDirectories?: boolean;
|
|
100
|
+
ShowHiddenFiles?: boolean;
|
|
101
|
+
ResolvesAliases?: boolean;
|
|
102
|
+
AllowsMultipleSelection?: boolean;
|
|
103
|
+
HideExtension?: boolean;
|
|
104
|
+
CanSelectHiddenExtension?: boolean;
|
|
105
|
+
TreatsFilePackagesAsDirectories?: boolean;
|
|
106
|
+
AllowsOtherFiletypes?: boolean;
|
|
107
|
+
Filters?: FileFilter[];
|
|
108
|
+
Title?: string;
|
|
109
|
+
Message?: string;
|
|
110
|
+
ButtonText?: string;
|
|
111
|
+
Directory?: string;
|
|
112
|
+
Detached?: boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Describes properties unique to OpenFileDialogOptions.
|
|
117
|
+
*/
|
|
118
|
+
export type OpenFileDialogOptions = DialogOptions;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Describes properties unique to SaveFileDialogOptions.
|
|
122
|
+
*/
|
|
123
|
+
export type SaveFileDialogOptions = DialogOptions & {
|
|
124
|
+
// Default filename to use for the save dialog.
|
|
125
|
+
Filename?: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Describes the properties of a WailsEvent object.
|
|
130
|
+
*/
|
|
131
|
+
export interface WailsEvent {
|
|
132
|
+
// The name of the event.
|
|
133
|
+
Name: string;
|
|
134
|
+
// Any data associated with the event.
|
|
135
|
+
Data?: unknown;
|
|
136
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {setupContextMenus} from "./contextmenu";
|
|
12
|
+
import {setupDrag} from "./drag";
|
|
13
|
+
import {reloadWML} from "./wml";
|
|
14
|
+
import {Emit, Off, OffAll, On, Once, OnMultiple, WailsEvent} from './events';
|
|
15
|
+
import {ByID, ByName, Plugin} from "./calls";
|
|
16
|
+
import {Error, Info, OpenFile, Question, SaveFile, Warning} from "./dialogs";
|
|
17
|
+
|
|
18
|
+
import * as Application from "./application";
|
|
19
|
+
import * as Browser from "./browser";
|
|
20
|
+
import * as Clipboard from "./clipboard";
|
|
21
|
+
import * as ContextMenu from "./contextmenu";
|
|
22
|
+
import * as Flags from "./flags";
|
|
23
|
+
import * as Runtime from "./runtime";
|
|
24
|
+
import * as Screens from "./screens";
|
|
25
|
+
import * as System from "./system";
|
|
26
|
+
import * as Window from "./window";
|
|
27
|
+
|
|
28
|
+
export { Application, Browser, Clipboard, ContextMenu, Flags, Runtime, Screens, System, Window };
|
|
29
|
+
|
|
30
|
+
export const Events = {
|
|
31
|
+
On,
|
|
32
|
+
Off,
|
|
33
|
+
OnMultiple,
|
|
34
|
+
WailsEvent,
|
|
35
|
+
OffAll,
|
|
36
|
+
Emit,
|
|
37
|
+
Once
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const Call = {
|
|
42
|
+
Plugin,
|
|
43
|
+
ByID,
|
|
44
|
+
ByName
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const Dialogs = {
|
|
48
|
+
Info,
|
|
49
|
+
Error,
|
|
50
|
+
OpenFile, Question, Warning, SaveFile
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setupContextMenus();
|
|
54
|
+
setupDrag();
|
|
55
|
+
|
|
56
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
57
|
+
reloadWML();
|
|
58
|
+
});
|
package/src/runtime.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
13
|
+
|
|
14
|
+
const runtimeURL = window.location.origin + "/wails/runtime";
|
|
15
|
+
|
|
16
|
+
// Object Names
|
|
17
|
+
export const objectNames = {
|
|
18
|
+
Call: 0,
|
|
19
|
+
Clipboard: 1,
|
|
20
|
+
Application: 2,
|
|
21
|
+
Events: 3,
|
|
22
|
+
ContextMenu: 4,
|
|
23
|
+
Dialog: 5,
|
|
24
|
+
Window: 6,
|
|
25
|
+
Screens: 7,
|
|
26
|
+
System: 8,
|
|
27
|
+
Browser: 9,
|
|
28
|
+
}
|
|
29
|
+
export let clientId = nanoid();
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a runtime caller function that invokes a specified method on a given object within a specified window context.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} object - The object on which the method is to be invoked.
|
|
35
|
+
* @param {string} windowName - The name of the window context in which the method should be called.
|
|
36
|
+
* @returns {Function} A runtime caller function that takes the method name and optionally arguments and invokes the method within the specified window context.
|
|
37
|
+
*/
|
|
38
|
+
export function newRuntimeCaller(object, windowName) {
|
|
39
|
+
return function (method, args=null) {
|
|
40
|
+
return runtimeCall(object + "." + method, windowName, args);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new runtime caller with specified ID.
|
|
46
|
+
*
|
|
47
|
+
* @param {object} object - The object to invoke the method on.
|
|
48
|
+
* @param {string} windowName - The name of the window.
|
|
49
|
+
* @return {Function} - The new runtime caller function.
|
|
50
|
+
*/
|
|
51
|
+
export function newRuntimeCallerWithID(object, windowName) {
|
|
52
|
+
return function (method, args=null) {
|
|
53
|
+
return runtimeCallWithID(object, method, windowName, args);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function runtimeCall(method, windowName, args) {
|
|
59
|
+
let url = new URL(runtimeURL);
|
|
60
|
+
if( method ) {
|
|
61
|
+
url.searchParams.append("method", method);
|
|
62
|
+
}
|
|
63
|
+
let fetchOptions = {
|
|
64
|
+
headers: {},
|
|
65
|
+
};
|
|
66
|
+
if (windowName) {
|
|
67
|
+
fetchOptions.headers["x-wails-window-name"] = windowName;
|
|
68
|
+
}
|
|
69
|
+
if (args) {
|
|
70
|
+
url.searchParams.append("args", JSON.stringify(args));
|
|
71
|
+
}
|
|
72
|
+
fetchOptions.headers["x-wails-client-id"] = clientId;
|
|
73
|
+
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
fetch(url, fetchOptions)
|
|
76
|
+
.then(response => {
|
|
77
|
+
if (response.ok) {
|
|
78
|
+
// check content type
|
|
79
|
+
if (response.headers.get("Content-Type") && response.headers.get("Content-Type").indexOf("application/json") !== -1) {
|
|
80
|
+
return response.json();
|
|
81
|
+
} else {
|
|
82
|
+
return response.text();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
reject(Error(response.statusText));
|
|
86
|
+
})
|
|
87
|
+
.then(data => resolve(data))
|
|
88
|
+
.catch(error => reject(error));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function runtimeCallWithID(objectID, method, windowName, args) {
|
|
93
|
+
let url = new URL(runtimeURL);
|
|
94
|
+
url.searchParams.append("object", objectID);
|
|
95
|
+
url.searchParams.append("method", method);
|
|
96
|
+
let fetchOptions = {
|
|
97
|
+
headers: {},
|
|
98
|
+
};
|
|
99
|
+
if (windowName) {
|
|
100
|
+
fetchOptions.headers["x-wails-window-name"] = windowName;
|
|
101
|
+
}
|
|
102
|
+
if (args) {
|
|
103
|
+
url.searchParams.append("args", JSON.stringify(args));
|
|
104
|
+
}
|
|
105
|
+
fetchOptions.headers["x-wails-client-id"] = clientId;
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
fetch(url, fetchOptions)
|
|
108
|
+
.then(response => {
|
|
109
|
+
if (response.ok) {
|
|
110
|
+
// check content type
|
|
111
|
+
if (response.headers.get("Content-Type") && response.headers.get("Content-Type").indexOf("application/json") !== -1) {
|
|
112
|
+
return response.json();
|
|
113
|
+
} else {
|
|
114
|
+
return response.text();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
reject(Error(response.statusText));
|
|
118
|
+
})
|
|
119
|
+
.then(data => resolve(data))
|
|
120
|
+
.catch(error => reject(error));
|
|
121
|
+
});
|
|
122
|
+
}
|
package/src/screens.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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").Screen} Screen
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {newRuntimeCallerWithID, objectNames} from "./runtime";
|
|
18
|
+
const call = newRuntimeCallerWithID(objectNames.Screens, '');
|
|
19
|
+
|
|
20
|
+
const getAll = 0;
|
|
21
|
+
const getPrimary = 1;
|
|
22
|
+
const getCurrent = 2;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Gets all screens.
|
|
26
|
+
* @returns {Promise<Screen[]>} A promise that resolves to an array of Screen objects.
|
|
27
|
+
*/
|
|
28
|
+
export function GetAll() {
|
|
29
|
+
return call(getAll);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the primary screen.
|
|
33
|
+
* @returns {Promise<Screen>} A promise that resolves to the primary screen.
|
|
34
|
+
*/
|
|
35
|
+
export function GetPrimary() {
|
|
36
|
+
return call(getPrimary);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the current active screen.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Promise<Screen>} A promise that resolves with the current active screen.
|
|
42
|
+
*/
|
|
43
|
+
export function GetCurrent() {
|
|
44
|
+
return call(getCurrent);
|
|
45
|
+
}
|
package/src/system.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
}
|