@adea-ai/app-framework 0.0.0-stage → 0.24.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 (474) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +30 -0
  3. package/README.md +967 -2
  4. package/dist/app/application.d.ts +47 -0
  5. package/dist/app/application.js +115 -0
  6. package/dist/app/create-application.d.ts +13 -0
  7. package/dist/app/create-application.js +178 -0
  8. package/dist/app/service-registry.d.ts +44 -0
  9. package/dist/app/service-registry.js +116 -0
  10. package/dist/appearance/appearance-host.d.ts +62 -0
  11. package/dist/appearance/appearance-host.js +115 -0
  12. package/dist/appearance/appearance-preferences.d.ts +106 -0
  13. package/dist/appearance/appearance-preferences.js +175 -0
  14. package/dist/appearance/composition.d.ts +11 -0
  15. package/dist/appearance/composition.js +16 -0
  16. package/dist/appearance/custom-theme-import.d.ts +14 -0
  17. package/dist/appearance/custom-theme-import.js +315 -0
  18. package/dist/appearance/custom-theme-library.d.ts +146 -0
  19. package/dist/appearance/custom-theme-library.js +378 -0
  20. package/dist/appearance/editor.d.ts +20 -0
  21. package/dist/appearance/editor.js +47 -0
  22. package/dist/appearance/theme-file-importer.d.ts +23 -0
  23. package/dist/appearance/theme-file-importer.js +66 -0
  24. package/dist/appearance/theme-record-adapter.d.ts +26 -0
  25. package/dist/appearance/theme-record-adapter.js +64 -0
  26. package/dist/appearance/theme-registry.d.ts +10 -0
  27. package/dist/appearance/theme-registry.js +16 -0
  28. package/dist/appearance/window-surface.d.ts +5 -0
  29. package/dist/appearance/window-surface.js +9 -0
  30. package/dist/ci/toolchain-identity.d.ts +39 -0
  31. package/dist/ci/toolchain-identity.js +196 -0
  32. package/dist/cli/cef-helper-cli.d.ts +2 -0
  33. package/dist/cli/cef-helper-cli.js +18 -0
  34. package/dist/cli/cli-runner.d.ts +8 -0
  35. package/dist/cli/cli-runner.js +23 -0
  36. package/dist/cli/create-application-cli.d.ts +2 -0
  37. package/dist/cli/create-application-cli.js +40 -0
  38. package/dist/cli/electrobun-shortcut-patch-cli.d.ts +2 -0
  39. package/dist/cli/electrobun-shortcut-patch-cli.js +17 -0
  40. package/dist/cli/framework-update-cli.d.ts +2 -0
  41. package/dist/cli/framework-update-cli.js +40 -0
  42. package/dist/cli/release-assets-plan-cli.d.ts +2 -0
  43. package/dist/cli/release-assets-plan-cli.js +14 -0
  44. package/dist/cli/release-cut-cli.d.ts +2 -0
  45. package/dist/cli/release-cut-cli.js +27 -0
  46. package/dist/cli/release-descriptor-staging-cli.d.ts +2 -0
  47. package/dist/cli/release-descriptor-staging-cli.js +45 -0
  48. package/dist/cli/release-finalize-cli.d.ts +1 -0
  49. package/dist/cli/release-finalize-cli.js +30 -0
  50. package/dist/cli/release-promote-cli.d.ts +2 -0
  51. package/dist/cli/release-promote-cli.js +32 -0
  52. package/dist/cli/release-publish-cli.d.ts +2 -0
  53. package/dist/cli/release-publish-cli.js +48 -0
  54. package/dist/cli/release-sign-cli.d.ts +2 -0
  55. package/dist/cli/release-sign-cli.js +13 -0
  56. package/dist/cli/release-step-cli.d.ts +2 -0
  57. package/dist/cli/release-step-cli.js +44 -0
  58. package/dist/cli/toolchain-identity-cli.d.ts +2 -0
  59. package/dist/cli/toolchain-identity-cli.js +10 -0
  60. package/dist/cli/update-helper-cli.d.ts +1 -0
  61. package/dist/cli/update-helper-cli.js +10 -0
  62. package/dist/cli/windows-runtime-patch-cli.d.ts +2 -0
  63. package/dist/cli/windows-runtime-patch-cli.js +17 -0
  64. package/dist/desktop/application-command-client.d.ts +15 -0
  65. package/dist/desktop/application-command-client.js +21 -0
  66. package/dist/desktop/channel-handshake.d.ts +32 -0
  67. package/dist/desktop/channel-handshake.js +111 -0
  68. package/dist/desktop/channel-proof.d.ts +43 -0
  69. package/dist/desktop/channel-proof.js +85 -0
  70. package/dist/desktop/client-assets.d.ts +7 -0
  71. package/dist/desktop/client-assets.js +59 -0
  72. package/dist/desktop/desktop-client.d.ts +23 -0
  73. package/dist/desktop/desktop-client.js +231 -0
  74. package/dist/desktop/desktop-gateway.d.ts +18 -0
  75. package/dist/desktop/desktop-gateway.js +146 -0
  76. package/dist/desktop/desktop-host.d.ts +48 -0
  77. package/dist/desktop/desktop-host.js +208 -0
  78. package/dist/desktop/desktop-stream.d.ts +36 -0
  79. package/dist/desktop/desktop-stream.js +231 -0
  80. package/dist/desktop/loopback-policy.d.ts +19 -0
  81. package/dist/desktop/loopback-policy.js +23 -0
  82. package/dist/desktop/open-url-channel.d.ts +15 -0
  83. package/dist/desktop/open-url-channel.js +55 -0
  84. package/dist/desktop/string-policy.d.ts +2 -0
  85. package/dist/desktop/string-policy.js +11 -0
  86. package/dist/framework-source.json +1 -0
  87. package/dist/installer/archive-entry.d.ts +6 -0
  88. package/dist/installer/archive-entry.js +14 -0
  89. package/dist/installer/command-artifact.d.ts +47 -0
  90. package/dist/installer/command-artifact.js +261 -0
  91. package/dist/installer/command-qualification-command.d.ts +12 -0
  92. package/dist/installer/command-qualification-command.js +71 -0
  93. package/dist/installer/hosted-runner.d.ts +4 -0
  94. package/dist/installer/hosted-runner.js +10 -0
  95. package/dist/installer/installed-payload.d.ts +29 -0
  96. package/dist/installer/installed-payload.js +312 -0
  97. package/dist/installer/installer-ci-bootstrap.d.ts +26 -0
  98. package/dist/installer/installer-ci-bootstrap.js +160 -0
  99. package/dist/installer/installer-ci-preflight.d.ts +1 -0
  100. package/dist/installer/installer-ci-preflight.js +49 -0
  101. package/dist/installer/installer-ci-worker.d.ts +1 -0
  102. package/dist/installer/installer-ci-worker.js +105 -0
  103. package/dist/installer/installer-extraction.d.ts +14 -0
  104. package/dist/installer/installer-extraction.js +289 -0
  105. package/dist/installer/installer-fetch-guard.d.ts +15 -0
  106. package/dist/installer/installer-fetch-guard.js +50 -0
  107. package/dist/installer/installer-identity.d.ts +23 -0
  108. package/dist/installer/installer-identity.js +286 -0
  109. package/dist/installer/installer-layout.d.ts +21 -0
  110. package/dist/installer/installer-layout.js +89 -0
  111. package/dist/installer/installer-observation.d.ts +64 -0
  112. package/dist/installer/installer-observation.js +473 -0
  113. package/dist/installer/installer-process-cleanup.d.ts +18 -0
  114. package/dist/installer/installer-process-cleanup.js +158 -0
  115. package/dist/installer/installer-qualification-command.d.ts +11 -0
  116. package/dist/installer/installer-qualification-command.js +71 -0
  117. package/dist/installer/installer-renderer-evidence.d.ts +43 -0
  118. package/dist/installer/installer-renderer-evidence.js +136 -0
  119. package/dist/installer/installer-upgrade-command.d.ts +37 -0
  120. package/dist/installer/installer-upgrade-command.js +172 -0
  121. package/dist/installer/installer-worker-guard.d.ts +21 -0
  122. package/dist/installer/installer-worker-guard.js +72 -0
  123. package/dist/installer/native-executable.d.ts +5 -0
  124. package/dist/installer/native-executable.js +21 -0
  125. package/dist/installer/upgrade-asset-download.d.ts +13 -0
  126. package/dist/installer/upgrade-asset-download.js +41 -0
  127. package/dist/installer/write-all.d.ts +6 -0
  128. package/dist/installer/write-all.js +11 -0
  129. package/dist/native/app-bundle.d.ts +28 -0
  130. package/dist/native/app-bundle.js +60 -0
  131. package/dist/native/cef-helper.d.ts +28 -0
  132. package/dist/native/cef-helper.js +402 -0
  133. package/dist/native/desktop-build-hook.d.ts +7 -0
  134. package/dist/native/desktop-build-hook.js +20 -0
  135. package/dist/native/electrobun-source-patch.d.ts +25 -0
  136. package/dist/native/electrobun-source-patch.js +93 -0
  137. package/dist/native/linux-cef-links.d.ts +2 -0
  138. package/dist/native/linux-cef-links.js +15 -0
  139. package/dist/native/native-secret-store.d.ts +27 -0
  140. package/dist/native/native-secret-store.js +70 -0
  141. package/dist/native/native-utilities.d.ts +24 -0
  142. package/dist/native/native-utilities.js +85 -0
  143. package/dist/native/partitioned-window.d.ts +34 -0
  144. package/dist/native/partitioned-window.js +44 -0
  145. package/dist/native/renderer-profile.d.ts +53 -0
  146. package/dist/native/renderer-profile.js +30 -0
  147. package/dist/native/secure-window.d.ts +38 -0
  148. package/dist/native/secure-window.js +77 -0
  149. package/dist/native/sidecar-services.d.ts +23 -0
  150. package/dist/native/sidecar-services.js +46 -0
  151. package/dist/native/sidecar.d.ts +81 -0
  152. package/dist/native/sidecar.js +250 -0
  153. package/dist/native/window-bootstrap.d.ts +24 -0
  154. package/dist/native/window-bootstrap.js +63 -0
  155. package/dist/native/window-options.d.ts +32 -0
  156. package/dist/native/window-options.js +23 -0
  157. package/dist/native/windows-build-hook-internal.d.ts +2 -0
  158. package/dist/native/windows-build-hook-internal.js +32 -0
  159. package/dist/native/windows-build-hook.d.ts +2 -0
  160. package/dist/native/windows-build-hook.js +12 -0
  161. package/dist/native/windows-runtime-patch-internal.d.ts +3 -0
  162. package/dist/native/windows-runtime-patch-internal.js +20 -0
  163. package/dist/native/windows-runtime-patch.d.ts +4 -0
  164. package/dist/native/windows-runtime-patch.js +12 -0
  165. package/dist/release/feed-release-cut.d.ts +23 -0
  166. package/dist/release/feed-release-cut.js +93 -0
  167. package/dist/release/feed-state.d.ts +25 -0
  168. package/dist/release/feed-state.js +81 -0
  169. package/dist/release/framework-package-publish.d.ts +21 -0
  170. package/dist/release/framework-package-publish.js +125 -0
  171. package/dist/release/framework-update.d.ts +30 -0
  172. package/dist/release/framework-update.js +139 -0
  173. package/dist/release/github-cli.d.ts +6 -0
  174. package/dist/release/github-cli.js +16 -0
  175. package/dist/release/github-release-assets.d.ts +3 -0
  176. package/dist/release/github-release-assets.js +24 -0
  177. package/dist/release/github-release-cut.d.ts +14 -0
  178. package/dist/release/github-release-cut.js +174 -0
  179. package/dist/release/github-release-lookup.d.ts +7 -0
  180. package/dist/release/github-release-lookup.js +29 -0
  181. package/dist/release/github-release-promotion.d.ts +10 -0
  182. package/dist/release/github-release-promotion.js +78 -0
  183. package/dist/release/github-release-provenance.d.ts +9 -0
  184. package/dist/release/github-release-provenance.js +27 -0
  185. package/dist/release/github-release-publisher.d.ts +9 -0
  186. package/dist/release/github-release-publisher.js +63 -0
  187. package/dist/release/github-release-qualification.d.ts +12 -0
  188. package/dist/release/github-release-qualification.js +80 -0
  189. package/dist/release/local-provenance.d.ts +24 -0
  190. package/dist/release/local-provenance.js +72 -0
  191. package/dist/release/local-release.d.ts +133 -0
  192. package/dist/release/local-release.js +387 -0
  193. package/dist/release/macos-dmg.d.ts +22 -0
  194. package/dist/release/macos-dmg.js +91 -0
  195. package/dist/release/release-artifact.d.ts +6 -0
  196. package/dist/release/release-artifact.js +38 -0
  197. package/dist/release/release-assets-plan.d.ts +14 -0
  198. package/dist/release/release-assets-plan.js +65 -0
  199. package/dist/release/release-config.d.ts +76 -0
  200. package/dist/release/release-config.js +180 -0
  201. package/dist/release/release-cut-command.d.ts +13 -0
  202. package/dist/release/release-cut-command.js +39 -0
  203. package/dist/release/release-cut.d.ts +54 -0
  204. package/dist/release/release-cut.js +76 -0
  205. package/dist/release/release-descriptor-staging.d.ts +34 -0
  206. package/dist/release/release-descriptor-staging.js +147 -0
  207. package/dist/release/release-finalize.d.ts +16 -0
  208. package/dist/release/release-finalize.js +104 -0
  209. package/dist/release/release-promotion-command.d.ts +12 -0
  210. package/dist/release/release-promotion-command.js +28 -0
  211. package/dist/release/release-promotion.d.ts +29 -0
  212. package/dist/release/release-promotion.js +57 -0
  213. package/dist/release/release-publication.d.ts +33 -0
  214. package/dist/release/release-publication.js +138 -0
  215. package/dist/release/release-publish-command.d.ts +7 -0
  216. package/dist/release/release-publish-command.js +91 -0
  217. package/dist/release/release-qualification.d.ts +106 -0
  218. package/dist/release/release-qualification.js +135 -0
  219. package/dist/release/release-staging.d.ts +9 -0
  220. package/dist/release/release-staging.js +61 -0
  221. package/dist/release/release-steps.d.ts +38 -0
  222. package/dist/release/release-steps.js +147 -0
  223. package/dist/release/retained-release-build.d.ts +19 -0
  224. package/dist/release/retained-release-build.js +122 -0
  225. package/dist/shell/app-shell.d.ts +61 -0
  226. package/dist/shell/app-shell.js +318 -0
  227. package/dist/shell/app-utilities.d.ts +122 -0
  228. package/dist/shell/app-utilities.js +334 -0
  229. package/dist/shell/application-menu-commands.d.ts +5 -0
  230. package/dist/shell/application-menu-commands.js +11 -0
  231. package/dist/shell/application-menu.d.ts +61 -0
  232. package/dist/shell/application-menu.js +208 -0
  233. package/dist/shell/help-shortcuts.d.ts +12 -0
  234. package/dist/shell/help-shortcuts.js +22 -0
  235. package/dist/shell/settings-sections.d.ts +31 -0
  236. package/dist/shell/settings-sections.js +50 -0
  237. package/dist/shell/shortcut-platform.d.ts +17 -0
  238. package/dist/shell/shortcut-platform.js +25 -0
  239. package/dist/update-helper.bundle.js +260 -0
  240. package/dist/updates/channel-update-manager.d.ts +46 -0
  241. package/dist/updates/channel-update-manager.js +114 -0
  242. package/dist/updates/desktop-updater.d.ts +104 -0
  243. package/dist/updates/desktop-updater.js +345 -0
  244. package/dist/updates/release-feed.d.ts +61 -0
  245. package/dist/updates/release-feed.js +111 -0
  246. package/dist/updates/release-location.d.ts +9 -0
  247. package/dist/updates/release-location.js +80 -0
  248. package/dist/updates/release-version.d.ts +12 -0
  249. package/dist/updates/release-version.js +43 -0
  250. package/dist/updates/signed-release.d.ts +63 -0
  251. package/dist/updates/signed-release.js +162 -0
  252. package/dist/updates/stable-file.d.ts +10 -0
  253. package/dist/updates/stable-file.js +22 -0
  254. package/dist/updates/update-adapter.d.ts +57 -0
  255. package/dist/updates/update-adapter.js +72 -0
  256. package/dist/updates/update-arm.d.ts +24 -0
  257. package/dist/updates/update-arm.js +95 -0
  258. package/dist/updates/update-channel-store.d.ts +8 -0
  259. package/dist/updates/update-channel-store.js +72 -0
  260. package/dist/updates/update-discovery.d.ts +13 -0
  261. package/dist/updates/update-discovery.js +56 -0
  262. package/dist/updates/update-download.d.ts +14 -0
  263. package/dist/updates/update-download.js +67 -0
  264. package/dist/updates/update-exclusive-rename.d.ts +2 -0
  265. package/dist/updates/update-exclusive-rename.js +52 -0
  266. package/dist/updates/update-extraction.d.ts +18 -0
  267. package/dist/updates/update-extraction.js +183 -0
  268. package/dist/updates/update-handoff-plan.d.ts +22 -0
  269. package/dist/updates/update-handoff-plan.js +28 -0
  270. package/dist/updates/update-helper.d.ts +24 -0
  271. package/dist/updates/update-helper.js +56 -0
  272. package/dist/updates/update-launch.d.ts +5 -0
  273. package/dist/updates/update-launch.js +27 -0
  274. package/dist/updates/update-manager.d.ts +40 -0
  275. package/dist/updates/update-manager.js +83 -0
  276. package/dist/updates/update-process-fence.d.ts +10 -0
  277. package/dist/updates/update-process-fence.js +114 -0
  278. package/dist/updates/update-resume.d.ts +13 -0
  279. package/dist/updates/update-resume.js +34 -0
  280. package/dist/updates/update-shutdown.d.ts +15 -0
  281. package/dist/updates/update-shutdown.js +29 -0
  282. package/dist/updates/update-state.d.ts +30 -0
  283. package/dist/updates/update-state.js +18 -0
  284. package/dist/updates/update-swap-stage.d.ts +27 -0
  285. package/dist/updates/update-swap-stage.js +58 -0
  286. package/dist/updates/update-swap.d.ts +10 -0
  287. package/dist/updates/update-swap.js +30 -0
  288. package/dist/views/app-about.d.ts +22 -0
  289. package/dist/views/app-about.js +43 -0
  290. package/dist/views/app-appearance.d.ts +11 -0
  291. package/dist/views/app-appearance.js +42 -0
  292. package/dist/views/app-help.d.ts +17 -0
  293. package/dist/views/app-help.js +42 -0
  294. package/dist/views/app-settings.d.ts +26 -0
  295. package/dist/views/app-settings.js +97 -0
  296. package/dist/views/appearance-surface.d.ts +9 -0
  297. package/dist/views/appearance-surface.js +334 -0
  298. package/dist/views/update-surface.d.ts +34 -0
  299. package/dist/views/update-surface.js +64 -0
  300. package/package.json +363 -4
  301. package/src/app/application.tsx +138 -0
  302. package/src/app/create-application.ts +245 -0
  303. package/src/app/service-registry.ts +124 -0
  304. package/src/appearance/appearance-host.tsx +205 -0
  305. package/src/appearance/appearance-preferences.ts +287 -0
  306. package/src/appearance/composition.ts +29 -0
  307. package/src/appearance/custom-theme-import.ts +424 -0
  308. package/src/appearance/custom-theme-library.ts +600 -0
  309. package/src/appearance/editor.ts +94 -0
  310. package/src/appearance/theme-file-importer.ts +103 -0
  311. package/src/appearance/theme-record-adapter.ts +106 -0
  312. package/src/appearance/theme-registry.ts +20 -0
  313. package/src/appearance/window-surface.ts +18 -0
  314. package/src/ci/toolchain-identity.ts +244 -0
  315. package/src/cli/cef-helper-cli.ts +21 -0
  316. package/src/cli/cli-runner.ts +29 -0
  317. package/src/cli/create-application-cli.ts +62 -0
  318. package/src/cli/electrobun-shortcut-patch-cli.ts +24 -0
  319. package/src/cli/framework-update-cli.ts +41 -0
  320. package/src/cli/release-assets-plan-cli.ts +14 -0
  321. package/src/cli/release-cut-cli.ts +41 -0
  322. package/src/cli/release-descriptor-staging-cli.ts +57 -0
  323. package/src/cli/release-finalize-cli.ts +34 -0
  324. package/src/cli/release-promote-cli.ts +31 -0
  325. package/src/cli/release-publish-cli.ts +46 -0
  326. package/src/cli/release-sign-cli.ts +24 -0
  327. package/src/cli/release-step-cli.ts +71 -0
  328. package/src/cli/toolchain-identity-cli.ts +12 -0
  329. package/src/cli/update-helper-cli.ts +12 -0
  330. package/src/cli/windows-runtime-patch-cli.ts +17 -0
  331. package/src/desktop/application-command-client.ts +43 -0
  332. package/src/desktop/channel-handshake.ts +136 -0
  333. package/src/desktop/channel-proof.ts +122 -0
  334. package/src/desktop/client-assets.ts +75 -0
  335. package/src/desktop/desktop-client.ts +303 -0
  336. package/src/desktop/desktop-gateway.ts +189 -0
  337. package/src/desktop/desktop-host.ts +335 -0
  338. package/src/desktop/desktop-stream.ts +324 -0
  339. package/src/desktop/loopback-policy.ts +41 -0
  340. package/src/desktop/open-url-channel.ts +79 -0
  341. package/src/desktop/string-policy.ts +9 -0
  342. package/src/installer/archive-entry.ts +32 -0
  343. package/src/installer/command-artifact.ts +307 -0
  344. package/src/installer/command-qualification-command.ts +75 -0
  345. package/src/installer/hosted-runner.ts +11 -0
  346. package/src/installer/installed-payload.ts +408 -0
  347. package/src/installer/installer-ci-bootstrap.ts +199 -0
  348. package/src/installer/installer-ci-preflight.ts +61 -0
  349. package/src/installer/installer-ci-worker.ts +105 -0
  350. package/src/installer/installer-extraction.ts +367 -0
  351. package/src/installer/installer-fetch-guard.ts +75 -0
  352. package/src/installer/installer-identity.ts +331 -0
  353. package/src/installer/installer-layout.ts +167 -0
  354. package/src/installer/installer-observation.ts +671 -0
  355. package/src/installer/installer-process-cleanup.ts +167 -0
  356. package/src/installer/installer-qualification-command.ts +81 -0
  357. package/src/installer/installer-renderer-evidence.ts +268 -0
  358. package/src/installer/installer-upgrade-command.ts +226 -0
  359. package/src/installer/installer-worker-guard.ts +112 -0
  360. package/src/installer/native-executable.ts +37 -0
  361. package/src/installer/upgrade-asset-download.ts +72 -0
  362. package/src/installer/write-all.ts +19 -0
  363. package/src/native/app-bundle.ts +86 -0
  364. package/src/native/cef-helper.ts +471 -0
  365. package/src/native/desktop-build-hook.ts +21 -0
  366. package/src/native/electrobun-cef-main-frame-bridges.patch +63 -0
  367. package/src/native/electrobun-source-patch.ts +107 -0
  368. package/src/native/electrobun-windows-shortcut-com.patch +923 -0
  369. package/src/native/linux-cef-links.ts +14 -0
  370. package/src/native/native-secret-store.ts +99 -0
  371. package/src/native/native-utilities.ts +166 -0
  372. package/src/native/partitioned-window.ts +62 -0
  373. package/src/native/renderer-profile.ts +27 -0
  374. package/src/native/secure-window.ts +115 -0
  375. package/src/native/sidecar-services.ts +71 -0
  376. package/src/native/sidecar.ts +387 -0
  377. package/src/native/window-bootstrap.ts +77 -0
  378. package/src/native/window-options.ts +24 -0
  379. package/src/native/windows-build-hook-internal.ts +49 -0
  380. package/src/native/windows-build-hook.ts +12 -0
  381. package/src/native/windows-runtime-patch-internal.ts +48 -0
  382. package/src/native/windows-runtime-patch.ts +15 -0
  383. package/src/release/feed-release-cut.ts +110 -0
  384. package/src/release/feed-state.ts +135 -0
  385. package/src/release/framework-package-publish.ts +163 -0
  386. package/src/release/framework-update.ts +196 -0
  387. package/src/release/github-cli.ts +27 -0
  388. package/src/release/github-release-assets.ts +36 -0
  389. package/src/release/github-release-cut.ts +237 -0
  390. package/src/release/github-release-lookup.ts +39 -0
  391. package/src/release/github-release-promotion.ts +112 -0
  392. package/src/release/github-release-provenance.ts +65 -0
  393. package/src/release/github-release-publisher.ts +90 -0
  394. package/src/release/github-release-qualification.ts +144 -0
  395. package/src/release/local-provenance.ts +92 -0
  396. package/src/release/local-release.ts +525 -0
  397. package/src/release/macos-dmg.ts +113 -0
  398. package/src/release/release-artifact.ts +53 -0
  399. package/src/release/release-assets-plan.ts +118 -0
  400. package/src/release/release-config.ts +420 -0
  401. package/src/release/release-cut-command.ts +80 -0
  402. package/src/release/release-cut.ts +133 -0
  403. package/src/release/release-descriptor-staging.ts +242 -0
  404. package/src/release/release-finalize.ts +191 -0
  405. package/src/release/release-promotion-command.ts +36 -0
  406. package/src/release/release-promotion.ts +132 -0
  407. package/src/release/release-publication.ts +213 -0
  408. package/src/release/release-publish-command.ts +163 -0
  409. package/src/release/release-qualification.ts +397 -0
  410. package/src/release/release-staging.ts +87 -0
  411. package/src/release/release-steps.ts +173 -0
  412. package/src/release/retained-release-build.ts +217 -0
  413. package/src/shell/app-shell.tsx +285 -0
  414. package/src/shell/app-utilities.tsx +437 -0
  415. package/src/shell/application-menu-commands.ts +6 -0
  416. package/src/shell/application-menu.ts +250 -0
  417. package/src/shell/help-shortcuts.ts +24 -0
  418. package/src/shell/settings-sections.ts +74 -0
  419. package/src/shell/shortcut-platform.ts +35 -0
  420. package/src/updates/channel-update-manager.ts +127 -0
  421. package/src/updates/desktop-updater.ts +440 -0
  422. package/src/updates/release-feed.ts +187 -0
  423. package/src/updates/release-location.ts +101 -0
  424. package/src/updates/release-version.ts +57 -0
  425. package/src/updates/signed-release.ts +311 -0
  426. package/src/updates/stable-file.ts +32 -0
  427. package/src/updates/update-adapter.ts +129 -0
  428. package/src/updates/update-arm.ts +107 -0
  429. package/src/updates/update-channel-store.ts +86 -0
  430. package/src/updates/update-discovery.ts +113 -0
  431. package/src/updates/update-download.ts +82 -0
  432. package/src/updates/update-exclusive-rename.ts +58 -0
  433. package/src/updates/update-extraction.ts +261 -0
  434. package/src/updates/update-handoff-plan.ts +75 -0
  435. package/src/updates/update-helper.ts +87 -0
  436. package/src/updates/update-launch.ts +33 -0
  437. package/src/updates/update-manager.ts +130 -0
  438. package/src/updates/update-process-fence.ts +125 -0
  439. package/src/updates/update-resume.ts +34 -0
  440. package/src/updates/update-shutdown.ts +37 -0
  441. package/src/updates/update-state.ts +34 -0
  442. package/src/updates/update-swap-stage.ts +75 -0
  443. package/src/updates/update-swap.ts +30 -0
  444. package/src/views/app-about.tsx +44 -0
  445. package/src/views/app-appearance.tsx +32 -0
  446. package/src/views/app-help.tsx +43 -0
  447. package/src/views/app-settings.tsx +88 -0
  448. package/src/views/appearance-surface.tsx +427 -0
  449. package/src/views/update-surface.tsx +85 -0
  450. package/templates/application/.gitattributes +1 -0
  451. package/templates/application/.github/workflows/release-assets.yml +29 -0
  452. package/templates/application/.github/workflows/release-finalize.yml +29 -0
  453. package/templates/application/.github/workflows/release-please.yml +19 -0
  454. package/templates/application/.github/workflows/release.yml +29 -0
  455. package/templates/application/.github/workflows/validation.yml +28 -0
  456. package/templates/application/.oxfmtrc.json +6 -0
  457. package/templates/application/.oxlintrc.json +48 -0
  458. package/templates/application/.release-please-manifest.json +3 -0
  459. package/templates/application/README.md +47 -0
  460. package/templates/application/electrobun.config.ts +22 -0
  461. package/templates/application/release-please-config.json +12 -0
  462. package/templates/application/scripts/app-version.ts +9 -0
  463. package/templates/application/scripts/build-desktop.ts +34 -0
  464. package/templates/application/scripts/secure-build.ts +1 -0
  465. package/templates/application/scripts/stage-release.ts +21 -0
  466. package/templates/application/src/bun/index.ts +80 -0
  467. package/templates/application/src/electrobun.d.ts +27 -0
  468. package/templates/application/src/web/index.html +12 -0
  469. package/templates/application/src/web/main.tsx +97 -0
  470. package/templates/application/src/web/public/icon.svg +1 -0
  471. package/templates/application/src/web/style.css +3 -0
  472. package/templates/application/tests/app-config.test.ts +9 -0
  473. package/templates/application/tsconfig.json +15 -0
  474. package/templates/application/vite.config.ts +10 -0
@@ -0,0 +1,24 @@
1
+ import type { HelpLink, HelpShortcut } from '@adea-ai/ui/components/composites/help-center'
2
+ import { platformModifierKey } from '@adea-ai/ui/components/ui/kbd'
3
+ import { shortcutModifierKey, type ShortcutPlatform } from './shortcut-platform'
4
+
5
+ export type { HelpLink, HelpShortcut }
6
+
7
+ /** Shortcuts the framework binds itself, drawn with the running platform's modifier. */
8
+ export function standardShortcuts(options: {
9
+ search?: boolean
10
+ settings?: boolean
11
+ /** A navigator-style platform string; ignored when `shortcutPlatform` is supplied. */
12
+ platform?: string
13
+ shortcutPlatform?: ShortcutPlatform
14
+ }): HelpShortcut[] {
15
+ const mod = options.shortcutPlatform
16
+ ? shortcutModifierKey(options.shortcutPlatform)
17
+ : platformModifierKey(options.platform)
18
+ return [
19
+ ...(options.search ? [{ label: 'Open search', keys: [mod, 'K'] }] : []),
20
+ ...(options.settings ? [{ label: 'Open settings', keys: [mod, ','] }] : []),
21
+ { label: 'Close panels and dialogs', keys: ['Esc'] },
22
+ ]
23
+ }
24
+ export * from './shortcut-platform'
@@ -0,0 +1,74 @@
1
+ import type { JSX } from 'solid-js'
2
+
3
+ /** One settings destination. The framework owns layout and navigation; the app owns the panel. */
4
+ export type ApplicationSettingsSection = Readonly<{
5
+ id: string
6
+ label: string
7
+ /** Visible group heading; sections sharing a group are listed together in order. */
8
+ group: string
9
+ icon?: JSX.Element
10
+ description?: string
11
+ render(): JSX.Element
12
+ }>
13
+
14
+ const sectionId = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/
15
+ const hashPrefix = '#settings'
16
+
17
+ /** Validate section identifiers, labels and groups before the dialog mounts. */
18
+ export function defineSettingsSections(
19
+ sections: readonly ApplicationSettingsSection[]
20
+ ): readonly ApplicationSettingsSection[] {
21
+ if (sections.length === 0) throw new Error('At least one settings section is required')
22
+ const ids = new Set<string>()
23
+ return Object.freeze(
24
+ sections.map((section) => {
25
+ if (
26
+ !sectionId.test(section.id) ||
27
+ !section.label.trim() ||
28
+ !section.group.trim() ||
29
+ typeof section.render !== 'function' ||
30
+ ids.has(section.id)
31
+ )
32
+ throw new Error('Settings section identifiers, labels and groups must be valid and unique')
33
+ ids.add(section.id)
34
+ return Object.freeze({ ...section })
35
+ })
36
+ )
37
+ }
38
+
39
+ /** The canonical deep link for a settings section. */
40
+ export function settingsHash(id: string): string {
41
+ return `${hashPrefix}/${id}`
42
+ }
43
+
44
+ /** Whether a location hash addresses the settings surface. */
45
+ export function isSettingsHash(hash: string): boolean {
46
+ return hash === hashPrefix || hash.startsWith(`${hashPrefix}/`)
47
+ }
48
+
49
+ /**
50
+ * The section a `#settings/<id>` hash addresses. When it names no known section, the
51
+ * known `fallback` section, or else the first section.
52
+ */
53
+ export function settingsSectionFromHash(
54
+ hash: string,
55
+ sections: readonly Pick<ApplicationSettingsSection, 'id'>[],
56
+ fallback?: string
57
+ ): string | undefined {
58
+ if (!isSettingsHash(hash)) return undefined
59
+ const known = (id: string | undefined) => sections.some((section) => section.id === id)
60
+ const candidate = hash.slice(hashPrefix.length + 1)
61
+ if (known(candidate)) return candidate
62
+ return known(fallback) ? fallback : sections[0]?.id
63
+ }
64
+
65
+ /** Group sections in first-appearance order for the shared settings navigation. */
66
+ export function settingsGroups(sections: readonly ApplicationSettingsSection[]) {
67
+ const groups = new Map<string, { value: string; label: string; icon?: JSX.Element }[]>()
68
+ for (const section of sections) {
69
+ const items = groups.get(section.group) ?? []
70
+ items.push({ value: section.id, label: section.label, icon: section.icon })
71
+ groups.set(section.group, items)
72
+ }
73
+ return [...groups].map(([label, items]) => ({ label, items }))
74
+ }
@@ -0,0 +1,35 @@
1
+ /** Which modifier family the running OS uses for chords: ⌘ on Apple platforms, Ctrl elsewhere. */
2
+ export type ShortcutPlatform = 'mac' | 'other'
3
+
4
+ const applePlatform = /Mac|iPhone|iPad|iPod/i
5
+
6
+ /** The shortcut platform the browser reports; `other` where there is no navigator. */
7
+ export function detectShortcutPlatform(): ShortcutPlatform {
8
+ return typeof navigator !== 'undefined' && applePlatform.test(navigator.platform)
9
+ ? 'mac'
10
+ : 'other'
11
+ }
12
+
13
+ /**
14
+ * The shortcut platform for an application identity. An explicit `shortcutPlatform`
15
+ * wins; a `platform` label that names an Apple OS keeps its earlier meaning; any other
16
+ * label (`desktop`, `web`, a product name) defers to the browser.
17
+ */
18
+ export function resolveShortcutPlatform(identity: {
19
+ platform?: string
20
+ shortcutPlatform?: ShortcutPlatform
21
+ }): ShortcutPlatform {
22
+ if (identity.shortcutPlatform) return identity.shortcutPlatform
23
+ if (identity.platform && applePlatform.test(identity.platform)) return 'mac'
24
+ return detectShortcutPlatform()
25
+ }
26
+
27
+ /** The modifier glyph drawn for a shortcut platform. */
28
+ export function shortcutModifierKey(platform: ShortcutPlatform): '⌘' | 'Ctrl' {
29
+ return platform === 'mac' ? '⌘' : 'Ctrl'
30
+ }
31
+
32
+ /** The settings chord as a menu row draws it: `⌘,` or `Ctrl+,`. */
33
+ export function settingsShortcutLabel(platform: ShortcutPlatform): string {
34
+ return platform === 'mac' ? '⌘,' : 'Ctrl+,'
35
+ }
@@ -0,0 +1,127 @@
1
+ import { createUpdateManager } from './update-manager'
2
+ import { isUpdateChannel, type UpdateChannel } from './release-version'
3
+ import { releaseChannelForUpdate } from './update-channel-store'
4
+ import type { ReleaseTrust } from './signed-release'
5
+ import type { FetchFunction } from './release-location'
6
+
7
+ type ManagerOptions = Parameters<typeof createUpdateManager>[0]
8
+ type State = ReturnType<ReturnType<typeof createUpdateManager>['status']>
9
+ /** Re-read the persisted channel for every check and bind an approval to that choice. */
10
+ export function createChannelUpdateManager(options: {
11
+ store: { read(): Promise<UpdateChannel>; save(channel: UpdateChannel): Promise<UpdateChannel> }
12
+ trust: Omit<ReleaseTrust, 'channel'>
13
+ discoveryNames: Record<UpdateChannel, string>
14
+ currentVersion: string
15
+ directory: string
16
+ maxBytes: number
17
+ stage: ManagerOptions['stage']
18
+ discover?: ManagerOptions['discover']
19
+ download?: ManagerOptions['download']
20
+ fetch?: FetchFunction
21
+ }) {
22
+ let busy = false,
23
+ active: { channel: UpdateChannel; manager: ReturnType<typeof createUpdateManager> } | undefined
24
+ let state: State = Object.freeze({
25
+ phase: 'idle',
26
+ currentVersion: options.currentVersion,
27
+ availableVersion: null,
28
+ error: null,
29
+ })
30
+ const acquire = () => {
31
+ if (busy) throw new Error('Update manager is busy')
32
+ busy = true
33
+ }
34
+ const idle = () =>
35
+ (state = Object.freeze({
36
+ phase: 'idle',
37
+ currentVersion: options.currentVersion,
38
+ availableVersion: null,
39
+ error: null,
40
+ }))
41
+ const failed = () =>
42
+ (state = Object.freeze({
43
+ phase: 'failed',
44
+ currentVersion: options.currentVersion,
45
+ availableVersion: null,
46
+ error: 'Update check failed. Please try again.',
47
+ }))
48
+ const status = () => active?.manager.status() ?? state
49
+ return {
50
+ status,
51
+ readChannel: () => options.store.read(),
52
+ async saveChannel(channel: UpdateChannel) {
53
+ if (!isUpdateChannel(channel)) throw new Error('Invalid update channel')
54
+ acquire()
55
+ try {
56
+ if (status().phase === 'staged') throw new Error('An update is already staged')
57
+ const saved = await options.store.save(channel)
58
+ if (saved !== channel) throw new Error('Update channel was not saved')
59
+ active = undefined
60
+ idle()
61
+ return saved
62
+ } finally {
63
+ busy = false
64
+ }
65
+ },
66
+ async check() {
67
+ acquire()
68
+ try {
69
+ if (status().phase === 'staged') throw new Error('An update is already staged')
70
+ active = undefined
71
+ state = Object.freeze({
72
+ phase: 'checking',
73
+ currentVersion: options.currentVersion,
74
+ availableVersion: null,
75
+ error: null,
76
+ })
77
+ try {
78
+ const channel = await options.store.read()
79
+ if (!isUpdateChannel(channel)) throw new Error('Invalid update channel')
80
+ const manager = createUpdateManager({
81
+ currentVersion: options.currentVersion,
82
+ trust: { ...options.trust, channel: releaseChannelForUpdate(channel) },
83
+ discoveryName: options.discoveryNames[channel],
84
+ directory: options.directory,
85
+ maxBytes: options.maxBytes,
86
+ discover: options.discover,
87
+ download: options.download,
88
+ fetch: options.fetch,
89
+ stage: async (input) => {
90
+ if ((await options.store.read()) !== channel)
91
+ throw new Error('Update channel changed')
92
+ await options.stage(input)
93
+ if ((await options.store.read()) !== channel)
94
+ throw new Error('Update channel changed')
95
+ },
96
+ })
97
+ active = { channel, manager }
98
+ state = await manager.check()
99
+ if ((await options.store.read()) !== channel) {
100
+ active = undefined
101
+ return failed()
102
+ }
103
+ return state
104
+ } catch {
105
+ active = undefined
106
+ return failed()
107
+ }
108
+ } finally {
109
+ busy = false
110
+ }
111
+ },
112
+ async install(input: { approved: boolean; expectedVersion: string }) {
113
+ acquire()
114
+ try {
115
+ if (!active || (await options.store.read()) !== active.channel) {
116
+ active = undefined
117
+ idle()
118
+ throw new Error('Update channel changed')
119
+ }
120
+ state = await active.manager.install(input)
121
+ return state
122
+ } finally {
123
+ busy = false
124
+ }
125
+ },
126
+ }
127
+ }
@@ -0,0 +1,440 @@
1
+ /**
2
+ * The desktop host's signed updater, the same for every framework app: the
3
+ * channel the user picked, discovery of that channel's signed descriptor for
4
+ * this platform, verified download, a staged swap beside the install and the
5
+ * post-exit helper that swaps it in and relaunches. `resumeUpdate` reports and
6
+ * cleans up after a helper on the next start.
7
+ *
8
+ * `registerUpdateServices` serves it as the `desktop_update_*` services that
9
+ * the web client's update adapter drives.
10
+ */
11
+ import { mkdir, realpath, rm } from 'node:fs/promises'
12
+ import { join, resolve } from 'node:path'
13
+ import { ServiceError, type createServiceRegistry } from '../app/service-registry'
14
+ import type { InstallerPlatform, InstallerRenderer } from '../installer/installer-layout'
15
+ import { createChannelUpdateManager } from './channel-update-manager'
16
+ import { isUpdateChannel, type UpdateChannel } from './release-version'
17
+ import { feedUrl, parseReleaseFeed } from './release-feed'
18
+ import type { ReleaseTrust } from './signed-release'
19
+ import type { UpdateState } from './update-adapter'
20
+ import { createUpdateChannelStore } from './update-channel-store'
21
+ import { armUpdateHelper } from './update-arm'
22
+ import { resumeUpdate } from './update-resume'
23
+ import { scheduleUpdateShutdown } from './update-shutdown'
24
+ import { stageUpdateSwap } from './update-swap-stage'
25
+ import type { NativeUpdateState } from './update-state'
26
+
27
+ /** Largest signed archive accepted for download. */
28
+ const MAX_DOWNLOAD_BYTES = 1024 * 1024 * 1024
29
+ /** Largest tree an archive may expand to. */
30
+ const MAX_EXPANDED_BYTES = 4 * 1024 * 1024 * 1024
31
+ /** Lets the install reply reach the window before the app quits. */
32
+ const QUIT_DELAY_MS = 250
33
+
34
+ export type DesktopUpdatePhase = UpdateState['phase']
35
+ /** The snapshot every update service returns. */
36
+ export type DesktopUpdateStatus = NativeUpdateState<DesktopUpdatePhase>
37
+
38
+ type Manager = Pick<
39
+ ReturnType<typeof createChannelUpdateManager>,
40
+ 'status' | 'readChannel' | 'saveChannel' | 'check' | 'install'
41
+ >
42
+ type ManagerPhase = ReturnType<Manager['status']>['phase']
43
+
44
+ /** The release identity an app's release-config.json declares. */
45
+ export type DesktopRelease = {
46
+ appId: string
47
+ appName: string
48
+ releaseSigningKeys: Readonly<Record<string, string>>
49
+ /** Where releases are published: `{ base: 'https://adea.dev/releases/', app: 'adea' }`. */
50
+ releaseFeed: Readonly<{ base: string; app: string }>
51
+ sidecars?: readonly string[]
52
+ }
53
+
54
+ /** The release platform this host runs on, or null where framework apps ship no build. */
55
+ export function updatePlatform(
56
+ platform: string = process.platform,
57
+ arch: string = process.arch
58
+ ): InstallerPlatform | null {
59
+ if (platform === 'darwin' && arch === 'arm64') return 'macos-arm64'
60
+ if (platform === 'win32' && arch === 'x64') return 'windows-x64'
61
+ if (platform === 'linux' && arch === 'x64') return 'linux-x64'
62
+ return null
63
+ }
64
+
65
+ /**
66
+ * The installed app tree the swap replaces: the `.app` bundle on macOS, the
67
+ * app directory elsewhere. The host entry runs from `Resources/app/bun`.
68
+ */
69
+ export function installTarget(entryDirectory: string, platform: InstallerPlatform): string {
70
+ return resolve(
71
+ entryDirectory,
72
+ ...(platform === 'macos-arm64' ? ['..', '..', '..', '..'] : ['..', '..', '..'])
73
+ )
74
+ }
75
+
76
+ /** Each channel's signed descriptor for `platform`, as the release workflows publish them. */
77
+ export function discoveryNames(platform: InstallerPlatform): Record<UpdateChannel, string> {
78
+ return {
79
+ stable: `stable-${platform}.json`,
80
+ 'pre-release': `daily-${platform}.json`,
81
+ dev: `dev-${platform}.json`,
82
+ }
83
+ }
84
+
85
+ /**
86
+ * What a descriptor must match: this app, repository and platform, signed by a
87
+ * configured key. Null until a key is configured, so such a build reports
88
+ * updates as unavailable instead of failing.
89
+ */
90
+ export function updateTrust(
91
+ platform: InstallerPlatform,
92
+ identity: {
93
+ appId: string
94
+ repository: string
95
+ feed: string
96
+ keys: Readonly<Record<string, string>>
97
+ }
98
+ ): Omit<ReleaseTrust, 'channel'> | null {
99
+ const entries = Object.entries(identity.keys)
100
+ if (entries.length === 0) return null
101
+ const [os, arch] = {
102
+ 'macos-arm64': ['darwin', 'arm64'],
103
+ 'windows-x64': ['win32', 'x64'],
104
+ 'linux-x64': ['linux', 'x64'],
105
+ }[platform] as [ReleaseTrust['platform'], ReleaseTrust['arch']]
106
+ return {
107
+ appId: identity.appId,
108
+ repository: identity.repository,
109
+ platform: os,
110
+ arch,
111
+ feed: identity.feed,
112
+ keys: new Map(entries),
113
+ }
114
+ }
115
+
116
+ const PHASES: Readonly<Record<ManagerPhase, DesktopUpdatePhase>> = {
117
+ idle: 'idle',
118
+ checking: 'checking',
119
+ current: 'current',
120
+ available: 'available',
121
+ downloading: 'downloading',
122
+ staging: 'installing',
123
+ staged: 'installed',
124
+ failed: 'failed',
125
+ }
126
+
127
+ export type UpdateInstallRequest = { expectedVersion: string; approved: boolean; restart?: boolean }
128
+
129
+ export type UpdaterOptions = {
130
+ appName: string
131
+ repository: string
132
+ currentVersion: string
133
+ changelog?: string
134
+ /** Null where updates cannot apply: an unsupported platform or no trusted key. */
135
+ manager: Manager | null
136
+ /** A status read while idle starts the one check, so a badge needs no second checker. */
137
+ checkWhenIdle?: boolean
138
+ /** Hand off to the post-exit helper and quit, after a staged install the user asked to restart. */
139
+ restart(version: string): Promise<void>
140
+ /** Aborts the download in flight. */
141
+ abortDownload?(): void
142
+ }
143
+
144
+ /** The update commands over a framework channel update manager. */
145
+ export function createUpdater(options: UpdaterOptions) {
146
+ const { manager, currentVersion } = options
147
+ const releases = `https://github.com/${options.repository}/releases`
148
+ let cancelRequested = false
149
+ let lastTag: string | null = null
150
+ // One check at a time.
151
+ let inFlight: Promise<DesktopUpdateStatus> | null = null
152
+ const snapshot = (): DesktopUpdateStatus => {
153
+ const state = manager?.status()
154
+ const available = state?.availableVersion ?? null
155
+ if (available) lastTag = `v${available}`
156
+ // An aborted download fails in the manager; report it as cancelled.
157
+ const phase: DesktopUpdatePhase = !state
158
+ ? 'unavailable'
159
+ : cancelRequested && state.phase === 'downloading'
160
+ ? 'cancelling'
161
+ : cancelRequested && state.phase === 'failed'
162
+ ? 'cancelled'
163
+ : PHASES[state.phase]
164
+ return {
165
+ current_version: currentVersion,
166
+ available_version: available,
167
+ release_date: null,
168
+ release_notes: null,
169
+ changelog: options.changelog ?? '',
170
+ github_url: lastTag ? `${releases}/tag/${lastTag}` : releases,
171
+ phase,
172
+ downloaded_bytes: 0,
173
+ total_bytes: null,
174
+ error: phase === 'cancelled' ? null : (state?.error ?? null),
175
+ restart_required: state?.phase === 'staged',
176
+ }
177
+ }
178
+ const active = (): Manager => {
179
+ if (!manager)
180
+ throw new ServiceError(
181
+ 'unsupported',
182
+ `Signed updates are not available for this ${options.appName} build`
183
+ )
184
+ return manager
185
+ }
186
+ const check = async (): Promise<DesktopUpdateStatus> => {
187
+ if (!manager) return snapshot()
188
+ cancelRequested = false
189
+ inFlight ??= manager
190
+ .check()
191
+ .then(snapshot)
192
+ .finally(() => {
193
+ inFlight = null
194
+ })
195
+ return inFlight
196
+ }
197
+ return {
198
+ async status(): Promise<DesktopUpdateStatus> {
199
+ if (options.checkWhenIdle && manager?.status().phase === 'idle') return check()
200
+ return inFlight ?? snapshot()
201
+ },
202
+ check,
203
+ async channel(): Promise<UpdateChannel> {
204
+ return manager ? manager.readChannel() : 'stable'
205
+ },
206
+ async saveChannel(channel: UpdateChannel): Promise<UpdateChannel> {
207
+ return active().saveChannel(channel)
208
+ },
209
+ async install(request: UpdateInstallRequest): Promise<DesktopUpdateStatus> {
210
+ const updates = active()
211
+ if (!request.approved)
212
+ throw new ServiceError('command_failed', 'update installation requires explicit approval')
213
+ cancelRequested = false
214
+ const state = await updates.install({
215
+ approved: true,
216
+ expectedVersion: request.expectedVersion,
217
+ })
218
+ if (state.phase === 'staged' && request.restart !== false && state.availableVersion)
219
+ await options.restart(state.availableVersion)
220
+ return snapshot()
221
+ },
222
+ async cancel(): Promise<DesktopUpdateStatus> {
223
+ // Only a download can stop; staging and a staged update finish.
224
+ if (manager?.status().phase === 'downloading' && options.abortDownload) {
225
+ cancelRequested = true
226
+ options.abortDownload()
227
+ }
228
+ return snapshot()
229
+ },
230
+ }
231
+ }
232
+
233
+ export type DesktopUpdater = ReturnType<typeof createUpdater>
234
+
235
+ /**
236
+ * The updater for the packaged app at `entryDirectory`. Clears downloads left
237
+ * by an earlier run and reports what an earlier helper did.
238
+ */
239
+ export async function createDesktopUpdater(options: {
240
+ release: DesktopRelease
241
+ repository: string
242
+ renderer: InstallerRenderer
243
+ entryDirectory: string
244
+ dataDirectory: string
245
+ /** Where the chosen channel is kept; the data directory unless given. */
246
+ stateDirectory?: string
247
+ currentVersion: string
248
+ changelog?: string
249
+ /** The shipped update helper, relative to `Resources/app`. */
250
+ helperScript: string
251
+ checkWhenIdle?: boolean
252
+ quit(): void
253
+ log(line: string): void
254
+ }): Promise<DesktopUpdater> {
255
+ const { release } = options
256
+ const platform = updatePlatform()
257
+ const trust =
258
+ platform &&
259
+ updateTrust(platform, {
260
+ appId: release.appId,
261
+ repository: options.repository,
262
+ feed: feedUrl(parseReleaseFeed(release.releaseFeed)),
263
+ keys: release.releaseSigningKeys,
264
+ })
265
+ let controller = new AbortController()
266
+ const updater = {
267
+ appName: release.appName,
268
+ repository: options.repository,
269
+ currentVersion: options.currentVersion,
270
+ changelog: options.changelog,
271
+ checkWhenIdle: options.checkWhenIdle,
272
+ abortDownload() {
273
+ controller.abort()
274
+ controller = new AbortController()
275
+ },
276
+ }
277
+ if (!platform || !trust)
278
+ return createUpdater({ ...updater, manager: null, restart: async () => {} })
279
+ const target = installTarget(options.entryDirectory, platform)
280
+ const resumed = await resumeUpdate({ target }).catch((error: unknown) => {
281
+ options.log(`update resume failed: ${String(error)}`)
282
+ return null
283
+ })
284
+ if (resumed?.status === 'updated') options.log(`updated to ${release.appName} ${resumed.version}`)
285
+ const state = options.stateDirectory ?? options.dataDirectory
286
+ await mkdir(state, { recursive: true, mode: 0o700 })
287
+ const downloads = join(options.dataDirectory, 'updates')
288
+ await rm(downloads, { recursive: true, force: true })
289
+ await mkdir(downloads, { recursive: true, mode: 0o700 })
290
+ const manager = createChannelUpdateManager({
291
+ store: createUpdateChannelStore(await realpath(state)),
292
+ trust,
293
+ discoveryNames: discoveryNames(platform),
294
+ currentVersion: options.currentVersion,
295
+ directory: await realpath(downloads),
296
+ maxBytes: MAX_DOWNLOAD_BYTES,
297
+ fetch: (input, init) =>
298
+ fetch(input, {
299
+ ...init,
300
+ signal: init?.signal
301
+ ? AbortSignal.any([init.signal, controller.signal])
302
+ : controller.signal,
303
+ }),
304
+ async stage({ descriptor, path, directory }) {
305
+ try {
306
+ await stageUpdateSwap({
307
+ descriptor,
308
+ trust: { ...trust, channel: descriptor.channel },
309
+ currentVersion: options.currentVersion,
310
+ approved: true,
311
+ approvedVersion: descriptor.version,
312
+ target,
313
+ appName: release.appName,
314
+ platform,
315
+ renderer: options.renderer,
316
+ archive: path,
317
+ maxCompressedBytes: MAX_DOWNLOAD_BYTES,
318
+ maxExpandedBytes: MAX_EXPANDED_BYTES,
319
+ ...(release.sidecars ? { sidecars: release.sidecars } : {}),
320
+ })
321
+ } finally {
322
+ await rm(directory, { recursive: true, force: true })
323
+ }
324
+ },
325
+ })
326
+ return createUpdater({
327
+ ...updater,
328
+ manager,
329
+ async restart(version) {
330
+ await scheduleUpdateShutdown({
331
+ reserve: () => ({}),
332
+ cancelReservation: () => {},
333
+ arm: () =>
334
+ armUpdateHelper({
335
+ target,
336
+ platform,
337
+ version,
338
+ helperScript: join(options.entryDirectory, '..', options.helperScript),
339
+ }),
340
+ quit: () => {
341
+ setTimeout(options.quit, QUIT_DELAY_MS)
342
+ return true
343
+ },
344
+ })
345
+ },
346
+ })
347
+ }
348
+
349
+ type Services<Principal> = ReturnType<typeof createServiceRegistry<Principal>>
350
+
351
+ function record(value: unknown, keys: readonly string[]): Record<string, unknown> {
352
+ if (
353
+ typeof value !== 'object' ||
354
+ value === null ||
355
+ Array.isArray(value) ||
356
+ Object.keys(value).some((key) => !keys.includes(key))
357
+ )
358
+ throw new Error('Invalid input')
359
+ return value as Record<string, unknown>
360
+ }
361
+
362
+ function parseNone(value: unknown): null {
363
+ if (value !== undefined && value !== null) record(value, [])
364
+ return null
365
+ }
366
+
367
+ /** The `desktop_update_channel_save` argument. */
368
+ export function parseUpdateChannel(value: unknown): UpdateChannel {
369
+ const { channel } = record(value, ['channel'])
370
+ if (!isUpdateChannel(channel)) throw new Error('Invalid input')
371
+ return channel
372
+ }
373
+
374
+ /** The `desktop_update_install` argument. */
375
+ export function parseUpdateInstall(value: unknown): UpdateInstallRequest {
376
+ const { expectedVersion, approved, restart } = record(value, [
377
+ 'expectedVersion',
378
+ 'approved',
379
+ 'restart',
380
+ ])
381
+ if (
382
+ typeof expectedVersion !== 'string' ||
383
+ expectedVersion.length > 64 ||
384
+ typeof approved !== 'boolean' ||
385
+ (restart !== undefined && typeof restart !== 'boolean')
386
+ )
387
+ throw new Error('Invalid input')
388
+ return { expectedVersion, approved, ...(restart === undefined ? {} : { restart }) }
389
+ }
390
+
391
+ /** Pass a service error through; give any other failure the update error code. */
392
+ function failure(error: unknown): never {
393
+ if (error instanceof ServiceError) throw error
394
+ throw new ServiceError('update_failed', error instanceof Error ? error.message : String(error))
395
+ }
396
+
397
+ /** Register the `desktop_update_*` services the web client's update adapter calls. */
398
+ export function registerUpdateServices<Principal>(options: {
399
+ services: Services<Principal>
400
+ updater: DesktopUpdater
401
+ authorize(principal: Principal): boolean
402
+ }): () => void {
403
+ const { services, updater } = options
404
+ const authorize = (principal: Principal) => options.authorize(principal)
405
+ const unregister = [
406
+ services.register('desktop_update_status', {
407
+ parse: parseNone,
408
+ authorize,
409
+ run: () => updater.status().catch(failure),
410
+ }),
411
+ services.register('desktop_update_channel', {
412
+ parse: parseNone,
413
+ authorize,
414
+ run: () => updater.channel().catch(failure),
415
+ }),
416
+ services.register('desktop_update_channel_save', {
417
+ parse: parseUpdateChannel,
418
+ authorize,
419
+ run: (_principal, channel) => updater.saveChannel(channel).catch(failure),
420
+ }),
421
+ services.register('desktop_update_check', {
422
+ parse: parseNone,
423
+ authorize,
424
+ run: () => updater.check().catch(failure),
425
+ }),
426
+ services.register('desktop_update_install', {
427
+ parse: parseUpdateInstall,
428
+ authorize,
429
+ run: (_principal, request) => updater.install(request).catch(failure),
430
+ }),
431
+ services.register('desktop_update_cancel', {
432
+ parse: parseNone,
433
+ authorize,
434
+ run: () => updater.cancel(),
435
+ }),
436
+ ]
437
+ return () => {
438
+ for (const remove of unregister) remove()
439
+ }
440
+ }