@adea-ai/app-framework 0.25.1 → 0.26.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/README.md +157 -19
- package/dist/app/application.d.ts +11 -4
- package/dist/app/application.js +24 -4
- package/dist/app/create-application.d.ts +9 -0
- package/dist/app/create-application.js +214 -143
- package/dist/app/private-group.d.ts +14 -0
- package/dist/app/private-group.js +39 -0
- package/dist/app/service-registry.d.ts +8 -4
- package/dist/app/service-registry.js +43 -6
- package/dist/appearance/custom-theme-import.d.ts +5 -7
- package/dist/appearance/custom-theme-import.js +66 -18
- package/dist/appearance/custom-theme-library.d.ts +51 -3
- package/dist/appearance/custom-theme-library.js +262 -33
- package/dist/appearance/editor.d.ts +3 -1
- package/dist/appearance/editor.js +37 -2
- package/dist/appearance/theme-file-importer.d.ts +7 -3
- package/dist/appearance/theme-file-importer.js +27 -7
- package/dist/appearance/theme-library-action-fence.d.ts +11 -0
- package/dist/appearance/theme-library-action-fence.js +29 -0
- package/dist/cli/cef-helper-cli.js +0 -0
- package/dist/cli/create-application-cli.js +0 -0
- package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
- package/dist/cli/framework-update-cli.js +16 -3
- package/dist/cli/macos-signing-cli.js +0 -0
- package/dist/cli/release-assets-plan-cli.js +0 -0
- package/dist/cli/release-cut-cli.js +0 -0
- package/dist/cli/release-descriptor-staging-cli.js +0 -0
- package/dist/cli/release-finalize-cli.js +0 -0
- package/dist/cli/release-promote-cli.js +0 -0
- package/dist/cli/release-publish-cli.js +0 -0
- package/dist/cli/release-sign-cli.js +0 -0
- package/dist/cli/release-step-cli.js +0 -0
- package/dist/cli/toolchain-identity-cli.js +0 -0
- package/dist/cli/windows-runtime-patch-cli.js +0 -0
- package/dist/desktop/application-command-client.d.ts +11 -1
- package/dist/desktop/application-command-client.js +66 -3
- package/dist/desktop/channel-handshake.d.ts +2 -1
- package/dist/desktop/channel-handshake.js +21 -5
- package/dist/desktop/client-asset-stream.d.ts +10 -0
- package/dist/desktop/client-asset-stream.js +97 -0
- package/dist/desktop/client-assets.d.ts +3 -1
- package/dist/desktop/client-assets.js +41 -6
- package/dist/desktop/desktop-client.d.ts +15 -1
- package/dist/desktop/desktop-client.js +235 -109
- package/dist/desktop/desktop-gateway.d.ts +2 -0
- package/dist/desktop/desktop-gateway.js +134 -22
- package/dist/desktop/desktop-host-websocket.d.ts +10 -0
- package/dist/desktop/desktop-host-websocket.js +28 -0
- package/dist/desktop/desktop-host.d.ts +9 -0
- package/dist/desktop/desktop-host.js +70 -61
- package/dist/desktop/desktop-port-file.d.ts +2 -0
- package/dist/desktop/desktop-port-file.js +23 -0
- package/dist/desktop/desktop-stream.d.ts +5 -0
- package/dist/desktop/desktop-stream.js +83 -15
- package/dist/desktop/gateway-limits.d.ts +2 -0
- package/dist/desktop/gateway-limits.js +6 -0
- package/dist/desktop/open-url-channel.d.ts +5 -3
- package/dist/desktop/open-url-channel.js +18 -5
- package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
- package/dist/desktop/typed-array-intrinsics.js +19 -0
- package/dist/framework-source.json +1 -1
- package/dist/installer/installed-payload.js +1 -1
- package/dist/installer/installer-ci-bootstrap.js +2 -1
- package/dist/installer/installer-command.d.ts +13 -0
- package/dist/installer/installer-command.js +47 -0
- package/dist/installer/installer-extraction.js +27 -61
- package/dist/installer/installer-identity.d.ts +19 -3
- package/dist/installer/installer-identity.js +58 -70
- package/dist/installer/installer-image-mount.d.ts +48 -0
- package/dist/installer/installer-image-mount.js +347 -0
- package/dist/installer/installer-layout.js +1 -1
- package/dist/installer/installer-process-cleanup.js +1 -1
- package/dist/installer/installer-renderer-evidence.js +6 -2
- package/dist/installer/upgrade-asset-download.js +30 -8
- package/dist/native/app-bundle.d.ts +2 -2
- package/dist/native/app-bundle.js +5 -4
- package/dist/native/cef-helper-download.d.ts +1 -0
- package/dist/native/cef-helper-download.js +35 -0
- package/dist/native/cef-helper.js +146 -61
- package/dist/native/exclusive-rename.d.ts +2 -0
- package/dist/native/exclusive-rename.js +52 -0
- package/dist/native/native-secret-store.js +5 -4
- package/dist/native/partitioned-window.d.ts +5 -2
- package/dist/native/partitioned-window.js +69 -9
- package/dist/native/sidecar-services.js +2 -2
- package/dist/native/sidecar.js +68 -25
- package/dist/native/window-bootstrap.js +2 -2
- package/dist/release/feed-state.js +2 -1
- package/dist/release/framework-update-lock.d.ts +2 -0
- package/dist/release/framework-update-lock.js +42 -0
- package/dist/release/framework-update.d.ts +6 -2
- package/dist/release/framework-update.js +165 -40
- package/dist/release/local-release.js +68 -39
- package/dist/release/release-config.js +1 -1
- package/dist/shared/discard-stream.d.ts +4 -0
- package/dist/shared/discard-stream.js +9 -0
- package/dist/shell/app-shell.js +59 -7
- package/dist/shell/app-utilities.js +2 -2
- package/dist/shell/application-menu.d.ts +13 -0
- package/dist/shell/application-menu.js +21 -8
- package/dist/update-helper.bundle.js +40 -4
- package/dist/updates/channel-update-manager.d.ts +2 -0
- package/dist/updates/channel-update-manager.js +15 -3
- package/dist/updates/desktop-updater.d.ts +2 -0
- package/dist/updates/desktop-updater.js +36 -7
- package/dist/updates/linux-process-state.d.ts +2 -0
- package/dist/updates/linux-process-state.js +13 -0
- package/dist/updates/release-location.js +5 -4
- package/dist/updates/update-adapter.js +5 -0
- package/dist/updates/update-arm.d.ts +2 -0
- package/dist/updates/update-arm.js +58 -7
- package/dist/updates/update-discovery.js +2 -1
- package/dist/updates/update-download-cleanup.d.ts +7 -0
- package/dist/updates/update-download-cleanup.js +21 -0
- package/dist/updates/update-download.js +41 -20
- package/dist/updates/update-exclusive-rename.d.ts +3 -2
- package/dist/updates/update-exclusive-rename.js +3 -50
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-manager.d.ts +17 -1
- package/dist/updates/update-manager.js +27 -8
- package/dist/updates/update-process-fence.js +18 -3
- package/dist/views/appearance-surface.js +51 -15
- package/package.json +8 -3
- package/src/app/application.tsx +49 -7
- package/src/appearance/custom-theme-import.ts +67 -7
- package/src/appearance/custom-theme-library.ts +391 -33
- package/src/appearance/editor.ts +49 -10
- package/src/appearance/theme-file-importer.ts +43 -12
- package/src/appearance/theme-library-action-fence.ts +28 -0
- package/src/desktop/client-asset-stream.ts +118 -0
- package/src/desktop/client-assets.ts +55 -5
- package/src/shell/app-shell.tsx +71 -8
- package/src/shell/app-utilities.tsx +2 -2
- package/src/updates/update-adapter.ts +5 -0
- package/src/views/appearance-surface.tsx +61 -29
- package/templates/application/README.md +5 -1
- package/templates/application/scripts/app-version.ts +7 -3
- package/templates/application/src/bun/index.ts +2 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readdir, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
// src/installer/installer-image-mount.ts
|
|
4
|
+
var FAILED_ATTACH_PROBES = 5;
|
|
5
|
+
var FAILED_ATTACH_PROBE_INTERVAL_MS = 500;
|
|
6
|
+
/** True when a directory tree contains a mount boundary below its parent. */
|
|
7
|
+
async function containsMountAt(path, expectedDevice) {
|
|
8
|
+
const info = await lstat(path);
|
|
9
|
+
if (!info.isDirectory() || info.isSymbolicLink()) return false;
|
|
10
|
+
if (info.dev !== expectedDevice) return true;
|
|
11
|
+
for (const name of await readdir(path)) {
|
|
12
|
+
const child = join(path, name), childInfo = await lstat(child);
|
|
13
|
+
if (!childInfo.isDirectory() || childInfo.isSymbolicLink()) continue;
|
|
14
|
+
if (childInfo.dev !== info.dev || await containsMountAt(child, info.dev)) return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
async function containsNestedMount(directory) {
|
|
19
|
+
const parentDevice = (await stat(dirname(directory))).dev;
|
|
20
|
+
return containsMountAt(directory, parentDevice);
|
|
21
|
+
}
|
|
22
|
+
async function installerImageMountState(mount) {
|
|
23
|
+
try {
|
|
24
|
+
const [own, parent] = await Promise.all([stat(mount), stat(dirname(mount))]);
|
|
25
|
+
return own.dev === parent.dev ? "unmounted" : "mounted";
|
|
26
|
+
} catch {
|
|
27
|
+
return "unknown";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function defaultInstallerImageMountIo(run) {
|
|
31
|
+
return {
|
|
32
|
+
run,
|
|
33
|
+
state: installerImageMountState,
|
|
34
|
+
containsNestedMount,
|
|
35
|
+
wait: Bun.sleep,
|
|
36
|
+
remove: (directory) => rm(directory, {
|
|
37
|
+
recursive: true,
|
|
38
|
+
force: true
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function assertNoNestedInstallerMount(directory, io) {
|
|
43
|
+
if (await io.containsNestedMount(directory)) throw new Error("Temporary directory contains a nested mount or has uncertain mount boundaries");
|
|
44
|
+
}
|
|
45
|
+
async function removeInstallerTemporaryDirectory(directory, io) {
|
|
46
|
+
await assertNoNestedInstallerMount(directory, io);
|
|
47
|
+
await io.remove(directory);
|
|
48
|
+
}
|
|
49
|
+
/** Skip only cleanup already owned by this exact lifecycle attempt. */
|
|
50
|
+
async function cleanupInstallerDirectoryAfterFailure(directory, error, io) {
|
|
51
|
+
if (error instanceof InstallerImageLifecycleError && error.directory === directory) return;
|
|
52
|
+
await removeInstallerTemporaryDirectory(directory, io);
|
|
53
|
+
}
|
|
54
|
+
var InstallerImageLifecycleError = class extends AggregateError {
|
|
55
|
+
directoryRetained;
|
|
56
|
+
directory;
|
|
57
|
+
phase;
|
|
58
|
+
constructor(errors, directoryRetained, directory, phase = "lifecycle", message) {
|
|
59
|
+
const primary = errors[0];
|
|
60
|
+
const defaultMessage = directoryRetained ? `Installer image preparation failed; temporary directory retained at ${directory}` : "Installer image preparation failed";
|
|
61
|
+
super(errors, message ?? defaultMessage, { cause: primary });
|
|
62
|
+
this.name = "InstallerImageLifecycleError";
|
|
63
|
+
this.directoryRetained = directoryRetained;
|
|
64
|
+
this.directory = directory;
|
|
65
|
+
this.phase = phase;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Attach an installer image, inspect/copy its contents, and reconcile the mount before
|
|
70
|
+
* allowing recursive cleanup. A failed attach is always treated as indeterminate because
|
|
71
|
+
* disk arbitration can finish mounting after the attach command has exited.
|
|
72
|
+
*/
|
|
73
|
+
async function withInstallerImage(options) {
|
|
74
|
+
const { directory, mount, image, env, io } = options;
|
|
75
|
+
const errors = [];
|
|
76
|
+
let attachSucceeded = false;
|
|
77
|
+
let mountedAtRequestedPath = false;
|
|
78
|
+
let result;
|
|
79
|
+
const observe = async () => {
|
|
80
|
+
try {
|
|
81
|
+
return await io.state(mount);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
errors.push(error);
|
|
84
|
+
return "unknown";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
let state = "unknown";
|
|
88
|
+
const forceDetachKnownMount = async () => {
|
|
89
|
+
try {
|
|
90
|
+
await io.run([
|
|
91
|
+
"/usr/bin/hdiutil",
|
|
92
|
+
"detach",
|
|
93
|
+
"-force",
|
|
94
|
+
mount
|
|
95
|
+
], env);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
errors.push(error);
|
|
98
|
+
}
|
|
99
|
+
state = await observe();
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
await io.run([
|
|
103
|
+
"/usr/bin/hdiutil",
|
|
104
|
+
"attach",
|
|
105
|
+
"-readonly",
|
|
106
|
+
"-nobrowse",
|
|
107
|
+
"-mountpoint",
|
|
108
|
+
mount,
|
|
109
|
+
image
|
|
110
|
+
], env);
|
|
111
|
+
attachSucceeded = true;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
errors.push(error);
|
|
114
|
+
}
|
|
115
|
+
state = await observe();
|
|
116
|
+
mountedAtRequestedPath = attachSucceeded && state === "mounted";
|
|
117
|
+
if (attachSucceeded && !mountedAtRequestedPath) errors.push(/* @__PURE__ */ new Error("Attach did not confirm a mount at the requested mountpoint"));
|
|
118
|
+
let normalDetachSucceeded = false;
|
|
119
|
+
if (mountedAtRequestedPath) {
|
|
120
|
+
try {
|
|
121
|
+
result = await options.work();
|
|
122
|
+
} catch (error) {
|
|
123
|
+
errors.push(error);
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
await io.run([
|
|
127
|
+
"/usr/bin/hdiutil",
|
|
128
|
+
"detach",
|
|
129
|
+
mount
|
|
130
|
+
], env);
|
|
131
|
+
normalDetachSucceeded = true;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
errors.push(error);
|
|
134
|
+
}
|
|
135
|
+
state = await observe();
|
|
136
|
+
if (state === "mounted") {
|
|
137
|
+
if (normalDetachSucceeded) errors.push(/* @__PURE__ */ new Error("Installer image remained mounted after detach"));
|
|
138
|
+
await forceDetachKnownMount();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!mountedAtRequestedPath) {
|
|
142
|
+
if (state === "mounted") await forceDetachKnownMount();
|
|
143
|
+
for (let attempt = 1; attempt < FAILED_ATTACH_PROBES; attempt++) {
|
|
144
|
+
try {
|
|
145
|
+
await io.wait(FAILED_ATTACH_PROBE_INTERVAL_MS);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
errors.push(error);
|
|
148
|
+
}
|
|
149
|
+
state = await observe();
|
|
150
|
+
if (state === "mounted") await forceDetachKnownMount();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
let safeToRemove = mountedAtRequestedPath && state === "unmounted";
|
|
154
|
+
if (state === "unknown") errors.push(/* @__PURE__ */ new Error("Cannot determine whether the installer image is still mounted"));
|
|
155
|
+
if (state === "mounted") errors.push(/* @__PURE__ */ new Error("Installer image remains mounted after forced detach"));
|
|
156
|
+
if (!mountedAtRequestedPath) errors.push(/* @__PURE__ */ new Error("Mount completion is indeterminate; temporary directory must be retained"));
|
|
157
|
+
if (safeToRemove) try {
|
|
158
|
+
await assertNoNestedInstallerMount(directory, io);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
safeToRemove = false;
|
|
161
|
+
errors.push(error);
|
|
162
|
+
}
|
|
163
|
+
if (errors.length > 0) {
|
|
164
|
+
let directoryRetained = !safeToRemove;
|
|
165
|
+
if (safeToRemove) try {
|
|
166
|
+
await removeInstallerTemporaryDirectory(directory, io);
|
|
167
|
+
directoryRetained = false;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
errors.push(error);
|
|
170
|
+
directoryRetained = true;
|
|
171
|
+
}
|
|
172
|
+
throw new InstallerImageLifecycleError(errors, directoryRetained, directory, mountedAtRequestedPath ? "lifecycle" : "attach");
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Retry a transient attach only with fresh mountpoints. Failed paths are retained and
|
|
178
|
+
* rechecked during backoff and after a later success; finite checks cannot rule out a
|
|
179
|
+
* mount that appears later, so callers must not treat retries as proof those paths are gone.
|
|
180
|
+
*/
|
|
181
|
+
async function withInstallerImageRetries(options) {
|
|
182
|
+
const maximumAttempts = Math.max(1, Math.floor(options.attempts ?? 3));
|
|
183
|
+
const failedAttempts = [];
|
|
184
|
+
const recoveryErrors = [];
|
|
185
|
+
const recoveryNotes = [];
|
|
186
|
+
const reconcileFailedAttempts = async () => {
|
|
187
|
+
const errors = [];
|
|
188
|
+
const notes = [];
|
|
189
|
+
let safe = true;
|
|
190
|
+
for (const attempt of failedAttempts) {
|
|
191
|
+
let state;
|
|
192
|
+
try {
|
|
193
|
+
state = await attempt.io.state(attempt.mount);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
errors.push(error);
|
|
196
|
+
state = "unknown";
|
|
197
|
+
}
|
|
198
|
+
if (state === "mounted") {
|
|
199
|
+
notes.push(`A late mount appeared at ${attempt.mount}; forced detach was attempted`);
|
|
200
|
+
try {
|
|
201
|
+
await attempt.io.run([
|
|
202
|
+
"/usr/bin/hdiutil",
|
|
203
|
+
"detach",
|
|
204
|
+
"-force",
|
|
205
|
+
attempt.mount
|
|
206
|
+
], options.env);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
errors.push(error);
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
state = await attempt.io.state(attempt.mount);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
errors.push(error);
|
|
214
|
+
state = "unknown";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (state !== "unmounted") {
|
|
218
|
+
safe = false;
|
|
219
|
+
errors.push(/* @__PURE__ */ new Error(`Prior installer mount state is ${state}; retained path ${attempt.mount}`));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
safe,
|
|
224
|
+
errors,
|
|
225
|
+
notes
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
const priorErrors = () => failedAttempts.map((attempt) => attempt.error);
|
|
229
|
+
for (let attempt = 1; attempt <= maximumAttempts; attempt++) {
|
|
230
|
+
const directory = await mkdtemp(join(options.parent, options.prefix));
|
|
231
|
+
const mount = join(directory, "mount");
|
|
232
|
+
const io = options.createIo?.(directory, mount) ?? defaultInstallerImageMountIo(options.run);
|
|
233
|
+
let lifecycleStarted = false;
|
|
234
|
+
try {
|
|
235
|
+
await mkdir(mount);
|
|
236
|
+
lifecycleStarted = true;
|
|
237
|
+
const result = await withInstallerImage({
|
|
238
|
+
directory,
|
|
239
|
+
mount,
|
|
240
|
+
image: options.image,
|
|
241
|
+
env: options.env,
|
|
242
|
+
io,
|
|
243
|
+
work: () => options.work(mount)
|
|
244
|
+
});
|
|
245
|
+
let state;
|
|
246
|
+
try {
|
|
247
|
+
state = await io.state(mount);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Cannot confirm the successful attempt is unmounted")], true, directory);
|
|
250
|
+
}
|
|
251
|
+
if (state === "mounted") {
|
|
252
|
+
const errors = [/* @__PURE__ */ new Error("Installer image remounted after successful cleanup")];
|
|
253
|
+
try {
|
|
254
|
+
await io.run([
|
|
255
|
+
"/usr/bin/hdiutil",
|
|
256
|
+
"detach",
|
|
257
|
+
"-force",
|
|
258
|
+
mount
|
|
259
|
+
], options.env);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
errors.push(error);
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
state = await io.state(mount);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
errors.push(error);
|
|
267
|
+
state = "unknown";
|
|
268
|
+
}
|
|
269
|
+
if (state === "unmounted") {
|
|
270
|
+
let directoryRetained = true;
|
|
271
|
+
try {
|
|
272
|
+
await removeInstallerTemporaryDirectory(directory, io);
|
|
273
|
+
directoryRetained = false;
|
|
274
|
+
} catch (error) {
|
|
275
|
+
errors.push(error);
|
|
276
|
+
}
|
|
277
|
+
throw new InstallerImageLifecycleError(errors, directoryRetained, directory);
|
|
278
|
+
}
|
|
279
|
+
errors.push(/* @__PURE__ */ new Error("Installer image remains mounted or unknown after forced detach"));
|
|
280
|
+
throw new InstallerImageLifecycleError(errors, true, directory);
|
|
281
|
+
}
|
|
282
|
+
if (state !== "unmounted") throw new InstallerImageLifecycleError([/* @__PURE__ */ new Error("Successful installer image attempt remains mounted or unknown")], true, directory);
|
|
283
|
+
if (failedAttempts.length > 0) {
|
|
284
|
+
const reconciliation = await reconcileFailedAttempts();
|
|
285
|
+
recoveryErrors.push(...reconciliation.errors);
|
|
286
|
+
recoveryNotes.push(...reconciliation.notes);
|
|
287
|
+
if (!reconciliation.safe) {
|
|
288
|
+
const errors = [...priorErrors(), ...reconciliation.errors];
|
|
289
|
+
try {
|
|
290
|
+
await removeInstallerTemporaryDirectory(directory, io);
|
|
291
|
+
} catch (cleanupError) {
|
|
292
|
+
errors.push(cleanupError);
|
|
293
|
+
}
|
|
294
|
+
throw new AggregateError(errors, "A prior installer mount is still mounted or uncertain after retry", { cause: failedAttempts[0].error });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
await removeInstallerTemporaryDirectory(directory, io);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
throw new InstallerImageLifecycleError([error], true, directory);
|
|
301
|
+
}
|
|
302
|
+
if (failedAttempts.length > 0) {
|
|
303
|
+
const failures = priorErrors();
|
|
304
|
+
if (options.onRecovered) options.onRecovered(failures);
|
|
305
|
+
else {
|
|
306
|
+
const retained = failedAttempts.map((failure) => failure.error.directory).join(", ");
|
|
307
|
+
const details = [...recoveryNotes, ...recoveryErrors.map((error) => String(error))];
|
|
308
|
+
console.warn(`Installer image attach recovered after ${failedAttempts.length} failed attempt(s); retained directories: ${retained}${details.length ? `; reconciliation: ${details.join("; ")}` : ""}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return result;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
if (error instanceof InstallerImageLifecycleError && error.directory === directory && error.phase === "attach") {
|
|
314
|
+
failedAttempts.push({
|
|
315
|
+
error,
|
|
316
|
+
mount,
|
|
317
|
+
io
|
|
318
|
+
});
|
|
319
|
+
if (attempt === maximumAttempts) {
|
|
320
|
+
const reconciliation = await reconcileFailedAttempts();
|
|
321
|
+
recoveryErrors.push(...reconciliation.errors);
|
|
322
|
+
recoveryNotes.push(...reconciliation.notes);
|
|
323
|
+
throw new AggregateError([...priorErrors(), ...reconciliation.errors], reconciliation.safe ? "Installer image attach attempts exhausted; failed paths were retained" : "Installer image attach attempts exhausted with a mounted or uncertain prior path", { cause: error });
|
|
324
|
+
}
|
|
325
|
+
try {
|
|
326
|
+
await io.wait(options.retryDelayMs ?? 5e3);
|
|
327
|
+
} catch (waitError) {
|
|
328
|
+
throw new AggregateError([...priorErrors(), waitError], "Installer image retry delay failed", { cause: waitError });
|
|
329
|
+
}
|
|
330
|
+
const reconciliation = await reconcileFailedAttempts();
|
|
331
|
+
recoveryErrors.push(...reconciliation.errors);
|
|
332
|
+
recoveryNotes.push(...reconciliation.notes);
|
|
333
|
+
if (!reconciliation.safe) throw new AggregateError([...priorErrors(), ...reconciliation.errors], "A prior installer mount is still mounted or uncertain; retry stopped", { cause: error });
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (!lifecycleStarted) try {
|
|
337
|
+
await removeInstallerTemporaryDirectory(directory, io);
|
|
338
|
+
} catch (cleanupError) {
|
|
339
|
+
throw new AggregateError([error, cleanupError], "Installer attempt cleanup failed", { cause: cleanupError });
|
|
340
|
+
}
|
|
341
|
+
if (failedAttempts.length > 0) throw new AggregateError([...priorErrors(), error], "Installer image attach attempts failed", { cause: error });
|
|
342
|
+
throw error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
throw new Error("Installer image attach attempts exhausted");
|
|
346
|
+
}
|
|
347
|
+
export { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, installerImageMountState, withInstallerImage, withInstallerImageRetries };
|
|
@@ -30,7 +30,7 @@ function paths(entries, fold) {
|
|
|
30
30
|
/** Check names before extraction. Callers must also reject unsafe links and archive entry types. */
|
|
31
31
|
function assertPayloadLayout(options) {
|
|
32
32
|
const { platform, appName, renderer } = options;
|
|
33
|
-
const sidecars = assertSidecarNames(options.sidecars ?? []);
|
|
33
|
+
const sidecars = assertSidecarNames(options.sidecars ?? [], platform);
|
|
34
34
|
assertPortableAppName(appName);
|
|
35
35
|
if (![
|
|
36
36
|
"macos-arm64",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assertInstallerContext } from "./installer-layout.js";
|
|
2
2
|
import { realpath } from "node:fs/promises";
|
|
3
|
+
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
3
4
|
import { execFile } from "node:child_process";
|
|
4
5
|
import { promisify } from "node:util";
|
|
5
|
-
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
6
6
|
// src/installer/installer-process-cleanup.ts
|
|
7
7
|
var execute = promisify(execFile);
|
|
8
8
|
/** Terminate only the verified app runtime process on a disposable runner. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertHostedRunner } from "./hosted-runner.js";
|
|
2
2
|
import { parseOfflinePolicy } from "../release/release-qualification.js";
|
|
3
|
+
import { discardStream } from "../shared/discard-stream.js";
|
|
3
4
|
// src/installer/installer-renderer-evidence.ts
|
|
4
5
|
function safeScriptString(value) {
|
|
5
6
|
return JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
|
|
@@ -22,7 +23,10 @@ function assertInstallerRendererObservation(value, offline = false) {
|
|
|
22
23
|
}
|
|
23
24
|
async function boundedBody(message, maximum) {
|
|
24
25
|
const declared = message.headers.get("content-length");
|
|
25
|
-
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > maximum))
|
|
26
|
+
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > maximum)) {
|
|
27
|
+
discardStream(message.body);
|
|
28
|
+
throw new Error("Renderer body exceeds bound");
|
|
29
|
+
}
|
|
26
30
|
if (!message.body) throw new Error("Missing renderer body");
|
|
27
31
|
const reader = message.body.getReader(), chunks = [];
|
|
28
32
|
let size = 0;
|
|
@@ -32,7 +36,7 @@ async function boundedBody(message, maximum) {
|
|
|
32
36
|
if (next.done) break;
|
|
33
37
|
size += next.value.length;
|
|
34
38
|
if (size > maximum) {
|
|
35
|
-
|
|
39
|
+
discardStream(reader);
|
|
36
40
|
throw new Error("Renderer body exceeds bound");
|
|
37
41
|
}
|
|
38
42
|
chunks.push(next.value);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isFeedAssetName, isFeedTag, parseFeedRelease } from "../updates/release-feed.js";
|
|
2
|
+
import { discardStream } from "../shared/discard-stream.js";
|
|
2
3
|
import { fetchReleaseLocation, readReleaseJson } from "../updates/release-location.js";
|
|
3
4
|
import { writeAll } from "./write-all.js";
|
|
4
5
|
import { open, unlink } from "node:fs/promises";
|
|
@@ -9,23 +10,44 @@ var MAX_COMPRESSED_BYTES = 1073741824;
|
|
|
9
10
|
async function downloadAsset(options) {
|
|
10
11
|
const { feed, tag, name, destination, fetch: fetcher } = options;
|
|
11
12
|
if (!isFeedTag(tag) || !isFeedAssetName(name)) throw new Error("Invalid release asset");
|
|
12
|
-
const
|
|
13
|
+
const metadataTimeout = AbortSignal.timeout(3e4);
|
|
14
|
+
const metadataSignal = options.signal ? AbortSignal.any([metadataTimeout, options.signal]) : metadataTimeout;
|
|
15
|
+
const release = parseFeedRelease(await readReleaseJson(await fetchReleaseLocation(`${feed}${tag}/release.json`, feed, fetcher, metadataSignal), 262144));
|
|
13
16
|
const digest = release.tag === tag ? release.assets.find((asset) => asset.name === name)?.sha256 : void 0;
|
|
14
17
|
if (!digest) throw new Error("Previous release asset has no recorded digest");
|
|
15
18
|
const response = await fetchReleaseLocation(`${feed}${tag}/${name}`, feed, fetcher, options.signal ?? AbortSignal.timeout(6e5));
|
|
16
19
|
if (response.status !== 200 || !response.body) {
|
|
17
|
-
|
|
20
|
+
discardStream(response.body);
|
|
18
21
|
throw new Error("Previous release download failed");
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
let file;
|
|
24
|
+
try {
|
|
25
|
+
file = await (options.openFile ?? open)(destination, "wx", 384);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
discardStream(response.body);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const hash = createHash("sha256");
|
|
21
31
|
let completed = false;
|
|
22
32
|
try {
|
|
23
33
|
let size = 0;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
const reader = response.body.getReader();
|
|
35
|
+
let ended = false;
|
|
36
|
+
try {
|
|
37
|
+
for (;;) {
|
|
38
|
+
const { value: chunk, done } = await reader.read();
|
|
39
|
+
if (done) {
|
|
40
|
+
ended = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
size += chunk.length;
|
|
44
|
+
if (size > MAX_COMPRESSED_BYTES) throw new Error("Previous release asset exceeds bound");
|
|
45
|
+
hash.update(chunk);
|
|
46
|
+
await writeAll(file, chunk);
|
|
47
|
+
}
|
|
48
|
+
} finally {
|
|
49
|
+
if (!ended) discardStream(reader);
|
|
50
|
+
reader.releaseLock();
|
|
29
51
|
}
|
|
30
52
|
if (hash.digest("hex") !== digest) throw new Error("Previous release asset differs from its digest");
|
|
31
53
|
await file.close();
|
|
@@ -15,8 +15,8 @@ export type PackagedVersion = Readonly<{
|
|
|
15
15
|
export declare function readPackagedVersion(entryDirectory: string): PackagedVersion;
|
|
16
16
|
/** Bundled sidecars live in `Resources/app/sidecars`; copy them there with Electrobun's `build.copy`. */
|
|
17
17
|
export declare const SIDECAR_DIRECTORY = "sidecars";
|
|
18
|
-
/** Validate
|
|
19
|
-
export declare function assertSidecarNames(names: unknown): readonly string[];
|
|
18
|
+
/** Validate lowercase sidecar names; reject Windows device names for Windows targets. */
|
|
19
|
+
export declare function assertSidecarNames(names: unknown, platform?: string): readonly string[];
|
|
20
20
|
/** The executable's file name on a platform (`process.platform` or an installer platform). */
|
|
21
21
|
export declare function sidecarFileName(name: string, platform: string): string;
|
|
22
22
|
/**
|
|
@@ -36,14 +36,15 @@ function readPackagedVersion(entryDirectory) {
|
|
|
36
36
|
}
|
|
37
37
|
/** Bundled sidecars live in `Resources/app/sidecars`; copy them there with Electrobun's `build.copy`. */
|
|
38
38
|
var SIDECAR_DIRECTORY = "sidecars";
|
|
39
|
-
/** Validate
|
|
40
|
-
function assertSidecarNames(names) {
|
|
41
|
-
|
|
39
|
+
/** Validate lowercase sidecar names; reject Windows device names for Windows targets. */
|
|
40
|
+
function assertSidecarNames(names, platform) {
|
|
41
|
+
const windows = platform === "win32" || platform === "windows-x64";
|
|
42
|
+
if (!Array.isArray(names) || names.length > 16 || names.some((name) => typeof name !== "string" || !/^[a-z0-9][a-z0-9_-]{0,63}$/.test(name)) || windows && names.some((name) => /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/.test(name)) || new Set(names).size !== names.length) throw new Error("Invalid sidecar names");
|
|
42
43
|
return [...names];
|
|
43
44
|
}
|
|
44
45
|
/** The executable's file name on a platform (`process.platform` or an installer platform). */
|
|
45
46
|
function sidecarFileName(name, platform) {
|
|
46
|
-
assertSidecarNames([name]);
|
|
47
|
+
assertSidecarNames([name], platform);
|
|
47
48
|
return platform === "win32" || platform === "windows-x64" ? `${name}.exe` : name;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadCefHelperInput(url: string, path: string, maxBytes: number): Promise<string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
// src/native/cef-helper-download.ts
|
|
4
|
+
async function downloadCefHelperInput(url, path, maxBytes) {
|
|
5
|
+
const hash = createHash("sha256");
|
|
6
|
+
const file = await open(path, "wx");
|
|
7
|
+
let size = 0;
|
|
8
|
+
let closeFailed = false;
|
|
9
|
+
let closeError;
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(9e5) });
|
|
12
|
+
if (!response.ok || !response.body) {
|
|
13
|
+
try {
|
|
14
|
+
response.body?.cancel().catch(() => {});
|
|
15
|
+
} catch {}
|
|
16
|
+
throw new Error("CEF helper download failed");
|
|
17
|
+
}
|
|
18
|
+
for await (const chunk of response.body) {
|
|
19
|
+
size += chunk.byteLength;
|
|
20
|
+
if (size > maxBytes) throw new Error("CEF helper download exceeded its size");
|
|
21
|
+
hash.update(chunk);
|
|
22
|
+
await file.writeFile(chunk);
|
|
23
|
+
}
|
|
24
|
+
} finally {
|
|
25
|
+
try {
|
|
26
|
+
await file.close();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
closeFailed = true;
|
|
29
|
+
closeError = error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (closeFailed) throw closeError;
|
|
33
|
+
return hash.digest("hex");
|
|
34
|
+
}
|
|
35
|
+
export { downloadCefHelperInput };
|