@adea-ai/app-framework 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +157 -19
  2. package/dist/app/application.d.ts +11 -4
  3. package/dist/app/application.js +24 -4
  4. package/dist/app/create-application.d.ts +9 -0
  5. package/dist/app/create-application.js +214 -143
  6. package/dist/app/private-group.d.ts +14 -0
  7. package/dist/app/private-group.js +39 -0
  8. package/dist/app/service-registry.d.ts +8 -4
  9. package/dist/app/service-registry.js +43 -6
  10. package/dist/appearance/custom-theme-import.d.ts +5 -7
  11. package/dist/appearance/custom-theme-import.js +66 -18
  12. package/dist/appearance/custom-theme-library.d.ts +51 -3
  13. package/dist/appearance/custom-theme-library.js +262 -33
  14. package/dist/appearance/editor.d.ts +3 -1
  15. package/dist/appearance/editor.js +37 -2
  16. package/dist/appearance/theme-file-importer.d.ts +7 -3
  17. package/dist/appearance/theme-file-importer.js +27 -7
  18. package/dist/appearance/theme-library-action-fence.d.ts +11 -0
  19. package/dist/appearance/theme-library-action-fence.js +29 -0
  20. package/dist/cli/cef-helper-cli.js +0 -0
  21. package/dist/cli/create-application-cli.js +0 -0
  22. package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
  23. package/dist/cli/framework-update-cli.js +16 -3
  24. package/dist/cli/macos-signing-cli.js +0 -0
  25. package/dist/cli/release-assets-plan-cli.js +0 -0
  26. package/dist/cli/release-cut-cli.js +0 -0
  27. package/dist/cli/release-descriptor-staging-cli.js +0 -0
  28. package/dist/cli/release-finalize-cli.js +0 -0
  29. package/dist/cli/release-promote-cli.js +0 -0
  30. package/dist/cli/release-publish-cli.js +0 -0
  31. package/dist/cli/release-sign-cli.js +0 -0
  32. package/dist/cli/release-step-cli.js +0 -0
  33. package/dist/cli/toolchain-identity-cli.js +0 -0
  34. package/dist/cli/windows-runtime-patch-cli.js +0 -0
  35. package/dist/desktop/application-command-client.d.ts +11 -1
  36. package/dist/desktop/application-command-client.js +66 -3
  37. package/dist/desktop/channel-handshake.d.ts +2 -1
  38. package/dist/desktop/channel-handshake.js +21 -5
  39. package/dist/desktop/client-asset-stream.d.ts +10 -0
  40. package/dist/desktop/client-asset-stream.js +97 -0
  41. package/dist/desktop/client-assets.d.ts +3 -1
  42. package/dist/desktop/client-assets.js +41 -6
  43. package/dist/desktop/desktop-client.d.ts +15 -1
  44. package/dist/desktop/desktop-client.js +235 -109
  45. package/dist/desktop/desktop-gateway.d.ts +2 -0
  46. package/dist/desktop/desktop-gateway.js +134 -22
  47. package/dist/desktop/desktop-host-websocket.d.ts +10 -0
  48. package/dist/desktop/desktop-host-websocket.js +28 -0
  49. package/dist/desktop/desktop-host.d.ts +9 -0
  50. package/dist/desktop/desktop-host.js +70 -61
  51. package/dist/desktop/desktop-port-file.d.ts +2 -0
  52. package/dist/desktop/desktop-port-file.js +23 -0
  53. package/dist/desktop/desktop-stream.d.ts +5 -0
  54. package/dist/desktop/desktop-stream.js +83 -15
  55. package/dist/desktop/gateway-limits.d.ts +2 -0
  56. package/dist/desktop/gateway-limits.js +6 -0
  57. package/dist/desktop/open-url-channel.d.ts +5 -3
  58. package/dist/desktop/open-url-channel.js +18 -5
  59. package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
  60. package/dist/desktop/typed-array-intrinsics.js +19 -0
  61. package/dist/framework-source.json +1 -1
  62. package/dist/installer/installed-payload.js +1 -1
  63. package/dist/installer/installer-ci-bootstrap.js +2 -1
  64. package/dist/installer/installer-command.d.ts +13 -0
  65. package/dist/installer/installer-command.js +47 -0
  66. package/dist/installer/installer-extraction.js +27 -61
  67. package/dist/installer/installer-identity.d.ts +19 -3
  68. package/dist/installer/installer-identity.js +58 -70
  69. package/dist/installer/installer-image-mount.d.ts +48 -0
  70. package/dist/installer/installer-image-mount.js +347 -0
  71. package/dist/installer/installer-layout.js +1 -1
  72. package/dist/installer/installer-process-cleanup.js +1 -1
  73. package/dist/installer/installer-renderer-evidence.js +6 -2
  74. package/dist/installer/upgrade-asset-download.js +30 -8
  75. package/dist/native/app-bundle.d.ts +2 -2
  76. package/dist/native/app-bundle.js +5 -4
  77. package/dist/native/cef-helper-download.d.ts +1 -0
  78. package/dist/native/cef-helper-download.js +35 -0
  79. package/dist/native/cef-helper.js +146 -61
  80. package/dist/native/exclusive-rename.d.ts +2 -0
  81. package/dist/native/exclusive-rename.js +52 -0
  82. package/dist/native/native-secret-store.js +5 -4
  83. package/dist/native/partitioned-window.d.ts +5 -2
  84. package/dist/native/partitioned-window.js +69 -9
  85. package/dist/native/sidecar-services.js +2 -2
  86. package/dist/native/sidecar.js +68 -25
  87. package/dist/native/window-bootstrap.js +2 -2
  88. package/dist/release/feed-state.js +2 -1
  89. package/dist/release/framework-update-lock.d.ts +2 -0
  90. package/dist/release/framework-update-lock.js +42 -0
  91. package/dist/release/framework-update.d.ts +6 -2
  92. package/dist/release/framework-update.js +165 -40
  93. package/dist/release/local-release.js +68 -39
  94. package/dist/release/release-config.js +1 -1
  95. package/dist/shared/discard-stream.d.ts +4 -0
  96. package/dist/shared/discard-stream.js +9 -0
  97. package/dist/shell/app-shell.js +59 -7
  98. package/dist/shell/app-utilities.js +2 -2
  99. package/dist/shell/application-menu.d.ts +13 -0
  100. package/dist/shell/application-menu.js +21 -8
  101. package/dist/update-helper.bundle.js +40 -4
  102. package/dist/updates/channel-update-manager.d.ts +2 -0
  103. package/dist/updates/channel-update-manager.js +15 -3
  104. package/dist/updates/desktop-updater.d.ts +2 -0
  105. package/dist/updates/desktop-updater.js +36 -7
  106. package/dist/updates/linux-process-state.d.ts +2 -0
  107. package/dist/updates/linux-process-state.js +13 -0
  108. package/dist/updates/release-location.js +5 -4
  109. package/dist/updates/update-adapter.js +5 -0
  110. package/dist/updates/update-arm.d.ts +2 -0
  111. package/dist/updates/update-arm.js +58 -7
  112. package/dist/updates/update-discovery.js +2 -1
  113. package/dist/updates/update-download-cleanup.d.ts +7 -0
  114. package/dist/updates/update-download-cleanup.js +21 -0
  115. package/dist/updates/update-download.js +41 -20
  116. package/dist/updates/update-exclusive-rename.d.ts +3 -2
  117. package/dist/updates/update-exclusive-rename.js +3 -50
  118. package/dist/updates/update-extraction.js +1 -1
  119. package/dist/updates/update-manager.d.ts +17 -1
  120. package/dist/updates/update-manager.js +27 -8
  121. package/dist/updates/update-process-fence.js +18 -3
  122. package/dist/views/appearance-surface.js +51 -15
  123. package/package.json +11 -6
  124. package/src/app/application.tsx +49 -7
  125. package/src/appearance/custom-theme-import.ts +67 -7
  126. package/src/appearance/custom-theme-library.ts +391 -33
  127. package/src/appearance/editor.ts +49 -10
  128. package/src/appearance/theme-file-importer.ts +43 -12
  129. package/src/appearance/theme-library-action-fence.ts +28 -0
  130. package/src/desktop/client-asset-stream.ts +118 -0
  131. package/src/desktop/client-assets.ts +55 -5
  132. package/src/shell/app-shell.tsx +71 -8
  133. package/src/shell/app-utilities.tsx +2 -2
  134. package/src/updates/update-adapter.ts +5 -0
  135. package/src/views/appearance-surface.tsx +61 -29
  136. package/templates/application/README.md +5 -1
  137. package/templates/application/scripts/app-version.ts +7 -3
  138. package/templates/application/src/bun/index.ts +2 -0
@@ -1,3 +1,4 @@
1
+ import { renameExclusive } from "../native/exclusive-rename.js";
1
2
  import { verifyReleaseDescriptor } from "../updates/signed-release.js";
2
3
  import { feedAssetKey, feedChannelKey, feedIndexKey, feedReleaseKey, feedUrl, parseReleaseLedger } from "../updates/release-feed.js";
3
4
  import { discoveryPolicies, parseReleaseConfig, platformPayloads, platformTargets } from "./release-config.js";
@@ -9,7 +10,7 @@ import { readFeedLedger, readFeedRelease, verifyFeedRelease } from "./feed-state
9
10
  import { fileIdentity } from "./release-publication.js";
10
11
  import { configuredSigningKey, signDiscoveryDescriptors, writeDescriptors } from "./release-descriptor-staging.js";
11
12
  import { promoteDailyRelease } from "./release-promotion.js";
12
- import { constants, copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
13
+ import { constants, copyFile, lstat, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
13
14
  import { dirname, join, resolve } from "node:path";
14
15
  import { createHash } from "node:crypto";
15
16
  // src/release/local-release.ts
@@ -154,46 +155,69 @@ var describe = (key, bytes, cacheControl) => ({
154
155
  /** Write `<out>/<key>` for each object and the plan beside them; `out` must not exist. */
155
156
  async function writeStagedTree(out, feed, assets, documents) {
156
157
  const root = resolve(out);
157
- await mkdir(root, { mode: 448 });
158
- const objects = [];
159
- for (const { key, path, artifact } of assets) {
160
- const target = join(root, key);
161
- await mkdir(dirname(target), {
162
- recursive: true,
163
- mode: 448
164
- });
165
- await copyFile(path, target, constants.COPYFILE_EXCL);
166
- if (JSON.stringify(await fileIdentity(target, artifact.name)) !== JSON.stringify(artifact)) throw new Error("Staged asset changed while copying");
167
- objects.push({
168
- key,
169
- size: artifact.size,
170
- sha256: artifact.digest.slice(7),
171
- contentType: key.endsWith(".json") ? "application/json" : "application/octet-stream",
172
- cacheControl: IMMUTABLE
173
- });
158
+ try {
159
+ await lstat(root);
160
+ throw new Error("Release output directory already exists");
161
+ } catch (error) {
162
+ if (error.code !== "ENOENT") throw error;
174
163
  }
175
- for (const { key, bytes } of documents) {
176
- const target = join(root, key);
177
- await mkdir(dirname(target), {
178
- recursive: true,
179
- mode: 448
180
- });
181
- await writeFile(target, bytes, {
164
+ await mkdir(dirname(root), {
165
+ recursive: true,
166
+ mode: 448
167
+ });
168
+ const staging = await mkdtemp(join(dirname(root), ".release-staging-"));
169
+ try {
170
+ const objects = [];
171
+ for (const { key, path, artifact } of assets) {
172
+ const target = join(staging, key);
173
+ await mkdir(dirname(target), {
174
+ recursive: true,
175
+ mode: 448
176
+ });
177
+ await copyFile(path, target, constants.COPYFILE_EXCL);
178
+ if (JSON.stringify(await fileIdentity(target, artifact.name)) !== JSON.stringify(artifact)) throw new Error("Staged asset changed while copying");
179
+ objects.push({
180
+ key,
181
+ size: artifact.size,
182
+ sha256: artifact.digest.slice(7),
183
+ contentType: key.endsWith(".json") ? "application/json" : "application/octet-stream",
184
+ cacheControl: IMMUTABLE
185
+ });
186
+ }
187
+ for (const { key, bytes } of documents) {
188
+ const target = join(staging, key);
189
+ await mkdir(dirname(target), {
190
+ recursive: true,
191
+ mode: 448
192
+ });
193
+ await writeFile(target, bytes, {
194
+ flag: "wx",
195
+ mode: 384
196
+ });
197
+ objects.push(describe(key, bytes, MUTABLE));
198
+ }
199
+ const plan = {
200
+ schema: 1,
201
+ base: feed.base,
202
+ objects
203
+ };
204
+ await writeFile(join(staging, UPLOAD_PLAN), jsonBytes(plan), {
182
205
  flag: "wx",
183
206
  mode: 384
184
207
  });
185
- objects.push(describe(key, bytes, MUTABLE));
208
+ renameExclusive(staging, root);
209
+ return plan;
210
+ } catch (error) {
211
+ try {
212
+ await rm(staging, {
213
+ recursive: true,
214
+ force: true
215
+ });
216
+ } catch (cleanupError) {
217
+ throw new AggregateError([error, cleanupError], "Release staging failed and its private temporary tree could not be removed", { cause: error });
218
+ }
219
+ throw error;
186
220
  }
187
- const plan = {
188
- schema: 1,
189
- base: feed.base,
190
- objects
191
- };
192
- await writeFile(join(root, UPLOAD_PLAN), jsonBytes(plan), {
193
- flag: "wx",
194
- mode: 384
195
- });
196
- return plan;
197
221
  }
198
222
  /** release.json, the ledger and the pointers `tag` now holds, in upload order. */
199
223
  function releaseDocuments(feed, ledger, release) {
@@ -209,8 +233,11 @@ function releaseDocuments(feed, ledger, release) {
209
233
  ...pointerChannels(ledger, release.tag).map((channel) => ({
210
234
  key: feedChannelKey(feed, channel),
211
235
  bytes: jsonBytes({
212
- ...release,
213
- channel
236
+ tag: release.tag,
237
+ channel,
238
+ publishedAt: release.publishedAt,
239
+ assets: release.assets,
240
+ ...channel === "stable" && release.missingPlatforms ? { missingPlatforms: release.missingPlatforms } : {}
214
241
  })
215
242
  }))
216
243
  ];
@@ -292,11 +319,13 @@ async function stageLocalRelease(options) {
292
319
  publishedAt: now
293
320
  }, ...ledger.releases].slice(0, 500)
294
321
  }, feed.app);
322
+ const remaining = remote?.missingPlatforms?.filter((name) => name !== platform);
295
323
  const release = {
296
324
  tag,
297
325
  channel: entry?.kind ?? channelOf(tag),
298
326
  publishedAt: remote?.publishedAt ?? now,
299
- assets: merged
327
+ assets: merged,
328
+ ...entry?.kind === "stable" && remaining?.length ? { missingPlatforms: remaining } : {}
300
329
  };
301
330
  return writeStagedTree(options.out, feed, uploads, releaseDocuments(feed, updated, release));
302
331
  }
@@ -53,7 +53,7 @@ function parseReleaseConfig(config) {
53
53
  const feed = parseReleaseFeed(config.releaseFeed);
54
54
  let sidecars;
55
55
  try {
56
- sidecars = assertSidecarNames(config.sidecars ?? []);
56
+ sidecars = assertSidecarNames(config.sidecars ?? [], "windows-x64");
57
57
  } catch {
58
58
  throw new Error("Invalid release sidecars");
59
59
  }
@@ -0,0 +1,4 @@
1
+ /** Initiate cleanup without letting a broken stream delay or replace the result. */
2
+ export declare function discardStream(stream: {
3
+ cancel(): Promise<unknown>;
4
+ } | null): void;
@@ -0,0 +1,9 @@
1
+ // src/shared/discard-stream.ts
2
+ /** Initiate cleanup without letting a broken stream delay or replace the result. */
3
+ function discardStream(stream) {
4
+ if (!stream) return;
5
+ try {
6
+ Promise.resolve(stream.cancel()).catch(() => {});
7
+ } catch {}
8
+ }
9
+ export { discardStream };
@@ -26,10 +26,52 @@ function createNarrow(query) {
26
26
  });
27
27
  return narrow;
28
28
  }
29
+ var nonTextInputTypes = /* @__PURE__ */ new Set([
30
+ "button",
31
+ "checkbox",
32
+ "color",
33
+ "file",
34
+ "hidden",
35
+ "image",
36
+ "radio",
37
+ "range",
38
+ "reset",
39
+ "submit"
40
+ ]);
41
+ /** Whether an element or an ancestor in its composed path accepts text editing. */
42
+ function isEditableElementPath(path) {
43
+ let inheritedEditable = false;
44
+ for (const target of path) {
45
+ if (!(target instanceof Element)) continue;
46
+ if (target instanceof HTMLInputElement) {
47
+ if (!target.disabled && !target.readOnly && !nonTextInputTypes.has(target.type)) return true;
48
+ } else if (target instanceof HTMLTextAreaElement) {
49
+ if (!target.disabled && !target.readOnly) return true;
50
+ }
51
+ const contentEditable = target.getAttribute("contenteditable")?.toLowerCase();
52
+ if (contentEditable === "false") return false;
53
+ if (contentEditable === "" || contentEditable === "true" || contentEditable === "plaintext-only") return true;
54
+ if (target instanceof HTMLElement && target.isContentEditable) inheritedEditable = true;
55
+ if (target.ownerDocument.designMode?.toLowerCase() === "on") inheritedEditable = true;
56
+ }
57
+ return inheritedEditable;
58
+ }
59
+ function hasEditableTarget(event) {
60
+ const path = event.composedPath();
61
+ if (path.some((target) => target instanceof Element)) return isEditableElementPath(path);
62
+ const activePath = [];
63
+ let activeElement = document.activeElement;
64
+ while (activeElement) {
65
+ activePath.push(activeElement);
66
+ activeElement = activeElement.shadowRoot?.activeElement ?? null;
67
+ }
68
+ return isEditableElementPath(activePath);
69
+ }
29
70
  /** Shared chrome and navigation composition; applications own routes and services. */
30
71
  function ApplicationShell(props) {
31
72
  let sidebarToggle;
32
73
  const narrow = createNarrow(() => props.drawer ? props.narrowQuery ?? "(max-width: 799px)" : void 0);
74
+ const sidebarMobile = createNarrow(() => !props.drawer && props.sidebar ? "(max-width: 48rem)" : void 0);
33
75
  const [drawerOpen, setDrawerOpen] = createSignal(false);
34
76
  const [drawerMounted, setDrawerMounted] = createSignal(false);
35
77
  createEffect(() => {
@@ -50,7 +92,7 @@ function ApplicationShell(props) {
50
92
  current?.onOpenChange(!current.open);
51
93
  };
52
94
  const handleToggle = (event) => {
53
- if (event.defaultPrevented || !toggleVisible() || !(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "b") return;
95
+ if (event.defaultPrevented || !toggleVisible() || !(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "b" || hasEditableTarget(event)) return;
54
96
  event.preventDefault();
55
97
  toggle();
56
98
  };
@@ -60,10 +102,10 @@ function ApplicationShell(props) {
60
102
  props.onSearch();
61
103
  };
62
104
  onMount(() => {
63
- window.addEventListener("keydown", handleSearch, { capture: true });
105
+ window.addEventListener("keydown", handleSearch);
64
106
  window.addEventListener("keydown", handleToggle);
65
107
  onCleanup(() => {
66
- window.removeEventListener("keydown", handleSearch, { capture: true });
108
+ window.removeEventListener("keydown", handleSearch);
67
109
  window.removeEventListener("keydown", handleToggle);
68
110
  });
69
111
  });
@@ -243,14 +285,24 @@ function ApplicationShell(props) {
243
285
  return props.sidebar;
244
286
  },
245
287
  children: (sidebar) => createComponent(PixelPane, {
246
- "class": "hidden overflow-visible md:block",
288
+ "class": "overflow-visible",
289
+ get hidden() {
290
+ return narrow() || sidebarMobile();
291
+ },
247
292
  get width() {
248
293
  return memo(() => !!sidebar().open)() ? sidebar().width : 0;
249
294
  },
250
295
  get children() {
251
- return createComponent(ContextualSidebar, mergeProps(sidebar, { get restoreFocusRef() {
252
- return sidebar().restoreFocusRef ?? (() => sidebarToggle);
253
- } }));
296
+ return createComponent(Show, {
297
+ get when() {
298
+ return !props.drawer || !narrow();
299
+ },
300
+ get children() {
301
+ return createComponent(ContextualSidebar, mergeProps(sidebar, { get restoreFocusRef() {
302
+ return sidebar().restoreFocusRef ?? (() => sidebarToggle);
303
+ } }));
304
+ }
305
+ });
254
306
  }
255
307
  })
256
308
  }), createComponent(Show, {
@@ -132,10 +132,10 @@ function ApplicationUtilities(props) {
132
132
  };
133
133
  onMount(() => {
134
134
  onHash();
135
- window.addEventListener("keydown", onKeyDown, { capture: true });
135
+ window.addEventListener("keydown", onKeyDown);
136
136
  window.addEventListener("hashchange", onHash);
137
137
  onCleanup(() => {
138
- window.removeEventListener("keydown", onKeyDown, { capture: true });
138
+ window.removeEventListener("keydown", onKeyDown);
139
139
  window.removeEventListener("hashchange", onHash);
140
140
  });
141
141
  });
@@ -32,6 +32,17 @@ export type ApplicationMenuOptions = Readonly<{
32
32
  helpLinks?: readonly ApplicationMenuLink[];
33
33
  /** App menus placed between View and Window. */
34
34
  sections?: readonly ApplicationMenuSection[];
35
+ /** Optional macOS presentation; other platforms keep the standard menu. */
36
+ macOS?: Readonly<{
37
+ /** Use the system About role instead of the framework command. */
38
+ about?: 'command' | 'native';
39
+ /** Include the Help menu. Defaults to true. */
40
+ help?: boolean;
41
+ /** Include the Settings key equivalent. Defaults to true. */
42
+ settingsAccelerator?: boolean;
43
+ /** Route Settings as an app-owned action instead of a framework command. */
44
+ settingsAction?: string;
45
+ }>;
35
46
  }>;
36
47
  /**
37
48
  * Build the standard native menu: application, Edit, View, app sections, Window and Help.
@@ -43,6 +54,8 @@ export type ApplicationMenuDispatch = Readonly<{
43
54
  /** Deliver a shared surface command to the window. */
44
55
  command(command: ApplicationMenuCommand): void;
45
56
  openExternal(url: string): unknown;
57
+ /** Observe browser launch failures without interrupting native menu dispatch. */
58
+ onOpenExternalError?(error: unknown): void | Promise<void>;
46
59
  /** App-owned actions from `sections`. */
47
60
  action?(action: string): void;
48
61
  }>;
@@ -35,7 +35,9 @@ function validLink(link) {
35
35
  */
36
36
  function createApplicationMenu(options) {
37
37
  const links = options.helpLinks ?? [];
38
- if (!label(options.name) || !Array.isArray(links) || links.length > 16 || !links.every(validLink) || (options.sections?.length ?? 0) > 8) throw new Error("Invalid application menu configuration");
38
+ const mac = options.platform === "darwin";
39
+ const macOS = options.macOS;
40
+ if (!label(options.name) || !Array.isArray(links) || links.length > 16 || !links.every(validLink) || (options.sections?.length ?? 0) > 8 || macOS !== void 0 && (typeof macOS !== "object" || macOS === null || Array.isArray(macOS) || macOS.about !== void 0 && macOS.about !== "command" && macOS.about !== "native" || macOS.help !== void 0 && typeof macOS.help !== "boolean" || macOS.settingsAccelerator !== void 0 && typeof macOS.settingsAccelerator !== "boolean" || macOS.settingsAction !== void 0 && (typeof macOS.settingsAction !== "string" || macOS.settingsAction.length > 200 || !appAction.test(macOS.settingsAction) || macOS.settingsAction.startsWith(prefix))) || mac && macOS?.help === false && links.length > 0) throw new Error("Invalid application menu configuration");
39
41
  const sections = (options.sections ?? []).map((section) => {
40
42
  if (!label(section.label)) throw new Error("Invalid application menu configuration");
41
43
  return {
@@ -43,15 +45,17 @@ function createApplicationMenu(options) {
43
45
  submenu: validateItems(section.items)
44
46
  };
45
47
  });
46
- const mac = options.platform === "darwin";
47
- const about = {
48
+ const about = mac && macOS?.about === "native" ? {
49
+ label: `About ${options.name}`,
50
+ role: "about"
51
+ } : {
48
52
  label: `About ${options.name}`,
49
53
  action: `${prefix}about`
50
54
  };
51
55
  const settings = options.settings ? [{
52
56
  label: mac ? "Settings…" : "Settings",
53
- action: `${prefix}settings`,
54
- accelerator: ","
57
+ action: mac && macOS?.settingsAction || `${prefix}settings`,
58
+ ...!mac || macOS?.settingsAccelerator !== false ? { accelerator: "," } : {}
55
59
  }] : [];
56
60
  const updates = options.updates ? [{
57
61
  label: "Check for Updates…",
@@ -115,10 +119,10 @@ function createApplicationMenu(options) {
115
119
  view,
116
120
  ...sections,
117
121
  window,
118
- {
122
+ ...macOS?.help === false ? [] : [{
119
123
  label: "Help",
120
124
  submenu: help
121
- }
125
+ }]
122
126
  ];
123
127
  return [
124
128
  {
@@ -154,13 +158,22 @@ function actionOf(event) {
154
158
  /** Route an `application-menu-clicked` event to shared commands, help links or app actions. */
155
159
  function createApplicationMenuHandler(options) {
156
160
  const links = [...options.helpLinks ?? []];
161
+ const reportOpenError = (error) => {
162
+ try {
163
+ Promise.resolve(options.onOpenExternalError?.(error)).catch(() => {});
164
+ } catch {}
165
+ };
157
166
  return (event) => {
158
167
  const action = actionOf(event);
159
168
  if (action === void 0) return;
160
169
  if (action.startsWith(linkPrefix)) {
161
170
  const index = action.slice(linkPrefix.length);
162
171
  const link = /^(?:0|[1-9]\d?)$/.test(index) ? links[Number(index)] : void 0;
163
- if (link && validLink(link)) options.openExternal(link.url);
172
+ if (link && validLink(link)) try {
173
+ Promise.resolve(options.openExternal(link.url)).catch(reportOpenError);
174
+ } catch (error) {
175
+ reportOpenError(error);
176
+ }
164
177
  return;
165
178
  }
166
179
  if (action.startsWith(prefix)) {
@@ -36,9 +36,26 @@ async function launchInstalledApp(platform, target, env = process.env) {
36
36
  // src/updates/update-process-fence.ts
37
37
  import { execFile } from "child_process";
38
38
  import { dlopen, FFIType, ptr } from "bun:ffi";
39
- import { realpath } from "fs/promises";
39
+ import { readFile, realpath } from "fs/promises";
40
40
  import { isAbsolute as isAbsolute2 } from "path";
41
41
  import { promisify } from "util";
42
+
43
+ // src/updates/linux-process-state.ts
44
+ function linuxProcessIsExited(stat, pid) {
45
+ const prefix = `${pid} (`;
46
+ const end = stat.lastIndexOf(")");
47
+ if (!stat.startsWith(prefix) || end < prefix.length || stat[end + 1] !== " ")
48
+ throw new Error("Invalid Linux process status");
49
+ const fields = stat.slice(end + 2).trimEnd().split(" ");
50
+ if (fields.length < 18 || !/^[A-Za-z]$/.test(fields[0]) || fields.slice(1, 18).some((field) => !/^-?\d+$/.test(field)))
51
+ throw new Error("Invalid Linux process status");
52
+ const threads = Number(fields[17]);
53
+ if (!Number.isSafeInteger(threads) || threads < 1)
54
+ throw new Error("Invalid Linux process status");
55
+ return fields[0] === "Z" && threads === 1;
56
+ }
57
+
58
+ // src/updates/update-process-fence.ts
42
59
  var execute = promisify(execFile);
43
60
  function isProcessRunning(pid) {
44
61
  try {
@@ -50,6 +67,22 @@ function isProcessRunning(pid) {
50
67
  throw new Error("Cannot inspect update process", { cause: error });
51
68
  }
52
69
  }
70
+ async function hasVerifiedProcessExited(pid) {
71
+ if (!isProcessRunning(pid))
72
+ return true;
73
+ if (process.platform !== "linux")
74
+ return false;
75
+ let stat;
76
+ try {
77
+ stat = await readFile(`/proc/${pid}/stat`, "utf8");
78
+ } catch (error) {
79
+ const code = error.code;
80
+ if ((code === "ENOENT" || code === "ESRCH") && !isProcessRunning(pid))
81
+ return true;
82
+ throw new Error("Cannot inspect update process", { cause: error });
83
+ }
84
+ return linuxProcessIsExited(stat, pid);
85
+ }
53
86
  async function waitForUpdateProcesses(options) {
54
87
  if (!Array.isArray(options.processes) || options.processes.length < 1 || options.processes.length > 16 || !Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 120000)
55
88
  throw new Error("Invalid update process fence");
@@ -128,7 +161,7 @@ async function waitForUpdateProcesses(options) {
128
161
  throw new Error("Update process acknowledgement must be synchronous");
129
162
  while (waiting.size) {
130
163
  for (const pid of waiting)
131
- if (!isProcessRunning(pid))
164
+ if (await hasVerifiedProcessExited(pid))
132
165
  waiting.delete(pid);
133
166
  if (!waiting.size)
134
167
  return;
@@ -142,10 +175,10 @@ async function waitForUpdateProcesses(options) {
142
175
  import { rm } from "fs/promises";
143
176
  import { basename, dirname as dirname2, isAbsolute as isAbsolute4, join as join2, resolve as resolve3 } from "path";
144
177
 
145
- // src/updates/update-exclusive-rename.ts
178
+ // src/native/exclusive-rename.ts
146
179
  import { dlopen as dlopen2, FFIType as FFIType2, ptr as ptr2 } from "bun:ffi";
147
180
  import { isAbsolute as isAbsolute3, resolve as resolve2 } from "path";
148
- function renameUpdateExclusive(source, destination) {
181
+ function renameExclusive(source, destination) {
149
182
  if (typeof source !== "string" || typeof destination !== "string" || !isAbsolute3(source) || !isAbsolute3(destination) || resolve2(source) !== source || resolve2(destination) !== destination || source === destination || source.includes("\x00") || destination.includes("\x00"))
150
183
  throw new Error("Invalid exclusive rename paths");
151
184
  if (process.platform === "darwin") {
@@ -188,6 +221,9 @@ function renameUpdateExclusive(source, destination) {
188
221
  throw new Error("Unsupported exclusive rename platform");
189
222
  }
190
223
 
224
+ // src/updates/update-exclusive-rename.ts
225
+ var renameUpdateExclusive = renameExclusive;
226
+
191
227
  // src/updates/update-swap.ts
192
228
  function updateStagingFor(target) {
193
229
  if (typeof target !== "string" || !isAbsolute4(target) || resolve3(target) !== target)
@@ -15,6 +15,8 @@ export declare function createChannelUpdateManager(options: {
15
15
  directory: string;
16
16
  maxBytes: number;
17
17
  stage: ManagerOptions['stage'];
18
+ /** Discard a downloaded result that is rejected before stage takes ownership. */
19
+ discardDownload?: ManagerOptions['stage'];
18
20
  discover?: ManagerOptions['discover'];
19
21
  download?: ManagerOptions['download'];
20
22
  fetch?: FetchFunction;
@@ -1,9 +1,13 @@
1
1
  import { isUpdateChannel } from "./release-version.js";
2
+ import { selectUpdateDownloadDiscard } from "./update-download-cleanup.js";
2
3
  import { createUpdateManager } from "./update-manager.js";
3
4
  import { releaseChannelForUpdate } from "./update-channel-store.js";
4
5
  // src/updates/channel-update-manager.ts
5
6
  /** Re-read the persisted channel for every check and bind an approval to that choice. */
6
7
  function createChannelUpdateManager(options) {
8
+ const directory = options.directory;
9
+ const download = options.download;
10
+ const discardDownload = selectUpdateDownloadDiscard(directory, download !== void 0, options.discardDownload);
7
11
  let busy = false, active;
8
12
  let state = Object.freeze({
9
13
  phase: "idle",
@@ -66,13 +70,21 @@ function createChannelUpdateManager(options) {
66
70
  channel: releaseChannelForUpdate(channel)
67
71
  },
68
72
  discoveryName: options.discoveryNames[channel],
69
- directory: options.directory,
73
+ directory,
70
74
  maxBytes: options.maxBytes,
71
75
  discover: options.discover,
72
- download: options.download,
76
+ download,
77
+ discardDownload,
73
78
  fetch: options.fetch,
74
79
  stage: async (input) => {
75
- if (await options.store.read() !== channel) throw new Error("Update channel changed");
80
+ try {
81
+ if (await options.store.read() !== channel) throw new Error("Update channel changed");
82
+ } catch (error) {
83
+ try {
84
+ await discardDownload?.(input);
85
+ } catch {}
86
+ throw error;
87
+ }
76
88
  await options.stage(input);
77
89
  if (await options.store.read() !== channel) throw new Error("Update channel changed");
78
90
  }
@@ -59,6 +59,8 @@ export type UpdaterOptions = {
59
59
  restart(version: string): Promise<void>;
60
60
  /** Aborts the download in flight. */
61
61
  abortDownload?(): void;
62
+ /** Whether staging is still waiting before the desktop stage callback starts. */
63
+ canCancelStaging?(): boolean;
62
64
  };
63
65
  /** The update commands over a framework channel update manager. */
64
66
  export declare function createUpdater(options: UpdaterOptions): {
@@ -2,6 +2,8 @@ import { ServiceError } from "../app/service-registry.js";
2
2
  import { feedUrl, parseReleaseFeed } from "./release-feed.js";
3
3
  import { isUpdateChannel } from "./release-version.js";
4
4
  import { stageUpdateSwap } from "./update-swap-stage.js";
5
+ import { downloadVerifiedRelease } from "./update-download.js";
6
+ import { discardOwnedUpdateDownload } from "./update-download-cleanup.js";
5
7
  import { createUpdateChannelStore } from "./update-channel-store.js";
6
8
  import { createChannelUpdateManager } from "./channel-update-manager.js";
7
9
  import { armUpdateHelper } from "./update-arm.js";
@@ -100,7 +102,7 @@ function createUpdater(options) {
100
102
  const state = manager?.status();
101
103
  const available = state?.availableVersion ?? null;
102
104
  if (available) lastTag = `v${available}`;
103
- const phase = !state ? "unavailable" : cancelRequested && state.phase === "downloading" ? "cancelling" : cancelRequested && state.phase === "failed" ? "cancelled" : PHASES[state.phase];
105
+ const phase = !state ? "unavailable" : cancelRequested && (state.phase === "downloading" || state.phase === "staging" && options.canCancelStaging?.() === true) ? "cancelling" : cancelRequested && state.phase === "failed" ? "cancelled" : PHASES[state.phase];
104
106
  return {
105
107
  current_version: currentVersion,
106
108
  available_version: available,
@@ -151,7 +153,8 @@ function createUpdater(options) {
151
153
  return snapshot();
152
154
  },
153
155
  async cancel() {
154
- if (manager?.status().phase === "downloading" && options.abortDownload) {
156
+ const phase = manager?.status().phase;
157
+ if (!cancelRequested && options.abortDownload && (phase === "downloading" || phase === "staging" && options.canCancelStaging?.() === true)) {
155
158
  cancelRequested = true;
156
159
  options.abortDownload();
157
160
  }
@@ -173,6 +176,8 @@ async function createDesktopUpdater(options) {
173
176
  keys: release.releaseSigningKeys
174
177
  });
175
178
  let controller = new AbortController();
179
+ let downloadSignal;
180
+ let stageStarted = false;
176
181
  const updater = {
177
182
  appName: release.appName,
178
183
  repository: options.repository,
@@ -182,6 +187,9 @@ async function createDesktopUpdater(options) {
182
187
  abortDownload() {
183
188
  controller.abort();
184
189
  controller = new AbortController();
190
+ },
191
+ canCancelStaging() {
192
+ return downloadSignal !== void 0 && !stageStarted;
185
193
  }
186
194
  };
187
195
  if (!platform || !trust) return createUpdater({
@@ -209,19 +217,35 @@ async function createDesktopUpdater(options) {
209
217
  recursive: true,
210
218
  mode: 448
211
219
  });
220
+ const downloadsRoot = await realpath(downloads);
212
221
  const manager = createChannelUpdateManager({
213
222
  store: createUpdateChannelStore(await realpath(state)),
214
223
  trust,
215
224
  discoveryNames: discoveryNames(platform),
216
225
  currentVersion: options.currentVersion,
217
- directory: await realpath(downloads),
226
+ directory: downloadsRoot,
218
227
  maxBytes: MAX_DOWNLOAD_BYTES,
228
+ download(input) {
229
+ const cancellation = controller.signal;
230
+ const signal = input.signal ? AbortSignal.any([input.signal, cancellation]) : cancellation;
231
+ downloadSignal = signal;
232
+ stageStarted = false;
233
+ return downloadVerifiedRelease({
234
+ ...input,
235
+ signal
236
+ });
237
+ },
219
238
  fetch: (input, init) => fetch(input, {
220
239
  ...init,
221
240
  signal: init?.signal ? AbortSignal.any([init.signal, controller.signal]) : controller.signal
222
241
  }),
242
+ async discardDownload({ directory }) {
243
+ await discardOwnedUpdateDownload(downloadsRoot, directory);
244
+ },
223
245
  async stage({ descriptor, path, directory }) {
224
246
  try {
247
+ if (!downloadSignal || downloadSignal.aborted) throw new Error("Update download cancelled");
248
+ stageStarted = true;
225
249
  await stageUpdateSwap({
226
250
  descriptor,
227
251
  trust: {
@@ -241,10 +265,15 @@ async function createDesktopUpdater(options) {
241
265
  ...release.sidecars ? { sidecars: release.sidecars } : {}
242
266
  });
243
267
  } finally {
244
- await rm(directory, {
245
- recursive: true,
246
- force: true
247
- });
268
+ try {
269
+ await rm(directory, {
270
+ recursive: true,
271
+ force: true
272
+ });
273
+ } finally {
274
+ downloadSignal = void 0;
275
+ stageStarted = false;
276
+ }
248
277
  }
249
278
  }
250
279
  });
@@ -0,0 +1,2 @@
1
+ /** True only for a Linux zombie thread-group leader with no other threads. */
2
+ export declare function linuxProcessIsExited(stat: string, pid: number): boolean;
@@ -0,0 +1,13 @@
1
+ // src/updates/linux-process-state.ts
2
+ /** True only for a Linux zombie thread-group leader with no other threads. */
3
+ function linuxProcessIsExited(stat, pid) {
4
+ const prefix = `${pid} (`;
5
+ const end = stat.lastIndexOf(")");
6
+ if (!stat.startsWith(prefix) || end < prefix.length || stat[end + 1] !== " ") throw new Error("Invalid Linux process status");
7
+ const fields = stat.slice(end + 2).trimEnd().split(" ");
8
+ if (fields.length < 18 || !/^[A-Za-z]$/.test(fields[0]) || fields.slice(1, 18).some((field) => !/^-?\d+$/.test(field))) throw new Error("Invalid Linux process status");
9
+ const threads = Number(fields[17]);
10
+ if (!Number.isSafeInteger(threads) || threads < 1) throw new Error("Invalid Linux process status");
11
+ return fields[0] === "Z" && threads === 1;
12
+ }
13
+ export { linuxProcessIsExited };