@adea-ai/app-framework 0.25.1 → 0.27.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 +163 -21
- 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/framework-update-cli.js +16 -3
- package/dist/cli/release-step-cli.js +6 -1
- 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 +22 -3
- package/dist/installer/installer-identity.js +63 -72
- package/dist/installer/installer-image-mount.d.ts +48 -0
- package/dist/installer/installer-image-mount.js +347 -0
- package/dist/installer/installer-layout.d.ts +2 -0
- package/dist/installer/installer-layout.js +6 -2
- 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/release/release-steps.d.ts +5 -0
- package/dist/release/release-steps.js +2 -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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { downloadCefHelperInput } from "./cef-helper-download.js";
|
|
1
2
|
import { CEF_BRIDGE_PATCH_PATH, CEF_HELPER_SOURCES, ELECTROBUN_COMMIT, PINNED_CEF_BRIDGE_PATCH, applyElectrobunPatch } from "./electrobun-source-patch.js";
|
|
2
|
-
import { chmod, lstat, mkdir, mkdtemp,
|
|
3
|
+
import { chmod, lstat, mkdir, mkdtemp, open, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
4
|
import { dirname, isAbsolute, join } from "node:path";
|
|
4
|
-
import { createWriteStream } from "node:fs";
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
7
7
|
import { availableParallelism, homedir } from "node:os";
|
|
@@ -13,6 +13,8 @@ var CHROMIUM_VERSION = "156.0.8078.17";
|
|
|
13
13
|
var MACOS_DEPLOYMENT_TARGET = "14.0";
|
|
14
14
|
/** Bump when the build recipe below changes, so cached helpers are rebuilt. */
|
|
15
15
|
var RECIPE = 1;
|
|
16
|
+
/** Change when the on-disk cache format changes, independently of the build recipe. */
|
|
17
|
+
var CACHE_FORMAT = 2;
|
|
16
18
|
/** Targets the packaged native probes exercise; any other CEF bundle fails closed. */
|
|
17
19
|
var TARGETS = {
|
|
18
20
|
"macos-arm64": {
|
|
@@ -54,7 +56,8 @@ function cefHelperCacheKey(os, arch) {
|
|
|
54
56
|
CEF_VERSION,
|
|
55
57
|
CHROMIUM_VERSION,
|
|
56
58
|
pin.sdkSha256,
|
|
57
|
-
RECIPE
|
|
59
|
+
RECIPE,
|
|
60
|
+
CACHE_FORMAT
|
|
58
61
|
]);
|
|
59
62
|
return `cef-helper-${os}-${arch}-${sha256(Buffer.from(identity)).slice(0, 16)}`;
|
|
60
63
|
}
|
|
@@ -68,60 +71,127 @@ function cefHelperCacheRoot(env) {
|
|
|
68
71
|
const base = process.platform === "darwin" ? join(homedir(), "Library", "Caches") : process.platform === "win32" ? env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local") : env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
|
|
69
72
|
return join(base, "adea-app-framework");
|
|
70
73
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
var CACHE_MANIFEST = "manifest.json";
|
|
75
|
+
var HASH_CHUNK_BYTES = 1048576;
|
|
76
|
+
function sameFile(left, right) {
|
|
77
|
+
return right.isFile() && left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
78
|
+
}
|
|
79
|
+
async function openRegular(path) {
|
|
80
|
+
const info = await lstat(path);
|
|
81
|
+
if (!info.isFile() || !Number.isSafeInteger(info.size) || info.size < 1) throw new Error("Invalid cached CEF helper");
|
|
82
|
+
const file = await open(path, "r");
|
|
77
83
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
if (!sameFile(info, await file.stat())) throw new Error("Invalid cached CEF helper");
|
|
85
|
+
return {
|
|
86
|
+
file,
|
|
87
|
+
info
|
|
88
|
+
};
|
|
81
89
|
} catch (error) {
|
|
82
|
-
|
|
90
|
+
await file.close();
|
|
91
|
+
throw error;
|
|
83
92
|
}
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
}
|
|
94
|
+
async function helperDigest(path, destination) {
|
|
95
|
+
const { file, info } = await openRegular(path);
|
|
96
|
+
const hash = createHash("sha256");
|
|
97
|
+
const buffer = Buffer.allocUnsafe(HASH_CHUNK_BYTES);
|
|
98
|
+
let offset = 0;
|
|
86
99
|
try {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
while (offset < info.size) {
|
|
101
|
+
const { bytesRead } = await file.read(buffer, 0, Math.min(buffer.length, info.size - offset), offset);
|
|
102
|
+
if (!bytesRead) throw new Error("Invalid cached CEF helper");
|
|
103
|
+
hash.update(buffer.subarray(0, bytesRead));
|
|
104
|
+
if (destination) {
|
|
105
|
+
let written = 0;
|
|
106
|
+
while (written < bytesRead) {
|
|
107
|
+
const result = await destination.write(buffer, written, bytesRead - written);
|
|
108
|
+
if (!result.bytesWritten) throw new Error("CEF helper copy failed");
|
|
109
|
+
written += result.bytesWritten;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
offset += bytesRead;
|
|
99
113
|
}
|
|
100
|
-
|
|
114
|
+
if (!sameFile(info, await file.stat())) throw new Error("Invalid cached CEF helper");
|
|
115
|
+
return {
|
|
116
|
+
size: offset,
|
|
117
|
+
sha256: hash.digest("hex")
|
|
118
|
+
};
|
|
101
119
|
} finally {
|
|
102
|
-
await
|
|
103
|
-
recursive: true,
|
|
104
|
-
force: true
|
|
105
|
-
});
|
|
120
|
+
await file.close();
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
|
-
async function
|
|
109
|
-
const
|
|
110
|
-
if (!response.ok || !response.body) throw new Error("CEF helper download failed");
|
|
111
|
-
const hash = createHash("sha256");
|
|
112
|
-
const file = createWriteStream(path, { flags: "wx" });
|
|
113
|
-
let size = 0;
|
|
123
|
+
async function readManifest(path) {
|
|
124
|
+
const { file, info } = await openRegular(path);
|
|
114
125
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
if (info.size > 1024) throw new Error("Invalid cached CEF helper");
|
|
127
|
+
const bytes = Buffer.alloc(info.size);
|
|
128
|
+
let offset = 0;
|
|
129
|
+
while (offset < bytes.length) {
|
|
130
|
+
const { bytesRead } = await file.read(bytes, offset, bytes.length - offset, offset);
|
|
131
|
+
if (!bytesRead) throw new Error("Invalid cached CEF helper");
|
|
132
|
+
offset += bytesRead;
|
|
120
133
|
}
|
|
134
|
+
if (!sameFile(info, await file.stat())) throw new Error("Invalid cached CEF helper");
|
|
135
|
+
return bytes.toString("utf8");
|
|
121
136
|
} finally {
|
|
122
|
-
await
|
|
137
|
+
await file.close();
|
|
123
138
|
}
|
|
124
|
-
|
|
139
|
+
}
|
|
140
|
+
async function verifyCachedHelper(entry, output, key) {
|
|
141
|
+
try {
|
|
142
|
+
if (!(await lstat(entry)).isDirectory()) throw new Error("Invalid cached CEF helper");
|
|
143
|
+
const manifest = await readManifest(join(entry, CACHE_MANIFEST));
|
|
144
|
+
const actual = await helperDigest(output);
|
|
145
|
+
if (manifest !== JSON.stringify({
|
|
146
|
+
key,
|
|
147
|
+
...actual
|
|
148
|
+
}) + "\n") throw new Error("Invalid cached CEF helper");
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (error.code === "ENOENT") throw new Error("Invalid cached CEF helper", { cause: error });
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Return the cached patched helper for this target, building it once from the pinned source. */
|
|
155
|
+
async function ensurePatchedCefHelper(env, os, arch, build = buildPatchedCefHelper) {
|
|
156
|
+
const pin = target(os, arch);
|
|
157
|
+
const root = cefHelperCacheRoot(env);
|
|
158
|
+
const key = cefHelperCacheKey(os, arch);
|
|
159
|
+
const entry = join(root, key);
|
|
160
|
+
const output = join(entry, pin.platform === "win" ? "process_helper.exe" : "process_helper");
|
|
161
|
+
try {
|
|
162
|
+
await lstat(entry);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error.code !== "ENOENT") throw error;
|
|
165
|
+
await mkdir(root, { recursive: true });
|
|
166
|
+
const work = await mkdtemp(join(root, ".build-"));
|
|
167
|
+
try {
|
|
168
|
+
const staged = join(work, "out");
|
|
169
|
+
await mkdir(staged);
|
|
170
|
+
const stagedOutput = join(staged, pin.platform === "win" ? "process_helper.exe" : "process_helper");
|
|
171
|
+
await build(pin, work, stagedOutput);
|
|
172
|
+
const digest = await helperDigest(stagedOutput);
|
|
173
|
+
await writeFile(join(staged, CACHE_MANIFEST), JSON.stringify({
|
|
174
|
+
key,
|
|
175
|
+
...digest
|
|
176
|
+
}) + "\n", { flag: "wx" });
|
|
177
|
+
try {
|
|
178
|
+
await rename(staged, entry);
|
|
179
|
+
} catch (publishError) {
|
|
180
|
+
if (![
|
|
181
|
+
"EEXIST",
|
|
182
|
+
"ENOTEMPTY",
|
|
183
|
+
"EPERM"
|
|
184
|
+
].includes(publishError.code ?? "")) throw publishError;
|
|
185
|
+
}
|
|
186
|
+
} finally {
|
|
187
|
+
await rm(work, {
|
|
188
|
+
recursive: true,
|
|
189
|
+
force: true
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
await verifyCachedHelper(entry, output, key);
|
|
194
|
+
return output;
|
|
125
195
|
}
|
|
126
196
|
function step(name, command, args, cwd) {
|
|
127
197
|
const result = spawnSync(command, args, {
|
|
@@ -156,14 +226,14 @@ async function buildPatchedCefHelper(pin, work, output) {
|
|
|
156
226
|
const source = join(work, "electrobun");
|
|
157
227
|
for (const path of Object.values(CEF_HELPER_SOURCES)) {
|
|
158
228
|
await mkdir(dirname(join(source, path)), { recursive: true });
|
|
159
|
-
await
|
|
229
|
+
await downloadCefHelperInput(`https://raw.githubusercontent.com/blackboardsh/electrobun/${ELECTROBUN_COMMIT}/${path}`, join(source, path), 65536);
|
|
160
230
|
}
|
|
161
231
|
step("source", "git", ["init", "-q"], source);
|
|
162
232
|
applyElectrobunPatch(source, CEF_BRIDGE_PATCH_PATH, PINNED_CEF_BRIDGE_PATCH);
|
|
163
233
|
const helperSource = join(source, CEF_HELPER_SOURCES[pin.platform]);
|
|
164
234
|
const distribution = `cef_binary_${CEF_VERSION}+chromium-${CHROMIUM_VERSION}_${pin.sdk}_minimal`;
|
|
165
235
|
const archive = join(work, "cef.tar.bz2");
|
|
166
|
-
if (await
|
|
236
|
+
if (await downloadCefHelperInput(`https://cef-builds.spotifycdn.com/${encodeURIComponent(distribution)}.tar.bz2`, archive, pin.sdkBytes) !== pin.sdkSha256 || (await stat(archive)).size !== pin.sdkBytes) throw new Error("Unexpected CEF distribution digest");
|
|
167
237
|
const cef = join(work, "cef");
|
|
168
238
|
await mkdir(cef);
|
|
169
239
|
const library = {
|
|
@@ -377,25 +447,40 @@ async function installPatchedCefHelpers(env, ensure = ensurePatchedCefHelper, st
|
|
|
377
447
|
if (!cef) return 0;
|
|
378
448
|
const pin = target(env.ELECTROBUN_OS, env.ELECTROBUN_ARCH);
|
|
379
449
|
if (!helpers.length) throw new Error("Expected bundled CEF helpers");
|
|
380
|
-
const
|
|
381
|
-
const
|
|
450
|
+
const patchedPath = await ensure(env, env.ELECTROBUN_OS, env.ELECTROBUN_ARCH);
|
|
451
|
+
const patched = await helperDigest(patchedPath);
|
|
382
452
|
const stock = [];
|
|
383
453
|
for (const path of helpers) {
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
454
|
+
const info = await lstat(path);
|
|
455
|
+
const digest = await helperDigest(path);
|
|
456
|
+
if (!sameFile(info, await lstat(path))) throw new Error("Unexpected CEF helper change");
|
|
457
|
+
if (digest.sha256 === (stockSha256 ?? pin.stockHelperSha256)) stock.push({
|
|
458
|
+
path,
|
|
459
|
+
info
|
|
460
|
+
});
|
|
461
|
+
else if (digest.sha256 !== patched.sha256) throw new Error("Unexpected CEF helper digest");
|
|
387
462
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
463
|
+
const staged = [];
|
|
464
|
+
try {
|
|
465
|
+
for (const { path, info } of stock) {
|
|
466
|
+
const temp = `${path}.${randomUUID()}.tmp`;
|
|
467
|
+
const output = await open(temp, "wx", info.mode & 511);
|
|
468
|
+
staged.push({
|
|
469
|
+
path,
|
|
470
|
+
temp
|
|
394
471
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
472
|
+
try {
|
|
473
|
+
const copied = await helperDigest(patchedPath, output);
|
|
474
|
+
if (copied.size !== patched.size || copied.sha256 !== patched.sha256) throw new Error("Unexpected CEF helper digest");
|
|
475
|
+
} finally {
|
|
476
|
+
await output.close();
|
|
477
|
+
}
|
|
478
|
+
await chmod(temp, info.mode & 511);
|
|
398
479
|
}
|
|
480
|
+
for (const { path, info } of stock) if (!sameFile(info, await lstat(path))) throw new Error("Unexpected CEF helper change");
|
|
481
|
+
for (const { path, temp } of staged) await rename(temp, path);
|
|
482
|
+
} finally {
|
|
483
|
+
for (const { temp } of staged) await rm(temp, { force: true });
|
|
399
484
|
}
|
|
400
485
|
return helpers.length;
|
|
401
486
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
2
|
+
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
3
|
+
// src/native/exclusive-rename.ts
|
|
4
|
+
/** Rename without replacing an existing destination on supported desktop platforms. */
|
|
5
|
+
function renameExclusive(source, destination) {
|
|
6
|
+
if (typeof source !== "string" || typeof destination !== "string" || !isAbsolute(source) || !isAbsolute(destination) || resolve(source) !== source || resolve(destination) !== destination || source === destination || source.includes("\0") || destination.includes("\0")) throw new Error("Invalid exclusive rename paths");
|
|
7
|
+
if (process.platform === "darwin") {
|
|
8
|
+
const library = dlopen("libSystem.B.dylib", { renamex_np: {
|
|
9
|
+
args: [
|
|
10
|
+
FFIType.ptr,
|
|
11
|
+
FFIType.ptr,
|
|
12
|
+
FFIType.u32
|
|
13
|
+
],
|
|
14
|
+
returns: FFIType.i32
|
|
15
|
+
} });
|
|
16
|
+
try {
|
|
17
|
+
const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
|
|
18
|
+
if (library.symbols.renamex_np(ptr(from), ptr(to), 4) !== 0) throw new Error("Exclusive rename failed");
|
|
19
|
+
} finally {
|
|
20
|
+
library.close();
|
|
21
|
+
}
|
|
22
|
+
} else if (process.platform === "linux") {
|
|
23
|
+
const library = dlopen("libc.so.6", { renameat2: {
|
|
24
|
+
args: [
|
|
25
|
+
FFIType.i32,
|
|
26
|
+
FFIType.ptr,
|
|
27
|
+
FFIType.i32,
|
|
28
|
+
FFIType.ptr,
|
|
29
|
+
FFIType.u32
|
|
30
|
+
],
|
|
31
|
+
returns: FFIType.i32
|
|
32
|
+
} });
|
|
33
|
+
try {
|
|
34
|
+
const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
|
|
35
|
+
if (library.symbols.renameat2(-100, ptr(from), -100, ptr(to), 1) !== 0) throw new Error("Exclusive rename failed");
|
|
36
|
+
} finally {
|
|
37
|
+
library.close();
|
|
38
|
+
}
|
|
39
|
+
} else if (process.platform === "win32") {
|
|
40
|
+
const library = dlopen("kernel32.dll", { MoveFileW: {
|
|
41
|
+
args: [FFIType.ptr, FFIType.ptr],
|
|
42
|
+
returns: FFIType.i32
|
|
43
|
+
} });
|
|
44
|
+
try {
|
|
45
|
+
const from = Buffer.from(source + "\0", "utf16le"), to = Buffer.from(destination + "\0", "utf16le");
|
|
46
|
+
if (library.symbols.MoveFileW(ptr(from), ptr(to)) === 0) throw new Error("Exclusive rename failed");
|
|
47
|
+
} finally {
|
|
48
|
+
library.close();
|
|
49
|
+
}
|
|
50
|
+
} else throw new Error("Unsupported exclusive rename platform");
|
|
51
|
+
}
|
|
52
|
+
export { renameExclusive };
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
var identifier = (value) => typeof value === "string" && value.length > 0 && value.length <= 128 && /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(value);
|
|
3
3
|
/** Native credentials only. Apps choose the service namespace and own authorization and migration. */
|
|
4
4
|
function createNativeSecretStore(options) {
|
|
5
|
+
const service = options.service;
|
|
5
6
|
const maxBytes = options.maxBytes ?? 2048;
|
|
6
|
-
if (!identifier(
|
|
7
|
+
if (!identifier(service) || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 2048) throw new Error("Invalid credential store configuration");
|
|
7
8
|
const backend = options.backend ?? Bun.secrets;
|
|
8
9
|
if (!backend || typeof backend.get !== "function" || typeof backend.set !== "function" || typeof backend.delete !== "function") throw new Error("Credential store unavailable");
|
|
9
10
|
let queue = Promise.resolve();
|
|
@@ -19,7 +20,7 @@ function createNativeSecretStore(options) {
|
|
|
19
20
|
async function read(account) {
|
|
20
21
|
try {
|
|
21
22
|
const value = await backend.get({
|
|
22
|
-
service
|
|
23
|
+
service,
|
|
23
24
|
name: account
|
|
24
25
|
});
|
|
25
26
|
if (value !== null && (typeof value !== "string" || value.includes("\0") || Buffer.byteLength(value, "utf8") > maxBytes)) throw new Error("Invalid native result");
|
|
@@ -39,7 +40,7 @@ function createNativeSecretStore(options) {
|
|
|
39
40
|
return ordered(async () => {
|
|
40
41
|
try {
|
|
41
42
|
await backend.set({
|
|
42
|
-
service
|
|
43
|
+
service,
|
|
43
44
|
name: key,
|
|
44
45
|
value,
|
|
45
46
|
persist: "local"
|
|
@@ -55,7 +56,7 @@ function createNativeSecretStore(options) {
|
|
|
55
56
|
return ordered(async () => {
|
|
56
57
|
try {
|
|
57
58
|
const removed = await backend.delete({
|
|
58
|
-
service
|
|
59
|
+
service,
|
|
59
60
|
name: key
|
|
60
61
|
});
|
|
61
62
|
if (typeof removed !== "boolean" || await read(key) !== null) throw new Error("Invalid native result");
|
|
@@ -24,8 +24,11 @@ export type PartitionedWindow = {
|
|
|
24
24
|
* runs synchronously, this assigns the partition to the first view initialized
|
|
25
25
|
* and restores `BrowserView.prototype.init` afterwards. It fails closed (and
|
|
26
26
|
* closes the window) unless exactly one view was created and the window's view
|
|
27
|
-
* reports the requested partition. Without a partition it
|
|
28
|
-
*
|
|
27
|
+
* reports the requested partition. Without a partition it calls `construct`
|
|
28
|
+
* with the default profile, unless a patch is active or the class could not be
|
|
29
|
+
* restored. An own accessor for `init` is unsupported. If restoration fails,
|
|
30
|
+
* this helper refuses that prototype and its descendants; it cannot repair a
|
|
31
|
+
* frozen prototype or control direct calls outside this helper.
|
|
29
32
|
*/
|
|
30
33
|
export declare function constructPartitionedWindow<Window extends PartitionedWindow>(options: {
|
|
31
34
|
BrowserView: PartitionableViewClass;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// src/native/partitioned-window.ts
|
|
2
2
|
var PARTITION = /^(?:persist:)?[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
3
3
|
var constructing = false;
|
|
4
|
+
var unrestored = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
function hasUnrestoredPrototype(prototype) {
|
|
6
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7
|
+
let current = prototype;
|
|
8
|
+
while (current) {
|
|
9
|
+
if (unrestored.has(current) || seen.has(current)) return true;
|
|
10
|
+
seen.add(current);
|
|
11
|
+
current = Object.getPrototypeOf(current);
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
var sameDescriptor = (a, b) => a === void 0 || b === void 0 ? a === b : a.value === b.value && a.get === b.get && a.set === b.set && a.writable === b.writable && a.enumerable === b.enumerable && a.configurable === b.configurable;
|
|
4
16
|
/**
|
|
5
17
|
* Construct a `BrowserWindow` whose own webview uses `partition`.
|
|
6
18
|
*
|
|
@@ -9,35 +21,83 @@ var constructing = false;
|
|
|
9
21
|
* runs synchronously, this assigns the partition to the first view initialized
|
|
10
22
|
* and restores `BrowserView.prototype.init` afterwards. It fails closed (and
|
|
11
23
|
* closes the window) unless exactly one view was created and the window's view
|
|
12
|
-
* reports the requested partition. Without a partition it
|
|
13
|
-
*
|
|
24
|
+
* reports the requested partition. Without a partition it calls `construct`
|
|
25
|
+
* with the default profile, unless a patch is active or the class could not be
|
|
26
|
+
* restored. An own accessor for `init` is unsupported. If restoration fails,
|
|
27
|
+
* this helper refuses that prototype and its descendants; it cannot repair a
|
|
28
|
+
* frozen prototype or control direct calls outside this helper.
|
|
14
29
|
*/
|
|
15
30
|
function constructPartitionedWindow(options) {
|
|
16
31
|
const { partition } = options;
|
|
32
|
+
const prototype = options.BrowserView.prototype;
|
|
33
|
+
if (hasUnrestoredPrototype(prototype)) throw new Error("Electrobun BrowserView could not be restored");
|
|
34
|
+
if (constructing) throw new Error("Partitioned windows must be constructed one at a time");
|
|
17
35
|
if (partition === void 0 || partition === null) return options.construct();
|
|
18
36
|
if (!PARTITION.test(partition)) throw new Error("Invalid browser partition");
|
|
19
|
-
const
|
|
37
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, "init");
|
|
38
|
+
if (descriptor && !("value" in descriptor)) throw new Error("Unsupported Electrobun BrowserView");
|
|
20
39
|
const init = prototype.init;
|
|
21
40
|
if (typeof init !== "function") throw new Error("Unsupported Electrobun BrowserView");
|
|
22
|
-
if (constructing) throw new Error("Partitioned windows must be constructed one at a time");
|
|
23
41
|
let views = 0;
|
|
24
42
|
let window;
|
|
43
|
+
let setupFailed = false;
|
|
44
|
+
let setupError;
|
|
45
|
+
let restoreFailed = false;
|
|
46
|
+
let restoreError;
|
|
25
47
|
constructing = true;
|
|
26
|
-
|
|
48
|
+
const patched = function() {
|
|
27
49
|
if (++views === 1) this.partition = partition;
|
|
28
50
|
return init.call(this);
|
|
29
51
|
};
|
|
30
52
|
try {
|
|
53
|
+
const patchDescriptor = descriptor ? {
|
|
54
|
+
...descriptor,
|
|
55
|
+
value: patched
|
|
56
|
+
} : {
|
|
57
|
+
value: patched,
|
|
58
|
+
writable: true,
|
|
59
|
+
enumerable: false,
|
|
60
|
+
configurable: true
|
|
61
|
+
};
|
|
62
|
+
Object.defineProperty(prototype, "init", patchDescriptor);
|
|
63
|
+
if (!sameDescriptor(Object.getOwnPropertyDescriptor(prototype, "init"), patchDescriptor)) throw new Error("Could not install Electrobun BrowserView patch");
|
|
31
64
|
window = options.construct();
|
|
65
|
+
} catch (error) {
|
|
66
|
+
setupFailed = true;
|
|
67
|
+
setupError = error;
|
|
32
68
|
} finally {
|
|
33
|
-
|
|
34
|
-
|
|
69
|
+
try {
|
|
70
|
+
if (!sameDescriptor(Object.getOwnPropertyDescriptor(prototype, "init"), descriptor)) {
|
|
71
|
+
if (descriptor) Object.defineProperty(prototype, "init", descriptor);
|
|
72
|
+
else Reflect.deleteProperty(prototype, "init");
|
|
73
|
+
}
|
|
74
|
+
if (!sameDescriptor(Object.getOwnPropertyDescriptor(prototype, "init"), descriptor)) {
|
|
75
|
+
restoreFailed = true;
|
|
76
|
+
restoreError = /* @__PURE__ */ new Error("BrowserView init did not restore");
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
restoreFailed = true;
|
|
80
|
+
restoreError = error;
|
|
81
|
+
} finally {
|
|
82
|
+
constructing = false;
|
|
83
|
+
}
|
|
35
84
|
}
|
|
36
|
-
if (
|
|
85
|
+
if (restoreFailed) {
|
|
86
|
+
unrestored.add(prototype);
|
|
87
|
+
try {
|
|
88
|
+
window?.close();
|
|
89
|
+
} catch {}
|
|
90
|
+
throw new Error("Electrobun BrowserView could not be restored", { cause: restoreError });
|
|
91
|
+
}
|
|
92
|
+
if (setupFailed) throw setupError;
|
|
93
|
+
if (!window) throw new Error("Electrobun did not create a window");
|
|
94
|
+
try {
|
|
95
|
+
if (views !== 1 || window.webview?.partition !== partition) throw new Error("Electrobun did not create the window view in the requested partition");
|
|
96
|
+
} catch (error) {
|
|
37
97
|
try {
|
|
38
98
|
window.close();
|
|
39
99
|
} catch {}
|
|
40
|
-
throw
|
|
100
|
+
throw error;
|
|
41
101
|
}
|
|
42
102
|
return window;
|
|
43
103
|
}
|
|
@@ -30,8 +30,8 @@ function registerSidecarServices(options) {
|
|
|
30
30
|
for (const command of commands) unregister.push(services.register(prefix + command, {
|
|
31
31
|
parse: (value) => parse(command, value),
|
|
32
32
|
authorize: (principal) => authorize(principal, command),
|
|
33
|
-
async run(_principal, args) {
|
|
34
|
-
const reply = await sidecar.call(command, args);
|
|
33
|
+
async run(_principal, args, signal) {
|
|
34
|
+
const reply = await sidecar.call(command, args, signal ? { signal } : void 0);
|
|
35
35
|
if (reply.ok) return reply.value;
|
|
36
36
|
throw new ServiceError(reply.reason, reply.error);
|
|
37
37
|
},
|