@reset-framework/sdk 1.1.2 → 1.1.5
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/LICENSE +20 -20
- package/README.md +41 -41
- package/package.json +1 -1
- package/src/client.js +834 -823
- package/src/errors.js +33 -33
- package/src/events.js +123 -123
- package/src/index.d.ts +574 -574
- package/src/index.js +39 -39
- package/src/transport.js +180 -180
package/src/client.js
CHANGED
|
@@ -1,835 +1,846 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createResetTransport,
|
|
3
|
-
getResetRuntime,
|
|
4
|
-
invoke,
|
|
5
|
-
invokeRaw,
|
|
6
|
-
isResetRuntimeAvailable
|
|
7
|
-
} from "./transport.js"
|
|
8
|
-
import { createEventApi } from "./events.js"
|
|
9
|
-
import { ResetProtocolError } from "./errors.js"
|
|
10
|
-
|
|
11
|
-
function isObjectLike(value) {
|
|
12
|
-
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function requireObject(value, command) {
|
|
16
|
-
if (!isObjectLike(value)) {
|
|
17
|
-
throw new ResetProtocolError(
|
|
18
|
-
`Reset runtime returned an invalid payload for '${command}'.`,
|
|
19
|
-
{ command }
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return value
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function requireStringField(record, field, command) {
|
|
27
|
-
const value = record[field]
|
|
28
|
-
|
|
29
|
-
if (typeof value !== "string" || value.trim() === "") {
|
|
30
|
-
throw new ResetProtocolError(
|
|
31
|
-
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
32
|
-
{ command }
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return value
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function requireBooleanField(record, field, command) {
|
|
40
|
-
const value = record[field]
|
|
41
|
-
|
|
42
|
-
if (typeof value !== "boolean") {
|
|
43
|
-
throw new ResetProtocolError(
|
|
44
|
-
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
45
|
-
{ command }
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return value
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function requireNumberField(record, field, command) {
|
|
53
|
-
const value = record[field]
|
|
54
|
-
|
|
55
|
-
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
56
|
-
throw new ResetProtocolError(
|
|
57
|
-
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
58
|
-
{ command }
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return value
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function optionalStringField(record, field, fallback, command) {
|
|
66
|
-
const value = record[field]
|
|
67
|
-
|
|
68
|
-
if (value === undefined || value === null) {
|
|
69
|
-
return fallback
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (typeof value !== "string") {
|
|
73
|
-
throw new ResetProtocolError(
|
|
74
|
-
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
75
|
-
{ command }
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return value
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function normalizeStringArray(value, field, command) {
|
|
83
|
-
if (!Array.isArray(value)) {
|
|
84
|
-
throw new ResetProtocolError(
|
|
85
|
-
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
86
|
-
{ command }
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return Object.freeze(
|
|
91
|
-
value.map((entry) => {
|
|
92
|
-
if (typeof entry !== "string") {
|
|
93
|
-
throw new ResetProtocolError(
|
|
94
|
-
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
95
|
-
{ command }
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return entry
|
|
100
|
-
})
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function normalizeAppInfo(payload, command) {
|
|
105
|
-
const record = requireObject(payload, command)
|
|
106
|
-
|
|
107
|
-
return Object.freeze({
|
|
108
|
-
id: requireStringField(record, "id", command),
|
|
109
|
-
name: requireStringField(record, "name", command),
|
|
110
|
-
slug: requireStringField(record, "slug", command),
|
|
111
|
-
version: requireStringField(record, "version", command),
|
|
112
|
-
windowTitle: requireStringField(record, "windowTitle", command)
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function normalizeRuntimeInfo(payload, command) {
|
|
117
|
-
const record = requireObject(payload, command)
|
|
118
|
-
|
|
119
|
-
return Object.freeze({
|
|
120
|
-
platform: requireStringField(record, "platform", command),
|
|
121
|
-
arch: requireStringField(record, "arch", command),
|
|
122
|
-
frameworkVersion: requireStringField(record, "frameworkVersion", command),
|
|
123
|
-
bridgeVersion: requireStringField(record, "bridgeVersion", command),
|
|
124
|
-
debug: requireBooleanField(record, "debug", command)
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function normalizeCapabilities(payload, command) {
|
|
129
|
-
const record = requireObject(payload, command)
|
|
130
|
-
const commands = Array.isArray(record.commands) ? record.commands : []
|
|
131
|
-
const permissions = Array.isArray(record.permissions) ? record.permissions : []
|
|
132
|
-
|
|
133
|
-
return Object.freeze({
|
|
134
|
-
commands: Object.freeze(commands.map((entry) => Object.freeze({ ...entry }))),
|
|
135
|
-
permissions: Object.freeze([...permissions])
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function normalizeProtocolLaunch(payload, command) {
|
|
140
|
-
const record = requireObject(payload, command)
|
|
141
|
-
|
|
142
|
-
return Object.freeze({
|
|
143
|
-
id: requireStringField(record, "id", command),
|
|
144
|
-
url: requireStringField(record, "url", command),
|
|
145
|
-
scheme: requireStringField(record, "scheme", command),
|
|
146
|
-
host: optionalStringField(record, "host", "", command),
|
|
147
|
-
path: optionalStringField(record, "path", "", command),
|
|
148
|
-
query: optionalStringField(record, "query", "", command),
|
|
149
|
-
fragment: optionalStringField(record, "fragment", "", command),
|
|
150
|
-
source: requireStringField(record, "source", command),
|
|
151
|
-
coldStart: requireBooleanField(record, "coldStart", command)
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function normalizeProtocolLaunchEnvelope(payload, command) {
|
|
156
|
-
const record = requireObject(payload, command)
|
|
157
|
-
const launch = record.launch
|
|
158
|
-
|
|
159
|
-
if (launch === null) {
|
|
160
|
-
return null
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return normalizeProtocolLaunch(launch, command)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function normalizeProtocolLaunchList(payload, command) {
|
|
167
|
-
const record = requireObject(payload, command)
|
|
168
|
-
const launches = record.launches
|
|
169
|
-
|
|
170
|
-
if (!Array.isArray(launches)) {
|
|
171
|
-
throw new ResetProtocolError(
|
|
172
|
-
`Reset runtime returned an invalid 'launches' field for '${command}'.`,
|
|
173
|
-
{ command }
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return Object.freeze(launches.map((entry) => normalizeProtocolLaunch(entry, command)))
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function normalizeProtocolInfo(payload, command) {
|
|
181
|
-
const record = requireObject(payload, command)
|
|
182
|
-
|
|
183
|
-
return Object.freeze({
|
|
184
|
-
supported: requireBooleanField(record, "supported", command),
|
|
185
|
-
module: requireStringField(record, "module", command),
|
|
186
|
-
platform: requireStringField(record, "platform", command),
|
|
187
|
-
configuredSchemes: normalizeStringArray(record.configuredSchemes ?? [], "configuredSchemes", command),
|
|
188
|
-
bundledSchemes: normalizeStringArray(record.bundledSchemes ?? [], "bundledSchemes", command),
|
|
189
|
-
eventName: requireStringField(record, "eventName", command),
|
|
190
|
-
pendingCount: requireNumberField(record, "pendingCount", command),
|
|
191
|
-
eventStreamActive: requireBooleanField(record, "eventStreamActive", command),
|
|
192
|
-
runtimeRegistration: requireBooleanField(record, "runtimeRegistration", command)
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function createCommandApi(transport) {
|
|
197
|
-
return Object.freeze({
|
|
198
|
-
invoke(command, payload = {}) {
|
|
199
|
-
return transport.invoke(command, payload)
|
|
200
|
-
},
|
|
201
|
-
invokeRaw(command, payload = {}) {
|
|
202
|
-
return transport.invokeRaw(command, payload)
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function createAppApi(transport) {
|
|
208
|
-
return Object.freeze({
|
|
209
|
-
async getId() {
|
|
210
|
-
const payload = requireObject(await transport.invoke("app.getId"), "app.getId")
|
|
211
|
-
return requireStringField(payload, "id", "app.getId")
|
|
212
|
-
},
|
|
213
|
-
async getName() {
|
|
214
|
-
const payload = requireObject(await transport.invoke("app.getName"), "app.getName")
|
|
215
|
-
return requireStringField(payload, "name", "app.getName")
|
|
216
|
-
},
|
|
217
|
-
async getSlug() {
|
|
218
|
-
const payload = requireObject(await transport.invoke("app.getSlug"), "app.getSlug")
|
|
219
|
-
return requireStringField(payload, "slug", "app.getSlug")
|
|
220
|
-
},
|
|
221
|
-
async getVersion() {
|
|
222
|
-
const payload = requireObject(await transport.invoke("app.getVersion"), "app.getVersion")
|
|
223
|
-
return requireStringField(payload, "version", "app.getVersion")
|
|
224
|
-
},
|
|
225
|
-
async getInfo() {
|
|
226
|
-
return normalizeAppInfo(await transport.invoke("app.getInfo"), "app.getInfo")
|
|
227
|
-
},
|
|
228
|
-
show() {
|
|
229
|
-
return transport.invoke("app.show")
|
|
230
|
-
},
|
|
231
|
-
hide() {
|
|
232
|
-
return transport.invoke("app.hide")
|
|
233
|
-
},
|
|
234
|
-
quit() {
|
|
235
|
-
return transport.invoke("app.quit")
|
|
236
|
-
},
|
|
237
|
-
relaunch() {
|
|
238
|
-
return transport.invoke("app.relaunch")
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function createRuntimeApi(transport) {
|
|
244
|
-
return Object.freeze({
|
|
245
|
-
async getPlatform() {
|
|
246
|
-
const payload = requireObject(await transport.invoke("runtime.getPlatform"), "runtime.getPlatform")
|
|
247
|
-
return requireStringField(payload, "platform", "runtime.getPlatform")
|
|
248
|
-
},
|
|
249
|
-
async getArchitecture() {
|
|
250
|
-
const payload = requireObject(await transport.invoke("runtime.getArchitecture"), "runtime.getArchitecture")
|
|
251
|
-
return requireStringField(payload, "arch", "runtime.getArchitecture")
|
|
252
|
-
},
|
|
253
|
-
async getFrameworkVersion() {
|
|
254
|
-
const payload = requireObject(
|
|
255
|
-
await transport.invoke("runtime.getFrameworkVersion"),
|
|
256
|
-
"runtime.getFrameworkVersion"
|
|
257
|
-
)
|
|
258
|
-
return requireStringField(payload, "version", "runtime.getFrameworkVersion")
|
|
259
|
-
},
|
|
260
|
-
async getBridgeVersion() {
|
|
261
|
-
const payload = requireObject(
|
|
262
|
-
await transport.invoke("runtime.getBridgeVersion"),
|
|
263
|
-
"runtime.getBridgeVersion"
|
|
264
|
-
)
|
|
265
|
-
return requireStringField(payload, "version", "runtime.getBridgeVersion")
|
|
266
|
-
},
|
|
267
|
-
async getInfo() {
|
|
268
|
-
return normalizeRuntimeInfo(await transport.invoke("runtime.getInfo"), "runtime.getInfo")
|
|
269
|
-
},
|
|
270
|
-
async getCapabilities() {
|
|
271
|
-
return normalizeCapabilities(
|
|
272
|
-
await transport.invoke("runtime.getCapabilities"),
|
|
273
|
-
"runtime.getCapabilities"
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
})
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function createWindowApi(transport) {
|
|
280
|
-
return Object.freeze({
|
|
281
|
-
getCurrent() {
|
|
282
|
-
return transport.invoke("window.getCurrent")
|
|
283
|
-
},
|
|
284
|
-
getInfo() {
|
|
285
|
-
return transport.invoke("window.getInfo")
|
|
286
|
-
},
|
|
287
|
-
list() {
|
|
288
|
-
return transport.invoke("window.list")
|
|
289
|
-
},
|
|
290
|
-
show() {
|
|
291
|
-
return transport.invoke("window.show")
|
|
292
|
-
},
|
|
293
|
-
hide() {
|
|
294
|
-
return transport.invoke("window.hide")
|
|
295
|
-
},
|
|
296
|
-
focus() {
|
|
297
|
-
return transport.invoke("window.focus")
|
|
298
|
-
},
|
|
299
|
-
close() {
|
|
300
|
-
return transport.invoke("window.close")
|
|
301
|
-
},
|
|
302
|
-
minimize() {
|
|
303
|
-
return transport.invoke("window.minimize")
|
|
304
|
-
},
|
|
305
|
-
maximize() {
|
|
306
|
-
return transport.invoke("window.maximize")
|
|
307
|
-
},
|
|
308
|
-
center() {
|
|
309
|
-
return transport.invoke("window.center")
|
|
310
|
-
},
|
|
311
|
-
setTitle(title) {
|
|
312
|
-
return transport.invoke("window.setTitle", { title })
|
|
313
|
-
},
|
|
314
|
-
setSize(width, height) {
|
|
315
|
-
return transport.invoke("window.setSize", { width, height })
|
|
316
|
-
},
|
|
317
|
-
setResizable(resizable) {
|
|
318
|
-
return transport.invoke("window.setResizable", { resizable })
|
|
319
|
-
}
|
|
320
|
-
})
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function createDialogApi(transport) {
|
|
324
|
-
return Object.freeze({
|
|
325
|
-
openFile(options = {}) {
|
|
326
|
-
return transport.invoke("dialog.openFile", options)
|
|
327
|
-
},
|
|
328
|
-
saveFile(options = {}) {
|
|
329
|
-
return transport.invoke("dialog.saveFile", options)
|
|
330
|
-
},
|
|
331
|
-
message(title, message) {
|
|
332
|
-
return transport.invoke("dialog.message", { title, message })
|
|
333
|
-
},
|
|
334
|
-
confirm(title, message) {
|
|
335
|
-
return transport.invoke("dialog.confirm", { title, message })
|
|
336
|
-
}
|
|
337
|
-
})
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function createFsApi(transport) {
|
|
341
|
-
return Object.freeze({
|
|
342
|
-
async readTextFile(path) {
|
|
343
|
-
const payload = requireObject(await transport.invoke("fs.readTextFile", { path }), "fs.readTextFile")
|
|
344
|
-
return requireStringField(payload, "text", "fs.readTextFile")
|
|
345
|
-
},
|
|
346
|
-
writeTextFile(path, text, options = {}) {
|
|
347
|
-
return transport.invoke("fs.writeTextFile", {
|
|
348
|
-
path,
|
|
349
|
-
text,
|
|
350
|
-
...options
|
|
351
|
-
})
|
|
352
|
-
},
|
|
353
|
-
async exists(path) {
|
|
354
|
-
const payload = requireObject(await transport.invoke("fs.exists", { path }), "fs.exists")
|
|
355
|
-
return requireBooleanField(payload, "exists", "fs.exists")
|
|
356
|
-
},
|
|
357
|
-
mkdir(path, options = {}) {
|
|
358
|
-
return transport.invoke("fs.mkdir", {
|
|
359
|
-
path,
|
|
360
|
-
...options
|
|
361
|
-
})
|
|
362
|
-
},
|
|
363
|
-
remove(path, options = {}) {
|
|
364
|
-
return transport.invoke("fs.remove", {
|
|
365
|
-
path,
|
|
366
|
-
...options
|
|
367
|
-
})
|
|
368
|
-
},
|
|
369
|
-
rename(from, to) {
|
|
370
|
-
return transport.invoke("fs.rename", { from, to })
|
|
371
|
-
},
|
|
372
|
-
async readDir(path) {
|
|
373
|
-
const payload = requireObject(await transport.invoke("fs.readDir", { path }), "fs.readDir")
|
|
374
|
-
return Array.isArray(payload.entries) ? payload.entries : []
|
|
375
|
-
}
|
|
376
|
-
})
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function createPathApi(transport) {
|
|
380
|
-
return Object.freeze({
|
|
381
|
-
async join(...segments) {
|
|
382
|
-
const payload = requireObject(await transport.invoke("path.join", { segments }), "path.join")
|
|
383
|
-
return requireStringField(payload, "path", "path.join")
|
|
384
|
-
},
|
|
385
|
-
async basename(path) {
|
|
386
|
-
const payload = requireObject(await transport.invoke("path.basename", { path }), "path.basename")
|
|
387
|
-
return requireStringField(payload, "name", "path.basename")
|
|
388
|
-
},
|
|
389
|
-
async dirname(path) {
|
|
390
|
-
const payload = requireObject(await transport.invoke("path.dirname", { path }), "path.dirname")
|
|
391
|
-
return requireStringField(payload, "path", "path.dirname")
|
|
392
|
-
},
|
|
393
|
-
async resolve(path, base) {
|
|
394
|
-
const payload = requireObject(await transport.invoke("path.resolve", { path, base }), "path.resolve")
|
|
395
|
-
return requireStringField(payload, "path", "path.resolve")
|
|
396
|
-
},
|
|
397
|
-
async getHomeDir() {
|
|
398
|
-
const payload = requireObject(await transport.invoke("path.getHomeDir"), "path.getHomeDir")
|
|
399
|
-
return requireStringField(payload, "path", "path.getHomeDir")
|
|
400
|
-
},
|
|
401
|
-
async getTempDir() {
|
|
402
|
-
const payload = requireObject(await transport.invoke("path.getTempDir"), "path.getTempDir")
|
|
403
|
-
return requireStringField(payload, "path", "path.getTempDir")
|
|
404
|
-
},
|
|
405
|
-
async getAppDataDir() {
|
|
406
|
-
const payload = requireObject(await transport.invoke("path.getAppDataDir"), "path.getAppDataDir")
|
|
407
|
-
return requireStringField(payload, "path", "path.getAppDataDir")
|
|
408
|
-
},
|
|
409
|
-
async getAppConfigDir() {
|
|
410
|
-
const payload = requireObject(await transport.invoke("path.getAppConfigDir"), "path.getAppConfigDir")
|
|
411
|
-
return requireStringField(payload, "path", "path.getAppConfigDir")
|
|
412
|
-
},
|
|
413
|
-
async getCacheDir() {
|
|
414
|
-
const payload = requireObject(await transport.invoke("path.getCacheDir"), "path.getCacheDir")
|
|
415
|
-
return requireStringField(payload, "path", "path.getCacheDir")
|
|
416
|
-
},
|
|
417
|
-
getInfo() {
|
|
418
|
-
return transport.invoke("path.getInfo")
|
|
419
|
-
}
|
|
420
|
-
})
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function createShellApi(transport) {
|
|
424
|
-
return Object.freeze({
|
|
425
|
-
openExternal(url) {
|
|
426
|
-
return transport.invoke("shell.openExternal", { url })
|
|
427
|
-
},
|
|
428
|
-
openPath(path) {
|
|
429
|
-
return transport.invoke("shell.openPath", { path })
|
|
430
|
-
},
|
|
431
|
-
showItemInFolder(path) {
|
|
432
|
-
return transport.invoke("shell.showItemInFolder", { path })
|
|
433
|
-
}
|
|
434
|
-
})
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function createClipboardApi(transport) {
|
|
438
|
-
return Object.freeze({
|
|
439
|
-
async readText() {
|
|
440
|
-
const payload = requireObject(await transport.invoke("clipboard.readText"), "clipboard.readText")
|
|
441
|
-
return requireStringField(payload, "text", "clipboard.readText")
|
|
442
|
-
},
|
|
443
|
-
writeText(text) {
|
|
444
|
-
return transport.invoke("clipboard.writeText", { text })
|
|
445
|
-
}
|
|
446
|
-
})
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function createNotificationApi(transport) {
|
|
450
|
-
return Object.freeze({
|
|
451
|
-
async isSupported() {
|
|
452
|
-
const payload = requireObject(
|
|
453
|
-
await transport.invoke("notification.isSupported"),
|
|
454
|
-
"notification.isSupported"
|
|
455
|
-
)
|
|
456
|
-
return requireBooleanField(payload, "supported", "notification.isSupported")
|
|
457
|
-
},
|
|
458
|
-
requestPermission() {
|
|
459
|
-
return transport.invoke("notification.requestPermission")
|
|
460
|
-
},
|
|
461
|
-
show(options) {
|
|
462
|
-
return transport.invoke("notification.show", options)
|
|
463
|
-
}
|
|
464
|
-
})
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function createScreenApi(transport) {
|
|
468
|
-
return Object.freeze({
|
|
469
|
-
getCursorPosition() {
|
|
470
|
-
return transport.invoke("screen.getCursorPosition")
|
|
471
|
-
},
|
|
472
|
-
getPrimaryDisplay() {
|
|
473
|
-
return transport.invoke("screen.getPrimaryDisplay")
|
|
474
|
-
},
|
|
475
|
-
async getDisplays() {
|
|
476
|
-
const payload = requireObject(await transport.invoke("screen.getDisplays"), "screen.getDisplays")
|
|
477
|
-
return Array.isArray(payload.displays) ? payload.displays : []
|
|
478
|
-
}
|
|
479
|
-
})
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function createStorageApi(transport) {
|
|
483
|
-
return Object.freeze({
|
|
484
|
-
async get(key) {
|
|
485
|
-
const payload = requireObject(await transport.invoke("storage.get", { key }), "storage.get")
|
|
486
|
-
return payload.value
|
|
487
|
-
},
|
|
488
|
-
set(key, value) {
|
|
489
|
-
return transport.invoke("storage.set", { key, value })
|
|
490
|
-
},
|
|
491
|
-
remove(key) {
|
|
492
|
-
return transport.invoke("storage.remove", { key })
|
|
493
|
-
},
|
|
494
|
-
clear() {
|
|
495
|
-
return transport.invoke("storage.clear")
|
|
496
|
-
},
|
|
497
|
-
async getAll() {
|
|
498
|
-
const payload = requireObject(await transport.invoke("storage.getAll"), "storage.getAll")
|
|
499
|
-
return requireObject(payload.entries ?? {}, "storage.getAll")
|
|
500
|
-
}
|
|
501
|
-
})
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
function createWebViewApi(transport) {
|
|
505
|
-
return Object.freeze({
|
|
506
|
-
getInfo() {
|
|
507
|
-
return transport.invoke("webview.getInfo")
|
|
508
|
-
},
|
|
509
|
-
reload() {
|
|
510
|
-
return transport.invoke("webview.reload")
|
|
511
|
-
},
|
|
512
|
-
goBack() {
|
|
513
|
-
return transport.invoke("webview.goBack")
|
|
514
|
-
},
|
|
515
|
-
goForward() {
|
|
516
|
-
return transport.invoke("webview.goForward")
|
|
517
|
-
},
|
|
518
|
-
navigate(options) {
|
|
519
|
-
return transport.invoke("webview.navigate", options)
|
|
520
|
-
},
|
|
521
|
-
setZoomFactor(factor) {
|
|
522
|
-
return transport.invoke("webview.setZoomFactor", { factor })
|
|
523
|
-
}
|
|
524
|
-
})
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
function createCryptoApi(transport) {
|
|
528
|
-
return Object.freeze({
|
|
529
|
-
getInfo() {
|
|
530
|
-
return transport.invoke("crypto.getInfo")
|
|
531
|
-
},
|
|
532
|
-
randomBytes(size, options = {}) {
|
|
533
|
-
return transport.invoke("crypto.randomBytes", {
|
|
534
|
-
size,
|
|
535
|
-
encoding: options.encoding
|
|
536
|
-
})
|
|
537
|
-
},
|
|
538
|
-
async randomUuid() {
|
|
539
|
-
const payload = requireObject(await transport.invoke("crypto.randomUuid"), "crypto.randomUuid")
|
|
540
|
-
return requireStringField(payload, "uuid", "crypto.randomUuid")
|
|
541
|
-
}
|
|
542
|
-
})
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function createProcessApi(transport) {
|
|
546
|
-
return Object.freeze({
|
|
547
|
-
async getPid() {
|
|
548
|
-
const payload = requireObject(await transport.invoke("process.getPid"), "process.getPid")
|
|
549
|
-
return requireNumberField(payload, "pid", "process.getPid")
|
|
550
|
-
},
|
|
551
|
-
async getCwd() {
|
|
552
|
-
const payload = requireObject(await transport.invoke("process.getCwd"), "process.getCwd")
|
|
553
|
-
return requireStringField(payload, "path", "process.getCwd")
|
|
554
|
-
},
|
|
555
|
-
getInfo() {
|
|
556
|
-
return transport.invoke("process.getInfo")
|
|
557
|
-
}
|
|
558
|
-
})
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function createPowerApi(transport) {
|
|
562
|
-
return Object.freeze({
|
|
563
|
-
getInfo() {
|
|
564
|
-
return transport.invoke("power.getInfo")
|
|
565
|
-
}
|
|
566
|
-
})
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function createMenuApi(transport) {
|
|
570
|
-
return Object.freeze({
|
|
571
|
-
getInfo() {
|
|
572
|
-
return transport.invoke("menu.getInfo")
|
|
573
|
-
},
|
|
574
|
-
setApplicationMenu(items) {
|
|
575
|
-
return transport.invoke("menu.setApplicationMenu", { items })
|
|
576
|
-
},
|
|
577
|
-
clearApplicationMenu() {
|
|
578
|
-
return transport.invoke("menu.clearApplicationMenu")
|
|
579
|
-
}
|
|
580
|
-
})
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function createTrayApi(transport) {
|
|
584
|
-
return Object.freeze({
|
|
585
|
-
getInfo() {
|
|
586
|
-
return transport.invoke("tray.getInfo")
|
|
587
|
-
},
|
|
588
|
-
create(options = {}) {
|
|
589
|
-
return transport.invoke("tray.create", options)
|
|
590
|
-
},
|
|
591
|
-
setTitle(title) {
|
|
592
|
-
return transport.invoke("tray.setTitle", { title })
|
|
593
|
-
},
|
|
594
|
-
setTooltip(tooltip) {
|
|
595
|
-
return transport.invoke("tray.setTooltip", { tooltip })
|
|
596
|
-
},
|
|
597
|
-
setMenu(items) {
|
|
598
|
-
return transport.invoke("tray.setMenu", { items })
|
|
599
|
-
},
|
|
600
|
-
destroy() {
|
|
601
|
-
return transport.invoke("tray.destroy")
|
|
602
|
-
}
|
|
603
|
-
})
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
function createShortcutApi(transport) {
|
|
607
|
-
return Object.freeze({
|
|
608
|
-
getInfo() {
|
|
609
|
-
return transport.invoke("shortcut.getInfo")
|
|
610
|
-
},
|
|
611
|
-
register(accelerator) {
|
|
612
|
-
return transport.invoke("shortcut.register", { accelerator })
|
|
613
|
-
},
|
|
614
|
-
unregister(accelerator) {
|
|
615
|
-
return transport.invoke("shortcut.unregister", { accelerator })
|
|
616
|
-
},
|
|
617
|
-
unregisterAll() {
|
|
618
|
-
return transport.invoke("shortcut.unregisterAll")
|
|
619
|
-
}
|
|
620
|
-
})
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function createProtocolApi(transport, events) {
|
|
624
|
-
return Object.freeze({
|
|
625
|
-
async getInfo() {
|
|
626
|
-
return normalizeProtocolInfo(await transport.invoke("protocol.getInfo"), "protocol.getInfo")
|
|
627
|
-
},
|
|
628
|
-
async activate() {
|
|
629
|
-
const payload = requireObject(await transport.invoke("protocol.activate"), "protocol.activate")
|
|
630
|
-
return Object.freeze({
|
|
631
|
-
active: requireBooleanField(payload, "active", "protocol.activate")
|
|
632
|
-
})
|
|
633
|
-
},
|
|
634
|
-
async getCurrentLaunch() {
|
|
635
|
-
return normalizeProtocolLaunchEnvelope(
|
|
636
|
-
await transport.invoke("protocol.getCurrentLaunch"),
|
|
637
|
-
"protocol.getCurrentLaunch"
|
|
638
|
-
)
|
|
639
|
-
},
|
|
640
|
-
async getPendingLaunches() {
|
|
641
|
-
return normalizeProtocolLaunchList(
|
|
642
|
-
await transport.invoke("protocol.getPendingLaunches"),
|
|
643
|
-
"protocol.getPendingLaunches"
|
|
644
|
-
)
|
|
645
|
-
},
|
|
646
|
-
async consumePendingLaunches() {
|
|
647
|
-
return normalizeProtocolLaunchList(
|
|
648
|
-
await transport.invoke("protocol.consumePendingLaunches"),
|
|
649
|
-
"protocol.consumePendingLaunches"
|
|
650
|
-
)
|
|
651
|
-
},
|
|
652
|
-
async listen(handler, options = {}) {
|
|
653
|
-
if (typeof handler !== "function") {
|
|
654
|
-
throw new TypeError("Reset protocol listener must be a function.")
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const consumePending = options.consumePending !== false
|
|
658
|
-
const seenLaunches = new Set()
|
|
659
|
-
const deliver = (payload) => {
|
|
660
|
-
const launch = normalizeProtocolLaunch(payload, "protocol.open")
|
|
661
|
-
if (seenLaunches.has(launch.id)) {
|
|
662
|
-
return
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
seenLaunches.add(launch.id)
|
|
666
|
-
handler(launch)
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
const dispose = events.listen("protocol.open", deliver)
|
|
670
|
-
await transport.invoke("protocol.activate")
|
|
671
|
-
|
|
672
|
-
if (consumePending) {
|
|
673
|
-
const pending = await transport.invoke("protocol.consumePendingLaunches")
|
|
674
|
-
for (const launch of normalizeProtocolLaunchList(pending, "protocol.consumePendingLaunches")) {
|
|
675
|
-
if (seenLaunches.has(launch.id)) {
|
|
676
|
-
continue
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
seenLaunches.add(launch.id)
|
|
680
|
-
handler(launch)
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
return dispose
|
|
685
|
-
},
|
|
686
|
-
register(options = {}) {
|
|
687
|
-
return transport.invoke("protocol.register", options)
|
|
688
|
-
},
|
|
689
|
-
unregister(options = {}) {
|
|
690
|
-
return transport.invoke("protocol.unregister", options)
|
|
691
|
-
}
|
|
692
|
-
})
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
function createUpdaterApi(transport) {
|
|
696
|
-
return Object.freeze({
|
|
697
|
-
getInfo() {
|
|
698
|
-
return transport.invoke("updater.getInfo")
|
|
699
|
-
},
|
|
700
|
-
check(options = {}) {
|
|
701
|
-
return transport.invoke("updater.check", options)
|
|
702
|
-
},
|
|
703
|
-
download(options = {}) {
|
|
704
|
-
return transport.invoke("updater.download", options)
|
|
705
|
-
},
|
|
706
|
-
install(options = {}) {
|
|
707
|
-
return transport.invoke("updater.install", options)
|
|
708
|
-
}
|
|
709
|
-
})
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
function createNetApi(transport) {
|
|
713
|
-
return Object.freeze({
|
|
714
|
-
request(options) {
|
|
715
|
-
return transport.invoke("net.request", options)
|
|
716
|
-
}
|
|
717
|
-
})
|
|
718
|
-
}
|
|
719
|
-
|
|
1
|
+
import {
|
|
2
|
+
createResetTransport,
|
|
3
|
+
getResetRuntime,
|
|
4
|
+
invoke,
|
|
5
|
+
invokeRaw,
|
|
6
|
+
isResetRuntimeAvailable
|
|
7
|
+
} from "./transport.js"
|
|
8
|
+
import { createEventApi } from "./events.js"
|
|
9
|
+
import { ResetProtocolError } from "./errors.js"
|
|
10
|
+
|
|
11
|
+
function isObjectLike(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function requireObject(value, command) {
|
|
16
|
+
if (!isObjectLike(value)) {
|
|
17
|
+
throw new ResetProtocolError(
|
|
18
|
+
`Reset runtime returned an invalid payload for '${command}'.`,
|
|
19
|
+
{ command }
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function requireStringField(record, field, command) {
|
|
27
|
+
const value = record[field]
|
|
28
|
+
|
|
29
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
30
|
+
throw new ResetProtocolError(
|
|
31
|
+
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
32
|
+
{ command }
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function requireBooleanField(record, field, command) {
|
|
40
|
+
const value = record[field]
|
|
41
|
+
|
|
42
|
+
if (typeof value !== "boolean") {
|
|
43
|
+
throw new ResetProtocolError(
|
|
44
|
+
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
45
|
+
{ command }
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function requireNumberField(record, field, command) {
|
|
53
|
+
const value = record[field]
|
|
54
|
+
|
|
55
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
56
|
+
throw new ResetProtocolError(
|
|
57
|
+
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
58
|
+
{ command }
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function optionalStringField(record, field, fallback, command) {
|
|
66
|
+
const value = record[field]
|
|
67
|
+
|
|
68
|
+
if (value === undefined || value === null) {
|
|
69
|
+
return fallback
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof value !== "string") {
|
|
73
|
+
throw new ResetProtocolError(
|
|
74
|
+
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
75
|
+
{ command }
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return value
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function normalizeStringArray(value, field, command) {
|
|
83
|
+
if (!Array.isArray(value)) {
|
|
84
|
+
throw new ResetProtocolError(
|
|
85
|
+
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
86
|
+
{ command }
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return Object.freeze(
|
|
91
|
+
value.map((entry) => {
|
|
92
|
+
if (typeof entry !== "string") {
|
|
93
|
+
throw new ResetProtocolError(
|
|
94
|
+
`Reset runtime returned an invalid '${field}' field for '${command}'.`,
|
|
95
|
+
{ command }
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return entry
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function normalizeAppInfo(payload, command) {
|
|
105
|
+
const record = requireObject(payload, command)
|
|
106
|
+
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
id: requireStringField(record, "id", command),
|
|
109
|
+
name: requireStringField(record, "name", command),
|
|
110
|
+
slug: requireStringField(record, "slug", command),
|
|
111
|
+
version: requireStringField(record, "version", command),
|
|
112
|
+
windowTitle: requireStringField(record, "windowTitle", command)
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeRuntimeInfo(payload, command) {
|
|
117
|
+
const record = requireObject(payload, command)
|
|
118
|
+
|
|
119
|
+
return Object.freeze({
|
|
120
|
+
platform: requireStringField(record, "platform", command),
|
|
121
|
+
arch: requireStringField(record, "arch", command),
|
|
122
|
+
frameworkVersion: requireStringField(record, "frameworkVersion", command),
|
|
123
|
+
bridgeVersion: requireStringField(record, "bridgeVersion", command),
|
|
124
|
+
debug: requireBooleanField(record, "debug", command)
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function normalizeCapabilities(payload, command) {
|
|
129
|
+
const record = requireObject(payload, command)
|
|
130
|
+
const commands = Array.isArray(record.commands) ? record.commands : []
|
|
131
|
+
const permissions = Array.isArray(record.permissions) ? record.permissions : []
|
|
132
|
+
|
|
133
|
+
return Object.freeze({
|
|
134
|
+
commands: Object.freeze(commands.map((entry) => Object.freeze({ ...entry }))),
|
|
135
|
+
permissions: Object.freeze([...permissions])
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function normalizeProtocolLaunch(payload, command) {
|
|
140
|
+
const record = requireObject(payload, command)
|
|
141
|
+
|
|
142
|
+
return Object.freeze({
|
|
143
|
+
id: requireStringField(record, "id", command),
|
|
144
|
+
url: requireStringField(record, "url", command),
|
|
145
|
+
scheme: requireStringField(record, "scheme", command),
|
|
146
|
+
host: optionalStringField(record, "host", "", command),
|
|
147
|
+
path: optionalStringField(record, "path", "", command),
|
|
148
|
+
query: optionalStringField(record, "query", "", command),
|
|
149
|
+
fragment: optionalStringField(record, "fragment", "", command),
|
|
150
|
+
source: requireStringField(record, "source", command),
|
|
151
|
+
coldStart: requireBooleanField(record, "coldStart", command)
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function normalizeProtocolLaunchEnvelope(payload, command) {
|
|
156
|
+
const record = requireObject(payload, command)
|
|
157
|
+
const launch = record.launch
|
|
158
|
+
|
|
159
|
+
if (launch === null) {
|
|
160
|
+
return null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return normalizeProtocolLaunch(launch, command)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function normalizeProtocolLaunchList(payload, command) {
|
|
167
|
+
const record = requireObject(payload, command)
|
|
168
|
+
const launches = record.launches
|
|
169
|
+
|
|
170
|
+
if (!Array.isArray(launches)) {
|
|
171
|
+
throw new ResetProtocolError(
|
|
172
|
+
`Reset runtime returned an invalid 'launches' field for '${command}'.`,
|
|
173
|
+
{ command }
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return Object.freeze(launches.map((entry) => normalizeProtocolLaunch(entry, command)))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function normalizeProtocolInfo(payload, command) {
|
|
181
|
+
const record = requireObject(payload, command)
|
|
182
|
+
|
|
183
|
+
return Object.freeze({
|
|
184
|
+
supported: requireBooleanField(record, "supported", command),
|
|
185
|
+
module: requireStringField(record, "module", command),
|
|
186
|
+
platform: requireStringField(record, "platform", command),
|
|
187
|
+
configuredSchemes: normalizeStringArray(record.configuredSchemes ?? [], "configuredSchemes", command),
|
|
188
|
+
bundledSchemes: normalizeStringArray(record.bundledSchemes ?? [], "bundledSchemes", command),
|
|
189
|
+
eventName: requireStringField(record, "eventName", command),
|
|
190
|
+
pendingCount: requireNumberField(record, "pendingCount", command),
|
|
191
|
+
eventStreamActive: requireBooleanField(record, "eventStreamActive", command),
|
|
192
|
+
runtimeRegistration: requireBooleanField(record, "runtimeRegistration", command)
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function createCommandApi(transport) {
|
|
197
|
+
return Object.freeze({
|
|
198
|
+
invoke(command, payload = {}) {
|
|
199
|
+
return transport.invoke(command, payload)
|
|
200
|
+
},
|
|
201
|
+
invokeRaw(command, payload = {}) {
|
|
202
|
+
return transport.invokeRaw(command, payload)
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function createAppApi(transport) {
|
|
208
|
+
return Object.freeze({
|
|
209
|
+
async getId() {
|
|
210
|
+
const payload = requireObject(await transport.invoke("app.getId"), "app.getId")
|
|
211
|
+
return requireStringField(payload, "id", "app.getId")
|
|
212
|
+
},
|
|
213
|
+
async getName() {
|
|
214
|
+
const payload = requireObject(await transport.invoke("app.getName"), "app.getName")
|
|
215
|
+
return requireStringField(payload, "name", "app.getName")
|
|
216
|
+
},
|
|
217
|
+
async getSlug() {
|
|
218
|
+
const payload = requireObject(await transport.invoke("app.getSlug"), "app.getSlug")
|
|
219
|
+
return requireStringField(payload, "slug", "app.getSlug")
|
|
220
|
+
},
|
|
221
|
+
async getVersion() {
|
|
222
|
+
const payload = requireObject(await transport.invoke("app.getVersion"), "app.getVersion")
|
|
223
|
+
return requireStringField(payload, "version", "app.getVersion")
|
|
224
|
+
},
|
|
225
|
+
async getInfo() {
|
|
226
|
+
return normalizeAppInfo(await transport.invoke("app.getInfo"), "app.getInfo")
|
|
227
|
+
},
|
|
228
|
+
show() {
|
|
229
|
+
return transport.invoke("app.show")
|
|
230
|
+
},
|
|
231
|
+
hide() {
|
|
232
|
+
return transport.invoke("app.hide")
|
|
233
|
+
},
|
|
234
|
+
quit() {
|
|
235
|
+
return transport.invoke("app.quit")
|
|
236
|
+
},
|
|
237
|
+
relaunch() {
|
|
238
|
+
return transport.invoke("app.relaunch")
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function createRuntimeApi(transport) {
|
|
244
|
+
return Object.freeze({
|
|
245
|
+
async getPlatform() {
|
|
246
|
+
const payload = requireObject(await transport.invoke("runtime.getPlatform"), "runtime.getPlatform")
|
|
247
|
+
return requireStringField(payload, "platform", "runtime.getPlatform")
|
|
248
|
+
},
|
|
249
|
+
async getArchitecture() {
|
|
250
|
+
const payload = requireObject(await transport.invoke("runtime.getArchitecture"), "runtime.getArchitecture")
|
|
251
|
+
return requireStringField(payload, "arch", "runtime.getArchitecture")
|
|
252
|
+
},
|
|
253
|
+
async getFrameworkVersion() {
|
|
254
|
+
const payload = requireObject(
|
|
255
|
+
await transport.invoke("runtime.getFrameworkVersion"),
|
|
256
|
+
"runtime.getFrameworkVersion"
|
|
257
|
+
)
|
|
258
|
+
return requireStringField(payload, "version", "runtime.getFrameworkVersion")
|
|
259
|
+
},
|
|
260
|
+
async getBridgeVersion() {
|
|
261
|
+
const payload = requireObject(
|
|
262
|
+
await transport.invoke("runtime.getBridgeVersion"),
|
|
263
|
+
"runtime.getBridgeVersion"
|
|
264
|
+
)
|
|
265
|
+
return requireStringField(payload, "version", "runtime.getBridgeVersion")
|
|
266
|
+
},
|
|
267
|
+
async getInfo() {
|
|
268
|
+
return normalizeRuntimeInfo(await transport.invoke("runtime.getInfo"), "runtime.getInfo")
|
|
269
|
+
},
|
|
270
|
+
async getCapabilities() {
|
|
271
|
+
return normalizeCapabilities(
|
|
272
|
+
await transport.invoke("runtime.getCapabilities"),
|
|
273
|
+
"runtime.getCapabilities"
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function createWindowApi(transport) {
|
|
280
|
+
return Object.freeze({
|
|
281
|
+
getCurrent() {
|
|
282
|
+
return transport.invoke("window.getCurrent")
|
|
283
|
+
},
|
|
284
|
+
getInfo() {
|
|
285
|
+
return transport.invoke("window.getInfo")
|
|
286
|
+
},
|
|
287
|
+
list() {
|
|
288
|
+
return transport.invoke("window.list")
|
|
289
|
+
},
|
|
290
|
+
show() {
|
|
291
|
+
return transport.invoke("window.show")
|
|
292
|
+
},
|
|
293
|
+
hide() {
|
|
294
|
+
return transport.invoke("window.hide")
|
|
295
|
+
},
|
|
296
|
+
focus() {
|
|
297
|
+
return transport.invoke("window.focus")
|
|
298
|
+
},
|
|
299
|
+
close() {
|
|
300
|
+
return transport.invoke("window.close")
|
|
301
|
+
},
|
|
302
|
+
minimize() {
|
|
303
|
+
return transport.invoke("window.minimize")
|
|
304
|
+
},
|
|
305
|
+
maximize() {
|
|
306
|
+
return transport.invoke("window.maximize")
|
|
307
|
+
},
|
|
308
|
+
center() {
|
|
309
|
+
return transport.invoke("window.center")
|
|
310
|
+
},
|
|
311
|
+
setTitle(title) {
|
|
312
|
+
return transport.invoke("window.setTitle", { title })
|
|
313
|
+
},
|
|
314
|
+
setSize(width, height) {
|
|
315
|
+
return transport.invoke("window.setSize", { width, height })
|
|
316
|
+
},
|
|
317
|
+
setResizable(resizable) {
|
|
318
|
+
return transport.invoke("window.setResizable", { resizable })
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function createDialogApi(transport) {
|
|
324
|
+
return Object.freeze({
|
|
325
|
+
openFile(options = {}) {
|
|
326
|
+
return transport.invoke("dialog.openFile", options)
|
|
327
|
+
},
|
|
328
|
+
saveFile(options = {}) {
|
|
329
|
+
return transport.invoke("dialog.saveFile", options)
|
|
330
|
+
},
|
|
331
|
+
message(title, message) {
|
|
332
|
+
return transport.invoke("dialog.message", { title, message })
|
|
333
|
+
},
|
|
334
|
+
confirm(title, message) {
|
|
335
|
+
return transport.invoke("dialog.confirm", { title, message })
|
|
336
|
+
}
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function createFsApi(transport) {
|
|
341
|
+
return Object.freeze({
|
|
342
|
+
async readTextFile(path) {
|
|
343
|
+
const payload = requireObject(await transport.invoke("fs.readTextFile", { path }), "fs.readTextFile")
|
|
344
|
+
return requireStringField(payload, "text", "fs.readTextFile")
|
|
345
|
+
},
|
|
346
|
+
writeTextFile(path, text, options = {}) {
|
|
347
|
+
return transport.invoke("fs.writeTextFile", {
|
|
348
|
+
path,
|
|
349
|
+
text,
|
|
350
|
+
...options
|
|
351
|
+
})
|
|
352
|
+
},
|
|
353
|
+
async exists(path) {
|
|
354
|
+
const payload = requireObject(await transport.invoke("fs.exists", { path }), "fs.exists")
|
|
355
|
+
return requireBooleanField(payload, "exists", "fs.exists")
|
|
356
|
+
},
|
|
357
|
+
mkdir(path, options = {}) {
|
|
358
|
+
return transport.invoke("fs.mkdir", {
|
|
359
|
+
path,
|
|
360
|
+
...options
|
|
361
|
+
})
|
|
362
|
+
},
|
|
363
|
+
remove(path, options = {}) {
|
|
364
|
+
return transport.invoke("fs.remove", {
|
|
365
|
+
path,
|
|
366
|
+
...options
|
|
367
|
+
})
|
|
368
|
+
},
|
|
369
|
+
rename(from, to) {
|
|
370
|
+
return transport.invoke("fs.rename", { from, to })
|
|
371
|
+
},
|
|
372
|
+
async readDir(path) {
|
|
373
|
+
const payload = requireObject(await transport.invoke("fs.readDir", { path }), "fs.readDir")
|
|
374
|
+
return Array.isArray(payload.entries) ? payload.entries : []
|
|
375
|
+
}
|
|
376
|
+
})
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function createPathApi(transport) {
|
|
380
|
+
return Object.freeze({
|
|
381
|
+
async join(...segments) {
|
|
382
|
+
const payload = requireObject(await transport.invoke("path.join", { segments }), "path.join")
|
|
383
|
+
return requireStringField(payload, "path", "path.join")
|
|
384
|
+
},
|
|
385
|
+
async basename(path) {
|
|
386
|
+
const payload = requireObject(await transport.invoke("path.basename", { path }), "path.basename")
|
|
387
|
+
return requireStringField(payload, "name", "path.basename")
|
|
388
|
+
},
|
|
389
|
+
async dirname(path) {
|
|
390
|
+
const payload = requireObject(await transport.invoke("path.dirname", { path }), "path.dirname")
|
|
391
|
+
return requireStringField(payload, "path", "path.dirname")
|
|
392
|
+
},
|
|
393
|
+
async resolve(path, base) {
|
|
394
|
+
const payload = requireObject(await transport.invoke("path.resolve", { path, base }), "path.resolve")
|
|
395
|
+
return requireStringField(payload, "path", "path.resolve")
|
|
396
|
+
},
|
|
397
|
+
async getHomeDir() {
|
|
398
|
+
const payload = requireObject(await transport.invoke("path.getHomeDir"), "path.getHomeDir")
|
|
399
|
+
return requireStringField(payload, "path", "path.getHomeDir")
|
|
400
|
+
},
|
|
401
|
+
async getTempDir() {
|
|
402
|
+
const payload = requireObject(await transport.invoke("path.getTempDir"), "path.getTempDir")
|
|
403
|
+
return requireStringField(payload, "path", "path.getTempDir")
|
|
404
|
+
},
|
|
405
|
+
async getAppDataDir() {
|
|
406
|
+
const payload = requireObject(await transport.invoke("path.getAppDataDir"), "path.getAppDataDir")
|
|
407
|
+
return requireStringField(payload, "path", "path.getAppDataDir")
|
|
408
|
+
},
|
|
409
|
+
async getAppConfigDir() {
|
|
410
|
+
const payload = requireObject(await transport.invoke("path.getAppConfigDir"), "path.getAppConfigDir")
|
|
411
|
+
return requireStringField(payload, "path", "path.getAppConfigDir")
|
|
412
|
+
},
|
|
413
|
+
async getCacheDir() {
|
|
414
|
+
const payload = requireObject(await transport.invoke("path.getCacheDir"), "path.getCacheDir")
|
|
415
|
+
return requireStringField(payload, "path", "path.getCacheDir")
|
|
416
|
+
},
|
|
417
|
+
getInfo() {
|
|
418
|
+
return transport.invoke("path.getInfo")
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function createShellApi(transport) {
|
|
424
|
+
return Object.freeze({
|
|
425
|
+
openExternal(url) {
|
|
426
|
+
return transport.invoke("shell.openExternal", { url })
|
|
427
|
+
},
|
|
428
|
+
openPath(path) {
|
|
429
|
+
return transport.invoke("shell.openPath", { path })
|
|
430
|
+
},
|
|
431
|
+
showItemInFolder(path) {
|
|
432
|
+
return transport.invoke("shell.showItemInFolder", { path })
|
|
433
|
+
}
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function createClipboardApi(transport) {
|
|
438
|
+
return Object.freeze({
|
|
439
|
+
async readText() {
|
|
440
|
+
const payload = requireObject(await transport.invoke("clipboard.readText"), "clipboard.readText")
|
|
441
|
+
return requireStringField(payload, "text", "clipboard.readText")
|
|
442
|
+
},
|
|
443
|
+
writeText(text) {
|
|
444
|
+
return transport.invoke("clipboard.writeText", { text })
|
|
445
|
+
}
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function createNotificationApi(transport) {
|
|
450
|
+
return Object.freeze({
|
|
451
|
+
async isSupported() {
|
|
452
|
+
const payload = requireObject(
|
|
453
|
+
await transport.invoke("notification.isSupported"),
|
|
454
|
+
"notification.isSupported"
|
|
455
|
+
)
|
|
456
|
+
return requireBooleanField(payload, "supported", "notification.isSupported")
|
|
457
|
+
},
|
|
458
|
+
requestPermission() {
|
|
459
|
+
return transport.invoke("notification.requestPermission")
|
|
460
|
+
},
|
|
461
|
+
show(options) {
|
|
462
|
+
return transport.invoke("notification.show", options)
|
|
463
|
+
}
|
|
464
|
+
})
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function createScreenApi(transport) {
|
|
468
|
+
return Object.freeze({
|
|
469
|
+
getCursorPosition() {
|
|
470
|
+
return transport.invoke("screen.getCursorPosition")
|
|
471
|
+
},
|
|
472
|
+
getPrimaryDisplay() {
|
|
473
|
+
return transport.invoke("screen.getPrimaryDisplay")
|
|
474
|
+
},
|
|
475
|
+
async getDisplays() {
|
|
476
|
+
const payload = requireObject(await transport.invoke("screen.getDisplays"), "screen.getDisplays")
|
|
477
|
+
return Array.isArray(payload.displays) ? payload.displays : []
|
|
478
|
+
}
|
|
479
|
+
})
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function createStorageApi(transport) {
|
|
483
|
+
return Object.freeze({
|
|
484
|
+
async get(key) {
|
|
485
|
+
const payload = requireObject(await transport.invoke("storage.get", { key }), "storage.get")
|
|
486
|
+
return payload.value
|
|
487
|
+
},
|
|
488
|
+
set(key, value) {
|
|
489
|
+
return transport.invoke("storage.set", { key, value })
|
|
490
|
+
},
|
|
491
|
+
remove(key) {
|
|
492
|
+
return transport.invoke("storage.remove", { key })
|
|
493
|
+
},
|
|
494
|
+
clear() {
|
|
495
|
+
return transport.invoke("storage.clear")
|
|
496
|
+
},
|
|
497
|
+
async getAll() {
|
|
498
|
+
const payload = requireObject(await transport.invoke("storage.getAll"), "storage.getAll")
|
|
499
|
+
return requireObject(payload.entries ?? {}, "storage.getAll")
|
|
500
|
+
}
|
|
501
|
+
})
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function createWebViewApi(transport) {
|
|
505
|
+
return Object.freeze({
|
|
506
|
+
getInfo() {
|
|
507
|
+
return transport.invoke("webview.getInfo")
|
|
508
|
+
},
|
|
509
|
+
reload() {
|
|
510
|
+
return transport.invoke("webview.reload")
|
|
511
|
+
},
|
|
512
|
+
goBack() {
|
|
513
|
+
return transport.invoke("webview.goBack")
|
|
514
|
+
},
|
|
515
|
+
goForward() {
|
|
516
|
+
return transport.invoke("webview.goForward")
|
|
517
|
+
},
|
|
518
|
+
navigate(options) {
|
|
519
|
+
return transport.invoke("webview.navigate", options)
|
|
520
|
+
},
|
|
521
|
+
setZoomFactor(factor) {
|
|
522
|
+
return transport.invoke("webview.setZoomFactor", { factor })
|
|
523
|
+
}
|
|
524
|
+
})
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function createCryptoApi(transport) {
|
|
528
|
+
return Object.freeze({
|
|
529
|
+
getInfo() {
|
|
530
|
+
return transport.invoke("crypto.getInfo")
|
|
531
|
+
},
|
|
532
|
+
randomBytes(size, options = {}) {
|
|
533
|
+
return transport.invoke("crypto.randomBytes", {
|
|
534
|
+
size,
|
|
535
|
+
encoding: options.encoding
|
|
536
|
+
})
|
|
537
|
+
},
|
|
538
|
+
async randomUuid() {
|
|
539
|
+
const payload = requireObject(await transport.invoke("crypto.randomUuid"), "crypto.randomUuid")
|
|
540
|
+
return requireStringField(payload, "uuid", "crypto.randomUuid")
|
|
541
|
+
}
|
|
542
|
+
})
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function createProcessApi(transport) {
|
|
546
|
+
return Object.freeze({
|
|
547
|
+
async getPid() {
|
|
548
|
+
const payload = requireObject(await transport.invoke("process.getPid"), "process.getPid")
|
|
549
|
+
return requireNumberField(payload, "pid", "process.getPid")
|
|
550
|
+
},
|
|
551
|
+
async getCwd() {
|
|
552
|
+
const payload = requireObject(await transport.invoke("process.getCwd"), "process.getCwd")
|
|
553
|
+
return requireStringField(payload, "path", "process.getCwd")
|
|
554
|
+
},
|
|
555
|
+
getInfo() {
|
|
556
|
+
return transport.invoke("process.getInfo")
|
|
557
|
+
}
|
|
558
|
+
})
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function createPowerApi(transport) {
|
|
562
|
+
return Object.freeze({
|
|
563
|
+
getInfo() {
|
|
564
|
+
return transport.invoke("power.getInfo")
|
|
565
|
+
}
|
|
566
|
+
})
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function createMenuApi(transport) {
|
|
570
|
+
return Object.freeze({
|
|
571
|
+
getInfo() {
|
|
572
|
+
return transport.invoke("menu.getInfo")
|
|
573
|
+
},
|
|
574
|
+
setApplicationMenu(items) {
|
|
575
|
+
return transport.invoke("menu.setApplicationMenu", { items })
|
|
576
|
+
},
|
|
577
|
+
clearApplicationMenu() {
|
|
578
|
+
return transport.invoke("menu.clearApplicationMenu")
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function createTrayApi(transport) {
|
|
584
|
+
return Object.freeze({
|
|
585
|
+
getInfo() {
|
|
586
|
+
return transport.invoke("tray.getInfo")
|
|
587
|
+
},
|
|
588
|
+
create(options = {}) {
|
|
589
|
+
return transport.invoke("tray.create", options)
|
|
590
|
+
},
|
|
591
|
+
setTitle(title) {
|
|
592
|
+
return transport.invoke("tray.setTitle", { title })
|
|
593
|
+
},
|
|
594
|
+
setTooltip(tooltip) {
|
|
595
|
+
return transport.invoke("tray.setTooltip", { tooltip })
|
|
596
|
+
},
|
|
597
|
+
setMenu(items) {
|
|
598
|
+
return transport.invoke("tray.setMenu", { items })
|
|
599
|
+
},
|
|
600
|
+
destroy() {
|
|
601
|
+
return transport.invoke("tray.destroy")
|
|
602
|
+
}
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function createShortcutApi(transport) {
|
|
607
|
+
return Object.freeze({
|
|
608
|
+
getInfo() {
|
|
609
|
+
return transport.invoke("shortcut.getInfo")
|
|
610
|
+
},
|
|
611
|
+
register(accelerator) {
|
|
612
|
+
return transport.invoke("shortcut.register", { accelerator })
|
|
613
|
+
},
|
|
614
|
+
unregister(accelerator) {
|
|
615
|
+
return transport.invoke("shortcut.unregister", { accelerator })
|
|
616
|
+
},
|
|
617
|
+
unregisterAll() {
|
|
618
|
+
return transport.invoke("shortcut.unregisterAll")
|
|
619
|
+
}
|
|
620
|
+
})
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function createProtocolApi(transport, events) {
|
|
624
|
+
return Object.freeze({
|
|
625
|
+
async getInfo() {
|
|
626
|
+
return normalizeProtocolInfo(await transport.invoke("protocol.getInfo"), "protocol.getInfo")
|
|
627
|
+
},
|
|
628
|
+
async activate() {
|
|
629
|
+
const payload = requireObject(await transport.invoke("protocol.activate"), "protocol.activate")
|
|
630
|
+
return Object.freeze({
|
|
631
|
+
active: requireBooleanField(payload, "active", "protocol.activate")
|
|
632
|
+
})
|
|
633
|
+
},
|
|
634
|
+
async getCurrentLaunch() {
|
|
635
|
+
return normalizeProtocolLaunchEnvelope(
|
|
636
|
+
await transport.invoke("protocol.getCurrentLaunch"),
|
|
637
|
+
"protocol.getCurrentLaunch"
|
|
638
|
+
)
|
|
639
|
+
},
|
|
640
|
+
async getPendingLaunches() {
|
|
641
|
+
return normalizeProtocolLaunchList(
|
|
642
|
+
await transport.invoke("protocol.getPendingLaunches"),
|
|
643
|
+
"protocol.getPendingLaunches"
|
|
644
|
+
)
|
|
645
|
+
},
|
|
646
|
+
async consumePendingLaunches() {
|
|
647
|
+
return normalizeProtocolLaunchList(
|
|
648
|
+
await transport.invoke("protocol.consumePendingLaunches"),
|
|
649
|
+
"protocol.consumePendingLaunches"
|
|
650
|
+
)
|
|
651
|
+
},
|
|
652
|
+
async listen(handler, options = {}) {
|
|
653
|
+
if (typeof handler !== "function") {
|
|
654
|
+
throw new TypeError("Reset protocol listener must be a function.")
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const consumePending = options.consumePending !== false
|
|
658
|
+
const seenLaunches = new Set()
|
|
659
|
+
const deliver = (payload) => {
|
|
660
|
+
const launch = normalizeProtocolLaunch(payload, "protocol.open")
|
|
661
|
+
if (seenLaunches.has(launch.id)) {
|
|
662
|
+
return
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
seenLaunches.add(launch.id)
|
|
666
|
+
handler(launch)
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const dispose = events.listen("protocol.open", deliver)
|
|
670
|
+
await transport.invoke("protocol.activate")
|
|
671
|
+
|
|
672
|
+
if (consumePending) {
|
|
673
|
+
const pending = await transport.invoke("protocol.consumePendingLaunches")
|
|
674
|
+
for (const launch of normalizeProtocolLaunchList(pending, "protocol.consumePendingLaunches")) {
|
|
675
|
+
if (seenLaunches.has(launch.id)) {
|
|
676
|
+
continue
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
seenLaunches.add(launch.id)
|
|
680
|
+
handler(launch)
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return dispose
|
|
685
|
+
},
|
|
686
|
+
register(options = {}) {
|
|
687
|
+
return transport.invoke("protocol.register", options)
|
|
688
|
+
},
|
|
689
|
+
unregister(options = {}) {
|
|
690
|
+
return transport.invoke("protocol.unregister", options)
|
|
691
|
+
}
|
|
692
|
+
})
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function createUpdaterApi(transport) {
|
|
696
|
+
return Object.freeze({
|
|
697
|
+
getInfo() {
|
|
698
|
+
return transport.invoke("updater.getInfo")
|
|
699
|
+
},
|
|
700
|
+
check(options = {}) {
|
|
701
|
+
return transport.invoke("updater.check", options)
|
|
702
|
+
},
|
|
703
|
+
download(options = {}) {
|
|
704
|
+
return transport.invoke("updater.download", options)
|
|
705
|
+
},
|
|
706
|
+
install(options = {}) {
|
|
707
|
+
return transport.invoke("updater.install", options)
|
|
708
|
+
}
|
|
709
|
+
})
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function createNetApi(transport) {
|
|
713
|
+
return Object.freeze({
|
|
714
|
+
request(options) {
|
|
715
|
+
return transport.invoke("net.request", options)
|
|
716
|
+
}
|
|
717
|
+
})
|
|
718
|
+
}
|
|
719
|
+
|
|
720
720
|
function scheduleFrontendReadySignal(transport) {
|
|
721
721
|
const target = typeof globalThis === "object" ? globalThis.window : undefined
|
|
722
722
|
|
|
723
723
|
if (typeof target === "undefined") {
|
|
724
|
-
return
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
if (target.__resetFrontendReadySignalScheduled) {
|
|
728
|
-
return
|
|
729
|
-
}
|
|
724
|
+
return
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (target.__resetFrontendReadySignalScheduled) {
|
|
728
|
+
return
|
|
729
|
+
}
|
|
730
730
|
|
|
731
731
|
target.__resetFrontendReadySignalScheduled = true
|
|
732
732
|
|
|
733
|
-
|
|
734
|
-
|
|
733
|
+
let attempts = 0
|
|
734
|
+
const maxAttempts = 20
|
|
735
|
+
|
|
736
|
+
const trySignal = () => {
|
|
737
|
+
if (transport.isAvailable()) {
|
|
738
|
+
transport.invokeRaw("runtime.signalFrontendReady", {}).catch(() => {})
|
|
735
739
|
return
|
|
736
740
|
}
|
|
737
741
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
export function createResetClient(source) {
|
|
743
|
-
const transport = createResetTransport(source)
|
|
744
|
-
const commands = createCommandApi(transport)
|
|
745
|
-
const app = createAppApi(transport)
|
|
746
|
-
const runtime = createRuntimeApi(transport)
|
|
747
|
-
const events = createEventApi(transport)
|
|
748
|
-
const windowApi = createWindowApi(transport)
|
|
749
|
-
const dialog = createDialogApi(transport)
|
|
750
|
-
const fs = createFsApi(transport)
|
|
751
|
-
const path = createPathApi(transport)
|
|
752
|
-
const shell = createShellApi(transport)
|
|
753
|
-
const clipboard = createClipboardApi(transport)
|
|
754
|
-
const notification = createNotificationApi(transport)
|
|
755
|
-
const screen = createScreenApi(transport)
|
|
756
|
-
const storage = createStorageApi(transport)
|
|
757
|
-
const webview = createWebViewApi(transport)
|
|
758
|
-
const crypto = createCryptoApi(transport)
|
|
759
|
-
const process = createProcessApi(transport)
|
|
760
|
-
const power = createPowerApi(transport)
|
|
761
|
-
const menu = createMenuApi(transport)
|
|
762
|
-
const tray = createTrayApi(transport)
|
|
763
|
-
const shortcut = createShortcutApi(transport)
|
|
764
|
-
const protocol = createProtocolApi(transport, events)
|
|
765
|
-
const updater = createUpdaterApi(transport)
|
|
766
|
-
const net = createNetApi(transport)
|
|
767
|
-
const client = Object.freeze({
|
|
768
|
-
isAvailable() {
|
|
769
|
-
return transport.isAvailable()
|
|
770
|
-
},
|
|
771
|
-
getRuntime() {
|
|
772
|
-
return transport.getRuntime()
|
|
773
|
-
},
|
|
774
|
-
commands,
|
|
775
|
-
app,
|
|
776
|
-
runtime,
|
|
777
|
-
events,
|
|
778
|
-
window: windowApi,
|
|
779
|
-
dialog,
|
|
780
|
-
fs,
|
|
781
|
-
path,
|
|
782
|
-
shell,
|
|
783
|
-
clipboard,
|
|
784
|
-
notification,
|
|
785
|
-
screen,
|
|
786
|
-
storage,
|
|
787
|
-
webview,
|
|
788
|
-
crypto,
|
|
789
|
-
process,
|
|
790
|
-
power,
|
|
791
|
-
menu,
|
|
792
|
-
tray,
|
|
793
|
-
shortcut,
|
|
794
|
-
protocol,
|
|
795
|
-
updater,
|
|
796
|
-
net
|
|
797
|
-
})
|
|
798
|
-
|
|
799
|
-
scheduleFrontendReadySignal(transport)
|
|
800
|
-
|
|
801
|
-
return client
|
|
802
|
-
}
|
|
742
|
+
attempts += 1
|
|
743
|
+
if (attempts >= maxAttempts) {
|
|
744
|
+
return
|
|
745
|
+
}
|
|
803
746
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
getResetRuntime,
|
|
807
|
-
invoke,
|
|
808
|
-
invokeRaw,
|
|
809
|
-
isResetRuntimeAvailable
|
|
810
|
-
} from "./transport.js"
|
|
747
|
+
setTimeout(trySignal, 100)
|
|
748
|
+
}
|
|
811
749
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
export
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
750
|
+
queueMicrotask(trySignal)
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
export function createResetClient(source) {
|
|
754
|
+
const transport = createResetTransport(source)
|
|
755
|
+
const commands = createCommandApi(transport)
|
|
756
|
+
const app = createAppApi(transport)
|
|
757
|
+
const runtime = createRuntimeApi(transport)
|
|
758
|
+
const events = createEventApi(transport)
|
|
759
|
+
const windowApi = createWindowApi(transport)
|
|
760
|
+
const dialog = createDialogApi(transport)
|
|
761
|
+
const fs = createFsApi(transport)
|
|
762
|
+
const path = createPathApi(transport)
|
|
763
|
+
const shell = createShellApi(transport)
|
|
764
|
+
const clipboard = createClipboardApi(transport)
|
|
765
|
+
const notification = createNotificationApi(transport)
|
|
766
|
+
const screen = createScreenApi(transport)
|
|
767
|
+
const storage = createStorageApi(transport)
|
|
768
|
+
const webview = createWebViewApi(transport)
|
|
769
|
+
const crypto = createCryptoApi(transport)
|
|
770
|
+
const process = createProcessApi(transport)
|
|
771
|
+
const power = createPowerApi(transport)
|
|
772
|
+
const menu = createMenuApi(transport)
|
|
773
|
+
const tray = createTrayApi(transport)
|
|
774
|
+
const shortcut = createShortcutApi(transport)
|
|
775
|
+
const protocol = createProtocolApi(transport, events)
|
|
776
|
+
const updater = createUpdaterApi(transport)
|
|
777
|
+
const net = createNetApi(transport)
|
|
778
|
+
const client = Object.freeze({
|
|
779
|
+
isAvailable() {
|
|
780
|
+
return transport.isAvailable()
|
|
781
|
+
},
|
|
782
|
+
getRuntime() {
|
|
783
|
+
return transport.getRuntime()
|
|
784
|
+
},
|
|
785
|
+
commands,
|
|
786
|
+
app,
|
|
787
|
+
runtime,
|
|
788
|
+
events,
|
|
789
|
+
window: windowApi,
|
|
790
|
+
dialog,
|
|
791
|
+
fs,
|
|
792
|
+
path,
|
|
793
|
+
shell,
|
|
794
|
+
clipboard,
|
|
795
|
+
notification,
|
|
796
|
+
screen,
|
|
797
|
+
storage,
|
|
798
|
+
webview,
|
|
799
|
+
crypto,
|
|
800
|
+
process,
|
|
801
|
+
power,
|
|
802
|
+
menu,
|
|
803
|
+
tray,
|
|
804
|
+
shortcut,
|
|
805
|
+
protocol,
|
|
806
|
+
updater,
|
|
807
|
+
net
|
|
808
|
+
})
|
|
809
|
+
|
|
810
|
+
scheduleFrontendReadySignal(transport)
|
|
811
|
+
|
|
812
|
+
return client
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
export {
|
|
816
|
+
createResetTransport,
|
|
817
|
+
getResetRuntime,
|
|
818
|
+
invoke,
|
|
819
|
+
invokeRaw,
|
|
820
|
+
isResetRuntimeAvailable
|
|
821
|
+
} from "./transport.js"
|
|
822
|
+
|
|
823
|
+
export const reset = createResetClient()
|
|
824
|
+
export const commands = reset.commands
|
|
825
|
+
export const app = reset.app
|
|
826
|
+
export const runtime = reset.runtime
|
|
827
|
+
export const events = reset.events
|
|
828
|
+
export const window = reset.window
|
|
829
|
+
export const dialog = reset.dialog
|
|
830
|
+
export const fs = reset.fs
|
|
831
|
+
export const path = reset.path
|
|
832
|
+
export const shell = reset.shell
|
|
833
|
+
export const clipboard = reset.clipboard
|
|
834
|
+
export const notification = reset.notification
|
|
835
|
+
export const screen = reset.screen
|
|
836
|
+
export const storage = reset.storage
|
|
837
|
+
export const webview = reset.webview
|
|
838
|
+
export const crypto = reset.crypto
|
|
839
|
+
export const process = reset.process
|
|
840
|
+
export const power = reset.power
|
|
841
|
+
export const menu = reset.menu
|
|
842
|
+
export const tray = reset.tray
|
|
843
|
+
export const shortcut = reset.shortcut
|
|
844
|
+
export const protocol = reset.protocol
|
|
845
|
+
export const updater = reset.updater
|
|
846
|
+
export const net = reset.net
|