@adea-ai/app-framework 0.24.0 → 0.25.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 +49 -1
- package/dist/cli/macos-signing-cli.d.ts +2 -0
- package/dist/cli/macos-signing-cli.js +14 -0
- package/dist/desktop/channel-proof.js +7 -1
- package/dist/framework-source.json +1 -1
- package/dist/release/framework-package-publish.js +4 -2
- package/dist/release/local-release.d.ts +2 -0
- package/dist/release/local-release.js +25 -2
- package/dist/release/macos-signing.d.ts +27 -0
- package/dist/release/macos-signing.js +101 -0
- package/dist/shell/app-shell.js +21 -33
- package/dist/shell/navigation-drawer.d.ts +12 -0
- package/dist/shell/navigation-drawer.js +42 -0
- package/dist/updates/release-feed.d.ts +2 -0
- package/dist/updates/release-feed.js +11 -2
- package/package.json +16 -4
- package/src/shell/app-shell.tsx +29 -20
- package/src/shell/navigation-drawer.tsx +36 -0
- package/src/app/create-application.ts +0 -245
- package/src/app/service-registry.ts +0 -124
- package/src/ci/toolchain-identity.ts +0 -244
- package/src/cli/cef-helper-cli.ts +0 -21
- package/src/cli/cli-runner.ts +0 -29
- package/src/cli/create-application-cli.ts +0 -62
- package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
- package/src/cli/framework-update-cli.ts +0 -41
- package/src/cli/release-assets-plan-cli.ts +0 -14
- package/src/cli/release-cut-cli.ts +0 -41
- package/src/cli/release-descriptor-staging-cli.ts +0 -57
- package/src/cli/release-finalize-cli.ts +0 -34
- package/src/cli/release-promote-cli.ts +0 -31
- package/src/cli/release-publish-cli.ts +0 -46
- package/src/cli/release-sign-cli.ts +0 -24
- package/src/cli/release-step-cli.ts +0 -71
- package/src/cli/toolchain-identity-cli.ts +0 -12
- package/src/cli/update-helper-cli.ts +0 -12
- package/src/cli/windows-runtime-patch-cli.ts +0 -17
- package/src/desktop/application-command-client.ts +0 -43
- package/src/desktop/channel-handshake.ts +0 -136
- package/src/desktop/channel-proof.ts +0 -122
- package/src/desktop/desktop-client.ts +0 -303
- package/src/desktop/desktop-gateway.ts +0 -189
- package/src/desktop/desktop-host.ts +0 -335
- package/src/desktop/desktop-stream.ts +0 -324
- package/src/desktop/loopback-policy.ts +0 -41
- package/src/desktop/open-url-channel.ts +0 -79
- package/src/desktop/string-policy.ts +0 -9
- package/src/installer/archive-entry.ts +0 -32
- package/src/installer/command-artifact.ts +0 -307
- package/src/installer/command-qualification-command.ts +0 -75
- package/src/installer/hosted-runner.ts +0 -11
- package/src/installer/installed-payload.ts +0 -408
- package/src/installer/installer-ci-bootstrap.ts +0 -199
- package/src/installer/installer-ci-preflight.ts +0 -61
- package/src/installer/installer-ci-worker.ts +0 -105
- package/src/installer/installer-extraction.ts +0 -367
- package/src/installer/installer-fetch-guard.ts +0 -75
- package/src/installer/installer-identity.ts +0 -331
- package/src/installer/installer-layout.ts +0 -167
- package/src/installer/installer-observation.ts +0 -671
- package/src/installer/installer-process-cleanup.ts +0 -167
- package/src/installer/installer-qualification-command.ts +0 -81
- package/src/installer/installer-renderer-evidence.ts +0 -268
- package/src/installer/installer-upgrade-command.ts +0 -226
- package/src/installer/installer-worker-guard.ts +0 -112
- package/src/installer/native-executable.ts +0 -37
- package/src/installer/upgrade-asset-download.ts +0 -72
- package/src/installer/write-all.ts +0 -19
- package/src/native/app-bundle.ts +0 -86
- package/src/native/cef-helper.ts +0 -471
- package/src/native/desktop-build-hook.ts +0 -21
- package/src/native/electrobun-source-patch.ts +0 -107
- package/src/native/linux-cef-links.ts +0 -14
- package/src/native/native-secret-store.ts +0 -99
- package/src/native/native-utilities.ts +0 -166
- package/src/native/partitioned-window.ts +0 -62
- package/src/native/secure-window.ts +0 -115
- package/src/native/sidecar-services.ts +0 -71
- package/src/native/sidecar.ts +0 -387
- package/src/native/window-bootstrap.ts +0 -77
- package/src/native/windows-build-hook-internal.ts +0 -49
- package/src/native/windows-build-hook.ts +0 -12
- package/src/native/windows-runtime-patch-internal.ts +0 -48
- package/src/native/windows-runtime-patch.ts +0 -15
- package/src/release/feed-release-cut.ts +0 -110
- package/src/release/feed-state.ts +0 -135
- package/src/release/framework-package-publish.ts +0 -163
- package/src/release/framework-update.ts +0 -196
- package/src/release/github-cli.ts +0 -27
- package/src/release/github-release-assets.ts +0 -36
- package/src/release/github-release-cut.ts +0 -237
- package/src/release/github-release-lookup.ts +0 -39
- package/src/release/github-release-promotion.ts +0 -112
- package/src/release/github-release-provenance.ts +0 -65
- package/src/release/github-release-publisher.ts +0 -90
- package/src/release/github-release-qualification.ts +0 -144
- package/src/release/local-provenance.ts +0 -92
- package/src/release/local-release.ts +0 -525
- package/src/release/macos-dmg.ts +0 -113
- package/src/release/release-artifact.ts +0 -53
- package/src/release/release-assets-plan.ts +0 -118
- package/src/release/release-config.ts +0 -420
- package/src/release/release-cut-command.ts +0 -80
- package/src/release/release-cut.ts +0 -133
- package/src/release/release-descriptor-staging.ts +0 -242
- package/src/release/release-finalize.ts +0 -191
- package/src/release/release-promotion-command.ts +0 -36
- package/src/release/release-promotion.ts +0 -132
- package/src/release/release-publication.ts +0 -213
- package/src/release/release-publish-command.ts +0 -163
- package/src/release/release-qualification.ts +0 -397
- package/src/release/release-staging.ts +0 -87
- package/src/release/release-steps.ts +0 -173
- package/src/release/retained-release-build.ts +0 -217
- package/src/shell/application-menu-commands.ts +0 -6
- package/src/shell/application-menu.ts +0 -250
- package/src/updates/channel-update-manager.ts +0 -127
- package/src/updates/desktop-updater.ts +0 -440
- package/src/updates/release-feed.ts +0 -187
- package/src/updates/release-location.ts +0 -101
- package/src/updates/signed-release.ts +0 -311
- package/src/updates/stable-file.ts +0 -32
- package/src/updates/update-arm.ts +0 -107
- package/src/updates/update-channel-store.ts +0 -86
- package/src/updates/update-discovery.ts +0 -113
- package/src/updates/update-download.ts +0 -82
- package/src/updates/update-exclusive-rename.ts +0 -58
- package/src/updates/update-extraction.ts +0 -261
- package/src/updates/update-handoff-plan.ts +0 -75
- package/src/updates/update-helper.ts +0 -87
- package/src/updates/update-launch.ts +0 -33
- package/src/updates/update-manager.ts +0 -130
- package/src/updates/update-process-fence.ts +0 -125
- package/src/updates/update-resume.ts +0 -34
- package/src/updates/update-shutdown.ts +0 -37
- package/src/updates/update-swap-stage.ts +0 -75
- package/src/updates/update-swap.ts +0 -30
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
3
|
-
import type { InstallerPlatform } from '../installer/installer-layout'
|
|
4
|
-
|
|
5
|
-
/** The Electrobun launcher inside an installed app tree. */
|
|
6
|
-
export function updateLauncherPath(platform: InstallerPlatform, target: string): string {
|
|
7
|
-
if (typeof target !== 'string' || !isAbsolute(target) || resolve(target) !== target)
|
|
8
|
-
throw new Error('Invalid update target')
|
|
9
|
-
if (platform === 'macos-arm64') return join(target, 'Contents', 'MacOS', 'launcher')
|
|
10
|
-
if (platform === 'windows-x64') return join(target, 'bin', 'launcher.exe')
|
|
11
|
-
if (platform === 'linux-x64') return join(target, 'bin', 'launcher')
|
|
12
|
-
throw new Error('Unsupported update platform')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Start the installed app's launcher detached from the helper. */
|
|
16
|
-
export async function launchInstalledApp(
|
|
17
|
-
platform: InstallerPlatform,
|
|
18
|
-
target: string,
|
|
19
|
-
env: Record<string, string | undefined> = process.env
|
|
20
|
-
): Promise<void> {
|
|
21
|
-
const executable = updateLauncherPath(platform, target)
|
|
22
|
-
const child = spawn(executable, [], {
|
|
23
|
-
cwd: dirname(executable),
|
|
24
|
-
detached: true,
|
|
25
|
-
stdio: 'ignore',
|
|
26
|
-
env,
|
|
27
|
-
})
|
|
28
|
-
await new Promise<void>((done, reject) => {
|
|
29
|
-
child.once('spawn', done)
|
|
30
|
-
child.once('error', reject)
|
|
31
|
-
})
|
|
32
|
-
child.unref()
|
|
33
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { discoverSignedRelease } from './update-discovery'
|
|
2
|
-
import { downloadVerifiedRelease } from './update-download'
|
|
3
|
-
import {
|
|
4
|
-
isVerifiedReleaseForTrust,
|
|
5
|
-
type ReleaseTrust,
|
|
6
|
-
type VerifiedRelease,
|
|
7
|
-
} from './signed-release'
|
|
8
|
-
import { versionLessThan } from './release-version'
|
|
9
|
-
import type { FetchFunction } from './release-location'
|
|
10
|
-
|
|
11
|
-
type Phase =
|
|
12
|
-
| 'idle'
|
|
13
|
-
| 'checking'
|
|
14
|
-
| 'current'
|
|
15
|
-
| 'available'
|
|
16
|
-
| 'downloading'
|
|
17
|
-
| 'staging'
|
|
18
|
-
| 'staged'
|
|
19
|
-
| 'failed'
|
|
20
|
-
type State = Readonly<{
|
|
21
|
-
phase: Phase
|
|
22
|
-
currentVersion: string
|
|
23
|
-
availableVersion: string | null
|
|
24
|
-
error: string | null
|
|
25
|
-
}>
|
|
26
|
-
/** Coordinates trusted discovery and download; the platform adapter owns safe application and recovery. */
|
|
27
|
-
export function createUpdateManager(options: {
|
|
28
|
-
currentVersion: string
|
|
29
|
-
trust: ReleaseTrust
|
|
30
|
-
discoveryName: string
|
|
31
|
-
directory: string
|
|
32
|
-
maxBytes: number
|
|
33
|
-
stage: (input: { descriptor: VerifiedRelease; path: string; directory: string }) => Promise<void>
|
|
34
|
-
discover?: typeof discoverSignedRelease
|
|
35
|
-
download?: typeof downloadVerifiedRelease
|
|
36
|
-
fetch?: FetchFunction
|
|
37
|
-
}) {
|
|
38
|
-
if (
|
|
39
|
-
!/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(options.currentVersion) ||
|
|
40
|
-
options.currentVersion.length > 64 ||
|
|
41
|
-
!Number.isSafeInteger(options.maxBytes) ||
|
|
42
|
-
options.maxBytes < 1 ||
|
|
43
|
-
typeof options.stage !== 'function'
|
|
44
|
-
)
|
|
45
|
-
throw new Error('Invalid update manager configuration')
|
|
46
|
-
let state: State = Object.freeze({
|
|
47
|
-
phase: 'idle',
|
|
48
|
-
currentVersion: options.currentVersion,
|
|
49
|
-
availableVersion: null,
|
|
50
|
-
error: null,
|
|
51
|
-
})
|
|
52
|
-
let pending: VerifiedRelease | undefined,
|
|
53
|
-
busy = false
|
|
54
|
-
const set = (
|
|
55
|
-
phase: Phase,
|
|
56
|
-
version: string | null = pending?.version ?? null,
|
|
57
|
-
error: string | null = null
|
|
58
|
-
): State =>
|
|
59
|
-
(state = Object.freeze({
|
|
60
|
-
phase,
|
|
61
|
-
currentVersion: options.currentVersion,
|
|
62
|
-
availableVersion: version,
|
|
63
|
-
error,
|
|
64
|
-
}))
|
|
65
|
-
const acquire = () => {
|
|
66
|
-
if (busy) throw new Error('Update manager is busy')
|
|
67
|
-
busy = true
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
status: () => state,
|
|
71
|
-
async check(): Promise<State> {
|
|
72
|
-
acquire()
|
|
73
|
-
if (state.phase === 'staged') {
|
|
74
|
-
busy = false
|
|
75
|
-
throw new Error('An update is already staged')
|
|
76
|
-
}
|
|
77
|
-
pending = undefined
|
|
78
|
-
set('checking', null)
|
|
79
|
-
try {
|
|
80
|
-
const descriptor = await (options.discover ?? discoverSignedRelease)({
|
|
81
|
-
trust: options.trust,
|
|
82
|
-
discoveryName: options.discoveryName,
|
|
83
|
-
fetch: options.fetch,
|
|
84
|
-
})
|
|
85
|
-
if (!isVerifiedReleaseForTrust(descriptor, options.trust))
|
|
86
|
-
throw new Error('Untrusted update')
|
|
87
|
-
if (!versionLessThan(options.currentVersion, descriptor.version))
|
|
88
|
-
return set('current', null)
|
|
89
|
-
pending = descriptor
|
|
90
|
-
return set('available')
|
|
91
|
-
} catch {
|
|
92
|
-
pending = undefined
|
|
93
|
-
return set('failed', null, 'Update check failed. Please try again.')
|
|
94
|
-
} finally {
|
|
95
|
-
busy = false
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
async install(input: { approved: boolean; expectedVersion: string }): Promise<State> {
|
|
99
|
-
acquire()
|
|
100
|
-
try {
|
|
101
|
-
if (
|
|
102
|
-
input.approved !== true ||
|
|
103
|
-
!pending ||
|
|
104
|
-
state.phase !== 'available' ||
|
|
105
|
-
input.expectedVersion !== pending.version
|
|
106
|
-
)
|
|
107
|
-
throw new Error('Update approval does not match the available version')
|
|
108
|
-
const descriptor = pending
|
|
109
|
-
set('downloading')
|
|
110
|
-
try {
|
|
111
|
-
const download = await (options.download ?? downloadVerifiedRelease)({
|
|
112
|
-
descriptor,
|
|
113
|
-
directory: options.directory,
|
|
114
|
-
maxBytes: options.maxBytes,
|
|
115
|
-
fetch: options.fetch,
|
|
116
|
-
})
|
|
117
|
-
set('staging')
|
|
118
|
-
await options.stage({ descriptor, ...download })
|
|
119
|
-
pending = undefined
|
|
120
|
-
return set('staged', descriptor.version)
|
|
121
|
-
} catch {
|
|
122
|
-
pending = undefined
|
|
123
|
-
return set('failed', null, 'Update staging failed. Please try again.')
|
|
124
|
-
}
|
|
125
|
-
} finally {
|
|
126
|
-
busy = false
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process'
|
|
2
|
-
import { dlopen, FFIType, ptr } from 'bun:ffi'
|
|
3
|
-
import { realpath } from 'node:fs/promises'
|
|
4
|
-
import { isAbsolute } from 'node:path'
|
|
5
|
-
import { promisify } from 'node:util'
|
|
6
|
-
const execute = promisify(execFile)
|
|
7
|
-
|
|
8
|
-
function isProcessRunning(pid: number): boolean {
|
|
9
|
-
try {
|
|
10
|
-
process.kill(pid, 0)
|
|
11
|
-
return true
|
|
12
|
-
} catch (error) {
|
|
13
|
-
if ((error as NodeJS.ErrnoException).code === 'ESRCH') return false
|
|
14
|
-
throw new Error('Cannot inspect update process', { cause: error })
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Wait without signalling only processes whose executables were verified. This is not complete app-process discovery. */
|
|
19
|
-
export async function waitForUpdateProcesses(options: {
|
|
20
|
-
processes: readonly { pid: number; executable: string }[]
|
|
21
|
-
timeoutMs: number
|
|
22
|
-
env?: Record<string, string | undefined>
|
|
23
|
-
onVerified?: () => void
|
|
24
|
-
}): Promise<void> {
|
|
25
|
-
if (
|
|
26
|
-
!Array.isArray(options.processes) ||
|
|
27
|
-
options.processes.length < 1 ||
|
|
28
|
-
options.processes.length > 16 ||
|
|
29
|
-
!Number.isSafeInteger(options.timeoutMs) ||
|
|
30
|
-
options.timeoutMs < 1 ||
|
|
31
|
-
options.timeoutMs > 120000
|
|
32
|
-
)
|
|
33
|
-
throw new Error('Invalid update process fence')
|
|
34
|
-
const seen = new Set<number>(),
|
|
35
|
-
env: Record<string, string> = {}
|
|
36
|
-
const deadline = Date.now() + options.timeoutMs
|
|
37
|
-
for (const key of ['PATH', 'SystemRoot', 'WINDIR', 'TMP', 'TEMP', 'TMPDIR', 'LANG', 'LC_ALL'])
|
|
38
|
-
if ((options.env ?? process.env)[key]) env[key] = (options.env ?? process.env)[key]!
|
|
39
|
-
async function executable(pid: number): Promise<string> {
|
|
40
|
-
if (process.platform === 'linux') return realpath(`/proc/${pid}/exe`)
|
|
41
|
-
if (process.platform === 'darwin')
|
|
42
|
-
return realpath(
|
|
43
|
-
(
|
|
44
|
-
await execute('/bin/ps', ['-p', String(pid), '-o', 'comm='], {
|
|
45
|
-
env,
|
|
46
|
-
timeout: Math.max(1, Math.min(5000, deadline - Date.now())),
|
|
47
|
-
maxBuffer: 16384,
|
|
48
|
-
})
|
|
49
|
-
).stdout.trim()
|
|
50
|
-
)
|
|
51
|
-
if (process.platform === 'win32') {
|
|
52
|
-
const library = dlopen('kernel32.dll', {
|
|
53
|
-
OpenProcess: { args: [FFIType.u32, FFIType.i32, FFIType.u32], returns: FFIType.ptr },
|
|
54
|
-
QueryFullProcessImageNameW: {
|
|
55
|
-
args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr],
|
|
56
|
-
returns: FFIType.i32,
|
|
57
|
-
},
|
|
58
|
-
CloseHandle: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
59
|
-
})
|
|
60
|
-
try {
|
|
61
|
-
const handle = library.symbols.OpenProcess(0x1000, 0, pid)
|
|
62
|
-
if (!handle) throw new Error('Cannot open update process')
|
|
63
|
-
try {
|
|
64
|
-
const buffer = Buffer.alloc(32768 * 2),
|
|
65
|
-
length = Buffer.alloc(4)
|
|
66
|
-
length.writeUInt32LE(32768)
|
|
67
|
-
if (!library.symbols.QueryFullProcessImageNameW(handle, 0, ptr(buffer), ptr(length)))
|
|
68
|
-
throw new Error('Cannot inspect update process')
|
|
69
|
-
const count = length.readUInt32LE()
|
|
70
|
-
if (!count || count >= 32768) throw new Error('Invalid update process path')
|
|
71
|
-
return await realpath(buffer.subarray(0, count * 2).toString('utf16le'))
|
|
72
|
-
} finally {
|
|
73
|
-
library.symbols.CloseHandle(handle)
|
|
74
|
-
}
|
|
75
|
-
} finally {
|
|
76
|
-
library.close()
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
throw new Error('Unsupported update process platform')
|
|
80
|
-
}
|
|
81
|
-
const waiting = new Set<number>()
|
|
82
|
-
for (const processInfo of options.processes) {
|
|
83
|
-
if (
|
|
84
|
-
!processInfo ||
|
|
85
|
-
!Number.isSafeInteger(processInfo.pid) ||
|
|
86
|
-
processInfo.pid < 2 ||
|
|
87
|
-
processInfo.pid > 0xffffffff ||
|
|
88
|
-
processInfo.pid === process.pid ||
|
|
89
|
-
seen.has(processInfo.pid) ||
|
|
90
|
-
typeof processInfo.executable !== 'string' ||
|
|
91
|
-
!isAbsolute(processInfo.executable)
|
|
92
|
-
)
|
|
93
|
-
throw new Error('Invalid update process identity')
|
|
94
|
-
if (Date.now() >= deadline) throw new Error('Update process fence timed out')
|
|
95
|
-
seen.add(processInfo.pid)
|
|
96
|
-
if (!isProcessRunning(processInfo.pid))
|
|
97
|
-
throw new Error('Update process exited before verification')
|
|
98
|
-
let actual: string
|
|
99
|
-
try {
|
|
100
|
-
actual = await executable(processInfo.pid)
|
|
101
|
-
} catch {
|
|
102
|
-
throw new Error('Cannot verify update process')
|
|
103
|
-
}
|
|
104
|
-
const expected = await realpath(processInfo.executable)
|
|
105
|
-
if (
|
|
106
|
-
process.platform === 'win32'
|
|
107
|
-
? actual.toLowerCase() !== expected.toLowerCase()
|
|
108
|
-
: actual !== expected
|
|
109
|
-
)
|
|
110
|
-
throw new Error('Update process executable mismatch')
|
|
111
|
-
waiting.add(processInfo.pid)
|
|
112
|
-
}
|
|
113
|
-
if (Date.now() >= deadline) throw new Error('Update process fence timed out')
|
|
114
|
-
for (const pid of waiting)
|
|
115
|
-
if (!isProcessRunning(pid)) throw new Error('Update process exited before verification')
|
|
116
|
-
const notified: unknown = options.onVerified?.()
|
|
117
|
-
if (typeof notified === 'object' && notified !== null && 'then' in notified)
|
|
118
|
-
throw new Error('Update process acknowledgement must be synchronous')
|
|
119
|
-
while (waiting.size) {
|
|
120
|
-
for (const pid of waiting) if (!isProcessRunning(pid)) waiting.delete(pid)
|
|
121
|
-
if (!waiting.size) return
|
|
122
|
-
if (Date.now() >= deadline) throw new Error('Update processes did not exit')
|
|
123
|
-
await Bun.sleep(Math.min(100, Math.max(1, deadline - Date.now())))
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { lstat, readFile, rm } from 'node:fs/promises'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { updateStagingFor } from './update-swap'
|
|
4
|
-
|
|
5
|
-
export type UpdateResumeResult = Readonly<
|
|
6
|
-
{ status: 'none' | 'in-progress' | 'not-applied' } | { status: 'updated'; version: string }
|
|
7
|
-
>
|
|
8
|
-
|
|
9
|
-
function alive(pid: number): boolean {
|
|
10
|
-
try {
|
|
11
|
-
process.kill(pid, 0)
|
|
12
|
-
return true
|
|
13
|
-
} catch (error) {
|
|
14
|
-
return (error as NodeJS.ErrnoException).code === 'EPERM'
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Call on app start. Reports whether an earlier helper installed an update and
|
|
20
|
-
* removes the staging directory, unless a helper is still running from it.
|
|
21
|
-
*/
|
|
22
|
-
export async function resumeUpdate(options: { target: string }): Promise<UpdateResumeResult> {
|
|
23
|
-
const staging = updateStagingFor(options.target)
|
|
24
|
-
const info = await lstat(staging).catch(() => undefined)
|
|
25
|
-
if (!info) return { status: 'none' }
|
|
26
|
-
if (!info.isDirectory() || info.isSymbolicLink())
|
|
27
|
-
throw new Error('Unexpected update staging entry')
|
|
28
|
-
const helper = Number(await readFile(join(staging, 'helper-armed'), 'utf8').catch(() => 0))
|
|
29
|
-
if (Number.isSafeInteger(helper) && helper > 1 && helper !== process.pid && alive(helper))
|
|
30
|
-
return { status: 'in-progress' }
|
|
31
|
-
const version = await readFile(join(staging, 'updated'), 'utf8').catch(() => undefined)
|
|
32
|
-
await rm(staging, { recursive: true, force: true })
|
|
33
|
-
return version ? { status: 'updated', version } : { status: 'not-applied' }
|
|
34
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reserve an app's existing quit approval before arming a post-exit helper.
|
|
3
|
-
* The native adapter must guarantee its token cannot be reused or vetoed again.
|
|
4
|
-
* `arm` must clean up partial startup before rejecting, and `quit` must only
|
|
5
|
-
* resolve after shutdown is accepted. The helper still needs a bounded process
|
|
6
|
-
* fence; this ordering alone does not establish that the app has exited.
|
|
7
|
-
*/
|
|
8
|
-
export async function scheduleUpdateShutdown<Token>(options: {
|
|
9
|
-
reserve(): Token | null | Promise<Token | null>
|
|
10
|
-
cancelReservation(token: Token): void | Promise<void>
|
|
11
|
-
arm(): Promise<{ cancel(): void | Promise<void> }>
|
|
12
|
-
quit(token: Token): boolean | Promise<boolean>
|
|
13
|
-
}): Promise<'cancelled' | 'scheduled'> {
|
|
14
|
-
const token = await options.reserve()
|
|
15
|
-
if (token === null) return 'cancelled'
|
|
16
|
-
if (token === undefined) throw new Error('Invalid update quit approval')
|
|
17
|
-
let helper: { cancel(): void | Promise<void> } | undefined
|
|
18
|
-
try {
|
|
19
|
-
helper = await options.arm()
|
|
20
|
-
if (!helper || typeof helper.cancel !== 'function')
|
|
21
|
-
throw new Error('Update helper was not armed')
|
|
22
|
-
if ((await options.quit(token)) !== true) throw new Error('Update shutdown rejected')
|
|
23
|
-
return 'scheduled'
|
|
24
|
-
} catch {
|
|
25
|
-
try {
|
|
26
|
-
await helper?.cancel()
|
|
27
|
-
} catch {
|
|
28
|
-
/* Do not mask the handoff failure. */
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
await options.cancelReservation(token)
|
|
32
|
-
} catch {
|
|
33
|
-
/* Do not mask the handoff failure. */
|
|
34
|
-
}
|
|
35
|
-
throw new Error('Update shutdown could not be scheduled')
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { lstat, mkdtemp, readFile, realpath, rm } from 'node:fs/promises'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { planUpdateHandoff } from './update-handoff-plan'
|
|
4
|
-
import { extractVerifiedUpdate } from './update-extraction'
|
|
5
|
-
import { renameUpdateExclusive } from './update-exclusive-rename'
|
|
6
|
-
import { updateStagingFor } from './update-swap'
|
|
7
|
-
import type { InstallerPlatform, InstallerRenderer } from '../installer/installer-layout'
|
|
8
|
-
import type { ReleaseTrust, VerifiedRelease } from './signed-release'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Extract an approved, signature-verified update into `candidate` inside a new
|
|
12
|
-
* private staging directory beside the install. Does not stop, replace or
|
|
13
|
-
* relaunch the app.
|
|
14
|
-
*/
|
|
15
|
-
export async function stageUpdateSwap(options: {
|
|
16
|
-
descriptor: VerifiedRelease
|
|
17
|
-
trust: ReleaseTrust
|
|
18
|
-
currentVersion: string
|
|
19
|
-
approved: boolean
|
|
20
|
-
approvedVersion: string
|
|
21
|
-
target: string
|
|
22
|
-
appName: string
|
|
23
|
-
platform: InstallerPlatform
|
|
24
|
-
renderer: InstallerRenderer
|
|
25
|
-
archive: string
|
|
26
|
-
maxCompressedBytes: number
|
|
27
|
-
maxExpandedBytes: number
|
|
28
|
-
/** Sidecar executables the app bundles; the update must contain each. */
|
|
29
|
-
sidecars?: readonly string[]
|
|
30
|
-
}): Promise<{ staging: string; candidate: string; version: string }> {
|
|
31
|
-
const plan = planUpdateHandoff(options)
|
|
32
|
-
const expectedHost = {
|
|
33
|
-
'macos-arm64': 'darwin/arm64',
|
|
34
|
-
'windows-x64': 'win32/x64',
|
|
35
|
-
'linux-x64': 'linux/x64',
|
|
36
|
-
}[plan.platform]
|
|
37
|
-
if (`${process.platform}/${process.arch}` !== expectedHost)
|
|
38
|
-
throw new Error('Update requires the matching native platform')
|
|
39
|
-
const info = await lstat(plan.target)
|
|
40
|
-
if (!info.isDirectory() || info.isSymbolicLink() || (await realpath(plan.target)) !== plan.target)
|
|
41
|
-
throw new Error('Invalid update install target')
|
|
42
|
-
const versionFile = join(
|
|
43
|
-
plan.target,
|
|
44
|
-
...(plan.platform === 'macos-arm64' ? ['Contents', 'Resources'] : ['Resources']),
|
|
45
|
-
'version.json'
|
|
46
|
-
)
|
|
47
|
-
const versionInfo = await lstat(versionFile)
|
|
48
|
-
if (!versionInfo.isFile() || versionInfo.size > 1024 * 1024)
|
|
49
|
-
throw new Error('Installed update version mismatch')
|
|
50
|
-
if (JSON.parse(await readFile(versionFile, 'utf8')).version !== plan.currentVersion)
|
|
51
|
-
throw new Error('Installed update version mismatch')
|
|
52
|
-
const staging = updateStagingFor(plan.target)
|
|
53
|
-
const preparing = await mkdtemp(`${staging}.preparing-`)
|
|
54
|
-
const candidate = join(staging, 'candidate')
|
|
55
|
-
let published = false
|
|
56
|
-
try {
|
|
57
|
-
const extracted = await extractVerifiedUpdate({
|
|
58
|
-
descriptor: options.descriptor,
|
|
59
|
-
archive: options.archive,
|
|
60
|
-
directory: preparing,
|
|
61
|
-
platform: plan.platform,
|
|
62
|
-
renderer: plan.renderer,
|
|
63
|
-
appName: plan.appName,
|
|
64
|
-
maxCompressedBytes: options.maxCompressedBytes,
|
|
65
|
-
maxExpandedBytes: options.maxExpandedBytes,
|
|
66
|
-
...(options.sidecars === undefined ? {} : { sidecars: options.sidecars }),
|
|
67
|
-
})
|
|
68
|
-
renameUpdateExclusive(extracted.payload, join(preparing, 'candidate'))
|
|
69
|
-
renameUpdateExclusive(preparing, staging)
|
|
70
|
-
published = true
|
|
71
|
-
return { staging, candidate, version: plan.version }
|
|
72
|
-
} finally {
|
|
73
|
-
if (!published) await rm(preparing, { recursive: true, force: true })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { rm } from 'node:fs/promises'
|
|
2
|
-
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
3
|
-
import { renameUpdateExclusive } from './update-exclusive-rename'
|
|
4
|
-
|
|
5
|
-
/** The private staging directory the framework keeps beside an install. */
|
|
6
|
-
export function updateStagingFor(target: string): string {
|
|
7
|
-
if (typeof target !== 'string' || !isAbsolute(target) || resolve(target) !== target)
|
|
8
|
-
throw new Error('Invalid update target')
|
|
9
|
-
return join(dirname(target), `.${basename(target)}.framework-update`)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Move the staged `candidate` into the install location once the app has
|
|
14
|
-
* exited. The old tree is moved aside into staging and deleted.
|
|
15
|
-
*/
|
|
16
|
-
export async function swapUpdateTree(options: { target: string; staging: string }): Promise<void> {
|
|
17
|
-
const { target, staging } = options
|
|
18
|
-
if (dirname(staging) !== dirname(target) || staging === target)
|
|
19
|
-
throw new Error('Invalid update swap context')
|
|
20
|
-
const old = join(staging, 'old')
|
|
21
|
-
renameUpdateExclusive(target, old)
|
|
22
|
-
try {
|
|
23
|
-
renameUpdateExclusive(join(staging, 'candidate'), target)
|
|
24
|
-
} catch (error) {
|
|
25
|
-
// Put the app back so it can still be launched.
|
|
26
|
-
renameUpdateExclusive(old, target)
|
|
27
|
-
throw error
|
|
28
|
-
}
|
|
29
|
-
await rm(old, { recursive: true, force: true })
|
|
30
|
-
}
|