@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.
- package/dist/android.js +39 -0
- package/{src → dist}/application.js +32 -46
- package/dist/browser.js +20 -0
- package/dist/callable.js +144 -0
- package/dist/calls.js +114 -0
- package/dist/cancellable.js +792 -0
- package/dist/clipboard.js +30 -0
- package/dist/contextmenu.js +83 -0
- package/dist/create.js +99 -0
- package/dist/dialogs.js +69 -0
- package/dist/drag.js +268 -0
- package/dist/environment.js +17 -0
- package/dist/event_types.js +292 -0
- package/dist/events.js +119 -0
- package/dist/flags.js +23 -0
- package/dist/index.js +88 -0
- package/dist/ios.js +28 -0
- package/dist/listener.js +44 -0
- package/dist/nanoid.js +38 -0
- package/dist/plugins/vite.js +64 -0
- package/dist/runtime.js +198 -0
- package/dist/screens.js +58 -0
- package/dist/system.js +158 -0
- package/dist/updater.js +74 -0
- package/dist/utils.js +98 -0
- package/dist/window.js +734 -0
- package/dist/wml.js +179 -0
- package/package.json +71 -26
- package/types/android.d.ts +21 -0
- package/types/application.d.ts +3 -10
- package/types/browser.d.ts +4 -4
- package/types/callable.d.ts +3 -0
- package/types/calls.d.ts +52 -24
- package/types/cancellable.d.ts +433 -0
- package/types/clipboard.d.ts +6 -5
- package/types/contextmenu.d.ts +1 -1
- package/types/create.d.ts +36 -0
- package/types/dialogs.d.ts +132 -20
- package/types/drag.d.ts +1 -4
- package/types/environment.d.ts +8 -0
- package/types/event_types.d.ts +281 -0
- package/types/events.d.ts +70 -33
- package/types/flags.d.ts +3 -3
- package/types/index.d.ts +32 -48
- package/types/ios.d.ts +13 -0
- package/types/listener.d.ts +9 -0
- package/types/nanoid.d.ts +1 -0
- package/types/plugins/vite.d.ts +10 -0
- package/types/runtime.d.ts +61 -22
- package/types/screens.d.ts +64 -7
- package/types/system.d.ts +74 -39
- package/types/updater.d.ts +65 -0
- package/types/utils.d.ts +21 -0
- package/types/window.d.ts +327 -13
- package/types/wml.d.ts +5 -3
- package/src/browser.js +0 -24
- package/src/calls.js +0 -123
- package/src/clipboard.js +0 -35
- package/src/contextmenu.js +0 -98
- package/src/dialogs.js +0 -138
- package/src/drag.js +0 -125
- package/src/events.js +0 -134
- package/src/flags.js +0 -63
- package/src/index.d.ts +0 -136
- package/src/index.js +0 -58
- package/src/runtime.js +0 -122
- package/src/screens.js +0 -45
- package/src/system.js +0 -122
- package/src/window.js +0 -122
- package/src/wml.js +0 -151
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
const TYPED_EVENTS_MODULE = "\0wailsio_runtime_events_typed";
|
|
11
|
+
/**
|
|
12
|
+
* A plugin that extends the wails runtime with locally generated code
|
|
13
|
+
* to provide support for typed custom events.
|
|
14
|
+
* With the plugin installed, vite will fail to build the project
|
|
15
|
+
* unless wails bindings have been generated first.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} [bindingsRoot] - The root import path for generated bindings
|
|
18
|
+
*/
|
|
19
|
+
export default function WailsTypedEvents(bindingsRoot) {
|
|
20
|
+
let bindingsId, runtimeId, eventsId;
|
|
21
|
+
return {
|
|
22
|
+
name: "wails-typed-events",
|
|
23
|
+
async buildStart() {
|
|
24
|
+
const bindingsPath = `${bindingsRoot}/github.com/wailsapp/wails/v3/internal/eventcreate`;
|
|
25
|
+
let resolution = await this.resolve(bindingsPath);
|
|
26
|
+
if (!resolution || resolution.external) {
|
|
27
|
+
this.error(`Event bindings module not found at import specifier '${bindingsPath}'. Please verify that the wails tool is up to date and the binding generator runs successfully. If you moved the bindings to a custom location, ensure you supplied the correct root path as the first argument to \`wailsTypedEventsPlugin\``);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
bindingsId = resolution.id;
|
|
31
|
+
resolution = await this.resolve("@wailsio/runtime");
|
|
32
|
+
if (!resolution || resolution.external) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
runtimeId = resolution.id;
|
|
36
|
+
resolution = await this.resolve("./events.js", runtimeId);
|
|
37
|
+
if (!resolution || resolution.external) {
|
|
38
|
+
this.error("Could not resolve events module within @wailsio/runtime package. Please verify that the module is correctly installed and up to date.");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
eventsId = resolution.id;
|
|
42
|
+
},
|
|
43
|
+
resolveId: {
|
|
44
|
+
order: 'pre',
|
|
45
|
+
handler(id, importer) {
|
|
46
|
+
if (bindingsId !== null
|
|
47
|
+
&& runtimeId !== null
|
|
48
|
+
&& eventsId !== null
|
|
49
|
+
&& importer === runtimeId
|
|
50
|
+
&& id === "./events.js") {
|
|
51
|
+
return TYPED_EVENTS_MODULE;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
load(id) {
|
|
57
|
+
if (id === TYPED_EVENTS_MODULE) {
|
|
58
|
+
return (`import ${JSON.stringify(bindingsId)};\n`
|
|
59
|
+
+ `export * from ${JSON.stringify(eventsId)};`);
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
var _a;
|
|
11
|
+
import { nanoid } from "./nanoid.js";
|
|
12
|
+
import { hasDOM } from "./environment.js";
|
|
13
|
+
// Resolved lazily: window does not exist when the module is imported during
|
|
14
|
+
// server-side rendering (#4679), and nothing can call the runtime there.
|
|
15
|
+
function runtimeURL() {
|
|
16
|
+
return window.location.origin + "/wails/runtime";
|
|
17
|
+
}
|
|
18
|
+
// Stay under WebView2's ~2MB request body buffering limit in WebResourceRequested.
|
|
19
|
+
const CHUNK_THRESHOLD = 512 * 1024;
|
|
20
|
+
// Re-export nanoid for custom transport implementations
|
|
21
|
+
export { nanoid };
|
|
22
|
+
// Object Names
|
|
23
|
+
export const objectNames = Object.freeze({
|
|
24
|
+
Call: 0,
|
|
25
|
+
Clipboard: 1,
|
|
26
|
+
Application: 2,
|
|
27
|
+
Events: 3,
|
|
28
|
+
ContextMenu: 4,
|
|
29
|
+
Dialog: 5,
|
|
30
|
+
Window: 6,
|
|
31
|
+
Screens: 7,
|
|
32
|
+
System: 8,
|
|
33
|
+
Browser: 9,
|
|
34
|
+
CancelCall: 10,
|
|
35
|
+
IOS: 11,
|
|
36
|
+
Android: 12,
|
|
37
|
+
});
|
|
38
|
+
export let clientId = nanoid();
|
|
39
|
+
/**
|
|
40
|
+
* Custom transport implementation (can be set by user)
|
|
41
|
+
*/
|
|
42
|
+
let customTransport = null;
|
|
43
|
+
/**
|
|
44
|
+
* Set a custom transport for all Wails runtime calls.
|
|
45
|
+
* This allows you to replace the default HTTP fetch transport with
|
|
46
|
+
* WebSockets, custom protocols, or any other mechanism.
|
|
47
|
+
*
|
|
48
|
+
* @param transport - Your custom transport implementation
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { setTransport } from '/wails/runtime.js';
|
|
53
|
+
*
|
|
54
|
+
* const wsTransport = {
|
|
55
|
+
* call: async (objectID, method, windowName, args) => {
|
|
56
|
+
* // Your WebSocket implementation
|
|
57
|
+
* }
|
|
58
|
+
* };
|
|
59
|
+
*
|
|
60
|
+
* setTransport(wsTransport);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function setTransport(transport) {
|
|
64
|
+
customTransport = transport;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the current transport (useful for extending/wrapping)
|
|
68
|
+
*/
|
|
69
|
+
export function getTransport() {
|
|
70
|
+
return customTransport;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new runtime caller with specified ID.
|
|
74
|
+
*
|
|
75
|
+
* @param object - The object to invoke the method on.
|
|
76
|
+
* @param windowName - The name of the window.
|
|
77
|
+
* @return The new runtime caller function.
|
|
78
|
+
*/
|
|
79
|
+
export function newRuntimeCaller(object, windowName = '') {
|
|
80
|
+
return function (method, args = null) {
|
|
81
|
+
return runtimeCallWithID(object, method, windowName, args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async function runtimeCallWithID(objectID, method, windowName, args) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
// Use custom transport if available
|
|
87
|
+
if (customTransport) {
|
|
88
|
+
return customTransport.call(objectID, method, windowName, args);
|
|
89
|
+
}
|
|
90
|
+
// Default HTTP fetch transport
|
|
91
|
+
let url = new URL(runtimeURL());
|
|
92
|
+
let body = {
|
|
93
|
+
object: objectID,
|
|
94
|
+
method
|
|
95
|
+
};
|
|
96
|
+
if (args !== null && args !== undefined) {
|
|
97
|
+
body.args = args;
|
|
98
|
+
}
|
|
99
|
+
let headers = {
|
|
100
|
+
["x-wails-client-id"]: clientId,
|
|
101
|
+
["Content-Type"]: "application/json"
|
|
102
|
+
};
|
|
103
|
+
if (windowName) {
|
|
104
|
+
headers["x-wails-window-name"] = windowName;
|
|
105
|
+
}
|
|
106
|
+
const bodyStr = JSON.stringify(body);
|
|
107
|
+
let response;
|
|
108
|
+
if (bodyStr.length > CHUNK_THRESHOLD) {
|
|
109
|
+
response = await sendChunked(url, headers, bodyStr);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
response = await fetch(url, { method: 'POST', headers, body: bodyStr });
|
|
113
|
+
}
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
throw new Error(await response.text());
|
|
116
|
+
}
|
|
117
|
+
if (((_b = (_a = response.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.indexOf("application/json")) !== null && _b !== void 0 ? _b : -1) !== -1) {
|
|
118
|
+
return response.json();
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return response.text();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// sendChunked splits a large serialised request body into CHUNK_THRESHOLD-sized
|
|
125
|
+
// byte chunks and sends them serially. Encoding to UTF-8 bytes before slicing
|
|
126
|
+
// prevents corruption of non-BMP characters (surrogate pairs) that would occur
|
|
127
|
+
// when splitting at JavaScript string indices. The Go transport assembles the
|
|
128
|
+
// raw bytes before processing. Only the final chunk's response carries the RPC result.
|
|
129
|
+
async function sendChunked(url, headers, bodyStr) {
|
|
130
|
+
const chunkId = nanoid();
|
|
131
|
+
const bodyBytes = new TextEncoder().encode(bodyStr);
|
|
132
|
+
const totalChunks = Math.ceil(bodyBytes.length / CHUNK_THRESHOLD);
|
|
133
|
+
for (let i = 0; i < totalChunks - 1; i++) {
|
|
134
|
+
const chunk = bodyBytes.subarray(i * CHUNK_THRESHOLD, (i + 1) * CHUNK_THRESHOLD);
|
|
135
|
+
const resp = await fetch(url, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
headers: Object.assign(Object.assign({}, headers), { 'x-wails-chunk-id': chunkId, 'x-wails-chunk-index': String(i), 'x-wails-chunk-total': String(totalChunks) }),
|
|
138
|
+
body: chunk,
|
|
139
|
+
});
|
|
140
|
+
if (!resp.ok) {
|
|
141
|
+
throw new Error(await resp.text());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return fetch(url, {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
headers: Object.assign(Object.assign({}, headers), { 'x-wails-chunk-id': chunkId, 'x-wails-chunk-index': String(totalChunks - 1), 'x-wails-chunk-total': String(totalChunks) }),
|
|
147
|
+
body: bodyBytes.subarray((totalChunks - 1) * CHUNK_THRESHOLD),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const androidBridge = hasDOM &&
|
|
151
|
+
typeof ((_a = window.wails) === null || _a === void 0 ? void 0 : _a.invokeAsync) === "function" ? window.wails : null;
|
|
152
|
+
if (androidBridge) {
|
|
153
|
+
const pending = new Map();
|
|
154
|
+
window._wailsAndroidCallback = (id, response, error) => {
|
|
155
|
+
var _a;
|
|
156
|
+
const promise = pending.get(id);
|
|
157
|
+
if (!promise)
|
|
158
|
+
return;
|
|
159
|
+
pending.delete(id);
|
|
160
|
+
if (error) {
|
|
161
|
+
promise.reject(new Error(error));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const envelope = JSON.parse(response !== null && response !== void 0 ? response : "{}");
|
|
166
|
+
if (!envelope.ok) {
|
|
167
|
+
promise.reject(new Error((_a = envelope.error) !== null && _a !== void 0 ? _a : "unknown runtime call error"));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
promise.resolve("text" in envelope ? envelope.text : envelope.data);
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
promise.reject(e);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
customTransport = {
|
|
177
|
+
call(objectID, method, windowName, args) {
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
const id = nanoid();
|
|
180
|
+
pending.set(id, { resolve, reject });
|
|
181
|
+
try {
|
|
182
|
+
androidBridge.invokeAsync(id, JSON.stringify({
|
|
183
|
+
object: objectID,
|
|
184
|
+
method: method,
|
|
185
|
+
windowName: windowName,
|
|
186
|
+
args: args !== null && args !== void 0 ? args : null,
|
|
187
|
+
clientId: clientId,
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
// Don't leak the pending entry if dispatch throws synchronously
|
|
192
|
+
pending.delete(id);
|
|
193
|
+
reject(e);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
package/dist/screens.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
|
+
import { newRuntimeCaller, objectNames } from "./runtime.js";
|
|
11
|
+
const call = newRuntimeCaller(objectNames.Screens);
|
|
12
|
+
const getAll = 0;
|
|
13
|
+
const getPrimary = 1;
|
|
14
|
+
const getCurrent = 2;
|
|
15
|
+
const getByID = 3;
|
|
16
|
+
const getByIndex = 4;
|
|
17
|
+
/**
|
|
18
|
+
* Gets all screens.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves to an array of Screen objects.
|
|
21
|
+
*/
|
|
22
|
+
export function GetAll() {
|
|
23
|
+
return call(getAll);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the primary screen.
|
|
27
|
+
*
|
|
28
|
+
* @returns A promise that resolves to the primary screen.
|
|
29
|
+
*/
|
|
30
|
+
export function GetPrimary() {
|
|
31
|
+
return call(getPrimary);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Gets the current active screen.
|
|
35
|
+
*
|
|
36
|
+
* @returns A promise that resolves with the current active screen.
|
|
37
|
+
*/
|
|
38
|
+
export function GetCurrent() {
|
|
39
|
+
return call(getCurrent);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets a screen by its unique display ID.
|
|
43
|
+
*
|
|
44
|
+
* @param id - The unique identifier of the screen.
|
|
45
|
+
* @returns A promise that resolves to the matching Screen.
|
|
46
|
+
*/
|
|
47
|
+
export function GetByID(id) {
|
|
48
|
+
return call(getByID, { id });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets a screen by its index in the screen list.
|
|
52
|
+
*
|
|
53
|
+
* @param index - The zero-based index of the screen.
|
|
54
|
+
* @returns A promise that resolves to the matching Screen.
|
|
55
|
+
*/
|
|
56
|
+
export function GetByIndex(index) {
|
|
57
|
+
return call(getByIndex, { index });
|
|
58
|
+
}
|
package/dist/system.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
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.System);
|
|
12
|
+
const SystemIsDarkMode = 0;
|
|
13
|
+
const SystemEnvironment = 1;
|
|
14
|
+
const SystemCapabilities = 2;
|
|
15
|
+
const _invoke = (function () {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
try {
|
|
18
|
+
// Windows WebView2
|
|
19
|
+
if ((_b = (_a = window.chrome) === null || _a === void 0 ? void 0 : _a.webview) === null || _b === void 0 ? void 0 : _b.postMessage) {
|
|
20
|
+
return window.chrome.webview.postMessage.bind(window.chrome.webview);
|
|
21
|
+
}
|
|
22
|
+
// macOS/iOS WKWebView
|
|
23
|
+
else if ((_e = (_d = (_c = window.webkit) === null || _c === void 0 ? void 0 : _c.messageHandlers) === null || _d === void 0 ? void 0 : _d['external']) === null || _e === void 0 ? void 0 : _e.postMessage) {
|
|
24
|
+
return window.webkit.messageHandlers['external'].postMessage.bind(window.webkit.messageHandlers['external']);
|
|
25
|
+
}
|
|
26
|
+
// Android WebView - uses addJavascriptInterface which exposes window.wails.invoke
|
|
27
|
+
else if ((_f = window.wails) === null || _f === void 0 ? void 0 : _f.invoke) {
|
|
28
|
+
return (msg) => window.wails.invoke(typeof msg === 'string' ? msg : JSON.stringify(msg));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) { }
|
|
32
|
+
console.warn('\n%c⚠️ Browser Environment Detected %c\n\n%cOnly UI previews are available in the browser. For full functionality, please run the application in desktop mode.\nMore information at: https://v3.wails.io/learn/build/#using-a-browser-for-development\n', 'background: #ffffff; color: #000000; font-weight: bold; padding: 4px 8px; border-radius: 4px; border: 2px solid #000000;', 'background: transparent;', 'color: #ffffff; font-style: italic; font-weight: bold;');
|
|
33
|
+
return null;
|
|
34
|
+
})();
|
|
35
|
+
export function invoke(msg) {
|
|
36
|
+
_invoke === null || _invoke === void 0 ? void 0 : _invoke(msg);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the system dark mode status.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves to a boolean value indicating if the system is in dark mode.
|
|
42
|
+
*/
|
|
43
|
+
export function IsDarkMode() {
|
|
44
|
+
return call(SystemIsDarkMode);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fetches the capabilities of the application from the server.
|
|
48
|
+
*
|
|
49
|
+
* @returns A promise that resolves to an object containing the capabilities.
|
|
50
|
+
*/
|
|
51
|
+
export async function Capabilities() {
|
|
52
|
+
return call(SystemCapabilities);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves environment details.
|
|
56
|
+
*
|
|
57
|
+
* @returns A promise that resolves to an object containing OS and system architecture.
|
|
58
|
+
*/
|
|
59
|
+
export function Environment() {
|
|
60
|
+
return call(SystemEnvironment);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the current operating system is Windows.
|
|
64
|
+
*
|
|
65
|
+
* @return True if the operating system is Windows, otherwise false.
|
|
66
|
+
*/
|
|
67
|
+
export function IsWindows() {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.OS) === "windows";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the current operating system is Linux.
|
|
73
|
+
*
|
|
74
|
+
* @returns Returns true if the current operating system is Linux, false otherwise.
|
|
75
|
+
*/
|
|
76
|
+
export function IsLinux() {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.OS) === "linux";
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Checks if the current environment is a macOS operating system.
|
|
82
|
+
*
|
|
83
|
+
* @returns True if the environment is macOS, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
export function IsMac() {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.OS) === "darwin";
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the current operating system is iOS.
|
|
91
|
+
*
|
|
92
|
+
* @returns True if the operating system is iOS, otherwise false.
|
|
93
|
+
*/
|
|
94
|
+
export function IsIOS() {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.OS) === "ios";
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Checks if the current operating system is Android.
|
|
100
|
+
*
|
|
101
|
+
* @returns True if the operating system is Android, otherwise false.
|
|
102
|
+
*/
|
|
103
|
+
export function IsAndroid() {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.OS) === "android";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Checks if the app is running on a mobile OS (iOS or Android).
|
|
109
|
+
*
|
|
110
|
+
* @returns True on iOS or Android, otherwise false.
|
|
111
|
+
*/
|
|
112
|
+
export function IsMobile() {
|
|
113
|
+
return IsIOS() || IsAndroid();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the app is running on a desktop OS (macOS, Windows or Linux).
|
|
117
|
+
*
|
|
118
|
+
* @returns True on macOS, Windows or Linux, otherwise false.
|
|
119
|
+
*/
|
|
120
|
+
export function IsDesktop() {
|
|
121
|
+
return IsMac() || IsWindows() || IsLinux();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Checks if the current environment architecture is AMD64.
|
|
125
|
+
*
|
|
126
|
+
* @returns True if the current environment architecture is AMD64, false otherwise.
|
|
127
|
+
*/
|
|
128
|
+
export function IsAMD64() {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.Arch) === "amd64";
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Checks if the current architecture is ARM.
|
|
134
|
+
*
|
|
135
|
+
* @returns True if the current architecture is ARM, false otherwise.
|
|
136
|
+
*/
|
|
137
|
+
export function IsARM() {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.Arch) === "arm";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks if the current environment is ARM64 architecture.
|
|
143
|
+
*
|
|
144
|
+
* @returns Returns true if the environment is ARM64 architecture, otherwise returns false.
|
|
145
|
+
*/
|
|
146
|
+
export function IsARM64() {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
return ((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.Arch) === "arm64";
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Reports whether the app is being run in debug mode.
|
|
152
|
+
*
|
|
153
|
+
* @returns True if the app is being run in debug mode.
|
|
154
|
+
*/
|
|
155
|
+
export function IsDebug() {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
return Boolean((_b = (_a = window._wails) === null || _a === void 0 ? void 0 : _a.environment) === null || _b === void 0 ? void 0 : _b.Debug);
|
|
158
|
+
}
|
package/dist/updater.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Updater event name constants.
|
|
12
|
+
*
|
|
13
|
+
* Use these instead of hard-coding string literals when subscribing to
|
|
14
|
+
* updater events from JavaScript:
|
|
15
|
+
*
|
|
16
|
+
* import { Events, Updater } from "@wailsio/runtime";
|
|
17
|
+
*
|
|
18
|
+
* Events.On(Updater.Events.UpdateAvailable, (e) => {
|
|
19
|
+
* console.log("update found:", e.data.version);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* Events.On(Updater.Events.DownloadProgress, (e) => {
|
|
23
|
+
* const p = e.data;
|
|
24
|
+
* console.log(`${p.written} / ${p.total} bytes`);
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* Mirrors the Go-side constants in `pkg/updater/events.go` and the
|
|
28
|
+
* user-action constants in `pkg/updater/window_lifecycle.go`. Any
|
|
29
|
+
* changes here must stay in sync with those files — there's an
|
|
30
|
+
* integration test that asserts the strings match.
|
|
31
|
+
*/
|
|
32
|
+
export const Events = Object.freeze({
|
|
33
|
+
/** A Check round-trip is starting. Payload: null. */
|
|
34
|
+
CheckStarted: "wails:updater:check-started",
|
|
35
|
+
/** Check found a newer release. Payload: Release. */
|
|
36
|
+
UpdateAvailable: "wails:updater:update-available",
|
|
37
|
+
/** Check confirmed the caller is up to date. Payload: null. */
|
|
38
|
+
NoUpdate: "wails:updater:no-update",
|
|
39
|
+
/** Download is starting. Payload: Release. */
|
|
40
|
+
DownloadStarted: "wails:updater:download-started",
|
|
41
|
+
/** Periodic progress tick during download (~10 Hz). Payload: Progress. */
|
|
42
|
+
DownloadProgress: "wails:updater:download-progress",
|
|
43
|
+
/** All bytes are on disk, but verification has not yet started. Payload: Release. */
|
|
44
|
+
DownloadComplete: "wails:updater:download-complete",
|
|
45
|
+
/** Signature / digest verification has started. Payload: Release. */
|
|
46
|
+
Verifying: "wails:updater:verifying",
|
|
47
|
+
/** The Updater is swapping the binary into place. Payload: Release. */
|
|
48
|
+
Installing: "wails:updater:installing",
|
|
49
|
+
/** Update is staged and a restart is pending. Payload: Release. */
|
|
50
|
+
UpdateReady: "wails:updater:update-ready",
|
|
51
|
+
/** Something failed. Payload: ErrorInfo { stage, message, provider }. */
|
|
52
|
+
Error: "wails:updater:error",
|
|
53
|
+
/** Host-side context delivered once per session. Payload: Meta { currentVersion, skippedVersion }. */
|
|
54
|
+
Meta: "wails:updater:meta",
|
|
55
|
+
/** Sub-namespace: user-action events that the UI emits BACK to the host. */
|
|
56
|
+
User: Object.freeze({
|
|
57
|
+
/** User clicked Install on an Available update. */
|
|
58
|
+
Install: "wails:updater:user:install",
|
|
59
|
+
/** User clicked Restart & Apply on a Ready update. */
|
|
60
|
+
Restart: "wails:updater:user:restart",
|
|
61
|
+
/** User clicked Skip This Version. */
|
|
62
|
+
Skip: "wails:updater:user:skip",
|
|
63
|
+
/** User clicked Remind Me Later. */
|
|
64
|
+
Remind: "wails:updater:user:remind",
|
|
65
|
+
/** User clicked Close / Cancel. */
|
|
66
|
+
Cancel: "wails:updater:user:cancel",
|
|
67
|
+
}),
|
|
68
|
+
/** Sub-namespace: framework-internal events the UI emits to coordinate
|
|
69
|
+
* with the host. Most app code can ignore these. */
|
|
70
|
+
Window: Object.freeze({
|
|
71
|
+
/** The window finished loading and asks the host to replay current state. */
|
|
72
|
+
Ready: "wails:updater:window:ready",
|
|
73
|
+
}),
|
|
74
|
+
});
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ __ _ __
|
|
3
|
+
| | / /___ _(_) /____
|
|
4
|
+
| | /| / / __ `/ / / ___/
|
|
5
|
+
| |/ |/ / /_/ / / (__ )
|
|
6
|
+
|__/|__/\__,_/_/_/____/
|
|
7
|
+
The electron alternative for Go
|
|
8
|
+
(c) Lea Anthony 2019-present
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Logs a message to the console with custom formatting.
|
|
12
|
+
*
|
|
13
|
+
* @param message - The message to be logged.
|
|
14
|
+
*/
|
|
15
|
+
export function debugLog(message) {
|
|
16
|
+
// eslint-disable-next-line
|
|
17
|
+
console.log('%c wails3 %c ' + message + ' ', 'background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem', 'background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether the webview supports the {@link MouseEvent#buttons} property.
|
|
21
|
+
* Looking at you macOS High Sierra!
|
|
22
|
+
*/
|
|
23
|
+
export function canTrackButtons() {
|
|
24
|
+
return (new MouseEvent('mousedown')).buttons === 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether the browser supports removing listeners by triggering an AbortSignal
|
|
28
|
+
* (see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal).
|
|
29
|
+
*/
|
|
30
|
+
export function canAbortListeners() {
|
|
31
|
+
if (!EventTarget || !AbortSignal || !AbortController)
|
|
32
|
+
return false;
|
|
33
|
+
let result = true;
|
|
34
|
+
const target = new EventTarget();
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
target.addEventListener('test', () => { result = false; }, { signal: controller.signal });
|
|
37
|
+
controller.abort();
|
|
38
|
+
target.dispatchEvent(new CustomEvent('test'));
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the closest HTMLElement ancestor of an event's target.
|
|
43
|
+
*/
|
|
44
|
+
export function eventTarget(event) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (event.target instanceof HTMLElement) {
|
|
47
|
+
return event.target;
|
|
48
|
+
}
|
|
49
|
+
else if (!(event.target instanceof HTMLElement) && event.target instanceof Node) {
|
|
50
|
+
return (_a = event.target.parentElement) !== null && _a !== void 0 ? _a : document.body;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return document.body;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/***
|
|
57
|
+
This technique for proper load detection is taken from HTMX:
|
|
58
|
+
|
|
59
|
+
BSD 2-Clause License
|
|
60
|
+
|
|
61
|
+
Copyright (c) 2020, Big Sky Software
|
|
62
|
+
All rights reserved.
|
|
63
|
+
|
|
64
|
+
Redistribution and use in source and binary forms, with or without
|
|
65
|
+
modification, are permitted provided that the following conditions are met:
|
|
66
|
+
|
|
67
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
68
|
+
list of conditions and the following disclaimer.
|
|
69
|
+
|
|
70
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
71
|
+
this list of conditions and the following disclaimer in the documentation
|
|
72
|
+
and/or other materials provided with the distribution.
|
|
73
|
+
|
|
74
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
75
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
76
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
77
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
78
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
79
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
80
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
81
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
82
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
83
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
84
|
+
|
|
85
|
+
***/
|
|
86
|
+
let isReady = false;
|
|
87
|
+
import { hasDOM } from "./environment.js";
|
|
88
|
+
if (hasDOM) {
|
|
89
|
+
document.addEventListener('DOMContentLoaded', () => { isReady = true; });
|
|
90
|
+
}
|
|
91
|
+
export function whenReady(callback) {
|
|
92
|
+
if (isReady || document.readyState === 'complete') {
|
|
93
|
+
callback();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
document.addEventListener('DOMContentLoaded', callback);
|
|
97
|
+
}
|
|
98
|
+
}
|