@adea-ai/app-framework 0.36.1 → 0.37.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 +2 -0
- package/dist/appearance/window-surface.d.ts +19 -0
- package/dist/appearance/window-surface.js +68 -1
- package/dist/cli/windows-installer-build-cli.d.ts +2 -0
- package/dist/cli/windows-installer-build-cli.js +14 -0
- package/dist/framework-source.json +1 -1
- package/dist/native/installer-archive.d.ts +42 -0
- package/dist/native/installer-archive.js +172 -0
- package/dist/native/window-surface-store.d.ts +16 -0
- package/dist/native/window-surface-store.js +69 -0
- package/dist/native/windows-extractor-build.d.ts +95 -0
- package/dist/native/windows-extractor-build.js +326 -0
- package/package.json +14 -1
- package/src/appearance/window-surface.ts +91 -5
- package/templates/application/src/bun/index.ts +15 -0
- package/templates/application/src/web/main.tsx +13 -1
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ test checks the file list against the exports.
|
|
|
81
81
|
| Appearance | `appearance-host`, `appearance-preferences`, `appearance-surface`, `custom-theme-library`, `window-surface` (all _solid_) |
|
|
82
82
|
| Desktop host | `desktop-host`, `desktop-gateway`, `desktop-client`, `desktop-detection`, `desktop-stream`, `channel-handshake`, `channel-proof`, `loopback-policy`, `open-url-channel`, `client-asset-manifest`, `client-assets` (source only) |
|
|
83
83
|
| Native windows and OS | `renderer-profile`, `secure-window`, `partitioned-window`, `window-options` (source only), `native-utilities`, `native-secret-store`, `app-bundle`, `sidecar`, `sidecar-services`, `desktop-build-hook`, `desktop-build`, `windows-runtime-patch`, `electrobun-types` (ambient types only) |
|
|
84
|
+
| Native installers | `windows-extractor-build`, `installer-archive`, `window-surface-store` |
|
|
84
85
|
| Updates | `desktop-updater`, `update-manager`, `update-inherited-launch-lease`, `packaged-launch-admission`, `packaged-update-startup`, `update-resume`, `channel-update-manager`, `update-channel-store`, `update-discovery`, `update-download`, `update-extraction`, `signed-release`, `release-feed`, `release-location`, `update-process-liveness`, `update-adapter` (_solid_), `release-version` (_solid_), `update-state` (source only), `update-helper.js` (bundled helper) |
|
|
85
86
|
| Release tooling | `release-config`, `release-cut`, `release-steps`, `release-staging`, `release-artifact`, `release-assets-plan`, `release-descriptor-staging`, `release-publication`, `release-publish-command`, `release-promotion`, `retained-release-build`, `github-release-publisher`, `github-release-qualification`, `github-release-promotion`, `macos-dmg` |
|
|
86
87
|
| Installer qualification | `installer-layout`, `installer-identity`, `installer-extraction`, `installed-payload`, `installer-observation`, `installer-qualification-command`, `installer-renderer-evidence` |
|
|
@@ -102,6 +103,7 @@ Commands (package `bin` entries):
|
|
|
102
103
|
| `adea-verify-macos-signing` | On a Mac, check every nested Mach-O in an app is signed alike and the seal verifies. |
|
|
103
104
|
| `adea-promote-release` | Promote the newest qualified daily to stable after the soak. |
|
|
104
105
|
| `adea-desktop-release` | In a GitLab release tag pipeline, build, sign and publish this runner's platform, then promote. |
|
|
106
|
+
| `adea-build-windows-installer` | Build a stable Windows x64 installer whose extractor carries the shortcut patch. |
|
|
105
107
|
| `adea-cef-helper` | Print the CEF helper cache key, or build the helper. |
|
|
106
108
|
| `adea-patch-windows-runtime` | Apply the checksum-guarded Windows runtime correction. |
|
|
107
109
|
| `adea-patch-electrobun-shortcuts` | Apply the shipped Windows shortcut patch to an Electrobun checkout. |
|
|
@@ -2,4 +2,23 @@ export type WindowSurface = 'theme' | 'frosted' | 'opaque';
|
|
|
2
2
|
type WindowSurfaceMirror = (surface: WindowSurface) => void;
|
|
3
3
|
export declare function registerWindowSurfaceMirror(next: WindowSurfaceMirror): void;
|
|
4
4
|
export declare function mirrorWindowSurface(surface: WindowSurface): void;
|
|
5
|
+
/**
|
|
6
|
+
* A mirror that retries a failed update once after `retryDelayMs`, never replaying a choice a
|
|
7
|
+
* newer one superseded. `whenSettled` runs before a retry (for example, until an uncertain
|
|
8
|
+
* write is fenced); `onFailure` hears about a mirror that still failed and may retry it later.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createWindowSurfaceMirror(update: (surface: WindowSurface) => Promise<void>, options?: {
|
|
11
|
+
retryDelayMs?: number;
|
|
12
|
+
whenSettled?: () => Promise<void>;
|
|
13
|
+
onFailure?: (surface: WindowSurface, retry: () => void) => void;
|
|
14
|
+
}): WindowSurfaceMirror;
|
|
15
|
+
/**
|
|
16
|
+
* The update `createWindowSurfaceMirror` needs, through the framework `shell.window-surface`
|
|
17
|
+
* service. The host persists every request it receives, so requests go out one at a time: a
|
|
18
|
+
* newer choice waits for the request in flight, and a choice superseded while it waits is never
|
|
19
|
+
* sent. The last write to reach the store is always the latest choice.
|
|
20
|
+
*/
|
|
21
|
+
export declare function desktopWindowSurfaceUpdate(invoke: (name: string, input: unknown) => Promise<{
|
|
22
|
+
ok: boolean;
|
|
23
|
+
}>): (surface: WindowSurface) => Promise<void>;
|
|
5
24
|
export {};
|
|
@@ -6,4 +6,71 @@ function registerWindowSurfaceMirror(next) {
|
|
|
6
6
|
function mirrorWindowSurface(surface) {
|
|
7
7
|
mirror?.(surface);
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A mirror that retries a failed update once after `retryDelayMs`, never replaying a choice a
|
|
11
|
+
* newer one superseded. `whenSettled` runs before a retry (for example, until an uncertain
|
|
12
|
+
* write is fenced); `onFailure` hears about a mirror that still failed and may retry it later.
|
|
13
|
+
*/
|
|
14
|
+
function createWindowSurfaceMirror(update, options = {}) {
|
|
15
|
+
const retryDelayMs = options.retryDelayMs ?? 500;
|
|
16
|
+
const whenSettled = options.whenSettled ?? (() => Promise.resolve());
|
|
17
|
+
if (!Number.isSafeInteger(retryDelayMs) || retryDelayMs < 0 || retryDelayMs > 2147483647) throw new Error("Invalid window surface retry delay");
|
|
18
|
+
let generation = 0;
|
|
19
|
+
let retryTimer;
|
|
20
|
+
return (surface) => {
|
|
21
|
+
const mine = ++generation;
|
|
22
|
+
if (retryTimer !== void 0) clearTimeout(retryTimer);
|
|
23
|
+
retryTimer = void 0;
|
|
24
|
+
const afterSettled = (retry) => void Promise.resolve().then(whenSettled).then(() => {
|
|
25
|
+
if (mine === generation) attempt(retry);
|
|
26
|
+
}).catch(reportFailure);
|
|
27
|
+
const reportFailure = () => {
|
|
28
|
+
if (mine !== generation) return;
|
|
29
|
+
let used = false;
|
|
30
|
+
try {
|
|
31
|
+
options.onFailure?.(surface, () => {
|
|
32
|
+
if (used || mine !== generation) return;
|
|
33
|
+
used = true;
|
|
34
|
+
afterSettled(true);
|
|
35
|
+
});
|
|
36
|
+
} catch {}
|
|
37
|
+
};
|
|
38
|
+
const attempt = (retry) => {
|
|
39
|
+
let result;
|
|
40
|
+
try {
|
|
41
|
+
result = update(surface);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
result = Promise.reject(error);
|
|
44
|
+
}
|
|
45
|
+
result.catch(() => {
|
|
46
|
+
if (mine !== generation) return;
|
|
47
|
+
if (!retry) return reportFailure();
|
|
48
|
+
retryTimer = setTimeout(() => {
|
|
49
|
+
retryTimer = void 0;
|
|
50
|
+
afterSettled(false);
|
|
51
|
+
}, retryDelayMs);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
attempt(true);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The update `createWindowSurfaceMirror` needs, through the framework `shell.window-surface`
|
|
59
|
+
* service. The host persists every request it receives, so requests go out one at a time: a
|
|
60
|
+
* newer choice waits for the request in flight, and a choice superseded while it waits is never
|
|
61
|
+
* sent. The last write to reach the store is always the latest choice.
|
|
62
|
+
*/
|
|
63
|
+
function desktopWindowSurfaceUpdate(invoke) {
|
|
64
|
+
let latest = 0;
|
|
65
|
+
let previous = Promise.resolve();
|
|
66
|
+
return (surface) => {
|
|
67
|
+
const mine = ++latest;
|
|
68
|
+
const request = previous.then(async () => {
|
|
69
|
+
if (mine !== latest) return;
|
|
70
|
+
if (!(await invoke("shell.window-surface", { surface })).ok) throw new Error("Unable to save the window surface");
|
|
71
|
+
});
|
|
72
|
+
previous = request.catch(() => void 0);
|
|
73
|
+
return request;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export { createWindowSurfaceMirror, desktopWindowSurfaceUpdate, mirrorWindowSurface, registerWindowSurfaceMirror };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { redactedErrorMessage, runCli } from "./cli-runner.js";
|
|
3
|
+
import { buildPatchedWindowsInstaller } from "../native/windows-extractor-build.js";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
// src/cli/windows-installer-build-cli.ts
|
|
6
|
+
await runCli((error) => `Unable to build the patched Windows installer: ${redactedErrorMessage(error)}`, async () => {
|
|
7
|
+
const [appName, appRoot = ".", ...extra] = process.argv.slice(2);
|
|
8
|
+
if (!appName || extra.length) throw new Error("Expected an app name and optional app root");
|
|
9
|
+
const installer = await buildPatchedWindowsInstaller({
|
|
10
|
+
appName,
|
|
11
|
+
appRoot: resolve(appRoot)
|
|
12
|
+
});
|
|
13
|
+
process.stdout.write(`${installer}\n`);
|
|
14
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.37.0","commit":"7b3918e5dc5726a4a22f3661aa0d2826e3149071"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type InstallerArchiveOutcome = {
|
|
2
|
+
state: 'removed';
|
|
3
|
+
path: string;
|
|
4
|
+
} | {
|
|
5
|
+
state: 'absent';
|
|
6
|
+
} | {
|
|
7
|
+
state: 'skipped';
|
|
8
|
+
reason: string;
|
|
9
|
+
};
|
|
10
|
+
/** What a descriptor-relative lookup of one name proved. */
|
|
11
|
+
export type EntryProbe = 'present' | 'absent' | 'unknown';
|
|
12
|
+
/** Descriptor-relative file operations; the seam the race tests use. */
|
|
13
|
+
export interface DescriptorOps {
|
|
14
|
+
/** `openat`; returns a descriptor or -1. */
|
|
15
|
+
openAt(dirFd: number, name: string, flags: number): number;
|
|
16
|
+
/** `unlinkat(dirFd, name, 0)`; returns 0 or -1. */
|
|
17
|
+
unlinkAt(dirFd: number, name: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether `name` exists in the directory, without following a final symlink
|
|
20
|
+
* (a dangling symlink is `present`). `absent` only when the kernel positively
|
|
21
|
+
* reported "no such entry"; any other failure is `unknown`, never `absent`.
|
|
22
|
+
*/
|
|
23
|
+
probe(dirFd: number, name: string): EntryProbe;
|
|
24
|
+
}
|
|
25
|
+
/** libc `openat`/`unlinkat`/`faccessat` through Bun's FFI, or null when unavailable. */
|
|
26
|
+
export declare function loadNativeOps(): DescriptorOps | null;
|
|
27
|
+
/** Test seams; production callers pass only the two directories. */
|
|
28
|
+
export interface RetireInstallerArchiveOptions {
|
|
29
|
+
/** The running bundle's `Resources` directory (`bundleResourcesDirectory(import.meta.dir)`). */
|
|
30
|
+
resourcesDir: string;
|
|
31
|
+
/** The directory Electrobun installs under (`Library/Application Support` on macOS); the one trusted root. */
|
|
32
|
+
applicationSupportDir: string;
|
|
33
|
+
ops?: DescriptorOps | null;
|
|
34
|
+
/** Runs once the directory chain is verified, before the prepared-record check. */
|
|
35
|
+
afterDirectoryVerified?: () => void;
|
|
36
|
+
/** Runs immediately before unlinking. */
|
|
37
|
+
beforeUnlink?: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Remove the installer's retained payload tar for the running build.
|
|
41
|
+
*/
|
|
42
|
+
export declare function retireInstallerArchive(options: RetireInstallerArchiveOptions): InstallerArchiveOutcome;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { FFIType, dlopen, read } from "bun:ffi";
|
|
3
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync } from "node:fs";
|
|
4
|
+
// src/native/installer-archive.ts
|
|
5
|
+
/** The extractor only accepts hashes of this shape when it names the tar. */
|
|
6
|
+
var SAFE_HASH = /^[A-Za-z0-9_-]+$/;
|
|
7
|
+
/** Identifier and channel become path components under Application Support. */
|
|
8
|
+
var SAFE_COMPONENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
9
|
+
/** Electrobun's record of an update it has staged; present means "hands off". */
|
|
10
|
+
var PREPARED_UPDATE_RECORD = ".electrobun-prepared-update.json";
|
|
11
|
+
/** `ENOENT` is 2 on both Linux and macOS. */
|
|
12
|
+
var ENOENT = 2;
|
|
13
|
+
var nativeOps;
|
|
14
|
+
var cstring = (value) => Buffer.from(`${value}\0`);
|
|
15
|
+
/** `AT_SYMLINK_NOFOLLOW` differs between macOS and Linux. */
|
|
16
|
+
var AT_SYMLINK_NOFOLLOW = process.platform === "darwin" ? 32 : 256;
|
|
17
|
+
var F_OK = 0;
|
|
18
|
+
/** libc `openat`/`unlinkat`/`faccessat` through Bun's FFI, or null when unavailable. */
|
|
19
|
+
function loadNativeOps() {
|
|
20
|
+
if (nativeOps !== void 0) return nativeOps;
|
|
21
|
+
try {
|
|
22
|
+
const library = dlopen(process.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", {
|
|
23
|
+
openat: {
|
|
24
|
+
args: [
|
|
25
|
+
FFIType.i32,
|
|
26
|
+
FFIType.cstring,
|
|
27
|
+
FFIType.i32
|
|
28
|
+
],
|
|
29
|
+
returns: FFIType.i32
|
|
30
|
+
},
|
|
31
|
+
unlinkat: {
|
|
32
|
+
args: [
|
|
33
|
+
FFIType.i32,
|
|
34
|
+
FFIType.cstring,
|
|
35
|
+
FFIType.i32
|
|
36
|
+
],
|
|
37
|
+
returns: FFIType.i32
|
|
38
|
+
},
|
|
39
|
+
faccessat: {
|
|
40
|
+
args: [
|
|
41
|
+
FFIType.i32,
|
|
42
|
+
FFIType.cstring,
|
|
43
|
+
FFIType.i32,
|
|
44
|
+
FFIType.i32
|
|
45
|
+
],
|
|
46
|
+
returns: FFIType.i32
|
|
47
|
+
},
|
|
48
|
+
[process.platform === "darwin" ? "__error" : "__errno_location"]: {
|
|
49
|
+
args: [],
|
|
50
|
+
returns: FFIType.ptr
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const errnoLocation = library.symbols[process.platform === "darwin" ? "__error" : "__errno_location"];
|
|
54
|
+
const errno = () => {
|
|
55
|
+
const location = errnoLocation();
|
|
56
|
+
return location ? read.i32(location) : void 0;
|
|
57
|
+
};
|
|
58
|
+
const openAt = (dirFd, name, flags) => library.symbols.openat(dirFd, cstring(name), flags);
|
|
59
|
+
nativeOps = {
|
|
60
|
+
openAt,
|
|
61
|
+
unlinkAt: (dirFd, name) => library.symbols.unlinkat(dirFd, cstring(name), 0),
|
|
62
|
+
probe: (dirFd, name) => {
|
|
63
|
+
if (library.symbols.faccessat(dirFd, cstring(name), F_OK, AT_SYMLINK_NOFOLLOW) === 0) return "present";
|
|
64
|
+
const accessErrno = errno();
|
|
65
|
+
const open = openAt(dirFd, name, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
66
|
+
if (open >= 0) {
|
|
67
|
+
closeSync(open);
|
|
68
|
+
return "present";
|
|
69
|
+
}
|
|
70
|
+
const openErrno = errno();
|
|
71
|
+
return accessErrno === ENOENT && openErrno === ENOENT ? "absent" : "unknown";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
} catch {
|
|
75
|
+
nativeOps = null;
|
|
76
|
+
}
|
|
77
|
+
return nativeOps;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Remove the installer's retained payload tar for the running build.
|
|
81
|
+
*/
|
|
82
|
+
function retireInstallerArchive(options) {
|
|
83
|
+
const held = [];
|
|
84
|
+
try {
|
|
85
|
+
const versionFile = join(options.resourcesDir, "version.json");
|
|
86
|
+
let raw;
|
|
87
|
+
try {
|
|
88
|
+
raw = readFileSync(versionFile, "utf8");
|
|
89
|
+
} catch {
|
|
90
|
+
return {
|
|
91
|
+
state: "skipped",
|
|
92
|
+
reason: "not a packaged install"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const identity = JSON.parse(raw);
|
|
96
|
+
if (typeof identity !== "object" || identity === null) return {
|
|
97
|
+
state: "skipped",
|
|
98
|
+
reason: "unreadable version identity"
|
|
99
|
+
};
|
|
100
|
+
const { identifier, channel, hash } = identity;
|
|
101
|
+
if (typeof identifier !== "string" || typeof channel !== "string" || typeof hash !== "string" || !SAFE_COMPONENT.test(identifier) || !SAFE_COMPONENT.test(channel) || !SAFE_HASH.test(hash)) return {
|
|
102
|
+
state: "skipped",
|
|
103
|
+
reason: "unsafe version identity"
|
|
104
|
+
};
|
|
105
|
+
const ops = options.ops === void 0 ? loadNativeOps() : options.ops;
|
|
106
|
+
const { O_RDONLY, O_DIRECTORY, O_NOFOLLOW, O_NONBLOCK } = constants;
|
|
107
|
+
if (!ops || O_DIRECTORY === void 0 || O_NOFOLLOW === void 0 || O_NONBLOCK === void 0) return {
|
|
108
|
+
state: "skipped",
|
|
109
|
+
reason: "descriptor-relative file operations are unavailable"
|
|
110
|
+
};
|
|
111
|
+
const chain = [
|
|
112
|
+
identifier,
|
|
113
|
+
channel,
|
|
114
|
+
"self-extraction"
|
|
115
|
+
];
|
|
116
|
+
let dirFd = openSync(options.applicationSupportDir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
|
|
117
|
+
held.push(dirFd);
|
|
118
|
+
let walked = options.applicationSupportDir;
|
|
119
|
+
for (const name of chain) {
|
|
120
|
+
walked = join(walked, name);
|
|
121
|
+
const next = ops.openAt(dirFd, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_NONBLOCK);
|
|
122
|
+
if (next < 0) return {
|
|
123
|
+
state: "skipped",
|
|
124
|
+
reason: "install directory is missing or not a real directory"
|
|
125
|
+
};
|
|
126
|
+
held.push(next);
|
|
127
|
+
dirFd = next;
|
|
128
|
+
}
|
|
129
|
+
options.afterDirectoryVerified?.();
|
|
130
|
+
if (ops.probe(dirFd, PREPARED_UPDATE_RECORD) !== "absent") return {
|
|
131
|
+
state: "skipped",
|
|
132
|
+
reason: "a prepared update record exists or cannot be ruled out"
|
|
133
|
+
};
|
|
134
|
+
const name = `${hash}.tar`;
|
|
135
|
+
const fileFd = ops.openAt(dirFd, name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
136
|
+
if (fileFd < 0) switch (ops.probe(dirFd, name)) {
|
|
137
|
+
case "absent": return { state: "absent" };
|
|
138
|
+
case "present": return {
|
|
139
|
+
state: "skipped",
|
|
140
|
+
reason: "not a regular file"
|
|
141
|
+
};
|
|
142
|
+
default: return {
|
|
143
|
+
state: "skipped",
|
|
144
|
+
reason: "the archive could not be inspected"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
held.push(fileFd);
|
|
148
|
+
if (!fstatSync(fileFd).isFile()) return {
|
|
149
|
+
state: "skipped",
|
|
150
|
+
reason: "not a regular file"
|
|
151
|
+
};
|
|
152
|
+
options.beforeUnlink?.();
|
|
153
|
+
if (ops.unlinkAt(dirFd, name) !== 0) return {
|
|
154
|
+
state: "skipped",
|
|
155
|
+
reason: "could not remove the archive"
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
state: "removed",
|
|
159
|
+
path: join(walked, name)
|
|
160
|
+
};
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return {
|
|
163
|
+
state: "skipped",
|
|
164
|
+
reason: error instanceof Error ? error.message : "unexpected failure"
|
|
165
|
+
};
|
|
166
|
+
} finally {
|
|
167
|
+
for (const fd of held) try {
|
|
168
|
+
closeSync(fd);
|
|
169
|
+
} catch {}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export { loadNativeOps, retireInstallerArchive };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { createServiceRegistry } from '../app/service-registry';
|
|
2
|
+
import type { WindowSurface } from '../appearance/window-surface';
|
|
3
|
+
/** The persisted surface; a missing, unreadable or unknown record is `theme`. */
|
|
4
|
+
export declare function readWindowSurface(stateFile: string): WindowSurface;
|
|
5
|
+
/** Whether the window is created see-through: only the frosted surface, only on macOS. */
|
|
6
|
+
export declare function windowSurfaceTransparent(surface: WindowSurface, platform: string): boolean;
|
|
7
|
+
/** Persist the surface atomically, readable by this user only. */
|
|
8
|
+
export declare function writeWindowSurface(stateFile: string, surface: WindowSurface): void;
|
|
9
|
+
/** Register `shell.window-surface`, which persists `{ surface }` and answers `{ surface, appliesOnRestart }`. */
|
|
10
|
+
export declare function registerWindowSurfaceService<Principal>(options: {
|
|
11
|
+
services: ReturnType<typeof createServiceRegistry<Principal>>;
|
|
12
|
+
stateFile: string;
|
|
13
|
+
authorize(principal: Principal): boolean | Promise<boolean>;
|
|
14
|
+
/** The surface the running window was created with; default: the persisted one at registration. */
|
|
15
|
+
current?: WindowSurface;
|
|
16
|
+
}): () => void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
// src/native/window-surface-store.ts
|
|
5
|
+
/**
|
|
6
|
+
* The native half of the appearance editor's glass setting. Electrobun 2.0.5 sets window
|
|
7
|
+
* transparency at creation only, so the host reads the persisted surface at startup and a
|
|
8
|
+
* change applies on the next launch. The web side persists each choice through the
|
|
9
|
+
* `shell.window-surface` service (see `createWindowSurfaceMirror`).
|
|
10
|
+
*/
|
|
11
|
+
var SURFACES = [
|
|
12
|
+
"theme",
|
|
13
|
+
"frosted",
|
|
14
|
+
"opaque"
|
|
15
|
+
];
|
|
16
|
+
var isWindowSurface = (value) => SURFACES.includes(value);
|
|
17
|
+
/** The persisted surface; a missing, unreadable or unknown record is `theme`. */
|
|
18
|
+
function readWindowSurface(stateFile) {
|
|
19
|
+
try {
|
|
20
|
+
const surface = JSON.parse(readFileSync(stateFile, "utf8"))?.windowSurface;
|
|
21
|
+
return isWindowSurface(surface) ? surface : "theme";
|
|
22
|
+
} catch {
|
|
23
|
+
return "theme";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Whether the window is created see-through: only the frosted surface, only on macOS. */
|
|
27
|
+
function windowSurfaceTransparent(surface, platform) {
|
|
28
|
+
return platform === "darwin" && surface === "frosted";
|
|
29
|
+
}
|
|
30
|
+
/** Persist the surface atomically, readable by this user only. */
|
|
31
|
+
function writeWindowSurface(stateFile, surface) {
|
|
32
|
+
if (!isWindowSurface(surface)) throw new Error("Invalid window surface");
|
|
33
|
+
mkdirSync(dirname(stateFile), {
|
|
34
|
+
recursive: true,
|
|
35
|
+
mode: 448
|
|
36
|
+
});
|
|
37
|
+
const temporary = join(dirname(stateFile), `.window-surface-${randomUUID()}.tmp`);
|
|
38
|
+
try {
|
|
39
|
+
writeFileSync(temporary, `${JSON.stringify({ windowSurface: surface })}\n`, {
|
|
40
|
+
mode: 384,
|
|
41
|
+
flag: "wx"
|
|
42
|
+
});
|
|
43
|
+
renameSync(temporary, stateFile);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
rmSync(temporary, { force: true });
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Register `shell.window-surface`, which persists `{ surface }` and answers `{ surface, appliesOnRestart }`. */
|
|
50
|
+
function registerWindowSurfaceService(options) {
|
|
51
|
+
const { services, stateFile, authorize } = options;
|
|
52
|
+
const current = options.current ?? readWindowSurface(stateFile);
|
|
53
|
+
return services.register("shell.window-surface", {
|
|
54
|
+
parse(value) {
|
|
55
|
+
const record = value;
|
|
56
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).length !== 1 || !isWindowSurface(record?.surface)) throw new Error("Invalid input");
|
|
57
|
+
return record.surface;
|
|
58
|
+
},
|
|
59
|
+
authorize: (principal) => authorize(principal),
|
|
60
|
+
run(_principal, surface) {
|
|
61
|
+
writeWindowSurface(stateFile, surface);
|
|
62
|
+
return {
|
|
63
|
+
surface,
|
|
64
|
+
appliesOnRestart: surface !== current
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export { readWindowSurface, registerWindowSurfaceService, windowSurfaceTransparent, writeWindowSurface };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Electrobun 2.0.5's Windows installer runs `extractor.exe`, whose shortcut code this
|
|
3
|
+
* framework patches (electrobun-windows-shortcut-com.patch). A stable Windows build
|
|
4
|
+
* rebuilds that extractor from the pinned source with the pinned Zig toolchain and points
|
|
5
|
+
* Electrobun at a copy of its devkit holding the rebuilt binary.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ELECTROBUN_VERSION = "2.0.5";
|
|
8
|
+
/** The Zig release Electrobun 2.0.5 builds with (its src/shared/build-dependencies.ts). */
|
|
9
|
+
export declare const ZIG_VERSION = "0.17.0";
|
|
10
|
+
/**
|
|
11
|
+
* Zig builds for the build host's own CPU unless told otherwise, and some Windows runners
|
|
12
|
+
* have AVX-512 while others do not; a native build then dies with STATUS_ILLEGAL_INSTRUCTION
|
|
13
|
+
* on another machine. Every Windows binary targets a fixed baseline instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ZIG_WINDOWS_TARGET: readonly ['-Dtarget=x86_64-windows-gnu', '-Dcpu=x86_64_v2'];
|
|
16
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
17
|
+
/** The extractor's name in a pinned Electrobun 2.0.5 Windows x64 devkit manifest. */
|
|
18
|
+
export declare function validateWindowsDevkitManifest(manifest: unknown): string;
|
|
19
|
+
/** A PE32+ x64 executable that keeps the Windows GUI subsystem (no console window). */
|
|
20
|
+
export declare function assertWindowsX64GuiExecutable(bytes: Uint8Array): void;
|
|
21
|
+
/**
|
|
22
|
+
* Copy the official devkit (hardlinks where possible) to `patchedCoreRoot` and replace only
|
|
23
|
+
* its extractor with `builtExtractor`. The official cached extractor must not change and the
|
|
24
|
+
* copy must hold the built bytes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function installPatchedExtractor(options: {
|
|
27
|
+
officialCoreRoot: string;
|
|
28
|
+
patchedCoreRoot: string;
|
|
29
|
+
builtExtractor: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
extractorName: string;
|
|
32
|
+
officialSha256: string;
|
|
33
|
+
builtSha256: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** A process the build runs; `capture` returns trimmed stdout. */
|
|
36
|
+
export type WindowsBuildCommand = (command: string, args: readonly string[], options?: {
|
|
37
|
+
cwd?: string;
|
|
38
|
+
env?: Env;
|
|
39
|
+
capture?: boolean;
|
|
40
|
+
}) => string;
|
|
41
|
+
type SpawnResult = {
|
|
42
|
+
status: number | null;
|
|
43
|
+
stdout?: string;
|
|
44
|
+
stderr?: string;
|
|
45
|
+
error?: Error;
|
|
46
|
+
};
|
|
47
|
+
/** Run a command with bounded output; a non-zero exit throws with its stderr. */
|
|
48
|
+
export declare function runBuildCommand(command: string, args: readonly string[], options?: {
|
|
49
|
+
cwd?: string;
|
|
50
|
+
env?: Env;
|
|
51
|
+
capture?: boolean;
|
|
52
|
+
spawnProcess?: (command: string, args: readonly string[], options: object) => SpawnResult;
|
|
53
|
+
}): string;
|
|
54
|
+
type FetchResponse = {
|
|
55
|
+
ok: boolean;
|
|
56
|
+
body: ReadableStream<Uint8Array> | null;
|
|
57
|
+
url: string;
|
|
58
|
+
};
|
|
59
|
+
/** Download the pinned Zig archive from ziglang.org and check its size and SHA-256. */
|
|
60
|
+
export declare function downloadPinnedZig(archivePath: string, options?: {
|
|
61
|
+
fetch?: (url: string, init: {
|
|
62
|
+
redirect: 'follow';
|
|
63
|
+
}) => Promise<FetchResponse>;
|
|
64
|
+
expectedSize?: number;
|
|
65
|
+
expectedSha256?: string;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Build a stable Windows x64 installer whose extractor carries the framework's shortcut
|
|
69
|
+
* patch: prepare Electrobun's devkit, fetch and patch the pinned source, build and test the
|
|
70
|
+
* extractor with the pinned Zig, swap it into a copy of the devkit, then run
|
|
71
|
+
* `electrobun build --env=stable` against that copy. Runs only on a disposable Windows x64
|
|
72
|
+
* CI runner (`CI=true`) and removes its scratch state, success or failure. Resolves the
|
|
73
|
+
* installer path.
|
|
74
|
+
*/
|
|
75
|
+
export declare function buildPatchedWindowsInstaller(options: {
|
|
76
|
+
/** The Electrobun project directory (its `electrobun.config.ts`). */
|
|
77
|
+
appRoot: string;
|
|
78
|
+
appName: string;
|
|
79
|
+
env?: Env;
|
|
80
|
+
platform?: string;
|
|
81
|
+
arch?: string;
|
|
82
|
+
/** Where scratch state goes; defaults to `RUNNER_TEMP`, then the system temp directory. */
|
|
83
|
+
scratchParent?: string;
|
|
84
|
+
runCommand?: WindowsBuildCommand;
|
|
85
|
+
fetch?: (url: string, init: {
|
|
86
|
+
redirect: 'follow';
|
|
87
|
+
}) => Promise<FetchResponse>;
|
|
88
|
+
zigArchiveSize?: number;
|
|
89
|
+
zigArchiveSha256?: string;
|
|
90
|
+
/** Replaces the pinned-patch apply step; tests only. */
|
|
91
|
+
applyPatch?: (sourceRoot: string) => void;
|
|
92
|
+
now?: () => number;
|
|
93
|
+
logStage?: (message: string) => void;
|
|
94
|
+
}): Promise<string>;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { ELECTROBUN_COMMIT, PINNED_SHORTCUT_PATCH, SHORTCUT_PATCH_PATH, applyElectrobunPatch } from "./electrobun-source-patch.js";
|
|
2
|
+
import { electrobunArtifacts } from "../release/release-steps.js";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { copyFileSync, createReadStream, createWriteStream, existsSync, linkSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync } from "node:fs";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { Readable } from "node:stream";
|
|
9
|
+
import { pipeline } from "node:stream/promises";
|
|
10
|
+
import { performance } from "node:perf_hooks";
|
|
11
|
+
// src/native/windows-extractor-build.ts
|
|
12
|
+
/**
|
|
13
|
+
* Electrobun 2.0.5's Windows installer runs `extractor.exe`, whose shortcut code this
|
|
14
|
+
* framework patches (electrobun-windows-shortcut-com.patch). A stable Windows build
|
|
15
|
+
* rebuilds that extractor from the pinned source with the pinned Zig toolchain and points
|
|
16
|
+
* Electrobun at a copy of its devkit holding the rebuilt binary.
|
|
17
|
+
*/
|
|
18
|
+
var ELECTROBUN_VERSION = "2.0.5";
|
|
19
|
+
/** The Zig release Electrobun 2.0.5 builds with (its src/shared/build-dependencies.ts). */
|
|
20
|
+
var ZIG_VERSION = "0.17.0";
|
|
21
|
+
/**
|
|
22
|
+
* Zig builds for the build host's own CPU unless told otherwise, and some Windows runners
|
|
23
|
+
* have AVX-512 while others do not; a native build then dies with STATUS_ILLEGAL_INSTRUCTION
|
|
24
|
+
* on another machine. Every Windows binary targets a fixed baseline instead.
|
|
25
|
+
*/
|
|
26
|
+
var ZIG_WINDOWS_TARGET = ["-Dtarget=x86_64-windows-gnu", "-Dcpu=x86_64_v2"];
|
|
27
|
+
var ZIG_WINDOWS_X64_URL = `https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-windows-${ZIG_VERSION}.zip`;
|
|
28
|
+
/** From ziglang.org's download index. */
|
|
29
|
+
var ZIG_WINDOWS_X64_SHA256 = "b5663f69581dcf391293fbf16c06cb80d81d806545ce618b4d0bab7f0eb8c428";
|
|
30
|
+
var ZIG_WINDOWS_X64_SIZE = 100268137;
|
|
31
|
+
var ELECTROBUN_SOURCE_URL = "https://github.com/blackboardsh/electrobun.git";
|
|
32
|
+
/** The extractor's name in a pinned Electrobun 2.0.5 Windows x64 devkit manifest. */
|
|
33
|
+
function validateWindowsDevkitManifest(manifest) {
|
|
34
|
+
const value = manifest;
|
|
35
|
+
if (value?.schemaVersion !== 1 || value.product?.name !== "electrobun" || value.product?.version !== "2.0.5" || value.target?.os !== "win" || value.target?.arch !== "x64" || value.layout?.runtime?.extractor !== "extractor.exe") throw new Error("Hutch core does not match the pinned Electrobun 2.0.5 Windows x64 devkit");
|
|
36
|
+
return "extractor.exe";
|
|
37
|
+
}
|
|
38
|
+
/** A PE32+ x64 executable that keeps the Windows GUI subsystem (no console window). */
|
|
39
|
+
function assertWindowsX64GuiExecutable(bytes) {
|
|
40
|
+
const buffer = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes);
|
|
41
|
+
if (buffer.length < 256 || buffer.toString("ascii", 0, 2) !== "MZ") throw new Error("Patched Electrobun extractor is not a valid PE executable");
|
|
42
|
+
const peOffset = buffer.readUInt32LE(60);
|
|
43
|
+
if (peOffset < 64 || peOffset + 94 > buffer.length || buffer.toString("ascii", peOffset, peOffset + 4) !== "PE\0\0") throw new Error("Patched Electrobun extractor has an invalid PE header");
|
|
44
|
+
if (buffer.readUInt16LE(peOffset + 4) !== 34404) throw new Error("Patched Electrobun extractor is not Windows x64");
|
|
45
|
+
const optionalHeader = peOffset + 24;
|
|
46
|
+
if (buffer.readUInt16LE(optionalHeader) !== 523) throw new Error("Patched Electrobun extractor does not use the PE32+ format");
|
|
47
|
+
if (buffer.readUInt16LE(optionalHeader + 68) !== 2) throw new Error("Patched Electrobun extractor must retain the Windows GUI subsystem");
|
|
48
|
+
}
|
|
49
|
+
async function sha256File(path) {
|
|
50
|
+
const hash = createHash("sha256");
|
|
51
|
+
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
52
|
+
return hash.digest("hex");
|
|
53
|
+
}
|
|
54
|
+
function hardlinkOrCopy(source, destination) {
|
|
55
|
+
try {
|
|
56
|
+
linkSync(source, destination);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const code = error.code ?? "";
|
|
59
|
+
if (![
|
|
60
|
+
"EACCES",
|
|
61
|
+
"EMLINK",
|
|
62
|
+
"EPERM",
|
|
63
|
+
"EXDEV",
|
|
64
|
+
"ENOTSUP"
|
|
65
|
+
].includes(code)) throw error;
|
|
66
|
+
copyFileSync(source, destination);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function copyTree(source, destination) {
|
|
70
|
+
for (const entry of readdirSync(source)) {
|
|
71
|
+
const from = join(source, entry);
|
|
72
|
+
const to = join(destination, entry);
|
|
73
|
+
const info = lstatSync(from);
|
|
74
|
+
if (info.isSymbolicLink()) throw new Error("Electrobun core must not contain symbolic links");
|
|
75
|
+
if (info.isDirectory()) {
|
|
76
|
+
mkdirSync(to);
|
|
77
|
+
copyTree(from, to);
|
|
78
|
+
} else if (info.isFile()) hardlinkOrCopy(from, to);
|
|
79
|
+
else throw new Error("Electrobun core contains an unsupported filesystem object");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Copy the official devkit (hardlinks where possible) to `patchedCoreRoot` and replace only
|
|
84
|
+
* its extractor with `builtExtractor`. The official cached extractor must not change and the
|
|
85
|
+
* copy must hold the built bytes.
|
|
86
|
+
*/
|
|
87
|
+
async function installPatchedExtractor(options) {
|
|
88
|
+
const { officialCoreRoot, patchedCoreRoot, builtExtractor } = options;
|
|
89
|
+
const extractorName = validateWindowsDevkitManifest(JSON.parse(readFileSync(join(officialCoreRoot, "native-devkit.json"), "utf8")));
|
|
90
|
+
const officialExtractor = join(officialCoreRoot, extractorName);
|
|
91
|
+
const patchedExtractor = join(patchedCoreRoot, extractorName);
|
|
92
|
+
if (!lstatSync(officialExtractor).isFile()) throw new Error("Pinned Electrobun core extractor is missing");
|
|
93
|
+
const builtBytes = readFileSync(builtExtractor);
|
|
94
|
+
assertWindowsX64GuiExecutable(builtBytes);
|
|
95
|
+
const officialSha256 = await sha256File(officialExtractor);
|
|
96
|
+
const builtSha256 = createHash("sha256").update(builtBytes).digest("hex");
|
|
97
|
+
if (existsSync(patchedCoreRoot)) throw new Error("Patched Electrobun core destination already exists");
|
|
98
|
+
mkdirSync(patchedCoreRoot, { recursive: true });
|
|
99
|
+
copyTree(officialCoreRoot, patchedCoreRoot);
|
|
100
|
+
unlinkSync(patchedExtractor);
|
|
101
|
+
copyFileSync(builtExtractor, patchedExtractor);
|
|
102
|
+
if (await sha256File(officialExtractor) !== officialSha256) throw new Error("Building the patched core modified the official cached Electrobun extractor");
|
|
103
|
+
if (await sha256File(patchedExtractor) !== builtSha256) throw new Error("Patched Electrobun core does not contain the built extractor bytes");
|
|
104
|
+
return {
|
|
105
|
+
extractorName,
|
|
106
|
+
officialSha256,
|
|
107
|
+
builtSha256
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Run a command with bounded output; a non-zero exit throws with its stderr. */
|
|
111
|
+
function runBuildCommand(command, args, options = {}) {
|
|
112
|
+
const result = (options.spawnProcess ?? ((cmd, argv, spawnOptions) => spawnSync(cmd, [...argv], spawnOptions)))(command, args, {
|
|
113
|
+
cwd: options.cwd,
|
|
114
|
+
env: options.env,
|
|
115
|
+
encoding: "utf8",
|
|
116
|
+
maxBuffer: 8388608,
|
|
117
|
+
stdio: options.capture ? [
|
|
118
|
+
"ignore",
|
|
119
|
+
"pipe",
|
|
120
|
+
"pipe"
|
|
121
|
+
] : "inherit"
|
|
122
|
+
});
|
|
123
|
+
if (result.error) throw result.error;
|
|
124
|
+
if (result.status !== 0) {
|
|
125
|
+
const detail = result.stderr?.trim();
|
|
126
|
+
throw new Error(`${command} exited with status ${result.status}${detail ? `: ${detail}` : ""}`);
|
|
127
|
+
}
|
|
128
|
+
return options.capture ? (result.stdout ?? "").trim() : "";
|
|
129
|
+
}
|
|
130
|
+
/** Download the pinned Zig archive from ziglang.org and check its size and SHA-256. */
|
|
131
|
+
async function downloadPinnedZig(archivePath, options = {}) {
|
|
132
|
+
const response = await (options.fetch ?? ((url, init) => fetch(url, init)))(ZIG_WINDOWS_X64_URL, { redirect: "follow" });
|
|
133
|
+
if (!response.ok || !response.body) throw new Error(`Could not download pinned Zig ${ZIG_VERSION}`);
|
|
134
|
+
if (new URL(response.url).hostname !== "ziglang.org") throw new Error("Pinned Zig download redirected away from ziglang.org");
|
|
135
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(archivePath, { flags: "wx" }));
|
|
136
|
+
if (statSync(archivePath).size !== (options.expectedSize ?? ZIG_WINDOWS_X64_SIZE)) throw new Error("Pinned Zig Windows archive has an unexpected size");
|
|
137
|
+
if (await sha256File(archivePath) !== (options.expectedSha256 ?? ZIG_WINDOWS_X64_SHA256)) throw new Error("Pinned Zig Windows archive failed its official SHA-256 check");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Build a stable Windows x64 installer whose extractor carries the framework's shortcut
|
|
141
|
+
* patch: prepare Electrobun's devkit, fetch and patch the pinned source, build and test the
|
|
142
|
+
* extractor with the pinned Zig, swap it into a copy of the devkit, then run
|
|
143
|
+
* `electrobun build --env=stable` against that copy. Runs only on a disposable Windows x64
|
|
144
|
+
* CI runner (`CI=true`) and removes its scratch state, success or failure. Resolves the
|
|
145
|
+
* installer path.
|
|
146
|
+
*/
|
|
147
|
+
async function buildPatchedWindowsInstaller(options) {
|
|
148
|
+
const env = options.env ?? process.env;
|
|
149
|
+
const runCommand = options.runCommand ?? ((command, args, runOptions) => runBuildCommand(command, args, runOptions));
|
|
150
|
+
const now = options.now ?? (() => performance.now());
|
|
151
|
+
const logStage = options.logStage ?? ((message) => console.log(message));
|
|
152
|
+
if ((options.platform ?? process.platform) !== "win32" || (options.arch ?? process.arch) !== "x64") throw new Error("The patched Electrobun installer build requires a native Windows x64 runner");
|
|
153
|
+
if (env.CI !== "true") throw new Error("The patched Electrobun installer build requires a disposable CI runner");
|
|
154
|
+
const appRoot = resolve(options.appRoot);
|
|
155
|
+
const [installerName] = electrobunArtifacts(options.appName, "windows-x64");
|
|
156
|
+
const parent = options.scratchParent ?? env.RUNNER_TEMP ?? tmpdir();
|
|
157
|
+
const scratch = mkdtempSync(join(parent, "framework-electrobun-extractor-"));
|
|
158
|
+
let stage;
|
|
159
|
+
let started = 0;
|
|
160
|
+
const finishStage = () => {
|
|
161
|
+
if (stage) logStage(`Windows installer stage ${stage}: ${Math.round(now() - started)} ms`);
|
|
162
|
+
};
|
|
163
|
+
const startStage = (name) => {
|
|
164
|
+
finishStage();
|
|
165
|
+
stage = name;
|
|
166
|
+
started = now();
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
startStage("hutch-prepare");
|
|
170
|
+
const hutchHome = join(scratch, "hutch");
|
|
171
|
+
mkdirSync(hutchHome);
|
|
172
|
+
const childEnv = {
|
|
173
|
+
...env,
|
|
174
|
+
HUTCH_HOME: hutchHome
|
|
175
|
+
};
|
|
176
|
+
runCommand("bun", [
|
|
177
|
+
"x",
|
|
178
|
+
"--bun",
|
|
179
|
+
"electrobun",
|
|
180
|
+
"prepare"
|
|
181
|
+
], {
|
|
182
|
+
cwd: appRoot,
|
|
183
|
+
env: childEnv
|
|
184
|
+
});
|
|
185
|
+
startStage("source-and-patch");
|
|
186
|
+
const sourceRoot = join(scratch, "electrobun-source");
|
|
187
|
+
runCommand("git", ["init", sourceRoot]);
|
|
188
|
+
runCommand("git", [
|
|
189
|
+
"-C",
|
|
190
|
+
sourceRoot,
|
|
191
|
+
"remote",
|
|
192
|
+
"add",
|
|
193
|
+
"origin",
|
|
194
|
+
ELECTROBUN_SOURCE_URL
|
|
195
|
+
]);
|
|
196
|
+
runCommand("git", [
|
|
197
|
+
"-C",
|
|
198
|
+
sourceRoot,
|
|
199
|
+
"fetch",
|
|
200
|
+
"--depth=1",
|
|
201
|
+
"origin",
|
|
202
|
+
ELECTROBUN_COMMIT
|
|
203
|
+
]);
|
|
204
|
+
runCommand("git", [
|
|
205
|
+
"-C",
|
|
206
|
+
sourceRoot,
|
|
207
|
+
"checkout",
|
|
208
|
+
"--detach",
|
|
209
|
+
"FETCH_HEAD"
|
|
210
|
+
]);
|
|
211
|
+
if (runCommand("git", [
|
|
212
|
+
"-C",
|
|
213
|
+
sourceRoot,
|
|
214
|
+
"rev-parse",
|
|
215
|
+
"HEAD"
|
|
216
|
+
], { capture: true }) !== "d06abc9edf0b4e55116129cabbfe17bf89e11791") throw new Error("Fetched Electrobun source does not match the pinned upstream commit");
|
|
217
|
+
(options.applyPatch ?? ((root) => applyElectrobunPatch(root, SHORTCUT_PATCH_PATH, PINNED_SHORTCUT_PATCH)))(sourceRoot);
|
|
218
|
+
startStage("zig-download-and-verification");
|
|
219
|
+
const archivePath = join(scratch, "zig-windows-x64.zip");
|
|
220
|
+
const zigRoot = join(scratch, "zig-toolchain");
|
|
221
|
+
mkdirSync(zigRoot);
|
|
222
|
+
await downloadPinnedZig(archivePath, {
|
|
223
|
+
...options.fetch ? { fetch: options.fetch } : {},
|
|
224
|
+
...options.zigArchiveSize === void 0 ? {} : { expectedSize: options.zigArchiveSize },
|
|
225
|
+
...options.zigArchiveSha256 === void 0 ? {} : { expectedSha256: options.zigArchiveSha256 }
|
|
226
|
+
});
|
|
227
|
+
startStage("zig-extraction-and-verification");
|
|
228
|
+
const systemRoot = env.SystemRoot ?? env.WINDIR;
|
|
229
|
+
if (!systemRoot) throw new Error("Windows system directory is unavailable");
|
|
230
|
+
const bsdtar = join(systemRoot, "System32", "tar.exe");
|
|
231
|
+
if (!/^bsdtar\s/i.test(runCommand(bsdtar, ["--version"], { capture: true }))) throw new Error("Windows extractor build requires the qualified system bsdtar");
|
|
232
|
+
runCommand(bsdtar, [
|
|
233
|
+
"-xf",
|
|
234
|
+
archivePath,
|
|
235
|
+
"-C",
|
|
236
|
+
zigRoot
|
|
237
|
+
]);
|
|
238
|
+
const zig = join(zigRoot, `zig-x86_64-windows-${ZIG_VERSION}`, "zig.exe");
|
|
239
|
+
if (runCommand(zig, ["version"], { capture: true }) !== "0.17.0") throw new Error("Downloaded Zig executable does not report the pinned version");
|
|
240
|
+
const extractorRoot = join(sourceRoot, "package", "src", "extractor");
|
|
241
|
+
const zigEnv = {
|
|
242
|
+
...childEnv,
|
|
243
|
+
ZIG_LOCAL_CACHE_DIR: join(scratch, "zig-local-cache"),
|
|
244
|
+
ZIG_GLOBAL_CACHE_DIR: join(scratch, "zig-global-cache")
|
|
245
|
+
};
|
|
246
|
+
startStage("shortcut-helper");
|
|
247
|
+
const shortcutTestHelper = join(scratch, "shortcut-test-helper.exe");
|
|
248
|
+
runCommand(zig, [
|
|
249
|
+
"cc",
|
|
250
|
+
"-target",
|
|
251
|
+
"x86_64-windows-gnu",
|
|
252
|
+
"-mcpu=x86_64_v2",
|
|
253
|
+
"-O2",
|
|
254
|
+
"-municode",
|
|
255
|
+
"-DELECTROBUN_WINDOWS_SHORTCUT_TESTING=1",
|
|
256
|
+
"-Werror=incompatible-pointer-types",
|
|
257
|
+
"windows_shortcut.c",
|
|
258
|
+
"windows_shortcut_test_helper.c",
|
|
259
|
+
"-lole32",
|
|
260
|
+
"-o",
|
|
261
|
+
shortcutTestHelper
|
|
262
|
+
], {
|
|
263
|
+
cwd: extractorRoot,
|
|
264
|
+
env: zigEnv
|
|
265
|
+
});
|
|
266
|
+
if (!existsSync(shortcutTestHelper)) throw new Error("Windows shortcut test helper was not built");
|
|
267
|
+
startStage("shortcut-tests");
|
|
268
|
+
runCommand(zig, [
|
|
269
|
+
"build",
|
|
270
|
+
"test",
|
|
271
|
+
"-Doptimize=ReleaseFast",
|
|
272
|
+
...ZIG_WINDOWS_TARGET
|
|
273
|
+
], {
|
|
274
|
+
cwd: extractorRoot,
|
|
275
|
+
env: {
|
|
276
|
+
...zigEnv,
|
|
277
|
+
ELECTROBUN_WINDOWS_SHORTCUT_TEST_HELPER: shortcutTestHelper
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
startStage("extractor-build");
|
|
281
|
+
runCommand(zig, [
|
|
282
|
+
"build",
|
|
283
|
+
"-Doptimize=ReleaseFast",
|
|
284
|
+
...ZIG_WINDOWS_TARGET
|
|
285
|
+
], {
|
|
286
|
+
cwd: extractorRoot,
|
|
287
|
+
env: zigEnv
|
|
288
|
+
});
|
|
289
|
+
const builtExtractor = join(extractorRoot, "zig-out", "bin", "extractor.exe");
|
|
290
|
+
assertWindowsX64GuiExecutable(readFileSync(builtExtractor));
|
|
291
|
+
startStage("patched-core");
|
|
292
|
+
const patched = await installPatchedExtractor({
|
|
293
|
+
officialCoreRoot: join(hutchHome, "releases", "electrobun", ELECTROBUN_VERSION, "windows-x64"),
|
|
294
|
+
patchedCoreRoot: join(scratch, "patched-electrobun-core"),
|
|
295
|
+
builtExtractor
|
|
296
|
+
});
|
|
297
|
+
startStage("installer-package");
|
|
298
|
+
runCommand("bun", [
|
|
299
|
+
"x",
|
|
300
|
+
"--bun",
|
|
301
|
+
"electrobun",
|
|
302
|
+
"build",
|
|
303
|
+
"--env=stable"
|
|
304
|
+
], {
|
|
305
|
+
cwd: appRoot,
|
|
306
|
+
env: {
|
|
307
|
+
...childEnv,
|
|
308
|
+
HUTCH_ELECTROBUN_DEVKIT_ROOT: join(scratch, "patched-electrobun-core")
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
const installer = join(appRoot, "artifacts", installerName);
|
|
312
|
+
if (!existsSync(installer)) throw new Error("Patched Electrobun build did not produce the Windows installer ZIP");
|
|
313
|
+
console.log(`Built Electrobun ${ELECTROBUN_VERSION} source ${ELECTROBUN_COMMIT}; Zig ${ZIG_VERSION}; extractor SHA-256 ${patched.builtSha256}`);
|
|
314
|
+
return installer;
|
|
315
|
+
} finally {
|
|
316
|
+
try {
|
|
317
|
+
finishStage();
|
|
318
|
+
} finally {
|
|
319
|
+
rmSync(scratch, {
|
|
320
|
+
recursive: true,
|
|
321
|
+
force: true
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
export { ELECTROBUN_VERSION, ZIG_VERSION, ZIG_WINDOWS_TARGET, assertWindowsX64GuiExecutable, buildPatchedWindowsInstaller, downloadPinnedZig, installPatchedExtractor, runBuildCommand, validateWindowsDevkitManifest };
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/app-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://gitlab.com/adea-ai/ade/app-framework.git"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
+
"adea-build-windows-installer": "./dist/cli/windows-installer-build-cli.js",
|
|
10
11
|
"adea-cef-helper": "./dist/cli/cef-helper-cli.js",
|
|
11
12
|
"adea-cut-release": "./dist/cli/release-cut-cli.js",
|
|
12
13
|
"adea-desktop-release": "./ci/desktop-release.sh",
|
|
@@ -344,6 +345,18 @@
|
|
|
344
345
|
"types": "./dist/native/desktop-build.d.ts",
|
|
345
346
|
"import": "./dist/native/desktop-build.js"
|
|
346
347
|
},
|
|
348
|
+
"./windows-extractor-build": {
|
|
349
|
+
"types": "./dist/native/windows-extractor-build.d.ts",
|
|
350
|
+
"import": "./dist/native/windows-extractor-build.js"
|
|
351
|
+
},
|
|
352
|
+
"./installer-archive": {
|
|
353
|
+
"types": "./dist/native/installer-archive.d.ts",
|
|
354
|
+
"import": "./dist/native/installer-archive.js"
|
|
355
|
+
},
|
|
356
|
+
"./window-surface-store": {
|
|
357
|
+
"types": "./dist/native/window-surface-store.d.ts",
|
|
358
|
+
"import": "./dist/native/window-surface-store.js"
|
|
359
|
+
},
|
|
347
360
|
"./electrobun-types": {
|
|
348
361
|
"types": "./src/native/electrobun-types.d.ts"
|
|
349
362
|
},
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// The desktop mirror for the glass appearance setting. The appearance editor
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// transport — dev-view stays platform-agnostic and calls the seam.
|
|
1
|
+
// The desktop mirror for the glass appearance setting. The appearance editor persists its
|
|
2
|
+
// surface device-locally, but the native window belongs to the host, which reads the
|
|
3
|
+
// mirrored value at startup (window-surface-store). The web side registers the transport:
|
|
4
|
+
// `registerWindowSurfaceMirror(createWindowSurfaceMirror(desktopWindowSurfaceUpdate(invoke)))`.
|
|
6
5
|
export type WindowSurface = 'theme' | 'frosted' | 'opaque'
|
|
7
6
|
|
|
8
7
|
type WindowSurfaceMirror = (surface: WindowSurface) => void
|
|
@@ -16,3 +15,90 @@ export function registerWindowSurfaceMirror(next: WindowSurfaceMirror): void {
|
|
|
16
15
|
export function mirrorWindowSurface(surface: WindowSurface): void {
|
|
17
16
|
mirror?.(surface)
|
|
18
17
|
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A mirror that retries a failed update once after `retryDelayMs`, never replaying a choice a
|
|
21
|
+
* newer one superseded. `whenSettled` runs before a retry (for example, until an uncertain
|
|
22
|
+
* write is fenced); `onFailure` hears about a mirror that still failed and may retry it later.
|
|
23
|
+
*/
|
|
24
|
+
export function createWindowSurfaceMirror(
|
|
25
|
+
update: (surface: WindowSurface) => Promise<void>,
|
|
26
|
+
options: {
|
|
27
|
+
retryDelayMs?: number
|
|
28
|
+
whenSettled?: () => Promise<void>
|
|
29
|
+
onFailure?: (surface: WindowSurface, retry: () => void) => void
|
|
30
|
+
} = {}
|
|
31
|
+
): WindowSurfaceMirror {
|
|
32
|
+
const retryDelayMs = options.retryDelayMs ?? 500
|
|
33
|
+
const whenSettled = options.whenSettled ?? (() => Promise.resolve())
|
|
34
|
+
if (!Number.isSafeInteger(retryDelayMs) || retryDelayMs < 0 || retryDelayMs > 2_147_483_647)
|
|
35
|
+
throw new Error('Invalid window surface retry delay')
|
|
36
|
+
let generation = 0
|
|
37
|
+
let retryTimer: ReturnType<typeof setTimeout> | undefined
|
|
38
|
+
return (surface) => {
|
|
39
|
+
const mine = ++generation
|
|
40
|
+
if (retryTimer !== undefined) clearTimeout(retryTimer)
|
|
41
|
+
retryTimer = undefined
|
|
42
|
+
const afterSettled = (retry: boolean) =>
|
|
43
|
+
void Promise.resolve()
|
|
44
|
+
.then(whenSettled)
|
|
45
|
+
.then(() => {
|
|
46
|
+
if (mine === generation) attempt(retry)
|
|
47
|
+
})
|
|
48
|
+
.catch(reportFailure)
|
|
49
|
+
const reportFailure = () => {
|
|
50
|
+
if (mine !== generation) return
|
|
51
|
+
let used = false
|
|
52
|
+
try {
|
|
53
|
+
options.onFailure?.(surface, () => {
|
|
54
|
+
if (used || mine !== generation) return
|
|
55
|
+
used = true
|
|
56
|
+
afterSettled(true)
|
|
57
|
+
})
|
|
58
|
+
} catch {
|
|
59
|
+
// A notification failure must not become an unhandled rejection.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const attempt = (retry: boolean) => {
|
|
63
|
+
let result: Promise<void>
|
|
64
|
+
try {
|
|
65
|
+
// Invoke at once so the latest intent is recorded before another write is queued.
|
|
66
|
+
result = update(surface)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
result = Promise.reject(error)
|
|
69
|
+
}
|
|
70
|
+
void result.catch(() => {
|
|
71
|
+
if (mine !== generation) return
|
|
72
|
+
if (!retry) return reportFailure()
|
|
73
|
+
retryTimer = setTimeout(() => {
|
|
74
|
+
retryTimer = undefined
|
|
75
|
+
afterSettled(false)
|
|
76
|
+
}, retryDelayMs)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
attempt(true)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The update `createWindowSurfaceMirror` needs, through the framework `shell.window-surface`
|
|
85
|
+
* service. The host persists every request it receives, so requests go out one at a time: a
|
|
86
|
+
* newer choice waits for the request in flight, and a choice superseded while it waits is never
|
|
87
|
+
* sent. The last write to reach the store is always the latest choice.
|
|
88
|
+
*/
|
|
89
|
+
export function desktopWindowSurfaceUpdate(
|
|
90
|
+
invoke: (name: string, input: unknown) => Promise<{ ok: boolean }>
|
|
91
|
+
): (surface: WindowSurface) => Promise<void> {
|
|
92
|
+
let latest = 0
|
|
93
|
+
let previous: Promise<unknown> = Promise.resolve()
|
|
94
|
+
return (surface) => {
|
|
95
|
+
const mine = ++latest
|
|
96
|
+
const request = previous.then(async () => {
|
|
97
|
+
if (mine !== latest) return
|
|
98
|
+
const result = await invoke('shell.window-surface', { surface })
|
|
99
|
+
if (!result.ok) throw new Error('Unable to save the window surface')
|
|
100
|
+
})
|
|
101
|
+
previous = request.catch(() => undefined)
|
|
102
|
+
return request
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -33,6 +33,11 @@ import {
|
|
|
33
33
|
electrobunFileDialogs,
|
|
34
34
|
registerNativeUtilities,
|
|
35
35
|
} from '@adea-ai/app-framework/native-utilities'
|
|
36
|
+
import {
|
|
37
|
+
readWindowSurface,
|
|
38
|
+
registerWindowSurfaceService,
|
|
39
|
+
windowSurfaceTransparent,
|
|
40
|
+
} from '@adea-ai/app-framework/window-surface-store'
|
|
36
41
|
import { appConfig } from '../app-config'
|
|
37
42
|
|
|
38
43
|
const HOST_DRAIN_TIMEOUT_MS = 5000
|
|
@@ -90,6 +95,15 @@ registerNativeUtilities({
|
|
|
90
95
|
openExternal: (url) => Utils.openExternal(url),
|
|
91
96
|
...electrobunFileDialogs(Utils),
|
|
92
97
|
})
|
|
98
|
+
// The appearance editor's glass choice: persisted here, applied when the window is created.
|
|
99
|
+
const windowSurfaceFile = join(dataDirectory, 'window-surface.json')
|
|
100
|
+
const windowSurface = readWindowSurface(windowSurfaceFile)
|
|
101
|
+
registerWindowSurfaceService({
|
|
102
|
+
services,
|
|
103
|
+
stateFile: windowSurfaceFile,
|
|
104
|
+
current: windowSurface,
|
|
105
|
+
authorize: (principal) => principal === 'app-window',
|
|
106
|
+
})
|
|
93
107
|
services.register('app.hello', {
|
|
94
108
|
parse: (value) => value,
|
|
95
109
|
authorize: (principal) => principal === 'app-window',
|
|
@@ -194,6 +208,7 @@ try {
|
|
|
194
208
|
portFile: join(dataDirectory, 'desktop-origin-port'),
|
|
195
209
|
initialPort: appConfig.initialPort ?? undefined,
|
|
196
210
|
title: appConfig.name,
|
|
211
|
+
transparent: windowSurfaceTransparent(windowSurface, process.platform),
|
|
197
212
|
renderer: appConfig.renderer,
|
|
198
213
|
platform: process.platform,
|
|
199
214
|
principal: 'app-window',
|
|
@@ -4,7 +4,12 @@ import { House } from 'lucide-solid'
|
|
|
4
4
|
import { Application, defineApplication } from '@adea-ai/app-framework/application'
|
|
5
5
|
import { ThemeProvider } from '@adea-ai/app-framework/appearance-host'
|
|
6
6
|
import { connectApplicationCommands } from '@adea-ai/app-framework/application-command-client'
|
|
7
|
-
import { createDesktopClient } from '@adea-ai/app-framework/desktop-client'
|
|
7
|
+
import { createDesktopClient, isFrameworkDesktop } from '@adea-ai/app-framework/desktop-client'
|
|
8
|
+
import {
|
|
9
|
+
createWindowSurfaceMirror,
|
|
10
|
+
desktopWindowSurfaceUpdate,
|
|
11
|
+
registerWindowSurfaceMirror,
|
|
12
|
+
} from '@adea-ai/app-framework/window-surface'
|
|
8
13
|
import { Button } from '@adea-ai/ui/components/ui/button'
|
|
9
14
|
import { appConfig } from '../app-config'
|
|
10
15
|
import './style.css'
|
|
@@ -12,6 +17,13 @@ import './style.css'
|
|
|
12
17
|
declare const __APP_VERSION__: string
|
|
13
18
|
|
|
14
19
|
const client = createDesktopClient()
|
|
20
|
+
// Persist the appearance editor's glass choice for the next window the host creates.
|
|
21
|
+
if (isFrameworkDesktop())
|
|
22
|
+
registerWindowSurfaceMirror(
|
|
23
|
+
createWindowSurfaceMirror(
|
|
24
|
+
desktopWindowSurfaceUpdate((name, input) => client.invoke(name, input))
|
|
25
|
+
)
|
|
26
|
+
)
|
|
15
27
|
const openExternal = async (url: string) => {
|
|
16
28
|
const result = await client.invoke('shell.open-external', { url })
|
|
17
29
|
if (
|