gloomberb 0.19.6 → 0.20.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/LICENSE +0 -4
- package/package.json +6 -5
- package/patches/electrobun-devkit@2.0.5.patch +148 -0
- package/src/api-client/bond-trades.ts +59 -0
- package/src/api-client/data.ts +21 -0
- package/src/api-client/index.ts +2 -0
- package/src/api-client/types/account.ts +86 -0
- package/src/api-client/types/assist.ts +32 -0
- package/src/api-client/types/auth.ts +63 -0
- package/src/api-client/types/billing.ts +54 -0
- package/src/api-client/types/chat.ts +180 -0
- package/src/api-client/types/congress.ts +107 -0
- package/src/api-client/types/credit.ts +110 -0
- package/src/api-client/types/econ.ts +158 -0
- package/src/api-client/types/equity-diagnostic.ts +73 -0
- package/src/api-client/types/filings-and-calls.ts +350 -0
- package/src/api-client/types/index.ts +25 -0
- package/src/api-client/types/jobs.ts +147 -0
- package/src/api-client/types/market.ts +122 -0
- package/src/api-client/types/news.ts +91 -0
- package/src/api-client/types/notes-and-theses.ts +172 -0
- package/src/api-client/types/quotes.ts +28 -0
- package/src/api-client/types/scanners.ts +125 -0
- package/src/api-client/types/screener.ts +65 -0
- package/src/api-client/types/search.ts +107 -0
- package/src/api-client/types/sync.ts +14 -0
- package/src/api-client/types/team-collections.ts +43 -0
- package/src/api-client/types/team-views.ts +32 -0
- package/src/api-client/types/teams.ts +135 -0
- package/src/api-client/types/ticker-data.ts +57 -0
- package/src/api-client/types/tweets.ts +59 -0
- package/src/api-client/types/world-venues.ts +23 -0
- package/src/app/runtime/desktop-deeplink.ts +41 -6
- package/src/app/star-prompt/status-line.tsx +1 -1
- package/src/app.tsx +1 -7
- package/src/architecture/ui-tokens-allowlist.json +0 -8
- package/src/cli/commands/ticker.ts +17 -4
- package/src/cli/desktop-pane-shot-browser.ts +69 -3
- package/src/cli/pane-functions/catalog.ts +3 -1
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +11 -2
- package/src/components/data-table/export.ts +4 -1
- package/src/components/layout/detached-pane-shell.tsx +10 -37
- package/src/components/layout/double-escape-close.ts +90 -0
- package/src/components/layout/header.tsx +3 -2
- package/src/components/layout/market-summary.ts +6 -3
- package/src/components/layout/pane/footer/index.tsx +2 -6
- package/src/components/layout/pane/footer/model.ts +6 -12
- package/src/components/layout/shell/active-drag.ts +53 -11
- package/src/components/layout/shell/drag/magnets.ts +128 -19
- package/src/components/layout/shell/pane/actions.ts +6 -2
- package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
- package/src/components/layout/status-bar.tsx +4 -78
- package/src/components/layout/status-widget-space.ts +5 -5
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +1 -1
- package/src/components/ui/data-table/index.tsx +5 -1
- package/src/components/ui/data-table/render-cell.ts +19 -0
- package/src/components/ui/delayed-mark.tsx +59 -7
- package/src/components/ui/icon.tsx +1 -8
- package/src/components/ui/menu.tsx +6 -1
- package/src/i18n/es.ts +3 -3
- package/src/i18n/ja.ts +3 -3
- package/src/i18n/ko.ts +3 -3
- package/src/i18n/zh-cn.ts +3 -3
- package/src/i18n/zh-tw.ts +3 -3
- package/src/plugins/builtin/chat/content/composer.tsx +21 -27
- package/src/plugins/builtin/chat/content/index.tsx +31 -3
- package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
- package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
- package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
- package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +32 -25
- package/src/plugins/builtin/congress-trades/model.ts +2 -1
- package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
- package/src/plugins/builtin/custom-view/index.tsx +1 -1
- package/src/plugins/builtin/custom-view/loader.ts +85 -8
- package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
- package/src/plugins/builtin/equity-screener/criterion-editor.tsx +13 -4
- package/src/plugins/builtin/equity-screener/headless.ts +33 -1
- package/src/plugins/builtin/equity-screener/model.ts +58 -15
- package/src/plugins/builtin/equity-screener/pane.tsx +36 -6
- package/src/plugins/builtin/executives/format.ts +5 -4
- package/src/plugins/builtin/executives/pane.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +55 -1
- package/src/plugins/builtin/insider/model.ts +30 -2
- package/src/plugins/builtin/jobs/model.ts +2 -2
- package/src/plugins/builtin/mna/model.ts +2 -2
- package/src/plugins/builtin/notes/files.ts +2 -0
- package/src/plugins/builtin/notes/owner.tsx +20 -1
- package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
- package/src/plugins/builtin/notes/store.ts +6 -1
- package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
- package/src/plugins/builtin/series-inventory.ts +1 -0
- package/src/plugins/builtin/shared/earnings-report.ts +7 -2
- package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
- package/src/plugins/builtin/short-interest/headless.ts +1 -1
- package/src/plugins/builtin/short-interest/model.ts +15 -6
- package/src/plugins/builtin/short-interest/types.ts +2 -0
- package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
- package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +5 -3
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
- package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
- package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
- package/src/plugins/builtin/trace-bonds/history.ts +155 -0
- package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
- package/src/plugins/installer.ts +16 -3
- package/src/plugins/plugin-names.ts +11 -2
- package/src/remote/controller.ts +9 -2
- package/src/remote/schema.ts +2 -1
- package/src/renderers/cloudflare/http-proxy.ts +67 -8
- package/src/renderers/cloudflare/proxy-session.ts +1 -1
- package/src/renderers/cloudflare/worker.ts +29 -2
- package/src/renderers/dom/desktop/icons.tsx +0 -2
- package/src/renderers/dom/styles.css +0 -3
- package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
- package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
- package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
- package/src/renderers/electrobun/bun/index.ts +19 -13
- package/src/renderers/electrobun/bun/window/create.ts +23 -3
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +4 -4
- package/src/renderers/electrobun/bun/window/events.ts +4 -4
- package/src/renderers/electrobun/bun/window/frame.ts +2 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +1 -1
- package/src/sources/gloomberb-cloud/index.ts +5 -7
- package/src/sources/provider-router/batches.ts +18 -3
- package/src/sources/provider-router/financials.ts +18 -4
- package/src/types/data-provider.ts +14 -0
- package/src/types/financials.ts +15 -3
- package/src/types/headless.ts +2 -0
- package/src/utils/double-escape-close.ts +38 -16
- package/src/utils/format.ts +23 -3
- package/src/utils/price-earnings.ts +18 -0
- package/patches/electrobun@1.18.1.patch +0 -633
- package/src/api-client/types.ts +0 -2441
|
@@ -1,633 +0,0 @@
|
|
|
1
|
-
diff --git a/dist/api/browser/index.ts b/dist/api/browser/index.ts
|
|
2
|
-
index 3e309b18fdbcec84a4a56f97df4debe7fb8246f8..03420222c1d9ba897835c5e7376c7153ede294fc 100644
|
|
3
|
-
--- a/dist/api/browser/index.ts
|
|
4
|
-
+++ b/dist/api/browser/index.ts
|
|
5
|
-
@@ -50,7 +50,7 @@ class Electroview<T extends RPCWithTransport> {
|
|
6
|
-
// Note: Using ws:// for localhost is intentional - all RPC messages are
|
|
7
|
-
// encrypted with per-webview AES-GCM keys, making TLS redundant
|
|
8
|
-
const socket = new WebSocket(
|
|
9
|
-
- `ws://localhost:${RPC_SOCKET_PORT}/socket?webviewId=${WEBVIEW_ID}`,
|
|
10
|
-
+ `ws://127.0.0.1:${RPC_SOCKET_PORT}/socket?webviewId=${WEBVIEW_ID}`,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
this.bunSocket = socket;
|
|
14
|
-
diff --git a/dist/api/bun/core/BrowserWindow.ts b/dist/api/bun/core/BrowserWindow.ts
|
|
15
|
-
index c26c2c977ee1fc25a8dc144b85bac8626a45f572..8920a2905380228c23cba66c20d9bfd19ee13e02 100644
|
|
16
|
-
--- a/dist/api/bun/core/BrowserWindow.ts
|
|
17
|
-
+++ b/dist/api/bun/core/BrowserWindow.ts
|
|
18
|
-
@@ -8,9 +8,18 @@ import { type RPCWithTransport } from "../../shared/rpc.js";
|
|
19
|
-
import { getNextWindowId } from "./windowIds";
|
|
20
|
-
import { GpuWindowMap } from "./GpuWindow";
|
|
21
|
-
import { WGPUView } from "./WGPUView";
|
|
22
|
-
+import { existsSync } from "fs";
|
|
23
|
-
+import { resolve } from "path";
|
|
24
|
-
|
|
25
|
-
const buildConfig = await BuildConfig.get();
|
|
26
|
-
|
|
27
|
-
+function defaultWindowIconPath(): string | null {
|
|
28
|
-
+ if (process.platform !== "win32") return null;
|
|
29
|
-
+
|
|
30
|
-
+ const iconPath = resolve("../Resources/app.ico");
|
|
31
|
-
+ return existsSync(iconPath) ? iconPath : null;
|
|
32
|
-
+}
|
|
33
|
-
+
|
|
34
|
-
export type WindowOptionsType<T = undefined> = {
|
|
35
|
-
trafficLightOffset?: {
|
|
36
|
-
x: number;
|
|
37
|
-
@@ -28,6 +37,7 @@ export type WindowOptionsType<T = undefined> = {
|
|
38
|
-
html: string | null;
|
|
39
|
-
preload: string | null;
|
|
40
|
-
viewsRoot: string | null;
|
|
41
|
-
+ iconPath?: string | null;
|
|
42
|
-
renderer: "native" | "cef";
|
|
43
|
-
rpc?: T;
|
|
44
|
-
styleMask?: {};
|
|
45
|
-
@@ -124,6 +134,7 @@ export class BrowserWindow<T extends RPCWithTransport = RPCWithTransport> {
|
|
46
|
-
html: string | null = null;
|
|
47
|
-
preload: string | null = null;
|
|
48
|
-
viewsRoot: string | null = null;
|
|
49
|
-
+ iconPath: string | null = null;
|
|
50
|
-
renderer: "native" | "cef" = "native";
|
|
51
|
-
transparent: boolean = false;
|
|
52
|
-
passthrough: boolean = false;
|
|
53
|
-
@@ -155,6 +166,7 @@ export class BrowserWindow<T extends RPCWithTransport = RPCWithTransport> {
|
|
54
|
-
this.html = options.html || null;
|
|
55
|
-
this.preload = options.preload || null;
|
|
56
|
-
this.viewsRoot = options.viewsRoot || null;
|
|
57
|
-
+ this.iconPath = options.iconPath ?? defaultWindowIconPath();
|
|
58
|
-
this.renderer = options.renderer || defaultOptions.renderer;
|
|
59
|
-
this.transparent = options.transparent ?? false;
|
|
60
|
-
this.passthrough = options.passthrough ?? false;
|
|
61
|
-
@@ -181,6 +193,7 @@ export class BrowserWindow<T extends RPCWithTransport = RPCWithTransport> {
|
|
62
|
-
id: this.id,
|
|
63
|
-
title: this.title,
|
|
64
|
-
url: this.url || "",
|
|
65
|
-
+ iconPath: this.iconPath,
|
|
66
|
-
frame: {
|
|
67
|
-
width: this.frame.width,
|
|
68
|
-
height: this.frame.height,
|
|
69
|
-
diff --git a/dist/api/bun/core/Socket.ts b/dist/api/bun/core/Socket.ts
|
|
70
|
-
index cdaa2bca0fabe577cb667056aa6f8f84211189c2..e9cdd82c934f6da58055dc8343ee3b953ec1ee81 100644
|
|
71
|
-
--- a/dist/api/bun/core/Socket.ts
|
|
72
|
-
+++ b/dist/api/bun/core/Socket.ts
|
|
73
|
-
@@ -3,13 +3,8 @@ import { BrowserView } from "./BrowserView";
|
|
74
|
-
import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
|
|
75
|
-
|
|
76
|
-
function base64ToUint8Array(base64: string) {
|
|
77
|
-
- {
|
|
78
|
-
- return new Uint8Array(
|
|
79
|
-
- atob(base64)
|
|
80
|
-
- .split("")
|
|
81
|
-
- .map((char) => char.charCodeAt(0)),
|
|
82
|
-
- );
|
|
83
|
-
- }
|
|
84
|
-
+ const bytes = Buffer.from(base64, "base64");
|
|
85
|
-
+ return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Encrypt function
|
|
89
|
-
@@ -65,6 +60,8 @@ const startRPCServer = () => {
|
|
90
|
-
while (port <= endPort) {
|
|
91
|
-
try {
|
|
92
|
-
server = Bun.serve<{ webviewId: number }>({
|
|
93
|
-
+ // Only this machine's webviews connect.
|
|
94
|
-
+ hostname: "127.0.0.1",
|
|
95
|
-
port,
|
|
96
|
-
fetch(req: Request, server: Server<{ webviewId: number }>) {
|
|
97
|
-
const url = new URL(req.url);
|
|
98
|
-
diff --git a/dist/api/bun/core/Updater.ts b/dist/api/bun/core/Updater.ts
|
|
99
|
-
index 39daf6d341780af8e30c2c50327162863f5977ec..4f3d2bef8e4b41a13a5a522c0af8dd700879a5db 100644
|
|
100
|
-
--- a/dist/api/bun/core/Updater.ts
|
|
101
|
-
+++ b/dist/api/bun/core/Updater.ts
|
|
102
|
-
@@ -132,6 +132,19 @@ let updateInfo: {
|
|
103
|
-
error: string;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
+// Where updates are fetched from when it is not the channel and baseUrl that
|
|
107
|
-
+// version.json names. Only the download URLs read it: the app data folder and
|
|
108
|
-
+// the "dev" check keep the installed build's own channel.
|
|
109
|
-
+let updateSource: { channel: string; baseUrl: string } | null = null;
|
|
110
|
-
+
|
|
111
|
-
+function updateSourceChannel(): string {
|
|
112
|
-
+ return updateSource?.channel ?? localInfo.channel;
|
|
113
|
-
+}
|
|
114
|
-
+
|
|
115
|
-
+function updateSourceBaseUrl(): string {
|
|
116
|
-
+ return updateSource?.baseUrl ?? localInfo.baseUrl;
|
|
117
|
-
+}
|
|
118
|
-
+
|
|
119
|
-
function cleanupExtractionFolder(
|
|
120
|
-
extractionFolder: string,
|
|
121
|
-
keepTarHash: string,
|
|
122
|
-
@@ -158,6 +171,54 @@ function cleanupExtractionFolder(
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
+/**
|
|
127
|
-
+ * Where the running app goes while the new one moves in: `<app>.previous`, or,
|
|
128
|
-
+ * when an older one is still there and cannot be removed (a bundle another
|
|
129
|
-
+ * user owns), a name of its own, so a copy left behind once never blocks
|
|
130
|
-
+ * every later update. The app removes the copies it left at its next start.
|
|
131
|
-
+ */
|
|
132
|
-
+function updateAsidePath(appPath: string): string {
|
|
133
|
-
+ const previous = `${appPath}.previous`;
|
|
134
|
-
+ if (!statSync(previous, { throwIfNoEntry: false })) return previous;
|
|
135
|
-
+ try {
|
|
136
|
-
+ rmSync(previous, { recursive: true, force: true });
|
|
137
|
-
+ } catch (e) {
|
|
138
|
-
+ // Left for the next start to remove; this update takes another name.
|
|
139
|
-
+ }
|
|
140
|
-
+ if (!statSync(previous, { throwIfNoEntry: false })) return previous;
|
|
141
|
-
+ for (let attempt = 0; ; attempt += 1) {
|
|
142
|
-
+ const unique = `${previous}-${Date.now().toString(36)}${attempt ? `-${attempt}` : ""}`;
|
|
143
|
-
+ if (!statSync(unique, { throwIfNoEntry: false })) return unique;
|
|
144
|
-
+ }
|
|
145
|
-
+}
|
|
146
|
-
+
|
|
147
|
-
+/**
|
|
148
|
-
+ * Puts the new app where the running one is. The running app is moved aside
|
|
149
|
-
+ * rather than deleted first, so a move that fails (another volume, a
|
|
150
|
-
+ * read-only one, no permission) puts it back instead of leaving no app at all.
|
|
151
|
-
+ * The copy moved aside is removed when it can be; one that cannot goes at the
|
|
152
|
-
+ * app's next start.
|
|
153
|
-
+ */
|
|
154
|
-
+function replaceAppBundle(runningAppPath: string, newAppPath: string) {
|
|
155
|
-
+ const hadRunningApp = !!statSync(runningAppPath, { throwIfNoEntry: false });
|
|
156
|
-
+ const asidePath = hadRunningApp ? updateAsidePath(runningAppPath) : null;
|
|
157
|
-
+ if (asidePath) renameSync(runningAppPath, asidePath);
|
|
158
|
-
+
|
|
159
|
-
+ emitStatus("replacing-app", "Installing new version...");
|
|
160
|
-
+ try {
|
|
161
|
-
+ renameSync(newAppPath, runningAppPath);
|
|
162
|
-
+ } catch (error) {
|
|
163
|
-
+ if (asidePath) renameSync(asidePath, runningAppPath);
|
|
164
|
-
+ throw error;
|
|
165
|
-
+ }
|
|
166
|
-
+ if (!asidePath) return;
|
|
167
|
-
+ try {
|
|
168
|
-
+ rmSync(asidePath, { recursive: true, force: true });
|
|
169
|
-
+ } catch (e) {
|
|
170
|
-
+ // The new app is in place; the app removes the old copy at its next start.
|
|
171
|
-
+ }
|
|
172
|
-
+}
|
|
173
|
-
+
|
|
174
|
-
const Updater = {
|
|
175
|
-
updateInfo: () => {
|
|
176
|
-
return updateInfo;
|
|
177
|
-
@@ -176,6 +237,12 @@ const Updater = {
|
|
178
|
-
onStatusChangeCallback = callback;
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
+ // Checks and downloads from `source` (a channel prefix and the URL its
|
|
182
|
-
+ // files sit under) until it is set again; null goes back to version.json.
|
|
183
|
-
+ setUpdateSource: (source: { channel: string; baseUrl: string } | null) => {
|
|
184
|
-
+ updateSource = source;
|
|
185
|
-
+ },
|
|
186
|
-
+
|
|
187
|
-
// todo: allow switching channels, by default will check the current channel
|
|
188
|
-
checkForUpdate: async () => {
|
|
189
|
-
emitStatus("checking", "Checking for updates...");
|
|
190
|
-
@@ -196,11 +263,11 @@ const Updater = {
|
|
191
|
-
|
|
192
|
-
const cacheBuster = Math.random().toString(36).substring(7);
|
|
193
|
-
const platformPrefix = getPlatformPrefix(
|
|
194
|
-
- localInfo.channel,
|
|
195
|
-
+ updateSourceChannel(),
|
|
196
|
-
currentOS,
|
|
197
|
-
currentArch,
|
|
198
|
-
);
|
|
199
|
-
- const updateInfoUrl = `${localInfo.baseUrl.replace(/\/+$/, "")}/${platformPrefix}-update.json?${cacheBuster}`;
|
|
200
|
-
+ const updateInfoUrl = `${updateSourceBaseUrl().replace(/\/+$/, "")}/${platformPrefix}-update.json?${cacheBuster}`;
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
const updateInfoResponse = await fetch(updateInfoUrl);
|
|
204
|
-
@@ -329,11 +396,11 @@ const Updater = {
|
|
205
|
-
|
|
206
|
-
// check if there's a patch file for it
|
|
207
|
-
const platformPrefix = getPlatformPrefix(
|
|
208
|
-
- localInfo.channel,
|
|
209
|
-
+ updateSourceChannel(),
|
|
210
|
-
currentOS,
|
|
211
|
-
currentArch,
|
|
212
|
-
);
|
|
213
|
-
- const patchUrl = `${localInfo.baseUrl.replace(/\/+$/, "")}/${platformPrefix}-${currentHash}.patch`;
|
|
214
|
-
+ const patchUrl = `${updateSourceBaseUrl().replace(/\/+$/, "")}/${platformPrefix}-${currentHash}.patch`;
|
|
215
|
-
emitStatus(
|
|
216
|
-
"fetching-patch",
|
|
217
|
-
`Checking for patch: ${currentHash.slice(0, 8)}`,
|
|
218
|
-
@@ -498,11 +565,25 @@ const Updater = {
|
|
219
|
-
// - macOS/Windows: Resources/version.json (inside the app bundle directory)
|
|
220
|
-
// - Linux: metadata.json (alongside the app bundle)
|
|
221
|
-
const resourcesDir = "Resources";
|
|
222
|
-
- const patchedTarBytes = await Bun.file(
|
|
223
|
-
- tmpPatchedTarFilePath,
|
|
224
|
-
- ).arrayBuffer();
|
|
225
|
-
- const patchedArchive = new Bun.Archive(patchedTarBytes);
|
|
226
|
-
- const patchedFiles = await patchedArchive.files();
|
|
227
|
-
+ let patchedFiles: Map<string, File>;
|
|
228
|
-
+ try {
|
|
229
|
-
+ const patchedTarBytes = await Bun.file(
|
|
230
|
-
+ tmpPatchedTarFilePath,
|
|
231
|
-
+ ).arrayBuffer();
|
|
232
|
-
+ const patchedArchive = new Bun.Archive(patchedTarBytes);
|
|
233
|
-
+ patchedFiles = await patchedArchive.files();
|
|
234
|
-
+ } catch (error) {
|
|
235
|
-
+ // bspatch does not check what it patches: from a damaged tar it
|
|
236
|
-
+ // makes one that does not read, and would at every retry. The
|
|
237
|
-
+ // full download replaces both.
|
|
238
|
-
+ const message = error instanceof Error ? error.message : String(error);
|
|
239
|
-
+ emitStatus("patch-failed", `Patched tar does not read: ${message}`, {
|
|
240
|
-
+ currentHash,
|
|
241
|
-
+ errorMessage: message,
|
|
242
|
-
+ });
|
|
243
|
-
+ console.error("patched tar does not read", error);
|
|
244
|
-
+ break;
|
|
245
|
-
+ }
|
|
246
|
-
|
|
247
|
-
for (const [filePath] of patchedFiles) {
|
|
248
|
-
if (
|
|
249
|
-
@@ -528,8 +609,11 @@ const Updater = {
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const hashFile = patchedFiles.get(hashFilePath);
|
|
253
|
-
- const hashFileJson = JSON.parse(await hashFile!.text());
|
|
254
|
-
- const nextHash = hashFileJson.hash;
|
|
255
|
-
+ // Unreadable, it has no hash below and the full download follows.
|
|
256
|
-
+ const nextHash: string = await hashFile!
|
|
257
|
-
+ .text()
|
|
258
|
-
+ .then((text) => JSON.parse(text)?.hash)
|
|
259
|
-
+ .catch(() => "");
|
|
260
|
-
|
|
261
|
-
if (seenHashes.includes(nextHash)) {
|
|
262
|
-
emitStatus(
|
|
263
|
-
@@ -612,12 +696,12 @@ const Updater = {
|
|
264
|
-
|
|
265
|
-
const cacheBuster = Math.random().toString(36).substring(7);
|
|
266
|
-
const platformPrefix = getPlatformPrefix(
|
|
267
|
-
- localInfo.channel,
|
|
268
|
-
+ updateSourceChannel(),
|
|
269
|
-
currentOS,
|
|
270
|
-
currentArch,
|
|
271
|
-
);
|
|
272
|
-
const tarballName = getTarballFileName(appFileName, currentOS);
|
|
273
|
-
- const urlToLatestTarball = `${localInfo.baseUrl.replace(/\/+$/, "")}/${platformPrefix}-${tarballName}`;
|
|
274
|
-
+ const urlToLatestTarball = `${updateSourceBaseUrl().replace(/\/+$/, "")}/${platformPrefix}-${tarballName}`;
|
|
275
|
-
const prevVersionCompressedTarballPath = join(
|
|
276
|
-
appDataFolder,
|
|
277
|
-
"self-extraction",
|
|
278
|
-
@@ -689,6 +773,13 @@ const Updater = {
|
|
279
|
-
emitStatus("error", updateInfo.error, { zstdPath });
|
|
280
|
-
console.error("zig-zstd not found:", zstdPath);
|
|
281
|
-
} else {
|
|
282
|
-
+ // Into a name of its own, renamed once whole: zig-zstd writes as
|
|
283
|
-
+ // it goes, and a run that failed (a download cut short) or never
|
|
284
|
-
+ // finished (the app quit) left part of a tar under the update's
|
|
285
|
-
+ // own name, which every later download took as done and every
|
|
286
|
-
+ // install then failed to unpack.
|
|
287
|
-
+ const partialTarPath = `${latestTarPath}.partial`;
|
|
288
|
-
+ rmSync(partialTarPath, { force: true });
|
|
289
|
-
const decompressResult = Bun.spawnSync(
|
|
290
|
-
[
|
|
291
|
-
zstdPath,
|
|
292
|
-
@@ -696,7 +787,7 @@ const Updater = {
|
|
293
|
-
"-i",
|
|
294
|
-
prevVersionCompressedTarballPath,
|
|
295
|
-
"-o",
|
|
296
|
-
- latestTarPath,
|
|
297
|
-
+ partialTarPath,
|
|
298
|
-
"--no-timing",
|
|
299
|
-
],
|
|
300
|
-
{
|
|
301
|
-
@@ -706,6 +797,7 @@ const Updater = {
|
|
302
|
-
},
|
|
303
|
-
);
|
|
304
|
-
if (!decompressResult.success) {
|
|
305
|
-
+ rmSync(partialTarPath, { force: true });
|
|
306
|
-
updateInfo.error = `zig-zstd failed with exit code ${decompressResult.exitCode}`;
|
|
307
|
-
emitStatus("error", updateInfo.error, {
|
|
308
|
-
zstdPath,
|
|
309
|
-
@@ -716,6 +808,7 @@ const Updater = {
|
|
310
|
-
zstdPath,
|
|
311
|
-
});
|
|
312
|
-
} else {
|
|
313
|
-
+ renameSync(partialTarPath, latestTarPath);
|
|
314
|
-
emitStatus("decompressing", "Decompression complete");
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
@@ -731,6 +824,8 @@ const Updater = {
|
|
318
|
-
// check for patch from that tar and apply it, until it matches the latest version
|
|
319
|
-
// as a fallback it should just download and unpack the latest version
|
|
320
|
-
updateInfo.updateReady = true;
|
|
321
|
-
+ // What failed on the way (a patch that did not apply) was recovered from.
|
|
322
|
-
+ updateInfo.error = "";
|
|
323
|
-
emitStatus(
|
|
324
|
-
"download-complete",
|
|
325
|
-
`Update ready to install (used ${usedPatchPath ? "patch" : "full download"} path)`,
|
|
326
|
-
@@ -741,7 +836,8 @@ const Updater = {
|
|
327
|
-
},
|
|
328
|
-
);
|
|
329
|
-
} else {
|
|
330
|
-
- updateInfo.error = "Failed to download latest version";
|
|
331
|
-
+ // Why it failed (zig-zstd's exit), when that is known.
|
|
332
|
-
+ if (!updateInfo.error) updateInfo.error = "Failed to download latest version";
|
|
333
|
-
emitStatus("error", "Failed to download latest version", { latestHash });
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
@@ -760,7 +856,12 @@ const Updater = {
|
|
337
|
-
mkdirSync(extractionFolder, { recursive: true });
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
- let latestHash = (await Updater.checkForUpdate()).hash;
|
|
341
|
-
+ // Install the build that was downloaded. Checking again here fetched
|
|
342
|
-
+ // the newest manifest instead: once a newer release was out (or the
|
|
343
|
-
+ // check failed offline) its tar was not there and the install
|
|
344
|
-
+ // returned without a word, so a download waiting for a restart could
|
|
345
|
-
+ // never be installed.
|
|
346
|
-
+ let latestHash = updateInfo.hash;
|
|
347
|
-
const latestTarPath = join(extractionFolder, `${latestHash}.tar`);
|
|
348
|
-
|
|
349
|
-
let appBundleSubpath: string = "";
|
|
350
|
-
@@ -782,9 +883,26 @@ const Updater = {
|
|
351
|
-
mkdirSync(extractionDir, { recursive: true });
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
- const latestTarBytes = await Bun.file(latestTarPath).arrayBuffer();
|
|
355
|
-
- const latestArchive = new Bun.Archive(latestTarBytes);
|
|
356
|
-
- await latestArchive.extract(extractionDir);
|
|
357
|
-
+ try {
|
|
358
|
-
+ const latestTarBytes = await Bun.file(latestTarPath).arrayBuffer();
|
|
359
|
-
+ const latestArchive = new Bun.Archive(latestTarBytes);
|
|
360
|
-
+ await latestArchive.extract(extractionDir);
|
|
361
|
-
+ } catch (error) {
|
|
362
|
-
+ // The tar goes, with what it unpacked: left in place, every later
|
|
363
|
-
+ // download took it as the update again and every install failed
|
|
364
|
-
+ // here the same way. The next download fetches a fresh copy.
|
|
365
|
-
+ const message = `Failed to extract update: ${error instanceof Error ? error.message : String(error)}`;
|
|
366
|
-
+ try {
|
|
367
|
-
+ rmSync(latestTarPath, { force: true });
|
|
368
|
-
+ } catch (e) {
|
|
369
|
-
+ // Best effort, like the cleanup below.
|
|
370
|
-
+ }
|
|
371
|
-
+ cleanupExtractionFolder(extractionFolder, latestHash);
|
|
372
|
-
+ updateInfo.updateReady = false;
|
|
373
|
-
+ emitStatus("error", message, { errorMessage: message });
|
|
374
|
-
+ console.error("Failed to extract update", error);
|
|
375
|
-
+ return;
|
|
376
|
-
+ }
|
|
377
|
-
|
|
378
|
-
if (currentOS === "macos") {
|
|
379
|
-
// Find the .app bundle by scanning extracted directory
|
|
380
|
-
@@ -894,14 +1012,7 @@ const Updater = {
|
|
381
|
-
emitStatus("replacing-app", "Removing old version...");
|
|
382
|
-
|
|
383
|
-
if (currentOS === "macos") {
|
|
384
|
-
- // Remove existing app before installing the new one
|
|
385
|
-
- if (statSync(runningAppBundlePath, { throwIfNoEntry: false })) {
|
|
386
|
-
- rmSync(runningAppBundlePath, { recursive: true });
|
|
387
|
-
- }
|
|
388
|
-
-
|
|
389
|
-
- emitStatus("replacing-app", "Installing new version...");
|
|
390
|
-
- // Move new app to running location
|
|
391
|
-
- renameSync(newAppBundlePath, runningAppBundlePath);
|
|
392
|
-
+ replaceAppBundle(runningAppBundlePath, newAppBundlePath);
|
|
393
|
-
|
|
394
|
-
// Remove quarantine extended attributes to prevent "damaged" error
|
|
395
|
-
// The inner bundle is already signed/notarized, but macOS applies
|
|
396
|
-
@@ -918,14 +1029,7 @@ const Updater = {
|
|
397
|
-
// On Linux, we now have directory bundles instead of AppImage files
|
|
398
|
-
// The app is stored in {appDataFolder}/app/
|
|
399
|
-
const appBundleDir = join(appDataFolder, "app");
|
|
400
|
-
-
|
|
401
|
-
- // Remove existing app directory if it exists
|
|
402
|
-
- if (statSync(appBundleDir, { throwIfNoEntry: false })) {
|
|
403
|
-
- rmSync(appBundleDir, { recursive: true });
|
|
404
|
-
- }
|
|
405
|
-
-
|
|
406
|
-
- // Move new app bundle directory to app location
|
|
407
|
-
- renameSync(newAppBundlePath, appBundleDir);
|
|
408
|
-
+ replaceAppBundle(appBundleDir, newAppBundlePath);
|
|
409
|
-
|
|
410
|
-
// Ensure launcher binary is executable
|
|
411
|
-
const launcherPath = join(appBundleDir, "bin", "launcher");
|
|
412
|
-
@@ -1071,14 +1175,18 @@ del "%~f0"
|
|
413
|
-
// current process has exited first. The detached shell survives our
|
|
414
|
-
// exit and polls until the process is gone.
|
|
415
|
-
const pid = process.pid;
|
|
416
|
-
+ // The shell, sleep and open by their full paths, from /: a terminal
|
|
417
|
-
+ // launch can hand the app a PATH without them, and a spawn into a
|
|
418
|
-
+ // folder that is gone fails as if the shell were missing.
|
|
419
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
420
|
-
Bun.spawn(
|
|
421
|
-
[
|
|
422
|
-
- "sh",
|
|
423
|
-
+ "/bin/sh",
|
|
424
|
-
"-c",
|
|
425
|
-
- `while kill -0 ${pid} 2>/dev/null; do sleep 0.5; done; sleep 1; open "${runningAppBundlePath}"`,
|
|
426
|
-
+ `while kill -0 ${pid} 2>/dev/null; do /bin/sleep 0.5; done; /bin/sleep 1; /usr/bin/open "${runningAppBundlePath}"`,
|
|
427
|
-
],
|
|
428
|
-
{
|
|
429
|
-
+ cwd: "/",
|
|
430
|
-
detached: true,
|
|
431
|
-
stdio: ["ignore", "ignore", "ignore"],
|
|
432
|
-
} as any,
|
|
433
|
-
@@ -1087,7 +1195,8 @@ del "%~f0"
|
|
434
|
-
// On Linux, launch the launcher binary inside the app directory
|
|
435
|
-
const launcherPath = join(runningAppBundlePath, "bin", "launcher");
|
|
436
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
437
|
-
- Bun.spawn(["sh", "-c", `"${launcherPath}" &`], {
|
|
438
|
-
+ Bun.spawn(["/bin/sh", "-c", `"${launcherPath}" &`], {
|
|
439
|
-
+ cwd: "/",
|
|
440
|
-
detached: true,
|
|
441
|
-
} as any);
|
|
442
|
-
}
|
|
443
|
-
diff --git a/dist/api/bun/preload/.generated/compiled.ts b/dist/api/bun/preload/.generated/compiled.ts
|
|
444
|
-
index 3ab1d7d8de8938ae60823650fd3a29b952a76cb6..e0e841e6a87ce41533c6bdda8d29400aaf478e31 100644
|
|
445
|
-
--- a/dist/api/bun/preload/.generated/compiled.ts
|
|
446
|
-
+++ b/dist/api/bun/preload/.generated/compiled.ts
|
|
447
|
-
@@ -2,7 +2,7 @@
|
|
448
|
-
// Run "bun build.ts" or "bun build:dev" from the package folder to regenerate.
|
|
449
|
-
|
|
450
|
-
// Full preload for trusted webviews (RPC, encryption, drag regions, webview tags)
|
|
451
|
-
-export const preloadScript = "(function(){// src/bun/preload/encryption.ts\nfunction base64ToUint8Array(base64) {\n return new Uint8Array(atob(base64).split(\"\").map((char) => char.charCodeAt(0)));\n}\nfunction uint8ArrayToBase64(uint8Array) {\n let binary = \"\";\n for (let i = 0;i < uint8Array.length; i++) {\n binary += String.fromCharCode(uint8Array[i]);\n }\n return btoa(binary);\n}\nasync function generateKeyFromBytes(rawKey) {\n return await window.crypto.subtle.importKey(\"raw\", rawKey, { name: \"AES-GCM\" }, true, [\"encrypt\", \"decrypt\"]);\n}\nasync function initEncryption() {\n const secretKey = await generateKeyFromBytes(new Uint8Array(window.__electrobunSecretKeyBytes));\n const encryptString = async (plaintext) => {\n const encoder = new TextEncoder;\n const encodedText = encoder.encode(plaintext);\n const iv = window.crypto.getRandomValues(new Uint8Array(12));\n const encryptedBuffer = await window.crypto.subtle.encrypt({ name: \"AES-GCM\", iv }, secretKey, encodedText);\n const encryptedData = new Uint8Array(encryptedBuffer.slice(0, -16));\n const tag = new Uint8Array(encryptedBuffer.slice(-16));\n return {\n encryptedData: uint8ArrayToBase64(encryptedData),\n iv: uint8ArrayToBase64(iv),\n tag: uint8ArrayToBase64(tag)\n };\n };\n const decryptString = async (encryptedDataB64, ivB64, tagB64) => {\n const encryptedData = base64ToUint8Array(encryptedDataB64);\n const iv = base64ToUint8Array(ivB64);\n const tag = base64ToUint8Array(tagB64);\n const combinedData = new Uint8Array(encryptedData.length + tag.length);\n combinedData.set(encryptedData);\n combinedData.set(tag, encryptedData.length);\n const decryptedBuffer = await window.crypto.subtle.decrypt({ name: \"AES-GCM\", iv }, secretKey, combinedData);\n const decoder = new TextDecoder;\n return decoder.decode(decryptedBuffer);\n };\n window.__electrobun_encrypt = encryptString;\n window.__electrobun_decrypt = decryptString;\n}\n\n// src/bun/preload/internalRpc.ts\nvar pendingRequests = {};\nvar requestId = 0;\nvar isProcessingQueue = false;\nvar sendQueue = [];\nfunction processQueue() {\n if (isProcessingQueue) {\n setTimeout(processQueue);\n return;\n }\n if (sendQueue.length === 0)\n return;\n isProcessingQueue = true;\n const batch = JSON.stringify(sendQueue);\n sendQueue.length = 0;\n window.__electrobunInternalBridge?.postMessage(batch);\n setTimeout(() => {\n isProcessingQueue = false;\n }, 2);\n}\nfunction send(type, payload) {\n sendQueue.push(JSON.stringify({ type: \"message\", id: type, payload }));\n processQueue();\n}\nfunction request(type, payload) {\n return new Promise((resolve, reject) => {\n const id = `req_${++requestId}_${Date.now()}`;\n pendingRequests[id] = { resolve, reject };\n sendQueue.push(JSON.stringify({\n type: \"request\",\n method: type,\n id,\n params: payload,\n hostWebviewId: window.__electrobunWebviewId\n }));\n processQueue();\n setTimeout(() => {\n if (pendingRequests[id]) {\n delete pendingRequests[id];\n reject(new Error(`Request timeout: ${type}`));\n }\n }, 1e4);\n });\n}\nfunction handleResponse(msg) {\n if (msg && msg.type === \"response\" && msg.id) {\n const pending = pendingRequests[msg.id];\n if (pending) {\n delete pendingRequests[msg.id];\n if (msg.success)\n pending.resolve(msg.payload);\n else\n pending.reject(msg.payload);\n }\n }\n}\n\n// src/bun/preload/dragRegions.ts\nfunction isAppRegionDrag(e) {\n const target = e.target;\n if (!target || !target.closest)\n return false;\n if (target.closest(\".electrobun-webkit-app-region-no-drag\") || target.closest('[style*=\"app-region\"][style*=\"no-drag\"]')) {\n return false;\n }\n const draggableByStyle = target.closest('[style*=\"app-region\"][style*=\"drag\"]');\n const draggableByClass = target.closest(\".electrobun-webkit-app-region-drag\");\n return !!(draggableByStyle || draggableByClass);\n}\nfunction initDragRegions() {\n document.addEventListener(\"mousedown\", (e) => {\n if (isAppRegionDrag(e)) {\n send(\"startWindowMove\", { id: window.__electrobunWindowId });\n }\n });\n document.addEventListener(\"mouseup\", (e) => {\n if (isAppRegionDrag(e)) {\n send(\"stopWindowMove\", { id: window.__electrobunWindowId });\n }\n });\n}\n\n// src/bun/preload/overlaySync.ts\nclass OverlaySyncController {\n element;\n options;\n lastRect = { x: 0, y: 0, width: 0, height: 0 };\n resizeObserver = null;\n positionLoop = null;\n resizeHandler = null;\n burstUntil = 0;\n constructor(element, options) {\n this.element = element;\n this.options = {\n onSync: options.onSync,\n getMasks: options.getMasks ?? (() => []),\n burstIntervalMs: options.burstIntervalMs ?? 50,\n baseIntervalMs: options.baseIntervalMs ?? 100,\n burstDurationMs: options.burstDurationMs ?? 500\n };\n }\n start() {\n this.resizeObserver = new ResizeObserver(() => this.sync());\n this.resizeObserver.observe(this.element);\n const loop = () => {\n this.sync();\n const now = performance.now();\n const interval = now < this.burstUntil ? this.options.burstIntervalMs : this.options.baseIntervalMs;\n this.positionLoop = setTimeout(loop, interval);\n };\n this.positionLoop = setTimeout(loop, this.options.baseIntervalMs);\n this.resizeHandler = () => this.sync(true);\n window.addEventListener(\"resize\", this.resizeHandler);\n }\n stop() {\n if (this.resizeObserver)\n this.resizeObserver.disconnect();\n if (this.positionLoop)\n clearTimeout(this.positionLoop);\n if (this.resizeHandler) {\n window.removeEventListener(\"resize\", this.resizeHandler);\n }\n this.resizeObserver = null;\n this.positionLoop = null;\n this.resizeHandler = null;\n }\n forceSync() {\n this.sync(true);\n }\n setLastRect(rect) {\n this.lastRect = rect;\n }\n sync(force = false) {\n const rect = this.element.getBoundingClientRect();\n const newRect = {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n };\n if (newRect.width === 0 && newRect.height === 0) {\n return;\n }\n if (!force && newRect.x === this.lastRect.x && newRect.y === this.lastRect.y && newRect.width === this.lastRect.width && newRect.height === this.lastRect.height) {\n return;\n }\n this.burstUntil = performance.now() + this.options.burstDurationMs;\n this.lastRect = newRect;\n const masks = this.options.getMasks();\n this.options.onSync(newRect, JSON.stringify(masks));\n }\n}\n\n// src/bun/preload/webviewTag.ts\nvar webviewRegistry = {};\n\nclass ElectrobunWebviewTag extends HTMLElement {\n webviewId = null;\n maskSelectors = new Set;\n _sync = null;\n transparent = false;\n passthroughEnabled = false;\n hidden = false;\n sandboxed = false;\n _eventListeners = {};\n static get observedAttributes() {\n return [\"src\", \"html\"];\n }\n constructor() {\n super();\n }\n connectedCallback() {\n requestAnimationFrame(() => this.initWebview());\n }\n attributeChangedCallback(name, oldValue, newValue) {\n if (oldValue === newValue)\n return;\n if (newValue === null)\n return;\n if (this.webviewId === null)\n return;\n if (name === \"src\")\n this.loadURL(newValue);\n else if (name === \"html\")\n this.loadHTML(newValue);\n }\n disconnectedCallback() {\n if (this.webviewId !== null) {\n send(\"webviewTagRemove\", { id: this.webviewId });\n delete webviewRegistry[this.webviewId];\n }\n if (this._sync)\n this._sync.stop();\n }\n async initWebview() {\n const rect = this.getBoundingClientRect();\n const initialRect = {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n };\n const url = this.getAttribute(\"src\");\n const html = this.getAttribute(\"html\");\n const preload = this.getAttribute(\"preload\");\n const partition = this.getAttribute(\"partition\");\n const renderer = this.getAttribute(\"renderer\") || \"native\";\n const masks = this.getAttribute(\"masks\");\n const sandbox = this.hasAttribute(\"sandbox\");\n this.sandboxed = sandbox;\n const transparent = this.hasAttribute(\"transparent\");\n const passthrough = this.hasAttribute(\"passthrough\");\n this.transparent = transparent;\n this.passthroughEnabled = passthrough;\n if (transparent)\n this.style.opacity = \"0\";\n if (passthrough)\n this.style.pointerEvents = \"none\";\n if (masks) {\n masks.split(\",\").forEach((s) => this.maskSelectors.add(s.trim()));\n }\n try {\n const webviewId = await request(\"webviewTagInit\", {\n hostWebviewId: window.__electrobunWebviewId,\n windowId: window.__electrobunWindowId,\n renderer,\n url,\n html,\n preload,\n partition,\n frame: {\n width: rect.width,\n height: rect.height,\n x: rect.x,\n y: rect.y\n },\n navigationRules: null,\n sandbox,\n transparent,\n passthrough\n });\n this.webviewId = webviewId;\n this.id = `electrobun-webview-${webviewId}`;\n webviewRegistry[webviewId] = this;\n this.setupObservers(initialRect);\n this.syncDimensions(true);\n requestAnimationFrame(() => {\n Object.values(webviewRegistry).forEach((webview) => {\n if (webview !== this && webview.webviewId !== null) {\n webview.syncDimensions(true);\n }\n });\n });\n } catch (err) {\n console.error(\"Failed to init webview:\", err);\n }\n }\n setupObservers(initialRect) {\n const getMasks = () => {\n const rect = this.getBoundingClientRect();\n const masks = [];\n this.maskSelectors.forEach((selector) => {\n try {\n document.querySelectorAll(selector).forEach((el) => {\n const mr = el.getBoundingClientRect();\n masks.push({\n x: mr.x - rect.x,\n y: mr.y - rect.y,\n width: mr.width,\n height: mr.height\n });\n });\n } catch (_e) {}\n });\n return masks;\n };\n this._sync = new OverlaySyncController(this, {\n onSync: (rect, masksJson) => {\n if (this.webviewId === null)\n return;\n send(\"webviewTagResize\", {\n id: this.webviewId,\n frame: rect,\n masks: masksJson\n });\n },\n getMasks,\n burstIntervalMs: 10,\n baseIntervalMs: 100,\n burstDurationMs: 50\n });\n this._sync.setLastRect(initialRect);\n this._sync.start();\n }\n syncDimensions(force = false) {\n if (!this._sync)\n return;\n if (force) {\n this._sync.forceSync();\n }\n }\n loadURL(url) {\n if (this.webviewId === null)\n return;\n this.setAttribute(\"src\", url);\n send(\"webviewTagUpdateSrc\", { id: this.webviewId, url });\n }\n loadHTML(html) {\n if (this.webviewId === null)\n return;\n send(\"webviewTagUpdateHtml\", { id: this.webviewId, html });\n }\n reload() {\n if (this.webviewId !== null)\n send(\"webviewTagReload\", { id: this.webviewId });\n }\n goBack() {\n if (this.webviewId !== null)\n send(\"webviewTagGoBack\", { id: this.webviewId });\n }\n goForward() {\n if (this.webviewId !== null)\n send(\"webviewTagGoForward\", { id: this.webviewId });\n }\n async canGoBack() {\n if (this.webviewId === null)\n return false;\n return await request(\"webviewTagCanGoBack\", {\n id: this.webviewId\n });\n }\n async canGoForward() {\n if (this.webviewId === null)\n return false;\n return await request(\"webviewTagCanGoForward\", {\n id: this.webviewId\n });\n }\n toggleTransparent(value) {\n if (this.webviewId === null)\n return;\n this.transparent = value !== undefined ? value : !this.transparent;\n this.style.opacity = this.transparent ? \"0\" : \"\";\n send(\"webviewTagSetTransparent\", {\n id: this.webviewId,\n transparent: this.transparent\n });\n }\n togglePassthrough(value) {\n if (this.webviewId === null)\n return;\n this.passthroughEnabled = value !== undefined ? value : !this.passthroughEnabled;\n this.style.pointerEvents = this.passthroughEnabled ? \"none\" : \"\";\n send(\"webviewTagSetPassthrough\", {\n id: this.webviewId,\n enablePassthrough: this.passthroughEnabled\n });\n }\n toggleHidden(value) {\n if (this.webviewId === null)\n return;\n this.hidden = value !== undefined ? value : !this.hidden;\n send(\"webviewTagSetHidden\", { id: this.webviewId, hidden: this.hidden });\n }\n addMaskSelector(selector) {\n this.maskSelectors.add(selector);\n this.syncDimensions(true);\n }\n removeMaskSelector(selector) {\n this.maskSelectors.delete(selector);\n this.syncDimensions(true);\n }\n setNavigationRules(rules) {\n if (this.webviewId !== null) {\n send(\"webviewTagSetNavigationRules\", { id: this.webviewId, rules });\n }\n }\n findInPage(searchText, options) {\n if (this.webviewId === null)\n return;\n const forward = options?.forward !== false;\n const matchCase = options?.matchCase || false;\n send(\"webviewTagFindInPage\", {\n id: this.webviewId,\n searchText,\n forward,\n matchCase\n });\n }\n stopFindInPage() {\n if (this.webviewId !== null)\n send(\"webviewTagStopFind\", { id: this.webviewId });\n }\n openDevTools() {\n if (this.webviewId !== null)\n send(\"webviewTagOpenDevTools\", { id: this.webviewId });\n }\n closeDevTools() {\n if (this.webviewId !== null)\n send(\"webviewTagCloseDevTools\", { id: this.webviewId });\n }\n toggleDevTools() {\n if (this.webviewId !== null)\n send(\"webviewTagToggleDevTools\", { id: this.webviewId });\n }\n executeJavascript(js) {\n if (this.webviewId === null)\n return;\n send(\"webviewTagExecuteJavascript\", { id: this.webviewId, js });\n }\n on(event, listener) {\n if (!this._eventListeners[event])\n this._eventListeners[event] = [];\n this._eventListeners[event].push(listener);\n }\n off(event, listener) {\n if (!this._eventListeners[event])\n return;\n const idx = this._eventListeners[event].indexOf(listener);\n if (idx !== -1)\n this._eventListeners[event].splice(idx, 1);\n }\n emit(event, detail) {\n const listeners = this._eventListeners[event];\n if (listeners) {\n const customEvent = new CustomEvent(event, { detail });\n listeners.forEach((fn) => fn(customEvent));\n }\n }\n get src() {\n return this.getAttribute(\"src\");\n }\n set src(value) {\n if (value) {\n this.setAttribute(\"src\", value);\n } else {\n this.removeAttribute(\"src\");\n }\n }\n get html() {\n return this.getAttribute(\"html\");\n }\n set html(value) {\n if (value) {\n this.setAttribute(\"html\", value);\n } else {\n this.removeAttribute(\"html\");\n }\n }\n get preload() {\n return this.getAttribute(\"preload\");\n }\n set preload(value) {\n if (value)\n this.setAttribute(\"preload\", value);\n else\n this.removeAttribute(\"preload\");\n }\n get renderer() {\n return this.getAttribute(\"renderer\") || \"native\";\n }\n set renderer(value) {\n this.setAttribute(\"renderer\", value);\n }\n get sandbox() {\n return this.sandboxed;\n }\n}\nfunction initWebviewTag() {\n if (!customElements.get(\"electrobun-webview\")) {\n customElements.define(\"electrobun-webview\", ElectrobunWebviewTag);\n }\n const injectStyles = () => {\n const style = document.createElement(\"style\");\n style.textContent = `\nelectrobun-webview {\n\tdisplay: block;\n\twidth: 800px;\n\theight: 300px;\n\tbackground: #fff;\n\tbackground-repeat: no-repeat !important;\n\toverflow: hidden;\n}\n`;\n if (document.head?.firstChild) {\n document.head.insertBefore(style, document.head.firstChild);\n } else if (document.head) {\n document.head.appendChild(style);\n }\n };\n if (document.head) {\n injectStyles();\n } else {\n document.addEventListener(\"DOMContentLoaded\", injectStyles);\n }\n}\n\n// src/bun/preload/wgpuTag.ts\nvar wgpuTagRegistry = {};\n\nclass ElectrobunWgpuTag extends HTMLElement {\n wgpuViewId = null;\n maskSelectors = new Set;\n _sync = null;\n transparent = false;\n passthroughEnabled = false;\n hidden = false;\n _eventListeners = {};\n constructor() {\n super();\n }\n connectedCallback() {\n requestAnimationFrame(() => this.initWgpuView());\n }\n disconnectedCallback() {\n if (this.wgpuViewId !== null) {\n send(\"wgpuTagRemove\", { id: this.wgpuViewId });\n delete wgpuTagRegistry[this.wgpuViewId];\n }\n if (this._sync)\n this._sync.stop();\n }\n async initWgpuView() {\n const rect = this.getBoundingClientRect();\n const initialRect = {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n };\n const transparent = this.hasAttribute(\"transparent\");\n const passthrough = this.hasAttribute(\"passthrough\");\n const hidden = this.hasAttribute(\"hidden\");\n const masks = this.getAttribute(\"masks\");\n this.transparent = transparent;\n this.passthroughEnabled = passthrough;\n this.hidden = hidden;\n if (masks) {\n masks.split(\",\").forEach((s) => this.maskSelectors.add(s.trim()));\n }\n if (transparent)\n this.style.opacity = \"0\";\n if (passthrough)\n this.style.pointerEvents = \"none\";\n try {\n const wgpuViewId = await request(\"wgpuTagInit\", {\n windowId: window.__electrobunWindowId,\n frame: {\n width: rect.width,\n height: rect.height,\n x: rect.x,\n y: rect.y\n },\n transparent,\n passthrough\n });\n this.wgpuViewId = wgpuViewId;\n this.id = `electrobun-wgpu-${wgpuViewId}`;\n wgpuTagRegistry[wgpuViewId] = this;\n this.setupObservers(initialRect);\n this.syncDimensions(true);\n if (hidden) {\n this.toggleHidden(true);\n }\n requestAnimationFrame(() => {\n Object.values(wgpuTagRegistry).forEach((view) => {\n if (view !== this && view.wgpuViewId !== null) {\n view.syncDimensions(true);\n }\n });\n });\n this.emit(\"ready\", { id: wgpuViewId });\n } catch (err) {\n console.error(\"Failed to init WGPU view:\", err);\n }\n }\n setupObservers(initialRect) {\n const getMasks = () => {\n const rect = this.getBoundingClientRect();\n const masks = [];\n this.maskSelectors.forEach((selector) => {\n try {\n document.querySelectorAll(selector).forEach((el) => {\n const mr = el.getBoundingClientRect();\n masks.push({\n x: mr.x - rect.x,\n y: mr.y - rect.y,\n width: mr.width,\n height: mr.height\n });\n });\n } catch (_e) {}\n });\n return masks;\n };\n this._sync = new OverlaySyncController(this, {\n onSync: (rect, masksJson) => {\n if (this.wgpuViewId === null)\n return;\n send(\"wgpuTagResize\", {\n id: this.wgpuViewId,\n frame: rect,\n masks: masksJson\n });\n },\n getMasks,\n burstIntervalMs: 10,\n baseIntervalMs: 100,\n burstDurationMs: 50\n });\n this._sync.setLastRect(initialRect);\n this._sync.start();\n }\n syncDimensions(force = false) {\n if (!this._sync)\n return;\n if (force) {\n this._sync.forceSync();\n }\n }\n toggleTransparent(value) {\n if (this.wgpuViewId === null)\n return;\n this.transparent = value !== undefined ? value : !this.transparent;\n this.style.opacity = this.transparent ? \"0\" : \"\";\n send(\"wgpuTagSetTransparent\", {\n id: this.wgpuViewId,\n transparent: this.transparent\n });\n }\n togglePassthrough(value) {\n if (this.wgpuViewId === null)\n return;\n this.passthroughEnabled = value !== undefined ? value : !this.passthroughEnabled;\n this.style.pointerEvents = this.passthroughEnabled ? \"none\" : \"\";\n send(\"wgpuTagSetPassthrough\", {\n id: this.wgpuViewId,\n passthrough: this.passthroughEnabled\n });\n }\n toggleHidden(value) {\n if (this.wgpuViewId === null)\n return;\n this.hidden = value !== undefined ? value : !this.hidden;\n send(\"wgpuTagSetHidden\", { id: this.wgpuViewId, hidden: this.hidden });\n }\n runTest() {\n if (this.wgpuViewId === null)\n return;\n send(\"wgpuTagRunTest\", { id: this.wgpuViewId });\n }\n addMaskSelector(selector) {\n this.maskSelectors.add(selector);\n this.syncDimensions(true);\n }\n removeMaskSelector(selector) {\n this.maskSelectors.delete(selector);\n this.syncDimensions(true);\n }\n on(event, listener) {\n if (!this._eventListeners[event])\n this._eventListeners[event] = [];\n this._eventListeners[event].push(listener);\n }\n off(event, listener) {\n if (!this._eventListeners[event])\n return;\n const idx = this._eventListeners[event].indexOf(listener);\n if (idx !== -1)\n this._eventListeners[event].splice(idx, 1);\n }\n emit(event, detail) {\n const listeners = this._eventListeners[event];\n if (listeners) {\n const customEvent = new CustomEvent(event, { detail });\n listeners.forEach((fn) => fn(customEvent));\n }\n }\n}\nfunction initWgpuTag() {\n if (!customElements.get(\"electrobun-wgpu\")) {\n customElements.define(\"electrobun-wgpu\", ElectrobunWgpuTag);\n }\n const injectStyles = () => {\n const style = document.createElement(\"style\");\n style.textContent = `\nelectrobun-wgpu {\n\tdisplay: block;\n\twidth: 800px;\n\theight: 300px;\n\tbackground: #000;\n\toverflow: hidden;\n}\n`;\n if (document.head?.firstChild) {\n document.head.insertBefore(style, document.head.firstChild);\n } else if (document.head) {\n document.head.appendChild(style);\n }\n };\n if (document.head) {\n injectStyles();\n } else {\n document.addEventListener(\"DOMContentLoaded\", injectStyles);\n }\n}\n\n// src/bun/preload/events.ts\nfunction emitWebviewEvent(eventName, detail) {\n setTimeout(() => {\n const bridge = window.__electrobunEventBridge || window.__electrobunInternalBridge;\n bridge?.postMessage(JSON.stringify({\n id: \"webviewEvent\",\n type: \"message\",\n payload: {\n id: window.__electrobunWebviewId,\n eventName,\n detail\n }\n }));\n });\n}\nfunction initLifecycleEvents() {\n window.addEventListener(\"load\", () => {\n if (window === window.top) {\n emitWebviewEvent(\"dom-ready\", document.location.href);\n }\n });\n window.addEventListener(\"popstate\", () => {\n emitWebviewEvent(\"did-navigate-in-page\", window.location.href);\n });\n window.addEventListener(\"hashchange\", () => {\n emitWebviewEvent(\"did-navigate-in-page\", window.location.href);\n });\n}\nvar cmdKeyHeld = false;\nvar cmdKeyTimestamp = 0;\nvar CMD_KEY_THRESHOLD_MS = 500;\nfunction isCmdHeld() {\n if (cmdKeyHeld)\n return true;\n return Date.now() - cmdKeyTimestamp < CMD_KEY_THRESHOLD_MS && cmdKeyTimestamp > 0;\n}\nfunction initCmdClickHandling() {\n window.addEventListener(\"keydown\", (event) => {\n if (event.key === \"Meta\" || event.metaKey) {\n cmdKeyHeld = true;\n cmdKeyTimestamp = Date.now();\n }\n }, true);\n window.addEventListener(\"keyup\", (event) => {\n if (event.key === \"Meta\") {\n cmdKeyHeld = false;\n cmdKeyTimestamp = Date.now();\n }\n }, true);\n window.addEventListener(\"blur\", () => {\n cmdKeyHeld = false;\n });\n window.addEventListener(\"click\", (event) => {\n if (event.metaKey || event.ctrlKey) {\n const anchor = event.target?.closest?.(\"a\");\n if (anchor && anchor.href) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: anchor.href,\n isCmdClick: true,\n isSPANavigation: false\n }));\n }\n }\n }, true);\n}\nfunction initSPANavigationInterception() {\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n history.pushState = function(state, title, url) {\n if (isCmdHeld() && url) {\n const resolvedUrl = new URL(String(url), window.location.href).href;\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: resolvedUrl,\n isCmdClick: true,\n isSPANavigation: true\n }));\n return;\n }\n return originalPushState.apply(this, [state, title, url]);\n };\n history.replaceState = function(state, title, url) {\n if (isCmdHeld() && url) {\n const resolvedUrl = new URL(String(url), window.location.href).href;\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: resolvedUrl,\n isCmdClick: true,\n isSPANavigation: true\n }));\n return;\n }\n return originalReplaceState.apply(this, [state, title, url]);\n };\n}\nfunction initOverscrollPrevention() {\n document.addEventListener(\"DOMContentLoaded\", () => {\n const style = document.createElement(\"style\");\n style.type = \"text/css\";\n style.appendChild(document.createTextNode(\"html, body { overscroll-behavior: none; }\"));\n document.head.appendChild(style);\n });\n}\n\n// src/bun/preload/index.ts\ninitEncryption().catch((err) => console.error(\"Failed to initialize encryption:\", err));\nvar internalMessageHandler = (msg) => {\n handleResponse(msg);\n};\nif (!window.__electrobun) {\n window.__electrobun = {\n receiveInternalMessageFromBun: internalMessageHandler,\n receiveMessageFromBun: (msg) => {\n console.log(\"receiveMessageFromBun (no handler):\", msg);\n }\n };\n} else {\n window.__electrobun.receiveInternalMessageFromBun = internalMessageHandler;\n window.__electrobun.receiveMessageFromBun = (msg) => {\n console.log(\"receiveMessageFromBun (no handler):\", msg);\n };\n}\nwindow.__electrobunSendToHost = (message) => {\n emitWebviewEvent(\"host-message\", JSON.stringify(message));\n};\ninitLifecycleEvents();\ninitCmdClickHandling();\ninitSPANavigationInterception();\ninitOverscrollPrevention();\ninitDragRegions();\ninitWebviewTag();\ninitWgpuTag();\n})();";
|
|
452
|
-
+export const preloadScript = "(function(){// src/bun/preload/encryption.ts\nfunction base64ToUint8Array(base64) {\n if (typeof Uint8Array.fromBase64 === \"function\") return Uint8Array.fromBase64(base64);\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0;i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n return bytes;\n}\nfunction uint8ArrayToBase64(uint8Array) {\n if (typeof uint8Array.toBase64 === \"function\") return uint8Array.toBase64();\n const parts = [];\n for (let i = 0;i < uint8Array.length; i += 32768) parts.push(String.fromCharCode.apply(null, uint8Array.subarray(i, i + 32768)));\n return btoa(parts.join(\"\"));\n}\nasync function generateKeyFromBytes(rawKey) {\n return await window.crypto.subtle.importKey(\"raw\", rawKey, { name: \"AES-GCM\" }, true, [\"encrypt\", \"decrypt\"]);\n}\nasync function initEncryption() {\n const secretKey = await generateKeyFromBytes(new Uint8Array(window.__electrobunSecretKeyBytes));\n const encryptString = async (plaintext) => {\n const encoder = new TextEncoder;\n const encodedText = encoder.encode(plaintext);\n const iv = window.crypto.getRandomValues(new Uint8Array(12));\n const encryptedBuffer = await window.crypto.subtle.encrypt({ name: \"AES-GCM\", iv }, secretKey, encodedText);\n const encryptedData = new Uint8Array(encryptedBuffer.slice(0, -16));\n const tag = new Uint8Array(encryptedBuffer.slice(-16));\n return {\n encryptedData: uint8ArrayToBase64(encryptedData),\n iv: uint8ArrayToBase64(iv),\n tag: uint8ArrayToBase64(tag)\n };\n };\n const decryptString = async (encryptedDataB64, ivB64, tagB64) => {\n const encryptedData = base64ToUint8Array(encryptedDataB64);\n const iv = base64ToUint8Array(ivB64);\n const tag = base64ToUint8Array(tagB64);\n const combinedData = new Uint8Array(encryptedData.length + tag.length);\n combinedData.set(encryptedData);\n combinedData.set(tag, encryptedData.length);\n const decryptedBuffer = await window.crypto.subtle.decrypt({ name: \"AES-GCM\", iv }, secretKey, combinedData);\n const decoder = new TextDecoder;\n return decoder.decode(decryptedBuffer);\n };\n window.__electrobun_encrypt = encryptString;\n window.__electrobun_decrypt = decryptString;\n}\n\n// src/bun/preload/internalRpc.ts\nvar pendingRequests = {};\nvar requestId = 0;\nvar isProcessingQueue = false;\nvar sendQueue = [];\nfunction processQueue() {\n if (isProcessingQueue) {\n setTimeout(processQueue);\n return;\n }\n if (sendQueue.length === 0)\n return;\n isProcessingQueue = true;\n const batch = JSON.stringify(sendQueue);\n sendQueue.length = 0;\n window.__electrobunInternalBridge?.postMessage(batch);\n setTimeout(() => {\n isProcessingQueue = false;\n }, 2);\n}\nfunction send(type, payload) {\n sendQueue.push(JSON.stringify({ type: \"message\", id: type, payload }));\n processQueue();\n}\nfunction request(type, payload) {\n return new Promise((resolve, reject) => {\n const id = `req_${++requestId}_${Date.now()}`;\n pendingRequests[id] = { resolve, reject };\n sendQueue.push(JSON.stringify({\n type: \"request\",\n method: type,\n id,\n params: payload,\n hostWebviewId: window.__electrobunWebviewId\n }));\n processQueue();\n setTimeout(() => {\n if (pendingRequests[id]) {\n delete pendingRequests[id];\n reject(new Error(`Request timeout: ${type}`));\n }\n }, 1e4);\n });\n}\nfunction handleResponse(msg) {\n if (msg && msg.type === \"response\" && msg.id) {\n const pending = pendingRequests[msg.id];\n if (pending) {\n delete pendingRequests[msg.id];\n if (msg.success)\n pending.resolve(msg.payload);\n else\n pending.reject(msg.payload);\n }\n }\n}\n\n// src/bun/preload/dragRegions.ts\nfunction isAppRegionDrag(e) {\n const target = e.target;\n if (!target || !target.closest)\n return false;\n if (target.closest(\".electrobun-webkit-app-region-no-drag\") || target.closest('[style*=\"app-region\"][style*=\"no-drag\"]')) {\n return false;\n }\n const draggableByStyle = target.closest('[style*=\"app-region\"][style*=\"drag\"]');\n const draggableByClass = target.closest(\".electrobun-webkit-app-region-drag\");\n return !!(draggableByStyle || draggableByClass);\n}\nfunction initDragRegions() {\n document.addEventListener(\"mousedown\", (e) => {\n if (isAppRegionDrag(e)) {\n send(\"startWindowMove\", { id: window.__electrobunWindowId });\n }\n });\n document.addEventListener(\"mouseup\", (e) => {\n if (isAppRegionDrag(e)) {\n send(\"stopWindowMove\", { id: window.__electrobunWindowId });\n }\n });\n}\n\n// src/bun/preload/overlaySync.ts\nclass OverlaySyncController {\n element;\n options;\n lastRect = { x: 0, y: 0, width: 0, height: 0 };\n resizeObserver = null;\n positionLoop = null;\n resizeHandler = null;\n burstUntil = 0;\n constructor(element, options) {\n this.element = element;\n this.options = {\n onSync: options.onSync,\n getMasks: options.getMasks ?? (() => []),\n burstIntervalMs: options.burstIntervalMs ?? 50,\n baseIntervalMs: options.baseIntervalMs ?? 100,\n burstDurationMs: options.burstDurationMs ?? 500\n };\n }\n start() {\n this.resizeObserver = new ResizeObserver(() => this.sync());\n this.resizeObserver.observe(this.element);\n const loop = () => {\n this.sync();\n const now = performance.now();\n const interval = now < this.burstUntil ? this.options.burstIntervalMs : this.options.baseIntervalMs;\n this.positionLoop = setTimeout(loop, interval);\n };\n this.positionLoop = setTimeout(loop, this.options.baseIntervalMs);\n this.resizeHandler = () => this.sync(true);\n window.addEventListener(\"resize\", this.resizeHandler);\n }\n stop() {\n if (this.resizeObserver)\n this.resizeObserver.disconnect();\n if (this.positionLoop)\n clearTimeout(this.positionLoop);\n if (this.resizeHandler) {\n window.removeEventListener(\"resize\", this.resizeHandler);\n }\n this.resizeObserver = null;\n this.positionLoop = null;\n this.resizeHandler = null;\n }\n forceSync() {\n this.sync(true);\n }\n setLastRect(rect) {\n this.lastRect = rect;\n }\n sync(force = false) {\n const rect = this.element.getBoundingClientRect();\n const newRect = {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n };\n if (newRect.width === 0 && newRect.height === 0) {\n return;\n }\n if (!force && newRect.x === this.lastRect.x && newRect.y === this.lastRect.y && newRect.width === this.lastRect.width && newRect.height === this.lastRect.height) {\n return;\n }\n this.burstUntil = performance.now() + this.options.burstDurationMs;\n this.lastRect = newRect;\n const masks = this.options.getMasks();\n this.options.onSync(newRect, JSON.stringify(masks));\n }\n}\n\n// src/bun/preload/webviewTag.ts\nvar webviewRegistry = {};\n\nclass ElectrobunWebviewTag extends HTMLElement {\n webviewId = null;\n maskSelectors = new Set;\n _sync = null;\n transparent = false;\n passthroughEnabled = false;\n hidden = false;\n sandboxed = false;\n _eventListeners = {};\n static get observedAttributes() {\n return [\"src\", \"html\"];\n }\n constructor() {\n super();\n }\n connectedCallback() {\n requestAnimationFrame(() => this.initWebview());\n }\n attributeChangedCallback(name, oldValue, newValue) {\n if (oldValue === newValue)\n return;\n if (newValue === null)\n return;\n if (this.webviewId === null)\n return;\n if (name === \"src\")\n this.loadURL(newValue);\n else if (name === \"html\")\n this.loadHTML(newValue);\n }\n disconnectedCallback() {\n if (this.webviewId !== null) {\n send(\"webviewTagRemove\", { id: this.webviewId });\n delete webviewRegistry[this.webviewId];\n }\n if (this._sync)\n this._sync.stop();\n }\n async initWebview() {\n const rect = this.getBoundingClientRect();\n const initialRect = {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n };\n const url = this.getAttribute(\"src\");\n const html = this.getAttribute(\"html\");\n const preload = this.getAttribute(\"preload\");\n const partition = this.getAttribute(\"partition\");\n const renderer = this.getAttribute(\"renderer\") || \"native\";\n const masks = this.getAttribute(\"masks\");\n const sandbox = this.hasAttribute(\"sandbox\");\n this.sandboxed = sandbox;\n const transparent = this.hasAttribute(\"transparent\");\n const passthrough = this.hasAttribute(\"passthrough\");\n this.transparent = transparent;\n this.passthroughEnabled = passthrough;\n if (transparent)\n this.style.opacity = \"0\";\n if (passthrough)\n this.style.pointerEvents = \"none\";\n if (masks) {\n masks.split(\",\").forEach((s) => this.maskSelectors.add(s.trim()));\n }\n try {\n const webviewId = await request(\"webviewTagInit\", {\n hostWebviewId: window.__electrobunWebviewId,\n windowId: window.__electrobunWindowId,\n renderer,\n url,\n html,\n preload,\n partition,\n frame: {\n width: rect.width,\n height: rect.height,\n x: rect.x,\n y: rect.y\n },\n navigationRules: null,\n sandbox,\n transparent,\n passthrough\n });\n this.webviewId = webviewId;\n this.id = `electrobun-webview-${webviewId}`;\n webviewRegistry[webviewId] = this;\n this.setupObservers(initialRect);\n this.syncDimensions(true);\n requestAnimationFrame(() => {\n Object.values(webviewRegistry).forEach((webview) => {\n if (webview !== this && webview.webviewId !== null) {\n webview.syncDimensions(true);\n }\n });\n });\n } catch (err) {\n console.error(\"Failed to init webview:\", err);\n }\n }\n setupObservers(initialRect) {\n const getMasks = () => {\n const rect = this.getBoundingClientRect();\n const masks = [];\n this.maskSelectors.forEach((selector) => {\n try {\n document.querySelectorAll(selector).forEach((el) => {\n const mr = el.getBoundingClientRect();\n masks.push({\n x: mr.x - rect.x,\n y: mr.y - rect.y,\n width: mr.width,\n height: mr.height\n });\n });\n } catch (_e) {}\n });\n return masks;\n };\n this._sync = new OverlaySyncController(this, {\n onSync: (rect, masksJson) => {\n if (this.webviewId === null)\n return;\n send(\"webviewTagResize\", {\n id: this.webviewId,\n frame: rect,\n masks: masksJson\n });\n },\n getMasks,\n burstIntervalMs: 10,\n baseIntervalMs: 100,\n burstDurationMs: 50\n });\n this._sync.setLastRect(initialRect);\n this._sync.start();\n }\n syncDimensions(force = false) {\n if (!this._sync)\n return;\n if (force) {\n this._sync.forceSync();\n }\n }\n loadURL(url) {\n if (this.webviewId === null)\n return;\n this.setAttribute(\"src\", url);\n send(\"webviewTagUpdateSrc\", { id: this.webviewId, url });\n }\n loadHTML(html) {\n if (this.webviewId === null)\n return;\n send(\"webviewTagUpdateHtml\", { id: this.webviewId, html });\n }\n reload() {\n if (this.webviewId !== null)\n send(\"webviewTagReload\", { id: this.webviewId });\n }\n goBack() {\n if (this.webviewId !== null)\n send(\"webviewTagGoBack\", { id: this.webviewId });\n }\n goForward() {\n if (this.webviewId !== null)\n send(\"webviewTagGoForward\", { id: this.webviewId });\n }\n async canGoBack() {\n if (this.webviewId === null)\n return false;\n return await request(\"webviewTagCanGoBack\", {\n id: this.webviewId\n });\n }\n async canGoForward() {\n if (this.webviewId === null)\n return false;\n return await request(\"webviewTagCanGoForward\", {\n id: this.webviewId\n });\n }\n toggleTransparent(value) {\n if (this.webviewId === null)\n return;\n this.transparent = value !== undefined ? value : !this.transparent;\n this.style.opacity = this.transparent ? \"0\" : \"\";\n send(\"webviewTagSetTransparent\", {\n id: this.webviewId,\n transparent: this.transparent\n });\n }\n togglePassthrough(value) {\n if (this.webviewId === null)\n return;\n this.passthroughEnabled = value !== undefined ? value : !this.passthroughEnabled;\n this.style.pointerEvents = this.passthroughEnabled ? \"none\" : \"\";\n send(\"webviewTagSetPassthrough\", {\n id: this.webviewId,\n enablePassthrough: this.passthroughEnabled\n });\n }\n toggleHidden(value) {\n if (this.webviewId === null)\n return;\n this.hidden = value !== undefined ? value : !this.hidden;\n send(\"webviewTagSetHidden\", { id: this.webviewId, hidden: this.hidden });\n }\n addMaskSelector(selector) {\n this.maskSelectors.add(selector);\n this.syncDimensions(true);\n }\n removeMaskSelector(selector) {\n this.maskSelectors.delete(selector);\n this.syncDimensions(true);\n }\n setNavigationRules(rules) {\n if (this.webviewId !== null) {\n send(\"webviewTagSetNavigationRules\", { id: this.webviewId, rules });\n }\n }\n findInPage(searchText, options) {\n if (this.webviewId === null)\n return;\n const forward = options?.forward !== false;\n const matchCase = options?.matchCase || false;\n send(\"webviewTagFindInPage\", {\n id: this.webviewId,\n searchText,\n forward,\n matchCase\n });\n }\n stopFindInPage() {\n if (this.webviewId !== null)\n send(\"webviewTagStopFind\", { id: this.webviewId });\n }\n openDevTools() {\n if (this.webviewId !== null)\n send(\"webviewTagOpenDevTools\", { id: this.webviewId });\n }\n closeDevTools() {\n if (this.webviewId !== null)\n send(\"webviewTagCloseDevTools\", { id: this.webviewId });\n }\n toggleDevTools() {\n if (this.webviewId !== null)\n send(\"webviewTagToggleDevTools\", { id: this.webviewId });\n }\n executeJavascript(js) {\n if (this.webviewId === null)\n return;\n send(\"webviewTagExecuteJavascript\", { id: this.webviewId, js });\n }\n on(event, listener) {\n if (!this._eventListeners[event])\n this._eventListeners[event] = [];\n this._eventListeners[event].push(listener);\n }\n off(event, listener) {\n if (!this._eventListeners[event])\n return;\n const idx = this._eventListeners[event].indexOf(listener);\n if (idx !== -1)\n this._eventListeners[event].splice(idx, 1);\n }\n emit(event, detail) {\n const listeners = this._eventListeners[event];\n if (listeners) {\n const customEvent = new CustomEvent(event, { detail });\n listeners.forEach((fn) => fn(customEvent));\n }\n }\n get src() {\n return this.getAttribute(\"src\");\n }\n set src(value) {\n if (value) {\n this.setAttribute(\"src\", value);\n } else {\n this.removeAttribute(\"src\");\n }\n }\n get html() {\n return this.getAttribute(\"html\");\n }\n set html(value) {\n if (value) {\n this.setAttribute(\"html\", value);\n } else {\n this.removeAttribute(\"html\");\n }\n }\n get preload() {\n return this.getAttribute(\"preload\");\n }\n set preload(value) {\n if (value)\n this.setAttribute(\"preload\", value);\n else\n this.removeAttribute(\"preload\");\n }\n get renderer() {\n return this.getAttribute(\"renderer\") || \"native\";\n }\n set renderer(value) {\n this.setAttribute(\"renderer\", value);\n }\n get sandbox() {\n return this.sandboxed;\n }\n}\nfunction initWebviewTag() {\n if (!customElements.get(\"electrobun-webview\")) {\n customElements.define(\"electrobun-webview\", ElectrobunWebviewTag);\n }\n const injectStyles = () => {\n const style = document.createElement(\"style\");\n style.textContent = `\nelectrobun-webview {\n\tdisplay: block;\n\twidth: 800px;\n\theight: 300px;\n\tbackground: #fff;\n\tbackground-repeat: no-repeat !important;\n\toverflow: hidden;\n}\n`;\n if (document.head?.firstChild) {\n document.head.insertBefore(style, document.head.firstChild);\n } else if (document.head) {\n document.head.appendChild(style);\n }\n };\n if (document.head) {\n injectStyles();\n } else {\n document.addEventListener(\"DOMContentLoaded\", injectStyles);\n }\n}\n\n// src/bun/preload/wgpuTag.ts\nvar wgpuTagRegistry = {};\n\nclass ElectrobunWgpuTag extends HTMLElement {\n wgpuViewId = null;\n maskSelectors = new Set;\n _sync = null;\n transparent = false;\n passthroughEnabled = false;\n hidden = false;\n _eventListeners = {};\n constructor() {\n super();\n }\n connectedCallback() {\n requestAnimationFrame(() => this.initWgpuView());\n }\n disconnectedCallback() {\n if (this.wgpuViewId !== null) {\n send(\"wgpuTagRemove\", { id: this.wgpuViewId });\n delete wgpuTagRegistry[this.wgpuViewId];\n }\n if (this._sync)\n this._sync.stop();\n }\n async initWgpuView() {\n const rect = this.getBoundingClientRect();\n const initialRect = {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height\n };\n const transparent = this.hasAttribute(\"transparent\");\n const passthrough = this.hasAttribute(\"passthrough\");\n const hidden = this.hasAttribute(\"hidden\");\n const masks = this.getAttribute(\"masks\");\n this.transparent = transparent;\n this.passthroughEnabled = passthrough;\n this.hidden = hidden;\n if (masks) {\n masks.split(\",\").forEach((s) => this.maskSelectors.add(s.trim()));\n }\n if (transparent)\n this.style.opacity = \"0\";\n if (passthrough)\n this.style.pointerEvents = \"none\";\n try {\n const wgpuViewId = await request(\"wgpuTagInit\", {\n windowId: window.__electrobunWindowId,\n frame: {\n width: rect.width,\n height: rect.height,\n x: rect.x,\n y: rect.y\n },\n transparent,\n passthrough\n });\n this.wgpuViewId = wgpuViewId;\n this.id = `electrobun-wgpu-${wgpuViewId}`;\n wgpuTagRegistry[wgpuViewId] = this;\n this.setupObservers(initialRect);\n this.syncDimensions(true);\n if (hidden) {\n this.toggleHidden(true);\n }\n requestAnimationFrame(() => {\n Object.values(wgpuTagRegistry).forEach((view) => {\n if (view !== this && view.wgpuViewId !== null) {\n view.syncDimensions(true);\n }\n });\n });\n this.emit(\"ready\", { id: wgpuViewId });\n } catch (err) {\n console.error(\"Failed to init WGPU view:\", err);\n }\n }\n setupObservers(initialRect) {\n const getMasks = () => {\n const rect = this.getBoundingClientRect();\n const masks = [];\n this.maskSelectors.forEach((selector) => {\n try {\n document.querySelectorAll(selector).forEach((el) => {\n const mr = el.getBoundingClientRect();\n masks.push({\n x: mr.x - rect.x,\n y: mr.y - rect.y,\n width: mr.width,\n height: mr.height\n });\n });\n } catch (_e) {}\n });\n return masks;\n };\n this._sync = new OverlaySyncController(this, {\n onSync: (rect, masksJson) => {\n if (this.wgpuViewId === null)\n return;\n send(\"wgpuTagResize\", {\n id: this.wgpuViewId,\n frame: rect,\n masks: masksJson\n });\n },\n getMasks,\n burstIntervalMs: 10,\n baseIntervalMs: 100,\n burstDurationMs: 50\n });\n this._sync.setLastRect(initialRect);\n this._sync.start();\n }\n syncDimensions(force = false) {\n if (!this._sync)\n return;\n if (force) {\n this._sync.forceSync();\n }\n }\n toggleTransparent(value) {\n if (this.wgpuViewId === null)\n return;\n this.transparent = value !== undefined ? value : !this.transparent;\n this.style.opacity = this.transparent ? \"0\" : \"\";\n send(\"wgpuTagSetTransparent\", {\n id: this.wgpuViewId,\n transparent: this.transparent\n });\n }\n togglePassthrough(value) {\n if (this.wgpuViewId === null)\n return;\n this.passthroughEnabled = value !== undefined ? value : !this.passthroughEnabled;\n this.style.pointerEvents = this.passthroughEnabled ? \"none\" : \"\";\n send(\"wgpuTagSetPassthrough\", {\n id: this.wgpuViewId,\n passthrough: this.passthroughEnabled\n });\n }\n toggleHidden(value) {\n if (this.wgpuViewId === null)\n return;\n this.hidden = value !== undefined ? value : !this.hidden;\n send(\"wgpuTagSetHidden\", { id: this.wgpuViewId, hidden: this.hidden });\n }\n runTest() {\n if (this.wgpuViewId === null)\n return;\n send(\"wgpuTagRunTest\", { id: this.wgpuViewId });\n }\n addMaskSelector(selector) {\n this.maskSelectors.add(selector);\n this.syncDimensions(true);\n }\n removeMaskSelector(selector) {\n this.maskSelectors.delete(selector);\n this.syncDimensions(true);\n }\n on(event, listener) {\n if (!this._eventListeners[event])\n this._eventListeners[event] = [];\n this._eventListeners[event].push(listener);\n }\n off(event, listener) {\n if (!this._eventListeners[event])\n return;\n const idx = this._eventListeners[event].indexOf(listener);\n if (idx !== -1)\n this._eventListeners[event].splice(idx, 1);\n }\n emit(event, detail) {\n const listeners = this._eventListeners[event];\n if (listeners) {\n const customEvent = new CustomEvent(event, { detail });\n listeners.forEach((fn) => fn(customEvent));\n }\n }\n}\nfunction initWgpuTag() {\n if (!customElements.get(\"electrobun-wgpu\")) {\n customElements.define(\"electrobun-wgpu\", ElectrobunWgpuTag);\n }\n const injectStyles = () => {\n const style = document.createElement(\"style\");\n style.textContent = `\nelectrobun-wgpu {\n\tdisplay: block;\n\twidth: 800px;\n\theight: 300px;\n\tbackground: #000;\n\toverflow: hidden;\n}\n`;\n if (document.head?.firstChild) {\n document.head.insertBefore(style, document.head.firstChild);\n } else if (document.head) {\n document.head.appendChild(style);\n }\n };\n if (document.head) {\n injectStyles();\n } else {\n document.addEventListener(\"DOMContentLoaded\", injectStyles);\n }\n}\n\n// src/bun/preload/events.ts\nfunction emitWebviewEvent(eventName, detail) {\n setTimeout(() => {\n const bridge = window.__electrobunEventBridge || window.__electrobunInternalBridge;\n bridge?.postMessage(JSON.stringify({\n id: \"webviewEvent\",\n type: \"message\",\n payload: {\n id: window.__electrobunWebviewId,\n eventName,\n detail\n }\n }));\n });\n}\nfunction initLifecycleEvents() {\n window.addEventListener(\"load\", () => {\n if (window === window.top) {\n emitWebviewEvent(\"dom-ready\", document.location.href);\n }\n });\n window.addEventListener(\"popstate\", () => {\n emitWebviewEvent(\"did-navigate-in-page\", window.location.href);\n });\n window.addEventListener(\"hashchange\", () => {\n emitWebviewEvent(\"did-navigate-in-page\", window.location.href);\n });\n}\nvar cmdKeyHeld = false;\nvar cmdKeyTimestamp = 0;\nvar CMD_KEY_THRESHOLD_MS = 500;\nfunction isCmdHeld() {\n if (cmdKeyHeld)\n return true;\n return Date.now() - cmdKeyTimestamp < CMD_KEY_THRESHOLD_MS && cmdKeyTimestamp > 0;\n}\nfunction initCmdClickHandling() {\n window.addEventListener(\"keydown\", (event) => {\n if (event.key === \"Meta\" || event.metaKey) {\n cmdKeyHeld = true;\n cmdKeyTimestamp = Date.now();\n }\n }, true);\n window.addEventListener(\"keyup\", (event) => {\n if (event.key === \"Meta\") {\n cmdKeyHeld = false;\n cmdKeyTimestamp = Date.now();\n }\n }, true);\n window.addEventListener(\"blur\", () => {\n cmdKeyHeld = false;\n });\n window.addEventListener(\"click\", (event) => {\n if (event.metaKey || event.ctrlKey) {\n const anchor = event.target?.closest?.(\"a\");\n if (anchor && anchor.href) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: anchor.href,\n isCmdClick: true,\n isSPANavigation: false\n }));\n }\n }\n }, true);\n}\nfunction initSPANavigationInterception() {\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n history.pushState = function(state, title, url) {\n if (isCmdHeld() && url) {\n const resolvedUrl = new URL(String(url), window.location.href).href;\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: resolvedUrl,\n isCmdClick: true,\n isSPANavigation: true\n }));\n return;\n }\n return originalPushState.apply(this, [state, title, url]);\n };\n history.replaceState = function(state, title, url) {\n if (isCmdHeld() && url) {\n const resolvedUrl = new URL(String(url), window.location.href).href;\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: resolvedUrl,\n isCmdClick: true,\n isSPANavigation: true\n }));\n return;\n }\n return originalReplaceState.apply(this, [state, title, url]);\n };\n}\nfunction initOverscrollPrevention() {\n document.addEventListener(\"DOMContentLoaded\", () => {\n const style = document.createElement(\"style\");\n style.type = \"text/css\";\n style.appendChild(document.createTextNode(\"html, body { overscroll-behavior: none; }\"));\n document.head.appendChild(style);\n });\n}\n\n// src/bun/preload/index.ts\ninitEncryption().catch((err) => console.error(\"Failed to initialize encryption:\", err));\nvar internalMessageHandler = (msg) => {\n handleResponse(msg);\n};\nif (!window.__electrobun) {\n window.__electrobun = {\n receiveInternalMessageFromBun: internalMessageHandler,\n receiveMessageFromBun: (msg) => {\n console.log(\"receiveMessageFromBun (no handler):\", msg);\n }\n };\n} else {\n window.__electrobun.receiveInternalMessageFromBun = internalMessageHandler;\n window.__electrobun.receiveMessageFromBun = (msg) => {\n console.log(\"receiveMessageFromBun (no handler):\", msg);\n };\n}\nwindow.__electrobunSendToHost = (message) => {\n emitWebviewEvent(\"host-message\", JSON.stringify(message));\n};\ninitLifecycleEvents();\ninitCmdClickHandling();\ninitSPANavigationInterception();\ninitOverscrollPrevention();\ninitDragRegions();\ninitWebviewTag();\ninitWgpuTag();\n})();";
|
|
453
|
-
|
|
454
|
-
// Minimal preload for sandboxed/untrusted webviews (lifecycle events only, no RPC)
|
|
455
|
-
export const preloadScriptSandboxed = "(function(){// src/bun/preload/events.ts\nfunction emitWebviewEvent(eventName, detail) {\n setTimeout(() => {\n const bridge = window.__electrobunEventBridge || window.__electrobunInternalBridge;\n bridge?.postMessage(JSON.stringify({\n id: \"webviewEvent\",\n type: \"message\",\n payload: {\n id: window.__electrobunWebviewId,\n eventName,\n detail\n }\n }));\n });\n}\nfunction initLifecycleEvents() {\n window.addEventListener(\"load\", () => {\n if (window === window.top) {\n emitWebviewEvent(\"dom-ready\", document.location.href);\n }\n });\n window.addEventListener(\"popstate\", () => {\n emitWebviewEvent(\"did-navigate-in-page\", window.location.href);\n });\n window.addEventListener(\"hashchange\", () => {\n emitWebviewEvent(\"did-navigate-in-page\", window.location.href);\n });\n}\nvar cmdKeyHeld = false;\nvar cmdKeyTimestamp = 0;\nvar CMD_KEY_THRESHOLD_MS = 500;\nfunction isCmdHeld() {\n if (cmdKeyHeld)\n return true;\n return Date.now() - cmdKeyTimestamp < CMD_KEY_THRESHOLD_MS && cmdKeyTimestamp > 0;\n}\nfunction initCmdClickHandling() {\n window.addEventListener(\"keydown\", (event) => {\n if (event.key === \"Meta\" || event.metaKey) {\n cmdKeyHeld = true;\n cmdKeyTimestamp = Date.now();\n }\n }, true);\n window.addEventListener(\"keyup\", (event) => {\n if (event.key === \"Meta\") {\n cmdKeyHeld = false;\n cmdKeyTimestamp = Date.now();\n }\n }, true);\n window.addEventListener(\"blur\", () => {\n cmdKeyHeld = false;\n });\n window.addEventListener(\"click\", (event) => {\n if (event.metaKey || event.ctrlKey) {\n const anchor = event.target?.closest?.(\"a\");\n if (anchor && anchor.href) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: anchor.href,\n isCmdClick: true,\n isSPANavigation: false\n }));\n }\n }\n }, true);\n}\nfunction initSPANavigationInterception() {\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n history.pushState = function(state, title, url) {\n if (isCmdHeld() && url) {\n const resolvedUrl = new URL(String(url), window.location.href).href;\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: resolvedUrl,\n isCmdClick: true,\n isSPANavigation: true\n }));\n return;\n }\n return originalPushState.apply(this, [state, title, url]);\n };\n history.replaceState = function(state, title, url) {\n if (isCmdHeld() && url) {\n const resolvedUrl = new URL(String(url), window.location.href).href;\n emitWebviewEvent(\"new-window-open\", JSON.stringify({\n url: resolvedUrl,\n isCmdClick: true,\n isSPANavigation: true\n }));\n return;\n }\n return originalReplaceState.apply(this, [state, title, url]);\n };\n}\nfunction initOverscrollPrevention() {\n document.addEventListener(\"DOMContentLoaded\", () => {\n const style = document.createElement(\"style\");\n style.type = \"text/css\";\n style.appendChild(document.createTextNode(\"html, body { overscroll-behavior: none; }\"));\n document.head.appendChild(style);\n });\n}\n\n// src/bun/preload/index-sandboxed.ts\ninitLifecycleEvents();\ninitCmdClickHandling();\ninitSPANavigationInterception();\ninitOverscrollPrevention();\n})();";
|
|
456
|
-
diff --git a/dist/api/bun/preload/encryption.ts b/dist/api/bun/preload/encryption.ts
|
|
457
|
-
index a7822d85c187c1edf361f2e65757057aad9da7b0..533d431c6cc2097951f421cb1fbe31428759f5ae 100644
|
|
458
|
-
--- a/dist/api/bun/preload/encryption.ts
|
|
459
|
-
+++ b/dist/api/bun/preload/encryption.ts
|
|
460
|
-
@@ -3,20 +3,27 @@
|
|
461
|
-
|
|
462
|
-
import "./globals.d.ts";
|
|
463
|
-
|
|
464
|
-
+// Native base64 where the engine has it (WebKit since Safari 18.2); the
|
|
465
|
-
+// fallbacks copy bytes in a loop and join strings in chunks. Splitting the
|
|
466
|
-
+// decoded string into an array of characters, or growing a string one byte
|
|
467
|
-
+// at a time, costs tens of milliseconds per megabyte on the main thread.
|
|
468
|
-
function base64ToUint8Array(base64: string): Uint8Array {
|
|
469
|
-
- return new Uint8Array(
|
|
470
|
-
- atob(base64)
|
|
471
|
-
- .split("")
|
|
472
|
-
- .map((char) => char.charCodeAt(0)),
|
|
473
|
-
- );
|
|
474
|
-
+ const native = Uint8Array as unknown as { fromBase64?: (value: string) => Uint8Array };
|
|
475
|
-
+ if (typeof native.fromBase64 === "function") return native.fromBase64(base64);
|
|
476
|
-
+ const binary = atob(base64);
|
|
477
|
-
+ const bytes = new Uint8Array(binary.length);
|
|
478
|
-
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
479
|
-
+ return bytes;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function uint8ArrayToBase64(uint8Array: Uint8Array): string {
|
|
483
|
-
- let binary = "";
|
|
484
|
-
- for (let i = 0; i < uint8Array.length; i++) {
|
|
485
|
-
- binary += String.fromCharCode(uint8Array[i]!);
|
|
486
|
-
+ const native = (uint8Array as unknown as { toBase64?: () => string }).toBase64;
|
|
487
|
-
+ if (typeof native === "function") return native.call(uint8Array);
|
|
488
|
-
+ const parts: string[] = [];
|
|
489
|
-
+ for (let i = 0; i < uint8Array.length; i += 32768) {
|
|
490
|
-
+ parts.push(String.fromCharCode.apply(null, uint8Array.subarray(i, i + 32768) as unknown as number[]));
|
|
491
|
-
}
|
|
492
|
-
- return btoa(binary);
|
|
493
|
-
+ return btoa(parts.join(""));
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
async function generateKeyFromBytes(rawKey: Uint8Array): Promise<CryptoKey> {
|
|
497
|
-
diff --git a/dist/api/bun/proc/native.ts b/dist/api/bun/proc/native.ts
|
|
498
|
-
index f0f6c2532ba2eb467ec1d452a25c835b6db72661..3b9cc732f8d71da17e71c019f0930e74d0fb578d 100644
|
|
499
|
-
--- a/dist/api/bun/proc/native.ts
|
|
500
|
-
+++ b/dist/api/bun/proc/native.ts
|
|
501
|
-
@@ -829,6 +829,7 @@ const _ffiImpl = {
|
|
502
|
-
id: number;
|
|
503
|
-
url: string | null;
|
|
504
|
-
title: string;
|
|
505
|
-
+ iconPath?: string | null;
|
|
506
|
-
frame: {
|
|
507
|
-
width: number;
|
|
508
|
-
height: number;
|
|
509
|
-
@@ -862,6 +863,7 @@ const _ffiImpl = {
|
|
510
|
-
id,
|
|
511
|
-
url: _url,
|
|
512
|
-
title,
|
|
513
|
-
+ iconPath,
|
|
514
|
-
frame: { x, y, width, height },
|
|
515
|
-
styleMask: {
|
|
516
|
-
Borderless,
|
|
517
|
-
@@ -926,6 +928,9 @@ const _ffiImpl = {
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
native_.symbols.setWindowTitle(windowPtr, toCString(title));
|
|
521
|
-
+ if (iconPath) {
|
|
522
|
-
+ native_.symbols.setWindowIcon(windowPtr, toCString(iconPath));
|
|
523
|
-
+ }
|
|
524
|
-
if (!hidden) {
|
|
525
|
-
native_.symbols.showWindow(windowPtr, activate);
|
|
526
|
-
}
|
|
527
|
-
@@ -1915,6 +1920,14 @@ process.on("SIGTERM", () => {
|
|
528
|
-
// }
|
|
529
|
-
// );
|
|
530
|
-
|
|
531
|
-
+// A JSCallback's cstring argument arrives as the pointer under Bun 1.3 and as
|
|
532
|
-
+// a string (null for NULL) under Bun 1.4, which Windows builds ship.
|
|
533
|
-
+function callbackString(value: unknown): string {
|
|
534
|
-
+ if (typeof value === "string") return value;
|
|
535
|
-
+ if (value === null || value === undefined) return "";
|
|
536
|
-
+ return new CString(value as Pointer).toString();
|
|
537
|
-
+}
|
|
538
|
-
+
|
|
539
|
-
const windowCloseCallback = new JSCallback(
|
|
540
|
-
(id) => {
|
|
541
|
-
const handler = electrobunEventEmitter.events.window.close;
|
|
542
|
-
@@ -2036,7 +2049,7 @@ const windowKeyCallback = new JSCallback(
|
|
543
|
-
|
|
544
|
-
const getMimeType = new JSCallback(
|
|
545
|
-
(filePath) => {
|
|
546
|
-
- const _filePath = new CString(filePath).toString();
|
|
547
|
-
+ const _filePath = callbackString(filePath);
|
|
548
|
-
const mimeType = Bun.file(_filePath).type; // || "application/octet-stream";
|
|
549
|
-
|
|
550
|
-
// For this usecase we generally don't want the charset included in the mimetype
|
|
551
|
-
@@ -2074,7 +2087,7 @@ const globalShortcutHandlers = new Map<string, () => void>();
|
|
552
|
-
if (native) {
|
|
553
|
-
const urlOpenCallback = new JSCallback(
|
|
554
|
-
(urlPtr) => {
|
|
555
|
-
- const url = new CString(urlPtr).toString();
|
|
556
|
-
+ const url = callbackString(urlPtr);
|
|
557
|
-
const handler = electrobunEventEmitter.events.app.openUrl;
|
|
558
|
-
const event = handler({ url });
|
|
559
|
-
electrobunEventEmitter.emitEvent(event);
|
|
560
|
-
@@ -2111,7 +2124,7 @@ if (native) {
|
|
561
|
-
|
|
562
|
-
const globalShortcutCallback = new JSCallback(
|
|
563
|
-
(acceleratorPtr) => {
|
|
564
|
-
- const accelerator = new CString(acceleratorPtr).toString();
|
|
565
|
-
+ const accelerator = callbackString(acceleratorPtr);
|
|
566
|
-
const handler = globalShortcutHandlers.get(accelerator);
|
|
567
|
-
if (handler) handler();
|
|
568
|
-
},
|
|
569
|
-
@@ -2505,8 +2518,8 @@ const webviewEventJSCallback = new JSCallback(
|
|
570
|
-
|
|
571
|
-
try {
|
|
572
|
-
// Convert cstring pointers to actual strings
|
|
573
|
-
- eventName = new CString(_eventName).toString();
|
|
574
|
-
- detail = new CString(_detail).toString();
|
|
575
|
-
+ eventName = callbackString(_eventName);
|
|
576
|
-
+ detail = callbackString(_detail);
|
|
577
|
-
} catch (err) {
|
|
578
|
-
console.error("[webviewEventJSCallback] Error converting strings:", err);
|
|
579
|
-
console.error("[webviewEventJSCallback] Raw values:", {
|
|
580
|
-
@@ -2528,7 +2541,7 @@ const webviewEventJSCallback = new JSCallback(
|
|
581
|
-
const bunBridgePostmessageHandler = new JSCallback(
|
|
582
|
-
(id, msg) => {
|
|
583
|
-
try {
|
|
584
|
-
- const msgStr = new CString(msg);
|
|
585
|
-
+ const msgStr = callbackString(msg);
|
|
586
|
-
|
|
587
|
-
if (!msgStr.length) {
|
|
588
|
-
return;
|
|
589
|
-
@@ -2564,7 +2577,7 @@ const bunBridgePostmessageHandler = new JSCallback(
|
|
590
|
-
const eventBridgeHandler = new JSCallback(
|
|
591
|
-
(_id: number, msg: number) => {
|
|
592
|
-
try {
|
|
593
|
-
- const message = new CString(msg as unknown as Pointer);
|
|
594
|
-
+ const message = callbackString(msg);
|
|
595
|
-
const rawMessage = message.toString().trim();
|
|
596
|
-
if (!rawMessage || (rawMessage[0] !== "{" && rawMessage[0] !== "[")) {
|
|
597
|
-
return;
|
|
598
|
-
@@ -2593,7 +2606,7 @@ const eventBridgeHandler = new JSCallback(
|
|
599
|
-
const internalBridgeHandler = new JSCallback(
|
|
600
|
-
(_id: number, msg: number) => {
|
|
601
|
-
try {
|
|
602
|
-
- const batchMessage = new CString(msg as unknown as Pointer);
|
|
603
|
-
+ const batchMessage = callbackString(msg);
|
|
604
|
-
const jsonBatch = JSON.parse(batchMessage.toString());
|
|
605
|
-
|
|
606
|
-
if (jsonBatch.id === "webviewEvent") {
|
|
607
|
-
@@ -2664,7 +2677,7 @@ const trayItemHandler = new JSCallback(
|
|
608
|
-
(id, action) => {
|
|
609
|
-
// Note: Some invisible character that doesn't appear in .length
|
|
610
|
-
// is causing issues
|
|
611
|
-
- const actionString = (new CString(action).toString() || "").trim();
|
|
612
|
-
+ const actionString = (callbackString(action) || "").trim();
|
|
613
|
-
|
|
614
|
-
// Use shared deserialization method
|
|
615
|
-
const { action: actualAction, data } = deserializeMenuAction(actionString);
|
|
616
|
-
@@ -2688,7 +2701,7 @@ const trayItemHandler = new JSCallback(
|
|
617
|
-
|
|
618
|
-
const applicationMenuHandler = new JSCallback(
|
|
619
|
-
(id, action) => {
|
|
620
|
-
- const actionString = new CString(action).toString();
|
|
621
|
-
+ const actionString = callbackString(action);
|
|
622
|
-
|
|
623
|
-
// Use shared deserialization method
|
|
624
|
-
const { action: actualAction, data } = deserializeMenuAction(actionString);
|
|
625
|
-
@@ -2711,7 +2724,7 @@ const applicationMenuHandler = new JSCallback(
|
|
626
|
-
|
|
627
|
-
const contextMenuHandler = new JSCallback(
|
|
628
|
-
(_id, action) => {
|
|
629
|
-
- const actionString = new CString(action).toString();
|
|
630
|
-
+ const actionString = callbackString(action);
|
|
631
|
-
|
|
632
|
-
// Use shared deserialization method
|
|
633
|
-
const { action: actualAction, data } = deserializeMenuAction(actionString);
|