@adea-ai/app-framework 0.0.0-stage → 0.24.1
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 +201 -0
- package/NOTICE +30 -0
- package/README.md +1009 -2
- package/dist/app/application.d.ts +47 -0
- package/dist/app/application.js +115 -0
- package/dist/app/create-application.d.ts +13 -0
- package/dist/app/create-application.js +178 -0
- package/dist/app/service-registry.d.ts +44 -0
- package/dist/app/service-registry.js +116 -0
- package/dist/appearance/appearance-host.d.ts +62 -0
- package/dist/appearance/appearance-host.js +115 -0
- package/dist/appearance/appearance-preferences.d.ts +106 -0
- package/dist/appearance/appearance-preferences.js +175 -0
- package/dist/appearance/composition.d.ts +11 -0
- package/dist/appearance/composition.js +16 -0
- package/dist/appearance/custom-theme-import.d.ts +14 -0
- package/dist/appearance/custom-theme-import.js +315 -0
- package/dist/appearance/custom-theme-library.d.ts +146 -0
- package/dist/appearance/custom-theme-library.js +378 -0
- package/dist/appearance/editor.d.ts +20 -0
- package/dist/appearance/editor.js +47 -0
- package/dist/appearance/theme-file-importer.d.ts +23 -0
- package/dist/appearance/theme-file-importer.js +66 -0
- package/dist/appearance/theme-record-adapter.d.ts +26 -0
- package/dist/appearance/theme-record-adapter.js +64 -0
- package/dist/appearance/theme-registry.d.ts +10 -0
- package/dist/appearance/theme-registry.js +16 -0
- package/dist/appearance/window-surface.d.ts +5 -0
- package/dist/appearance/window-surface.js +9 -0
- package/dist/ci/toolchain-identity.d.ts +39 -0
- package/dist/ci/toolchain-identity.js +196 -0
- package/dist/cli/cef-helper-cli.d.ts +2 -0
- package/dist/cli/cef-helper-cli.js +18 -0
- package/dist/cli/cli-runner.d.ts +8 -0
- package/dist/cli/cli-runner.js +23 -0
- package/dist/cli/create-application-cli.d.ts +2 -0
- package/dist/cli/create-application-cli.js +40 -0
- package/dist/cli/electrobun-shortcut-patch-cli.d.ts +2 -0
- package/dist/cli/electrobun-shortcut-patch-cli.js +17 -0
- package/dist/cli/framework-update-cli.d.ts +2 -0
- package/dist/cli/framework-update-cli.js +40 -0
- package/dist/cli/release-assets-plan-cli.d.ts +2 -0
- package/dist/cli/release-assets-plan-cli.js +14 -0
- package/dist/cli/release-cut-cli.d.ts +2 -0
- package/dist/cli/release-cut-cli.js +27 -0
- package/dist/cli/release-descriptor-staging-cli.d.ts +2 -0
- package/dist/cli/release-descriptor-staging-cli.js +45 -0
- package/dist/cli/release-finalize-cli.d.ts +1 -0
- package/dist/cli/release-finalize-cli.js +30 -0
- package/dist/cli/release-promote-cli.d.ts +2 -0
- package/dist/cli/release-promote-cli.js +32 -0
- package/dist/cli/release-publish-cli.d.ts +2 -0
- package/dist/cli/release-publish-cli.js +48 -0
- package/dist/cli/release-sign-cli.d.ts +2 -0
- package/dist/cli/release-sign-cli.js +13 -0
- package/dist/cli/release-step-cli.d.ts +2 -0
- package/dist/cli/release-step-cli.js +44 -0
- package/dist/cli/toolchain-identity-cli.d.ts +2 -0
- package/dist/cli/toolchain-identity-cli.js +10 -0
- package/dist/cli/update-helper-cli.d.ts +1 -0
- package/dist/cli/update-helper-cli.js +10 -0
- package/dist/cli/windows-runtime-patch-cli.d.ts +2 -0
- package/dist/cli/windows-runtime-patch-cli.js +17 -0
- package/dist/desktop/application-command-client.d.ts +15 -0
- package/dist/desktop/application-command-client.js +21 -0
- package/dist/desktop/channel-handshake.d.ts +32 -0
- package/dist/desktop/channel-handshake.js +111 -0
- package/dist/desktop/channel-proof.d.ts +43 -0
- package/dist/desktop/channel-proof.js +85 -0
- package/dist/desktop/client-assets.d.ts +7 -0
- package/dist/desktop/client-assets.js +59 -0
- package/dist/desktop/desktop-client.d.ts +23 -0
- package/dist/desktop/desktop-client.js +231 -0
- package/dist/desktop/desktop-gateway.d.ts +18 -0
- package/dist/desktop/desktop-gateway.js +146 -0
- package/dist/desktop/desktop-host.d.ts +48 -0
- package/dist/desktop/desktop-host.js +208 -0
- package/dist/desktop/desktop-stream.d.ts +36 -0
- package/dist/desktop/desktop-stream.js +231 -0
- package/dist/desktop/loopback-policy.d.ts +19 -0
- package/dist/desktop/loopback-policy.js +23 -0
- package/dist/desktop/open-url-channel.d.ts +15 -0
- package/dist/desktop/open-url-channel.js +55 -0
- package/dist/desktop/string-policy.d.ts +2 -0
- package/dist/desktop/string-policy.js +11 -0
- package/dist/framework-source.json +1 -0
- package/dist/installer/archive-entry.d.ts +6 -0
- package/dist/installer/archive-entry.js +14 -0
- package/dist/installer/command-artifact.d.ts +47 -0
- package/dist/installer/command-artifact.js +261 -0
- package/dist/installer/command-qualification-command.d.ts +12 -0
- package/dist/installer/command-qualification-command.js +71 -0
- package/dist/installer/hosted-runner.d.ts +4 -0
- package/dist/installer/hosted-runner.js +10 -0
- package/dist/installer/installed-payload.d.ts +29 -0
- package/dist/installer/installed-payload.js +312 -0
- package/dist/installer/installer-ci-bootstrap.d.ts +26 -0
- package/dist/installer/installer-ci-bootstrap.js +160 -0
- package/dist/installer/installer-ci-preflight.d.ts +1 -0
- package/dist/installer/installer-ci-preflight.js +49 -0
- package/dist/installer/installer-ci-worker.d.ts +1 -0
- package/dist/installer/installer-ci-worker.js +105 -0
- package/dist/installer/installer-extraction.d.ts +14 -0
- package/dist/installer/installer-extraction.js +289 -0
- package/dist/installer/installer-fetch-guard.d.ts +15 -0
- package/dist/installer/installer-fetch-guard.js +50 -0
- package/dist/installer/installer-identity.d.ts +23 -0
- package/dist/installer/installer-identity.js +286 -0
- package/dist/installer/installer-layout.d.ts +21 -0
- package/dist/installer/installer-layout.js +89 -0
- package/dist/installer/installer-observation.d.ts +64 -0
- package/dist/installer/installer-observation.js +473 -0
- package/dist/installer/installer-process-cleanup.d.ts +18 -0
- package/dist/installer/installer-process-cleanup.js +158 -0
- package/dist/installer/installer-qualification-command.d.ts +11 -0
- package/dist/installer/installer-qualification-command.js +71 -0
- package/dist/installer/installer-renderer-evidence.d.ts +43 -0
- package/dist/installer/installer-renderer-evidence.js +136 -0
- package/dist/installer/installer-upgrade-command.d.ts +37 -0
- package/dist/installer/installer-upgrade-command.js +172 -0
- package/dist/installer/installer-worker-guard.d.ts +21 -0
- package/dist/installer/installer-worker-guard.js +72 -0
- package/dist/installer/native-executable.d.ts +5 -0
- package/dist/installer/native-executable.js +21 -0
- package/dist/installer/upgrade-asset-download.d.ts +13 -0
- package/dist/installer/upgrade-asset-download.js +41 -0
- package/dist/installer/write-all.d.ts +6 -0
- package/dist/installer/write-all.js +11 -0
- package/dist/native/app-bundle.d.ts +28 -0
- package/dist/native/app-bundle.js +60 -0
- package/dist/native/cef-helper.d.ts +28 -0
- package/dist/native/cef-helper.js +402 -0
- package/dist/native/desktop-build-hook.d.ts +7 -0
- package/dist/native/desktop-build-hook.js +20 -0
- package/dist/native/electrobun-source-patch.d.ts +25 -0
- package/dist/native/electrobun-source-patch.js +93 -0
- package/dist/native/linux-cef-links.d.ts +2 -0
- package/dist/native/linux-cef-links.js +15 -0
- package/dist/native/native-secret-store.d.ts +27 -0
- package/dist/native/native-secret-store.js +70 -0
- package/dist/native/native-utilities.d.ts +24 -0
- package/dist/native/native-utilities.js +85 -0
- package/dist/native/partitioned-window.d.ts +34 -0
- package/dist/native/partitioned-window.js +44 -0
- package/dist/native/renderer-profile.d.ts +53 -0
- package/dist/native/renderer-profile.js +30 -0
- package/dist/native/secure-window.d.ts +38 -0
- package/dist/native/secure-window.js +77 -0
- package/dist/native/sidecar-services.d.ts +23 -0
- package/dist/native/sidecar-services.js +46 -0
- package/dist/native/sidecar.d.ts +81 -0
- package/dist/native/sidecar.js +250 -0
- package/dist/native/window-bootstrap.d.ts +24 -0
- package/dist/native/window-bootstrap.js +63 -0
- package/dist/native/window-options.d.ts +32 -0
- package/dist/native/window-options.js +23 -0
- package/dist/native/windows-build-hook-internal.d.ts +2 -0
- package/dist/native/windows-build-hook-internal.js +32 -0
- package/dist/native/windows-build-hook.d.ts +2 -0
- package/dist/native/windows-build-hook.js +12 -0
- package/dist/native/windows-runtime-patch-internal.d.ts +3 -0
- package/dist/native/windows-runtime-patch-internal.js +20 -0
- package/dist/native/windows-runtime-patch.d.ts +4 -0
- package/dist/native/windows-runtime-patch.js +12 -0
- package/dist/release/feed-release-cut.d.ts +23 -0
- package/dist/release/feed-release-cut.js +93 -0
- package/dist/release/feed-state.d.ts +25 -0
- package/dist/release/feed-state.js +81 -0
- package/dist/release/framework-package-publish.d.ts +21 -0
- package/dist/release/framework-package-publish.js +127 -0
- package/dist/release/framework-update.d.ts +30 -0
- package/dist/release/framework-update.js +139 -0
- package/dist/release/github-cli.d.ts +6 -0
- package/dist/release/github-cli.js +16 -0
- package/dist/release/github-release-assets.d.ts +3 -0
- package/dist/release/github-release-assets.js +24 -0
- package/dist/release/github-release-cut.d.ts +14 -0
- package/dist/release/github-release-cut.js +174 -0
- package/dist/release/github-release-lookup.d.ts +7 -0
- package/dist/release/github-release-lookup.js +29 -0
- package/dist/release/github-release-promotion.d.ts +10 -0
- package/dist/release/github-release-promotion.js +78 -0
- package/dist/release/github-release-provenance.d.ts +9 -0
- package/dist/release/github-release-provenance.js +27 -0
- package/dist/release/github-release-publisher.d.ts +9 -0
- package/dist/release/github-release-publisher.js +63 -0
- package/dist/release/github-release-qualification.d.ts +12 -0
- package/dist/release/github-release-qualification.js +80 -0
- package/dist/release/local-provenance.d.ts +24 -0
- package/dist/release/local-provenance.js +72 -0
- package/dist/release/local-release.d.ts +133 -0
- package/dist/release/local-release.js +387 -0
- package/dist/release/macos-dmg.d.ts +22 -0
- package/dist/release/macos-dmg.js +91 -0
- package/dist/release/release-artifact.d.ts +6 -0
- package/dist/release/release-artifact.js +38 -0
- package/dist/release/release-assets-plan.d.ts +14 -0
- package/dist/release/release-assets-plan.js +65 -0
- package/dist/release/release-config.d.ts +76 -0
- package/dist/release/release-config.js +180 -0
- package/dist/release/release-cut-command.d.ts +13 -0
- package/dist/release/release-cut-command.js +39 -0
- package/dist/release/release-cut.d.ts +54 -0
- package/dist/release/release-cut.js +76 -0
- package/dist/release/release-descriptor-staging.d.ts +34 -0
- package/dist/release/release-descriptor-staging.js +147 -0
- package/dist/release/release-finalize.d.ts +16 -0
- package/dist/release/release-finalize.js +104 -0
- package/dist/release/release-promotion-command.d.ts +12 -0
- package/dist/release/release-promotion-command.js +28 -0
- package/dist/release/release-promotion.d.ts +29 -0
- package/dist/release/release-promotion.js +57 -0
- package/dist/release/release-publication.d.ts +33 -0
- package/dist/release/release-publication.js +138 -0
- package/dist/release/release-publish-command.d.ts +7 -0
- package/dist/release/release-publish-command.js +91 -0
- package/dist/release/release-qualification.d.ts +106 -0
- package/dist/release/release-qualification.js +135 -0
- package/dist/release/release-staging.d.ts +9 -0
- package/dist/release/release-staging.js +61 -0
- package/dist/release/release-steps.d.ts +38 -0
- package/dist/release/release-steps.js +147 -0
- package/dist/release/retained-release-build.d.ts +19 -0
- package/dist/release/retained-release-build.js +122 -0
- package/dist/shell/app-shell.d.ts +61 -0
- package/dist/shell/app-shell.js +306 -0
- package/dist/shell/app-utilities.d.ts +122 -0
- package/dist/shell/app-utilities.js +334 -0
- package/dist/shell/application-menu-commands.d.ts +5 -0
- package/dist/shell/application-menu-commands.js +11 -0
- package/dist/shell/application-menu.d.ts +61 -0
- package/dist/shell/application-menu.js +208 -0
- package/dist/shell/help-shortcuts.d.ts +12 -0
- package/dist/shell/help-shortcuts.js +22 -0
- package/dist/shell/navigation-drawer.d.ts +12 -0
- package/dist/shell/navigation-drawer.js +42 -0
- package/dist/shell/settings-sections.d.ts +31 -0
- package/dist/shell/settings-sections.js +50 -0
- package/dist/shell/shortcut-platform.d.ts +17 -0
- package/dist/shell/shortcut-platform.js +25 -0
- package/dist/update-helper.bundle.js +260 -0
- package/dist/updates/channel-update-manager.d.ts +46 -0
- package/dist/updates/channel-update-manager.js +114 -0
- package/dist/updates/desktop-updater.d.ts +104 -0
- package/dist/updates/desktop-updater.js +345 -0
- package/dist/updates/release-feed.d.ts +61 -0
- package/dist/updates/release-feed.js +111 -0
- package/dist/updates/release-location.d.ts +9 -0
- package/dist/updates/release-location.js +80 -0
- package/dist/updates/release-version.d.ts +12 -0
- package/dist/updates/release-version.js +43 -0
- package/dist/updates/signed-release.d.ts +63 -0
- package/dist/updates/signed-release.js +162 -0
- package/dist/updates/stable-file.d.ts +10 -0
- package/dist/updates/stable-file.js +22 -0
- package/dist/updates/update-adapter.d.ts +57 -0
- package/dist/updates/update-adapter.js +72 -0
- package/dist/updates/update-arm.d.ts +24 -0
- package/dist/updates/update-arm.js +95 -0
- package/dist/updates/update-channel-store.d.ts +8 -0
- package/dist/updates/update-channel-store.js +72 -0
- package/dist/updates/update-discovery.d.ts +13 -0
- package/dist/updates/update-discovery.js +56 -0
- package/dist/updates/update-download.d.ts +14 -0
- package/dist/updates/update-download.js +67 -0
- package/dist/updates/update-exclusive-rename.d.ts +2 -0
- package/dist/updates/update-exclusive-rename.js +52 -0
- package/dist/updates/update-extraction.d.ts +18 -0
- package/dist/updates/update-extraction.js +183 -0
- package/dist/updates/update-handoff-plan.d.ts +22 -0
- package/dist/updates/update-handoff-plan.js +28 -0
- package/dist/updates/update-helper.d.ts +24 -0
- package/dist/updates/update-helper.js +56 -0
- package/dist/updates/update-launch.d.ts +5 -0
- package/dist/updates/update-launch.js +27 -0
- package/dist/updates/update-manager.d.ts +40 -0
- package/dist/updates/update-manager.js +83 -0
- package/dist/updates/update-process-fence.d.ts +10 -0
- package/dist/updates/update-process-fence.js +114 -0
- package/dist/updates/update-resume.d.ts +13 -0
- package/dist/updates/update-resume.js +34 -0
- package/dist/updates/update-shutdown.d.ts +15 -0
- package/dist/updates/update-shutdown.js +29 -0
- package/dist/updates/update-state.d.ts +30 -0
- package/dist/updates/update-state.js +18 -0
- package/dist/updates/update-swap-stage.d.ts +27 -0
- package/dist/updates/update-swap-stage.js +58 -0
- package/dist/updates/update-swap.d.ts +10 -0
- package/dist/updates/update-swap.js +30 -0
- package/dist/views/app-about.d.ts +22 -0
- package/dist/views/app-about.js +43 -0
- package/dist/views/app-appearance.d.ts +11 -0
- package/dist/views/app-appearance.js +42 -0
- package/dist/views/app-help.d.ts +17 -0
- package/dist/views/app-help.js +42 -0
- package/dist/views/app-settings.d.ts +26 -0
- package/dist/views/app-settings.js +97 -0
- package/dist/views/appearance-surface.d.ts +9 -0
- package/dist/views/appearance-surface.js +334 -0
- package/dist/views/update-surface.d.ts +34 -0
- package/dist/views/update-surface.js +64 -0
- package/package.json +374 -4
- package/src/app/application.tsx +138 -0
- package/src/appearance/appearance-host.tsx +205 -0
- package/src/appearance/appearance-preferences.ts +287 -0
- package/src/appearance/composition.ts +29 -0
- package/src/appearance/custom-theme-import.ts +424 -0
- package/src/appearance/custom-theme-library.ts +600 -0
- package/src/appearance/editor.ts +94 -0
- package/src/appearance/theme-file-importer.ts +103 -0
- package/src/appearance/theme-record-adapter.ts +106 -0
- package/src/appearance/theme-registry.ts +20 -0
- package/src/appearance/window-surface.ts +18 -0
- package/src/desktop/client-assets.ts +75 -0
- package/src/native/electrobun-cef-main-frame-bridges.patch +63 -0
- package/src/native/electrobun-windows-shortcut-com.patch +923 -0
- package/src/native/renderer-profile.ts +27 -0
- package/src/native/window-options.ts +24 -0
- package/src/shell/app-shell.tsx +294 -0
- package/src/shell/app-utilities.tsx +437 -0
- package/src/shell/help-shortcuts.ts +24 -0
- package/src/shell/navigation-drawer.tsx +36 -0
- package/src/shell/settings-sections.ts +74 -0
- package/src/shell/shortcut-platform.ts +35 -0
- package/src/updates/release-version.ts +57 -0
- package/src/updates/update-adapter.ts +129 -0
- package/src/updates/update-state.ts +34 -0
- package/src/views/app-about.tsx +44 -0
- package/src/views/app-appearance.tsx +32 -0
- package/src/views/app-help.tsx +43 -0
- package/src/views/app-settings.tsx +88 -0
- package/src/views/appearance-surface.tsx +427 -0
- package/src/views/update-surface.tsx +85 -0
- package/templates/application/.gitattributes +1 -0
- package/templates/application/.github/workflows/release-assets.yml +29 -0
- package/templates/application/.github/workflows/release-finalize.yml +29 -0
- package/templates/application/.github/workflows/release-please.yml +19 -0
- package/templates/application/.github/workflows/release.yml +29 -0
- package/templates/application/.github/workflows/validation.yml +28 -0
- package/templates/application/.oxfmtrc.json +6 -0
- package/templates/application/.oxlintrc.json +48 -0
- package/templates/application/.release-please-manifest.json +3 -0
- package/templates/application/README.md +47 -0
- package/templates/application/electrobun.config.ts +22 -0
- package/templates/application/release-please-config.json +12 -0
- package/templates/application/scripts/app-version.ts +9 -0
- package/templates/application/scripts/build-desktop.ts +34 -0
- package/templates/application/scripts/secure-build.ts +1 -0
- package/templates/application/scripts/stage-release.ts +21 -0
- package/templates/application/src/bun/index.ts +80 -0
- package/templates/application/src/electrobun.d.ts +27 -0
- package/templates/application/src/web/index.html +12 -0
- package/templates/application/src/web/main.tsx +97 -0
- package/templates/application/src/web/public/icon.svg +1 -0
- package/templates/application/src/web/style.css +3 -0
- package/templates/application/tests/app-config.test.ts +9 -0
- package/templates/application/tsconfig.json +15 -0
- package/templates/application/vite.config.ts +10 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isUpdateChannel } from "./release-version.js";
|
|
2
|
+
import { openUnchangedFile, sameFile } from "./stable-file.js";
|
|
3
|
+
import { lstat, open, realpath, rename, unlink } from "node:fs/promises";
|
|
4
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
// src/updates/update-channel-store.ts
|
|
7
|
+
/** Persist one app-owned update channel; the caller must supply a private state directory. */
|
|
8
|
+
function createUpdateChannelStore(directory) {
|
|
9
|
+
if (typeof directory !== "string" || !isAbsolute(directory) || resolve(directory) !== directory) throw new Error("Invalid update channel directory");
|
|
10
|
+
const path = join(directory, "update-channel.json");
|
|
11
|
+
let queue = Promise.resolve();
|
|
12
|
+
async function assertDirectory() {
|
|
13
|
+
const info = await lstat(directory);
|
|
14
|
+
if (!info.isDirectory() || info.isSymbolicLink() || await realpath(directory) !== directory) throw new Error("Invalid update channel directory");
|
|
15
|
+
}
|
|
16
|
+
async function read() {
|
|
17
|
+
await assertDirectory();
|
|
18
|
+
let info;
|
|
19
|
+
try {
|
|
20
|
+
info = await lstat(path);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code === "ENOENT") return "stable";
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 4096) throw new Error("Invalid update channel file");
|
|
26
|
+
const { file, before } = await openUnchangedFile(path, info, "Invalid update channel file");
|
|
27
|
+
try {
|
|
28
|
+
const bytes = Buffer.alloc(before.size + 1);
|
|
29
|
+
const fileRead = await file.read(bytes, 0, bytes.length, 0);
|
|
30
|
+
if (fileRead.bytesRead !== before.size) throw new Error("Invalid update channel file");
|
|
31
|
+
const value = JSON.parse(bytes.subarray(0, fileRead.bytesRead).toString("utf8"));
|
|
32
|
+
const after = await file.stat();
|
|
33
|
+
if (!sameFile(before, after) || typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).length !== 1 || !isUpdateChannel(value.channel)) throw new Error("Invalid update channel file");
|
|
34
|
+
return value.channel;
|
|
35
|
+
} finally {
|
|
36
|
+
await file.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function ordered(task) {
|
|
40
|
+
const result = queue.then(task);
|
|
41
|
+
queue = result.then(() => {}, () => {});
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
read: () => ordered(read),
|
|
46
|
+
save: (channel) => ordered(async () => {
|
|
47
|
+
if (!isUpdateChannel(channel)) throw new Error("Invalid update channel");
|
|
48
|
+
await assertDirectory();
|
|
49
|
+
const temporary = join(directory, `.update-channel-${randomUUID()}.tmp`);
|
|
50
|
+
const file = await open(temporary, "wx", 384);
|
|
51
|
+
let moved = false;
|
|
52
|
+
try {
|
|
53
|
+
await file.writeFile(JSON.stringify({ channel }) + "\n");
|
|
54
|
+
await file.sync();
|
|
55
|
+
await file.close();
|
|
56
|
+
await rename(temporary, path);
|
|
57
|
+
moved = true;
|
|
58
|
+
if (await read() !== channel) throw new Error("Update channel write did not persist");
|
|
59
|
+
return channel;
|
|
60
|
+
} finally {
|
|
61
|
+
await file.close().catch(() => {});
|
|
62
|
+
if (!moved) await unlink(temporary).catch(() => {});
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Shared UI uses pre-release; release descriptors use daily. */
|
|
68
|
+
function releaseChannelForUpdate(channel) {
|
|
69
|
+
if (!isUpdateChannel(channel)) throw new Error("Invalid update channel");
|
|
70
|
+
return channel === "pre-release" ? "daily" : channel;
|
|
71
|
+
}
|
|
72
|
+
export { createUpdateChannelStore, releaseChannelForUpdate };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReleaseTrust, type VerifiedRelease } from './signed-release';
|
|
2
|
+
import { type FetchFunction } from './release-location';
|
|
3
|
+
/** Discover and authenticate the app's channel descriptor without trusting feed metadata as an update. */
|
|
4
|
+
export declare function discoverSignedRelease(options: {
|
|
5
|
+
trust: ReleaseTrust;
|
|
6
|
+
discoveryName: string;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
fetch?: FetchFunction;
|
|
10
|
+
/** Take the newest release of the channel that sorts below this version instead of the
|
|
11
|
+
* channel pointer's release. */
|
|
12
|
+
olderThan?: string;
|
|
13
|
+
}): Promise<VerifiedRelease>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isRepositorySlug, verifyReleaseDescriptor } from "./signed-release.js";
|
|
2
|
+
import { parseFeedRelease, parseReleaseLedger } from "./release-feed.js";
|
|
3
|
+
import { versionLessThan } from "./release-version.js";
|
|
4
|
+
import { fetchReleaseLocation, readReleaseBytes, readReleaseJson } from "./release-location.js";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
// src/updates/update-discovery.ts
|
|
7
|
+
var MAX_POINTER_BYTES = 262144;
|
|
8
|
+
var MAX_LEDGER_BYTES = 1048576;
|
|
9
|
+
/** Discover and authenticate the app's channel descriptor without trusting feed metadata as an update. */
|
|
10
|
+
async function discoverSignedRelease(options) {
|
|
11
|
+
const { trust, discoveryName, olderThan } = options;
|
|
12
|
+
const timeout = options.timeoutMs ?? 1e4;
|
|
13
|
+
if (!trust || !isRepositorySlug(trust.repository) || ![
|
|
14
|
+
"stable",
|
|
15
|
+
"daily",
|
|
16
|
+
"dev"
|
|
17
|
+
].includes(trust.channel) || typeof trust.feed !== "string" || typeof discoveryName !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,199}\.json$/.test(discoveryName) || discoveryName === "release.json" || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 6e4) throw new Error("Invalid release discovery policy");
|
|
18
|
+
const controller = new AbortController(), timer = setTimeout(() => controller.abort(), timeout);
|
|
19
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
20
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
21
|
+
const get = (path) => fetchReleaseLocation(`${trust.feed}${path}`, trust.feed, fetcher, signal);
|
|
22
|
+
try {
|
|
23
|
+
if (signal.aborted) throw new Error("Release discovery cancelled");
|
|
24
|
+
let selected = null;
|
|
25
|
+
if (olderThan === void 0) {
|
|
26
|
+
selected = parseFeedRelease(await readReleaseJson(await get(`channels/${trust.channel}.json`), MAX_POINTER_BYTES));
|
|
27
|
+
if (selected.channel !== trust.channel) throw new Error("Invalid channel pointer");
|
|
28
|
+
} else {
|
|
29
|
+
const kinds = trust.channel === "stable" ? ["stable"] : trust.channel === "dev" ? ["dev"] : ["daily", "stable"];
|
|
30
|
+
const entry = parseReleaseLedger(await readReleaseJson(await get("index.json"), MAX_LEDGER_BYTES), new URL(trust.feed).pathname.split("/").at(-2)).releases.find((item) => kinds.includes(item.kind) && versionLessThan(item.tag, olderThan));
|
|
31
|
+
if (entry) {
|
|
32
|
+
selected = parseFeedRelease(await readReleaseJson(await get(`${entry.tag}/release.json`), MAX_POINTER_BYTES));
|
|
33
|
+
if (selected.tag !== entry.tag) throw new Error("Invalid feed release");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const listed = selected?.assets.find((asset) => asset.name === discoveryName);
|
|
37
|
+
if (!selected || !listed) throw new Error("No qualified channel descriptor is available");
|
|
38
|
+
const { tag } = selected;
|
|
39
|
+
const bytes = await readReleaseBytes(await get(`${tag}/${discoveryName}`), 65536);
|
|
40
|
+
if (bytes.length !== listed.size || createHash("sha256").update(bytes).digest("hex") !== listed.sha256) throw new Error("Channel descriptor differs from its release");
|
|
41
|
+
let signed;
|
|
42
|
+
try {
|
|
43
|
+
signed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
44
|
+
} catch {
|
|
45
|
+
throw new Error("Invalid release feed response");
|
|
46
|
+
}
|
|
47
|
+
const result = verifyReleaseDescriptor(signed, trust);
|
|
48
|
+
if (!result.ok || result.descriptor.tag !== tag) throw new Error("Untrusted channel descriptor");
|
|
49
|
+
const payload = selected.assets.find((asset) => asset.name === result.descriptor.asset.name);
|
|
50
|
+
if (!payload || payload.size !== result.descriptor.asset.size || payload.sha256 !== result.descriptor.asset.sha256) throw new Error("Release payload is missing or differs from its descriptor");
|
|
51
|
+
return result.descriptor;
|
|
52
|
+
} finally {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export { discoverSignedRelease };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type VerifiedRelease } from './signed-release';
|
|
2
|
+
import { type FetchFunction } from './release-location';
|
|
3
|
+
/** Download an authenticated release to a new private directory; caller owns cleanup and installation. */
|
|
4
|
+
export declare function downloadVerifiedRelease(options: {
|
|
5
|
+
descriptor: VerifiedRelease;
|
|
6
|
+
directory: string;
|
|
7
|
+
maxBytes: number;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
fetch?: FetchFunction;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
path: string;
|
|
13
|
+
directory: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isVerifiedRelease, verifyReleaseStream } from "./signed-release.js";
|
|
2
|
+
import { fetchReleaseLocation } from "./release-location.js";
|
|
3
|
+
import { mkdtemp, open, rm } from "node:fs/promises";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
// src/updates/update-download.ts
|
|
6
|
+
/** Download an authenticated release to a new private directory; caller owns cleanup and installation. */
|
|
7
|
+
async function downloadVerifiedRelease(options) {
|
|
8
|
+
const { descriptor, maxBytes } = options;
|
|
9
|
+
const timeout = options.timeoutMs ?? 12e4;
|
|
10
|
+
if (!isVerifiedRelease(descriptor) || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || descriptor.asset.size > maxBytes || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 6e5) throw new Error("Invalid verified download request");
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
13
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
14
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
15
|
+
let temporary;
|
|
16
|
+
try {
|
|
17
|
+
if (signal.aborted) throw new Error("Release download cancelled");
|
|
18
|
+
const { url, name } = descriptor.asset;
|
|
19
|
+
const feed = url.slice(0, url.length - `${descriptor.tag}/${name}`.length);
|
|
20
|
+
const response = await fetchReleaseLocation(url, feed, fetcher, signal);
|
|
21
|
+
if (response.status !== 200 || !response.body) {
|
|
22
|
+
await response.body?.cancel();
|
|
23
|
+
throw new Error("Release download failed");
|
|
24
|
+
}
|
|
25
|
+
const length = response.headers.get("content-length");
|
|
26
|
+
if (length !== null && (!/^\d+$/.test(length) || Number(length) !== descriptor.asset.size)) {
|
|
27
|
+
await response.body.cancel();
|
|
28
|
+
throw new Error("Release download size mismatch");
|
|
29
|
+
}
|
|
30
|
+
temporary = await mkdtemp(join(resolve(options.directory), "framework-update-"));
|
|
31
|
+
const path = join(temporary, "archive");
|
|
32
|
+
const file = await open(path, "wx", 384);
|
|
33
|
+
try {
|
|
34
|
+
async function* writeChunks() {
|
|
35
|
+
let size = 0;
|
|
36
|
+
for await (const chunk of response.body) {
|
|
37
|
+
if (!(chunk instanceof Uint8Array) || signal.aborted) throw new Error("Invalid download chunk");
|
|
38
|
+
size += chunk.length;
|
|
39
|
+
if (!Number.isSafeInteger(size) || size > descriptor.asset.size) throw new Error("Release download exceeds signed size");
|
|
40
|
+
let offset = 0;
|
|
41
|
+
while (offset < chunk.length) {
|
|
42
|
+
const { bytesWritten } = await file.write(chunk, offset, chunk.length - offset);
|
|
43
|
+
if (!bytesWritten) throw new Error("Unable to write update");
|
|
44
|
+
offset += bytesWritten;
|
|
45
|
+
}
|
|
46
|
+
yield chunk;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!await verifyReleaseStream(writeChunks(), descriptor)) throw new Error("Release download verification failed");
|
|
50
|
+
} finally {
|
|
51
|
+
await file.close();
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
path,
|
|
55
|
+
directory: temporary
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (temporary) await rm(temporary, {
|
|
59
|
+
recursive: true,
|
|
60
|
+
force: true
|
|
61
|
+
});
|
|
62
|
+
throw error;
|
|
63
|
+
} finally {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export { downloadVerifiedRelease };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
2
|
+
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
3
|
+
// src/updates/update-exclusive-rename.ts
|
|
4
|
+
/** Rename without replacing an existing destination. The caller must validate and own both parent directories. */
|
|
5
|
+
function renameUpdateExclusive(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 { renameUpdateExclusive };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type InstallerPlatform, type InstallerRenderer } from '../installer/installer-layout';
|
|
2
|
+
import { type VerifiedRelease } from './signed-release';
|
|
3
|
+
/** Extract a verified full update into a new private directory. Does not replace an installed app. */
|
|
4
|
+
export declare function extractVerifiedUpdate(options: {
|
|
5
|
+
descriptor: VerifiedRelease;
|
|
6
|
+
archive: string;
|
|
7
|
+
directory: string;
|
|
8
|
+
platform: InstallerPlatform;
|
|
9
|
+
renderer: InstallerRenderer;
|
|
10
|
+
appName: string;
|
|
11
|
+
maxCompressedBytes: number;
|
|
12
|
+
maxExpandedBytes: number;
|
|
13
|
+
/** Sidecar executables the app bundles; each must be a present, executable file. */
|
|
14
|
+
sidecars?: readonly string[];
|
|
15
|
+
}): Promise<{
|
|
16
|
+
directory: string;
|
|
17
|
+
payload: string;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { assertSidecarNames, sidecarBundlePath } from "../native/app-bundle.js";
|
|
2
|
+
import { assertBuildMetadata, assertPayloadLayout, assertPortableAppName } from "../installer/installer-layout.js";
|
|
3
|
+
import { isVerifiedRelease, verifyReleaseStream } from "./signed-release.js";
|
|
4
|
+
import { safeArchivePath } from "../installer/archive-entry.js";
|
|
5
|
+
import { isLinuxCefLibraryLink } from "../native/linux-cef-links.js";
|
|
6
|
+
import { lstat, mkdir, mkdtemp, open, readFile, realpath, rm, symlink } from "node:fs/promises";
|
|
7
|
+
import { isAbsolute, join } from "node:path";
|
|
8
|
+
import { constants as constants$1 } from "node:fs";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { x } from "tar";
|
|
11
|
+
import { createZstdDecompress } from "node:zlib";
|
|
12
|
+
import { Transform } from "node:stream";
|
|
13
|
+
import { pipeline } from "node:stream/promises";
|
|
14
|
+
// src/updates/update-extraction.ts
|
|
15
|
+
/** Extract a verified full update into a new private directory. Does not replace an installed app. */
|
|
16
|
+
async function extractVerifiedUpdate(options) {
|
|
17
|
+
const { descriptor, archive, platform, renderer, appName, maxCompressedBytes, maxExpandedBytes } = options;
|
|
18
|
+
const expected = {
|
|
19
|
+
"macos-arm64": ["darwin", "arm64"],
|
|
20
|
+
"windows-x64": ["win32", "x64"],
|
|
21
|
+
"linux-x64": ["linux", "x64"]
|
|
22
|
+
};
|
|
23
|
+
if (!isVerifiedRelease(descriptor) || !expected[platform] || descriptor.platform !== expected[platform][0] || descriptor.arch !== expected[platform][1] || !isAbsolute(archive) || !isAbsolute(options.directory) || !Number.isSafeInteger(maxCompressedBytes) || maxCompressedBytes < 1 || descriptor.asset.size > maxCompressedBytes || !Number.isSafeInteger(maxExpandedBytes) || maxExpandedBytes < 1) throw new Error("Invalid update extraction context");
|
|
24
|
+
assertPortableAppName(appName);
|
|
25
|
+
const sidecars = assertSidecarNames(options.sidecars ?? []);
|
|
26
|
+
const archiveRoot = platform === "macos-arm64" ? `${appName}.app` : appName.replaceAll(" ", "");
|
|
27
|
+
const info = await lstat(archive);
|
|
28
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size !== descriptor.asset.size) throw new Error("Invalid update archive");
|
|
29
|
+
const file = await open(archive, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
|
|
30
|
+
let directory;
|
|
31
|
+
try {
|
|
32
|
+
const before = await file.stat();
|
|
33
|
+
if (!before.isFile() || before.dev !== info.dev || before.ino !== info.ino || before.size !== info.size || !await verifyReleaseStream(file.createReadStream({
|
|
34
|
+
autoClose: false,
|
|
35
|
+
start: 0
|
|
36
|
+
}), descriptor)) throw new Error("Update archive verification failed");
|
|
37
|
+
const parent = await realpath(options.directory);
|
|
38
|
+
if (!(await lstat(parent)).isDirectory()) throw new Error("Invalid update staging directory");
|
|
39
|
+
directory = await mkdtemp(join(parent, "framework-update-extract-"));
|
|
40
|
+
const payloadRoot = join(directory, "payload"), decompressed = join(directory, "payload.tar");
|
|
41
|
+
await mkdir(payloadRoot, { mode: 448 });
|
|
42
|
+
const entries = [], links = [], seen = /* @__PURE__ */ new Set(), fold = platform === "windows-x64";
|
|
43
|
+
let invalid = false;
|
|
44
|
+
const reject = () => {
|
|
45
|
+
invalid = true;
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
let expanded = 0, fileBytes = 0;
|
|
49
|
+
const bound = new Transform({ transform(chunk, _encoding, done) {
|
|
50
|
+
expanded += chunk.length;
|
|
51
|
+
if (!Number.isSafeInteger(expanded) || expanded > maxExpandedBytes) done(/* @__PURE__ */ new Error("Expanded update exceeds bound"));
|
|
52
|
+
else done(null, chunk);
|
|
53
|
+
} });
|
|
54
|
+
const hash = createHash("sha256");
|
|
55
|
+
let compressedBytes = 0;
|
|
56
|
+
const verifyInput = new Transform({ transform(chunk, _encoding, done) {
|
|
57
|
+
compressedBytes += chunk.length;
|
|
58
|
+
if (!Number.isSafeInteger(compressedBytes) || compressedBytes > descriptor.asset.size) done(/* @__PURE__ */ new Error("Update archive exceeds signed size"));
|
|
59
|
+
else {
|
|
60
|
+
hash.update(chunk);
|
|
61
|
+
done(null, chunk);
|
|
62
|
+
}
|
|
63
|
+
} });
|
|
64
|
+
const output = await open(decompressed, "wx", 384);
|
|
65
|
+
try {
|
|
66
|
+
await pipeline(file.createReadStream({
|
|
67
|
+
autoClose: false,
|
|
68
|
+
start: 0
|
|
69
|
+
}), verifyInput, createZstdDecompress(), bound, output.createWriteStream({ autoClose: true }));
|
|
70
|
+
} finally {
|
|
71
|
+
await output.close();
|
|
72
|
+
}
|
|
73
|
+
if (compressedBytes !== descriptor.asset.size || hash.digest("hex") !== descriptor.asset.sha256) throw new Error("Update archive changed during decompression");
|
|
74
|
+
await x({
|
|
75
|
+
file: decompressed,
|
|
76
|
+
cwd: payloadRoot,
|
|
77
|
+
strict: true,
|
|
78
|
+
preserveOwner: false,
|
|
79
|
+
chmod: true,
|
|
80
|
+
umask: 3602,
|
|
81
|
+
maxMetaEntrySize: 1048576,
|
|
82
|
+
filter(path, entry) {
|
|
83
|
+
if (!("type" in entry)) return reject();
|
|
84
|
+
if (path === "." || path === "./") {
|
|
85
|
+
if (entry.type !== "Directory") return reject();
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const normalized = safeArchivePath(path, fold);
|
|
89
|
+
if (!normalized) return reject();
|
|
90
|
+
const canonical = normalized.normalize("NFC"), canonicalRoot = archiveRoot.normalize("NFC");
|
|
91
|
+
const key = fold ? canonical.toLowerCase() : canonical;
|
|
92
|
+
const rootKey = fold ? canonicalRoot.toLowerCase() : canonicalRoot;
|
|
93
|
+
if (key !== rootKey && !key.startsWith(rootKey + "/")) return reject();
|
|
94
|
+
if (seen.has(key) || seen.size >= 2e5) return reject();
|
|
95
|
+
const relative = normalized.slice(archiveRoot.length + 1), linkTarget = typeof entry.linkpath === "string" ? entry.linkpath : "";
|
|
96
|
+
const cefLink = platform === "linux-x64" && renderer === "cef" && entry.type === "SymbolicLink" && isLinuxCefLibraryLink(relative, linkTarget);
|
|
97
|
+
if (entry.type !== "File" && entry.type !== "Directory" && !cefLink) return reject();
|
|
98
|
+
seen.add(key);
|
|
99
|
+
entries.push(normalized);
|
|
100
|
+
if (cefLink) {
|
|
101
|
+
links.push({
|
|
102
|
+
path: normalized,
|
|
103
|
+
target: linkTarget
|
|
104
|
+
});
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (entry.type === "File") {
|
|
108
|
+
if (!Number.isSafeInteger(entry.size) || entry.size < 0) return reject();
|
|
109
|
+
fileBytes += entry.size;
|
|
110
|
+
if (!Number.isSafeInteger(fileBytes) || fileBytes > maxExpandedBytes) return reject();
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
if (invalid) throw new Error("Unsafe or unsupported update archive entry");
|
|
116
|
+
if (links.length) {
|
|
117
|
+
const bin = join(payloadRoot, archiveRoot, "bin"), cef = join(bin, "cef");
|
|
118
|
+
for (const path of [
|
|
119
|
+
join(payloadRoot, archiveRoot),
|
|
120
|
+
bin,
|
|
121
|
+
cef
|
|
122
|
+
]) {
|
|
123
|
+
const value = await lstat(path);
|
|
124
|
+
if (!value.isDirectory() || value.isSymbolicLink()) throw new Error("Invalid CEF link directory");
|
|
125
|
+
}
|
|
126
|
+
for (const link of links) {
|
|
127
|
+
const destination = join(payloadRoot, link.path), target = join(bin, link.target), value = await lstat(target);
|
|
128
|
+
if (!value.isFile() || value.isSymbolicLink()) throw new Error("Invalid CEF link target");
|
|
129
|
+
await symlink(link.target, destination);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
await rm(decompressed);
|
|
133
|
+
const after = await file.stat();
|
|
134
|
+
if (after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size || after.mtimeMs !== before.mtimeMs || !await verifyReleaseStream(file.createReadStream({
|
|
135
|
+
autoClose: false,
|
|
136
|
+
start: 0
|
|
137
|
+
}), descriptor)) throw new Error("Update archive changed during extraction");
|
|
138
|
+
assertPayloadLayout({
|
|
139
|
+
platform,
|
|
140
|
+
renderer,
|
|
141
|
+
appName,
|
|
142
|
+
entries,
|
|
143
|
+
sidecars
|
|
144
|
+
});
|
|
145
|
+
const prefix = platform === "macos-arm64" ? join(`${appName}.app`, "Contents") : appName.replaceAll(" ", "");
|
|
146
|
+
const resources = join(payloadRoot, prefix, "Resources");
|
|
147
|
+
const bin = platform === "macos-arm64" ? "MacOS" : "bin", suffix = platform === "windows-x64" ? ".exe" : "";
|
|
148
|
+
const executables = [
|
|
149
|
+
join(bin, `launcher${suffix}`),
|
|
150
|
+
join(bin, `bun${suffix}`),
|
|
151
|
+
...sidecars.map((name) => sidecarBundlePath(name, platform))
|
|
152
|
+
];
|
|
153
|
+
const critical = [
|
|
154
|
+
...executables,
|
|
155
|
+
"Resources/main.js",
|
|
156
|
+
"Resources/app/bun/index.js",
|
|
157
|
+
"Resources/app/client/index.html"
|
|
158
|
+
];
|
|
159
|
+
for (const path of critical) {
|
|
160
|
+
const item = await lstat(join(payloadRoot, prefix, path));
|
|
161
|
+
if (!item.isFile() || item.isSymbolicLink() || item.size < 1 || platform !== "windows-x64" && process.platform !== "win32" && executables.includes(path) && !(item.mode & 64)) throw new Error("Invalid critical update file");
|
|
162
|
+
}
|
|
163
|
+
for (const name of ["version.json", "build.json"]) {
|
|
164
|
+
const metadata = await lstat(join(resources, name));
|
|
165
|
+
if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size < 1 || metadata.size > 1048576) throw new Error("Invalid update metadata");
|
|
166
|
+
}
|
|
167
|
+
if (JSON.parse(await readFile(join(resources, "version.json"), "utf8")).version !== descriptor.version) throw new Error("Update version mismatch");
|
|
168
|
+
assertBuildMetadata(JSON.parse(await readFile(join(resources, "build.json"), "utf8")), renderer);
|
|
169
|
+
return {
|
|
170
|
+
directory,
|
|
171
|
+
payload: join(payloadRoot, platform === "macos-arm64" ? `${appName}.app` : prefix)
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (directory) await rm(directory, {
|
|
175
|
+
recursive: true,
|
|
176
|
+
force: true
|
|
177
|
+
});
|
|
178
|
+
throw error;
|
|
179
|
+
} finally {
|
|
180
|
+
await file.close();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export { extractVerifiedUpdate };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type InstallerPlatform, type InstallerRenderer } from '../installer/installer-layout';
|
|
2
|
+
import { type ReleaseTrust, type VerifiedRelease } from './signed-release';
|
|
3
|
+
/** Validate an explicitly approved update and its intended installation. This plan does not move files or launch a helper. */
|
|
4
|
+
export declare function planUpdateHandoff(options: {
|
|
5
|
+
descriptor: VerifiedRelease;
|
|
6
|
+
trust: ReleaseTrust;
|
|
7
|
+
currentVersion: string;
|
|
8
|
+
approved: boolean;
|
|
9
|
+
approvedVersion: string;
|
|
10
|
+
target: string;
|
|
11
|
+
appName: string;
|
|
12
|
+
platform: InstallerPlatform;
|
|
13
|
+
renderer: InstallerRenderer;
|
|
14
|
+
}): Readonly<{
|
|
15
|
+
target: string;
|
|
16
|
+
appName: string;
|
|
17
|
+
platform: InstallerPlatform;
|
|
18
|
+
renderer: InstallerRenderer;
|
|
19
|
+
currentVersion: string;
|
|
20
|
+
version: string;
|
|
21
|
+
archiveSha256: string;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { assertPortableAppName } from "../installer/installer-layout.js";
|
|
2
|
+
import { isVerifiedReleaseForTrust } from "./signed-release.js";
|
|
3
|
+
import { versionLessThan } from "./release-version.js";
|
|
4
|
+
import { basename, isAbsolute, resolve } from "node:path";
|
|
5
|
+
// src/updates/update-handoff-plan.ts
|
|
6
|
+
/** Validate an explicitly approved update and its intended installation. This plan does not move files or launch a helper. */
|
|
7
|
+
function planUpdateHandoff(options) {
|
|
8
|
+
const { descriptor, trust, currentVersion, approved, approvedVersion, target, appName, platform, renderer } = options;
|
|
9
|
+
assertPortableAppName(appName);
|
|
10
|
+
const expected = {
|
|
11
|
+
"macos-arm64": ["darwin", "arm64"],
|
|
12
|
+
"windows-x64": ["win32", "x64"],
|
|
13
|
+
"linux-x64": ["linux", "x64"]
|
|
14
|
+
};
|
|
15
|
+
if (!expected[platform] || !["native", "cef"].includes(renderer) || !isVerifiedReleaseForTrust(descriptor, trust) || descriptor.platform !== expected[platform][0] || descriptor.arch !== expected[platform][1] || approved !== true || approvedVersion !== descriptor.version || typeof currentVersion !== "string" || currentVersion.length > 64 || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(currentVersion) || !versionLessThan(currentVersion, descriptor.version)) throw new Error("Invalid approved update");
|
|
16
|
+
const name = platform === "macos-arm64" ? `${appName}.app` : "app";
|
|
17
|
+
if (typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target || basename(target) !== name) throw new Error("Invalid update target");
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
target,
|
|
20
|
+
appName,
|
|
21
|
+
platform,
|
|
22
|
+
renderer,
|
|
23
|
+
currentVersion,
|
|
24
|
+
version: descriptor.version,
|
|
25
|
+
archiveSha256: descriptor.asset.sha256
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export { planUpdateHandoff };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InstallerPlatform } from '../installer/installer-layout';
|
|
2
|
+
/** Everything the post-exit helper needs, written by the app into its private staging directory. */
|
|
3
|
+
export type UpdateHelperRequest = Readonly<{
|
|
4
|
+
schema: 1;
|
|
5
|
+
target: string;
|
|
6
|
+
platform: InstallerPlatform;
|
|
7
|
+
version: string;
|
|
8
|
+
processes: readonly Readonly<{
|
|
9
|
+
pid: number;
|
|
10
|
+
executable: string;
|
|
11
|
+
}>[];
|
|
12
|
+
processTimeoutMs: number;
|
|
13
|
+
}>;
|
|
14
|
+
/** Validate a helper request's shape. */
|
|
15
|
+
export declare function parseUpdateHelperRequest(value: unknown): UpdateHelperRequest;
|
|
16
|
+
/**
|
|
17
|
+
* The post-exit helper: wait for the app's processes to exit, swap in the
|
|
18
|
+
* staged candidate, record the new version and relaunch the app. Run from a
|
|
19
|
+
* copy outside the install tree; `armUpdateHelper` prepares that copy.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runUpdateHelper(options: {
|
|
22
|
+
staging: string;
|
|
23
|
+
env?: Record<string, string | undefined>;
|
|
24
|
+
}): Promise<'updated' | 'failed'>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { swapUpdateTree, updateStagingFor } from "./update-swap.js";
|
|
2
|
+
import { launchInstalledApp } from "./update-launch.js";
|
|
3
|
+
import { waitForUpdateProcesses } from "./update-process-fence.js";
|
|
4
|
+
import { lstat, open, writeFile } from "node:fs/promises";
|
|
5
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
6
|
+
import { constants as constants$1, writeFileSync } from "node:fs";
|
|
7
|
+
// src/updates/update-helper.ts
|
|
8
|
+
/** Validate a helper request's shape. */
|
|
9
|
+
function parseUpdateHelperRequest(value) {
|
|
10
|
+
const data = value;
|
|
11
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 || typeof data.target !== "string" || !isAbsolute(data.target) || resolve(data.target) !== data.target || ![
|
|
12
|
+
"macos-arm64",
|
|
13
|
+
"windows-x64",
|
|
14
|
+
"linux-x64"
|
|
15
|
+
].includes(data.platform) || typeof data.version !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(data.version) || !Array.isArray(data.processes) || !Number.isSafeInteger(data.processTimeoutMs) || data.processTimeoutMs < 1 || data.processTimeoutMs > 12e4) throw new Error("Invalid update helper request");
|
|
16
|
+
return Object.freeze(data);
|
|
17
|
+
}
|
|
18
|
+
async function readRequest(staging) {
|
|
19
|
+
const path = join(staging, "request.json"), info = await lstat(path);
|
|
20
|
+
if (!info.isFile() || info.size < 1 || info.size > 65536) throw new Error("Invalid update helper request");
|
|
21
|
+
const file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
|
|
22
|
+
try {
|
|
23
|
+
return parseUpdateHelperRequest(JSON.parse(await file.readFile("utf8")));
|
|
24
|
+
} finally {
|
|
25
|
+
await file.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The post-exit helper: wait for the app's processes to exit, swap in the
|
|
30
|
+
* staged candidate, record the new version and relaunch the app. Run from a
|
|
31
|
+
* copy outside the install tree; `armUpdateHelper` prepares that copy.
|
|
32
|
+
*/
|
|
33
|
+
async function runUpdateHelper(options) {
|
|
34
|
+
const request = await readRequest(options.staging);
|
|
35
|
+
if (updateStagingFor(request.target) !== options.staging) throw new Error("Update helper request does not match its staging directory");
|
|
36
|
+
await waitForUpdateProcesses({
|
|
37
|
+
processes: request.processes,
|
|
38
|
+
timeoutMs: request.processTimeoutMs,
|
|
39
|
+
onVerified: () => writeFileSync(join(options.staging, "helper-armed"), String(process.pid), {
|
|
40
|
+
flag: "wx",
|
|
41
|
+
mode: 384
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
let outcome = "failed";
|
|
45
|
+
try {
|
|
46
|
+
await swapUpdateTree({
|
|
47
|
+
target: request.target,
|
|
48
|
+
staging: options.staging
|
|
49
|
+
});
|
|
50
|
+
await writeFile(join(options.staging, "updated"), request.version, { mode: 384 });
|
|
51
|
+
outcome = "updated";
|
|
52
|
+
} catch {}
|
|
53
|
+
await launchInstalledApp(request.platform, request.target, options.env);
|
|
54
|
+
return outcome;
|
|
55
|
+
}
|
|
56
|
+
export { parseUpdateHelperRequest, runUpdateHelper };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InstallerPlatform } from '../installer/installer-layout';
|
|
2
|
+
/** The Electrobun launcher inside an installed app tree. */
|
|
3
|
+
export declare function updateLauncherPath(platform: InstallerPlatform, target: string): string;
|
|
4
|
+
/** Start the installed app's launcher detached from the helper. */
|
|
5
|
+
export declare function launchInstalledApp(platform: InstallerPlatform, target: string, env?: Record<string, string | undefined>): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
// src/updates/update-launch.ts
|
|
4
|
+
/** The Electrobun launcher inside an installed app tree. */
|
|
5
|
+
function updateLauncherPath(platform, target) {
|
|
6
|
+
if (typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update target");
|
|
7
|
+
if (platform === "macos-arm64") return join(target, "Contents", "MacOS", "launcher");
|
|
8
|
+
if (platform === "windows-x64") return join(target, "bin", "launcher.exe");
|
|
9
|
+
if (platform === "linux-x64") return join(target, "bin", "launcher");
|
|
10
|
+
throw new Error("Unsupported update platform");
|
|
11
|
+
}
|
|
12
|
+
/** Start the installed app's launcher detached from the helper. */
|
|
13
|
+
async function launchInstalledApp(platform, target, env = process.env) {
|
|
14
|
+
const executable = updateLauncherPath(platform, target);
|
|
15
|
+
const child = spawn(executable, [], {
|
|
16
|
+
cwd: dirname(executable),
|
|
17
|
+
detached: true,
|
|
18
|
+
stdio: "ignore",
|
|
19
|
+
env
|
|
20
|
+
});
|
|
21
|
+
await new Promise((done, reject) => {
|
|
22
|
+
child.once("spawn", done);
|
|
23
|
+
child.once("error", reject);
|
|
24
|
+
});
|
|
25
|
+
child.unref();
|
|
26
|
+
}
|
|
27
|
+
export { launchInstalledApp, updateLauncherPath };
|