electrobun 1.9.0-beta.3 → 1.10.1-beta.0
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/bun.lock +3 -20
- package/dist/api/browser/index.ts +13 -113
- package/dist/api/browser/rpc/webview.ts +1 -1
- package/dist/api/bun/ElectrobunConfig.ts +11 -0
- package/dist/api/bun/core/BrowserView.ts +9 -109
- package/dist/api/bun/core/BrowserWindow.ts +1 -7
- package/dist/api/bun/core/BuildConfig.ts +1 -0
- package/dist/api/bun/core/Socket.ts +5 -5
- package/dist/api/bun/core/Updater.ts +3 -6
- package/dist/api/bun/index.ts +8 -1
- package/dist/api/shared/cef-version.ts +5 -0
- package/dist/api/shared/rpc.ts +538 -0
- package/package.json +62 -62
- package/src/cli/index.ts +262 -15
package/bun.lock
CHANGED
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "electrobun",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@types/bun": "^1.3.8",
|
|
8
9
|
"archiver": "^7.0.1",
|
|
9
10
|
"png-to-ico": "^2.1.8",
|
|
10
11
|
"rcedit": "^4.0.1",
|
|
11
|
-
"rpc-anywhere": "1.5.0",
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/archiver": "^6.0.3",
|
|
15
|
-
"@types/bun": "1.1.9",
|
|
16
15
|
"typescript": "^5.9.3",
|
|
17
16
|
},
|
|
18
17
|
},
|
|
@@ -26,22 +25,12 @@
|
|
|
26
25
|
|
|
27
26
|
"@types/archiver": ["@types/archiver@6.0.4", "", { "dependencies": { "@types/readdir-glob": "*" } }, "sha512-ULdQpARQ3sz9WH4nb98mJDYA0ft2A8C4f4fovvUcFwINa1cgGjY36JCAYuP5YypRq4mco1lJp1/7jEMS2oR0Hg=="],
|
|
28
27
|
|
|
29
|
-
"@types/bun": ["@types/bun@1.
|
|
30
|
-
|
|
31
|
-
"@types/filesystem": ["@types/filesystem@0.0.36", "", { "dependencies": { "@types/filewriter": "*" } }, "sha512-vPDXOZuannb9FZdxgHnqSwAG/jvdGM8Wq+6N4D/d80z+D4HWH+bItqsZaVRQykAn6WEVeEkLm2oQigyHtgb0RA=="],
|
|
32
|
-
|
|
33
|
-
"@types/filewriter": ["@types/filewriter@0.0.33", "", {}, "sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g=="],
|
|
34
|
-
|
|
35
|
-
"@types/har-format": ["@types/har-format@1.2.16", "", {}, "sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A=="],
|
|
28
|
+
"@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
|
|
36
29
|
|
|
37
30
|
"@types/node": ["@types/node@17.0.45", "", {}, "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw=="],
|
|
38
31
|
|
|
39
32
|
"@types/readdir-glob": ["@types/readdir-glob@1.1.5", "", { "dependencies": { "@types/node": "*" } }, "sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg=="],
|
|
40
33
|
|
|
41
|
-
"@types/webextension-polyfill": ["@types/webextension-polyfill@0.12.3", "", {}, "sha512-F58aDVSeN/MjUGazXo/cPsmR76EvqQhQ1v4x23hFjUX0cfAJYE+JBWwiOGW36/VJGGxoH74sVlRIF3z7SJCKyg=="],
|
|
42
|
-
|
|
43
|
-
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
|
|
44
|
-
|
|
45
34
|
"abort-controller": ["abort-controller@3.0.0", "", { "dependencies": { "event-target-shim": "^5.0.0" } }, "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg=="],
|
|
46
35
|
|
|
47
36
|
"ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="],
|
|
@@ -64,13 +53,11 @@
|
|
|
64
53
|
|
|
65
54
|
"brace-expansion": ["brace-expansion@2.0.2", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="],
|
|
66
55
|
|
|
67
|
-
"browser-namespace": ["browser-namespace@1.4.0", "", { "dependencies": { "@types/filesystem": "*", "@types/har-format": "*", "@types/webextension-polyfill": "*" } }, "sha512-9b4yNTNs+8HVPssSq8RSZMRunf+G4cVQ2PMtOTn+uEVFOW5C0Uo+eGXuJ5LfxS1UDph5oAdWj92thPyxVhpqXg=="],
|
|
68
|
-
|
|
69
56
|
"buffer": ["buffer@6.0.3", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" } }, "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA=="],
|
|
70
57
|
|
|
71
58
|
"buffer-crc32": ["buffer-crc32@1.0.0", "", {}, "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w=="],
|
|
72
59
|
|
|
73
|
-
"bun-types": ["bun-types@1.
|
|
60
|
+
"bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
|
|
74
61
|
|
|
75
62
|
"color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
|
|
76
63
|
|
|
@@ -158,8 +145,6 @@
|
|
|
158
145
|
|
|
159
146
|
"readdir-glob": ["readdir-glob@1.1.3", "", { "dependencies": { "minimatch": "^5.1.0" } }, "sha512-v05I2k7xN8zXvPD9N+z/uhXPaj0sUFCe2rcWZIpBsqxfP7xXFQ0tipAd/wjj1YxWyWtUS5IDJpOG82JKt2EAVA=="],
|
|
160
147
|
|
|
161
|
-
"rpc-anywhere": ["rpc-anywhere@1.5.0", "", { "dependencies": { "browser-namespace": "^1.4.0" } }, "sha512-ZYrB0foAM4oE7oBnUH3BL7LwtW9d6+RkzL/rFnjj8GCaFt5c81Rbw6oVl6u9AMsGONsKeJX0mL62TpbPXSO6og=="],
|
|
162
|
-
|
|
163
148
|
"safe-buffer": ["safe-buffer@5.2.1", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
|
|
164
149
|
|
|
165
150
|
"shebang-command": ["shebang-command@2.0.0", "", { "dependencies": { "shebang-regex": "^3.0.0" } }, "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA=="],
|
|
@@ -200,8 +185,6 @@
|
|
|
200
185
|
|
|
201
186
|
"@types/readdir-glob/@types/node": ["@types/node@20.12.14", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg=="],
|
|
202
187
|
|
|
203
|
-
"@types/ws/@types/node": ["@types/node@20.12.14", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg=="],
|
|
204
|
-
|
|
205
188
|
"bun-types/@types/node": ["@types/node@20.12.14", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg=="],
|
|
206
189
|
|
|
207
190
|
"glob/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type RPCSchema,
|
|
3
|
-
type RPCRequestHandler,
|
|
4
|
-
type RPCOptions,
|
|
5
|
-
type RPCMessageHandlerFn,
|
|
6
|
-
type WildcardRPCMessageHandlerFn,
|
|
7
3
|
type RPCTransport,
|
|
4
|
+
type ElectrobunRPCSchema,
|
|
5
|
+
type ElectrobunRPCConfig,
|
|
6
|
+
type RPCWithTransport,
|
|
8
7
|
createRPC,
|
|
9
|
-
|
|
8
|
+
defineElectrobunRPC,
|
|
9
|
+
} from "../shared/rpc.js";
|
|
10
10
|
import {
|
|
11
11
|
ConfigureWebviewTags,
|
|
12
12
|
type WebviewTagElement,
|
|
@@ -14,25 +14,12 @@ import {
|
|
|
14
14
|
} from "./webviewtag";
|
|
15
15
|
// todo: should this just be injected as a preload script?
|
|
16
16
|
import { isAppRegionDrag } from "./stylesAndElements";
|
|
17
|
-
import type {
|
|
18
|
-
BuiltinBunToWebviewSchema,
|
|
19
|
-
BuiltinWebviewToBunSchema,
|
|
20
|
-
} from "./builtinrpcSchema";
|
|
21
17
|
import type {
|
|
22
18
|
InternalWebviewHandlers,
|
|
23
19
|
WebviewTagHandlers,
|
|
24
20
|
} from "./rpc/webview";
|
|
25
21
|
import "./global.d.ts";
|
|
26
22
|
|
|
27
|
-
interface ElectrobunWebviewRPCSChema {
|
|
28
|
-
bun: RPCSchema;
|
|
29
|
-
webview: RPCSchema;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface RPCWithTransport {
|
|
33
|
-
setTransport: (transport: RPCTransport) => void;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
23
|
const WEBVIEW_ID = window.__electrobunWebviewId;
|
|
37
24
|
const WINDOW_ID = window.__electrobunWindowId;
|
|
38
25
|
const RPC_SOCKET_PORT = window.__electrobunRpcSocketPort;
|
|
@@ -289,51 +276,13 @@ class Electroview<T extends RPCWithTransport> {
|
|
|
289
276
|
this.rpcHandler(msg);
|
|
290
277
|
}
|
|
291
278
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
handlers: {
|
|
300
|
-
requests?: RPCRequestHandler<WebviewSchema["requests"]>;
|
|
301
|
-
messages?: {
|
|
302
|
-
[key in keyof WebviewSchema["messages"]]: RPCMessageHandlerFn<
|
|
303
|
-
WebviewSchema["messages"],
|
|
304
|
-
key
|
|
305
|
-
>;
|
|
306
|
-
} & {
|
|
307
|
-
"*"?: WildcardRPCMessageHandlerFn<WebviewSchema["messages"]>;
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
}) {
|
|
311
|
-
// Note: RPC Anywhere requires defining the requests that a schema handles and the messages that a schema sends.
|
|
312
|
-
// eg: BunSchema {
|
|
313
|
-
// requests: // ... requests bun handles, sent by webview
|
|
314
|
-
// messages: // ... messages bun sends, handled by webview
|
|
315
|
-
// }
|
|
316
|
-
// In some generlized contexts that makes sense,
|
|
317
|
-
// In the Electrobun context it can feel a bit counter-intuitive so we swap this around a bit. In Electrobun, the
|
|
318
|
-
// webview and bun are known endpoints so we simplify schema definitions by combining them.
|
|
319
|
-
// Schema {
|
|
320
|
-
// bun: BunSchema {
|
|
321
|
-
// requests: // ... requests bun sends, handled by webview,
|
|
322
|
-
// messages: // ... messages bun sends, handled by webview
|
|
323
|
-
// },
|
|
324
|
-
// webview: WebviewSchema {
|
|
325
|
-
// requests: // ... requests webview sends, handled by bun,
|
|
326
|
-
// messages: // ... messages webview sends, handled by bun
|
|
327
|
-
// },
|
|
328
|
-
// }
|
|
329
|
-
// electrobun also treats messages as "requests that we don't wait for to complete", and normalizes specifying the
|
|
330
|
-
// handlers for them alongside request handlers.
|
|
331
|
-
|
|
332
|
-
const builtinHandlers: {
|
|
333
|
-
requests: RPCRequestHandler<BuiltinBunToWebviewSchema["requests"]>;
|
|
334
|
-
} = {
|
|
335
|
-
requests: {
|
|
336
|
-
evaluateJavascriptWithResponse: ({ script }) => {
|
|
279
|
+
static defineRPC<Schema extends ElectrobunRPCSchema>(
|
|
280
|
+
config: ElectrobunRPCConfig<Schema, "webview">,
|
|
281
|
+
) {
|
|
282
|
+
return defineElectrobunRPC("webview", {
|
|
283
|
+
...config,
|
|
284
|
+
extraRequestHandlers: {
|
|
285
|
+
evaluateJavascriptWithResponse: ({ script }: { script: string }) => {
|
|
337
286
|
return new Promise((resolve) => {
|
|
338
287
|
try {
|
|
339
288
|
const resultFunction = new Function(script);
|
|
@@ -358,56 +307,7 @@ class Electroview<T extends RPCWithTransport> {
|
|
|
358
307
|
});
|
|
359
308
|
},
|
|
360
309
|
},
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
type mixedWebviewSchema = {
|
|
364
|
-
requests: BunSchema["requests"] & BuiltinWebviewToBunSchema["requests"];
|
|
365
|
-
messages: WebviewSchema["messages"];
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
type mixedBunSchema = {
|
|
369
|
-
requests: WebviewSchema["requests"] &
|
|
370
|
-
BuiltinBunToWebviewSchema["requests"];
|
|
371
|
-
messages: BunSchema["messages"];
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
const rpcOptions = {
|
|
375
|
-
maxRequestTime: config.maxRequestTime,
|
|
376
|
-
requestHandler: {
|
|
377
|
-
...config.handlers.requests,
|
|
378
|
-
...builtinHandlers.requests,
|
|
379
|
-
},
|
|
380
|
-
transport: {
|
|
381
|
-
// Note: RPC Anywhere will throw if you try add a message listener if transport.registerHandler is falsey
|
|
382
|
-
registerHandler: () => {},
|
|
383
|
-
},
|
|
384
|
-
} as RPCOptions<mixedBunSchema, mixedWebviewSchema>;
|
|
385
|
-
|
|
386
|
-
const rpc = createRPC<mixedBunSchema, mixedWebviewSchema>(rpcOptions);
|
|
387
|
-
|
|
388
|
-
const messageHandlers = config.handlers.messages;
|
|
389
|
-
if (messageHandlers) {
|
|
390
|
-
// note: this can only be done once there is a transport
|
|
391
|
-
// @ts-ignore - this is due to all the schema mixing we're doing, fine to ignore
|
|
392
|
-
// while types in here are borked, they resolve correctly/bubble up to the defineRPC call site.
|
|
393
|
-
rpc.addMessageListener(
|
|
394
|
-
"*",
|
|
395
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
396
|
-
(messageName: keyof WebviewSchema["messages"], payload: any) => {
|
|
397
|
-
const globalHandler = messageHandlers["*"];
|
|
398
|
-
if (globalHandler) {
|
|
399
|
-
globalHandler(messageName, payload);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const messageHandler = messageHandlers[messageName];
|
|
403
|
-
if (messageHandler) {
|
|
404
|
-
messageHandler(payload);
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
return rpc;
|
|
310
|
+
});
|
|
411
311
|
}
|
|
412
312
|
}
|
|
413
313
|
|
|
@@ -123,6 +123,17 @@ export interface ElectrobunConfig {
|
|
|
123
123
|
*/
|
|
124
124
|
asarUnpack?: string[];
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Override the CEF (Chromium Embedded Framework) version.
|
|
128
|
+
* Format: "CEF_VERSION+chromium-CHROMIUM_VERSION"
|
|
129
|
+
* Example: "144.0.11+ge135be2+chromium-144.0.7559.97"
|
|
130
|
+
*
|
|
131
|
+
* Check the electrobun-cef-compat compatibility matrix for tested combinations
|
|
132
|
+
* before overriding. Using an untested version may cause runtime issues.
|
|
133
|
+
* @default Uses the version bundled with this Electrobun release
|
|
134
|
+
*/
|
|
135
|
+
cefVersion?: string;
|
|
136
|
+
|
|
126
137
|
/**
|
|
127
138
|
* macOS-specific build configuration
|
|
128
139
|
*/
|
|
@@ -2,13 +2,11 @@ import { native, toCString, ffi } from "../proc/native";
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import electrobunEventEmitter from "../events/eventEmitter";
|
|
4
4
|
import {
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
createRPC,
|
|
11
|
-
} from "rpc-anywhere";
|
|
5
|
+
type ElectrobunRPCSchema,
|
|
6
|
+
type ElectrobunRPCConfig,
|
|
7
|
+
type RPCWithTransport,
|
|
8
|
+
defineElectrobunRPC,
|
|
9
|
+
} from "../../shared/rpc.js";
|
|
12
10
|
import { Updater } from "./Updater";
|
|
13
11
|
import { BuildConfig } from "./BuildConfig";
|
|
14
12
|
import { rpcPort, sendMessageToWebviewViaSocket } from "./Socket";
|
|
@@ -41,18 +39,6 @@ type BrowserViewOptions<T = undefined> = {
|
|
|
41
39
|
// renderer:
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
interface ElectrobunWebviewRPCSChema {
|
|
45
|
-
bun: RPCSchema;
|
|
46
|
-
webview: RPCSchema;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface RPCWithTransport {
|
|
50
|
-
setTransport: (transport: {
|
|
51
|
-
send: (msg: unknown) => void;
|
|
52
|
-
registerHandler: (handler: (msg: unknown) => void) => void;
|
|
53
|
-
}) => void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
42
|
const hash = await Updater.localInfo.hash();
|
|
57
43
|
const buildConfig = await BuildConfig.get();
|
|
58
44
|
|
|
@@ -327,95 +313,9 @@ export class BrowserView<T extends RPCWithTransport = RPCWithTransport> {
|
|
|
327
313
|
return Object.values(BrowserViewMap);
|
|
328
314
|
}
|
|
329
315
|
|
|
330
|
-
static defineRPC<
|
|
331
|
-
Schema
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
>(config: {
|
|
335
|
-
maxRequestTime?: number;
|
|
336
|
-
handlers: {
|
|
337
|
-
requests?: RPCRequestHandler<BunSchema["requests"]>;
|
|
338
|
-
messages?: {
|
|
339
|
-
[key in keyof BunSchema["messages"]]: RPCMessageHandlerFn<
|
|
340
|
-
BunSchema["messages"],
|
|
341
|
-
key
|
|
342
|
-
>;
|
|
343
|
-
} & {
|
|
344
|
-
"*"?: WildcardRPCMessageHandlerFn<BunSchema["messages"]>;
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
|
-
}) {
|
|
348
|
-
// Note: RPC Anywhere requires defining the requests that a schema handles and the messages that a schema sends.
|
|
349
|
-
// eg: BunSchema {
|
|
350
|
-
// requests: // ... requests bun handles, sent by webview
|
|
351
|
-
// messages: // ... messages bun sends, handled by webview
|
|
352
|
-
// }
|
|
353
|
-
// In some generlized contexts that makes sense,
|
|
354
|
-
// In the Electrobun context it can feel a bit counter-intuitive so we swap this around a bit. In Electrobun, the
|
|
355
|
-
// webview and bun are known endpoints so we simplify schema definitions by combining them.
|
|
356
|
-
// Schema {
|
|
357
|
-
// bun: BunSchema {
|
|
358
|
-
// requests: // ... requests bun handles, sent by webview,
|
|
359
|
-
// messages: // ... messages bun handles, sent by webview
|
|
360
|
-
// },
|
|
361
|
-
// webview: WebviewSchema {
|
|
362
|
-
// requests: // ... requests webview handles, sent by bun,
|
|
363
|
-
// messages: // ... messages webview handles, sent by bun
|
|
364
|
-
// },
|
|
365
|
-
// }
|
|
366
|
-
// This way from bun, webview.rpc.request.getTitle() and webview.rpc.send.someMessage maps to the schema
|
|
367
|
-
// MySchema.webview.requests.getTitle and MySchema.webview.messages.someMessage
|
|
368
|
-
// and in the webview, Electroview.rpc.request.getFileContents maps to
|
|
369
|
-
// MySchema.bun.requests.getFileContents.
|
|
370
|
-
// electrobun also treats messages as "requests that we don't wait for to complete", and normalizes specifying the
|
|
371
|
-
// handlers for them alongside request handlers.
|
|
372
|
-
|
|
373
|
-
type mixedWebviewSchema = {
|
|
374
|
-
requests: BunSchema["requests"]; // & BuiltinWebviewToBunSchema["requests"];
|
|
375
|
-
messages: WebviewSchema["messages"];
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
type mixedBunSchema = {
|
|
379
|
-
requests: WebviewSchema["requests"];
|
|
380
|
-
messages: BunSchema["messages"];
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
const rpcOptions = {
|
|
384
|
-
maxRequestTime: config.maxRequestTime,
|
|
385
|
-
requestHandler: {
|
|
386
|
-
...config.handlers.requests,
|
|
387
|
-
// ...internalRpcHandlers,
|
|
388
|
-
},
|
|
389
|
-
transport: {
|
|
390
|
-
// Note: RPC Anywhere will throw if you try add a message listener if transport.registerHandler is falsey
|
|
391
|
-
registerHandler: () => {},
|
|
392
|
-
},
|
|
393
|
-
} as RPCOptions<mixedWebviewSchema, mixedBunSchema>;
|
|
394
|
-
|
|
395
|
-
const rpc = createRPC<mixedWebviewSchema, mixedBunSchema>(rpcOptions);
|
|
396
|
-
|
|
397
|
-
const messageHandlers = config.handlers.messages;
|
|
398
|
-
if (messageHandlers) {
|
|
399
|
-
// note: this can only be done once there is a transport
|
|
400
|
-
// @ts-ignore - this is due to all the schema mixing we're doing, fine to ignore
|
|
401
|
-
// while types in here are borked, they resolve correctly/bubble up to the defineRPC call site.
|
|
402
|
-
rpc.addMessageListener(
|
|
403
|
-
"*",
|
|
404
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
405
|
-
(messageName: keyof BunSchema["messages"], payload: any) => {
|
|
406
|
-
const globalHandler = messageHandlers["*"];
|
|
407
|
-
if (globalHandler) {
|
|
408
|
-
globalHandler(messageName, payload);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const messageHandler = messageHandlers[messageName];
|
|
412
|
-
if (messageHandler) {
|
|
413
|
-
messageHandler(payload);
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
return rpc;
|
|
316
|
+
static defineRPC<Schema extends ElectrobunRPCSchema>(
|
|
317
|
+
config: ElectrobunRPCConfig<Schema, "bun">,
|
|
318
|
+
) {
|
|
319
|
+
return defineElectrobunRPC("bun", config);
|
|
420
320
|
}
|
|
421
321
|
}
|
|
@@ -4,6 +4,7 @@ import { BrowserView } from "./BrowserView";
|
|
|
4
4
|
import { type Pointer } from "bun:ffi";
|
|
5
5
|
import { BuildConfig } from "./BuildConfig";
|
|
6
6
|
import { quit } from "./Utils";
|
|
7
|
+
import { type RPCWithTransport } from "../../shared/rpc.js";
|
|
7
8
|
|
|
8
9
|
const buildConfig = await BuildConfig.get();
|
|
9
10
|
|
|
@@ -66,13 +67,6 @@ electrobunEventEmitter.on("close", (event: { data: { id: number } }) => {
|
|
|
66
67
|
}
|
|
67
68
|
});
|
|
68
69
|
|
|
69
|
-
interface RPCWithTransport {
|
|
70
|
-
setTransport: (transport: {
|
|
71
|
-
send: (msg: unknown) => void;
|
|
72
|
-
registerHandler: (handler: (msg: unknown) => void) => void;
|
|
73
|
-
}) => void;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
70
|
export class BrowserWindow<T extends RPCWithTransport = RPCWithTransport> {
|
|
77
71
|
id: number = nextWindowId++;
|
|
78
72
|
ptr!: Pointer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServerWebSocket } from "bun";
|
|
1
|
+
import type { Server, ServerWebSocket } from "bun";
|
|
2
2
|
import { BrowserView } from "./BrowserView";
|
|
3
3
|
import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
|
|
4
4
|
|
|
@@ -58,7 +58,7 @@ const startRPCServer = () => {
|
|
|
58
58
|
try {
|
|
59
59
|
server = Bun.serve<{ webviewId: number }>({
|
|
60
60
|
port,
|
|
61
|
-
fetch(req, server) {
|
|
61
|
+
fetch(req: Request, server: Server<{ webviewId: number }>) {
|
|
62
62
|
const url = new URL(req.url);
|
|
63
63
|
// const token = new URL(req.url).searchParams.get("token");
|
|
64
64
|
// if (token !== AUTH_TOKEN)
|
|
@@ -84,7 +84,7 @@ const startRPCServer = () => {
|
|
|
84
84
|
maxPayloadLength: payloadLimit,
|
|
85
85
|
// Anything beyond the backpressure limit will be dropped
|
|
86
86
|
backpressureLimit: payloadLimit * 2,
|
|
87
|
-
open(ws) {
|
|
87
|
+
open(ws: ServerWebSocket<{ webviewId: number }>) {
|
|
88
88
|
if (!ws?.data) {
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
@@ -96,7 +96,7 @@ const startRPCServer = () => {
|
|
|
96
96
|
socketMap[webviewId].socket = ws;
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
close(ws
|
|
99
|
+
close(ws: ServerWebSocket<{ webviewId: number }>, _code: number, _reason: string) {
|
|
100
100
|
if (!ws?.data) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
@@ -107,7 +107,7 @@ const startRPCServer = () => {
|
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
109
|
|
|
110
|
-
message(ws
|
|
110
|
+
message(ws: ServerWebSocket<{ webviewId: number }>, message: string | Buffer) {
|
|
111
111
|
if (!ws?.data) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
@@ -58,6 +58,8 @@ export interface UpdateStatusDetails {
|
|
|
58
58
|
usedPatchPath?: boolean;
|
|
59
59
|
errorMessage?: string;
|
|
60
60
|
url?: string;
|
|
61
|
+
zstdPath?: string;
|
|
62
|
+
exitCode?: number | null;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export interface UpdateStatusEntry {
|
|
@@ -1145,9 +1147,4 @@ del "%~f0"
|
|
|
1145
1147
|
},
|
|
1146
1148
|
};
|
|
1147
1149
|
|
|
1148
|
-
export {
|
|
1149
|
-
Updater,
|
|
1150
|
-
type UpdateStatusType,
|
|
1151
|
-
type UpdateStatusEntry,
|
|
1152
|
-
type UpdateStatusDetails,
|
|
1153
|
-
};
|
|
1150
|
+
export { Updater };
|
package/dist/api/bun/index.ts
CHANGED
|
@@ -12,7 +12,12 @@ import {
|
|
|
12
12
|
} from "./core/Updater";
|
|
13
13
|
import * as Utils from "./core/Utils";
|
|
14
14
|
import type { MessageBoxOptions, MessageBoxResponse } from "./core/Utils";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
type RPCSchema,
|
|
17
|
+
type ElectrobunRPCSchema,
|
|
18
|
+
createRPC,
|
|
19
|
+
defineElectrobunRPC,
|
|
20
|
+
} from "../shared/rpc.js";
|
|
16
21
|
import type ElectrobunEvent from "./events/event";
|
|
17
22
|
import * as PATHS from "./core/Paths";
|
|
18
23
|
import * as Socket from "./core/Socket";
|
|
@@ -31,6 +36,7 @@ import { BuildConfig, type BuildConfigType } from "./core/BuildConfig";
|
|
|
31
36
|
// Named Exports
|
|
32
37
|
export {
|
|
33
38
|
type RPCSchema,
|
|
39
|
+
type ElectrobunRPCSchema,
|
|
34
40
|
type ElectrobunEvent,
|
|
35
41
|
type ElectrobunConfig,
|
|
36
42
|
type BuildConfigType,
|
|
@@ -46,6 +52,7 @@ export {
|
|
|
46
52
|
type UpdateStatusEntry,
|
|
47
53
|
type UpdateStatusDetails,
|
|
48
54
|
createRPC,
|
|
55
|
+
defineElectrobunRPC,
|
|
49
56
|
BrowserWindow,
|
|
50
57
|
BrowserView,
|
|
51
58
|
Tray,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Default CEF version shipped with this Electrobun release.
|
|
2
|
+
// All platforms use the same version. Update this single pair when bumping CEF.
|
|
3
|
+
export const CEF_VERSION = `144.0.11+ge135be2`;
|
|
4
|
+
export const CHROMIUM_VERSION = `144.0.7559.97`;
|
|
5
|
+
export const DEFAULT_CEF_VERSION_STRING = `${CEF_VERSION}+chromium-${CHROMIUM_VERSION}`;
|