@gloom-sh/terminal 0.19.5 → 0.20.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 (318) hide show
  1. package/LICENSE +0 -4
  2. package/package.json +6 -5
  3. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  4. package/patches/electrobun-devkit@2.0.5.patch +148 -0
  5. package/src/api-client/bond-trades.ts +59 -0
  6. package/src/api-client/data.ts +21 -0
  7. package/src/api-client/equity-screener.ts +23 -0
  8. package/src/api-client/index.ts +2 -0
  9. package/src/api-client/types/account.ts +86 -0
  10. package/src/api-client/types/assist.ts +32 -0
  11. package/src/api-client/types/auth.ts +63 -0
  12. package/src/api-client/types/billing.ts +54 -0
  13. package/src/api-client/types/chat.ts +180 -0
  14. package/src/api-client/types/congress.ts +107 -0
  15. package/src/api-client/types/credit.ts +110 -0
  16. package/src/api-client/types/econ.ts +158 -0
  17. package/src/api-client/types/equity-diagnostic.ts +73 -0
  18. package/src/api-client/types/filings-and-calls.ts +350 -0
  19. package/src/api-client/types/index.ts +25 -0
  20. package/src/api-client/types/jobs.ts +147 -0
  21. package/src/api-client/types/market.ts +122 -0
  22. package/src/api-client/types/news.ts +91 -0
  23. package/src/api-client/types/notes-and-theses.ts +172 -0
  24. package/src/api-client/types/quotes.ts +28 -0
  25. package/src/api-client/types/scanners.ts +125 -0
  26. package/src/api-client/types/screener.ts +65 -0
  27. package/src/api-client/types/search.ts +107 -0
  28. package/src/api-client/types/sync.ts +14 -0
  29. package/src/api-client/types/team-collections.ts +43 -0
  30. package/src/api-client/types/team-views.ts +32 -0
  31. package/src/api-client/types/teams.ts +135 -0
  32. package/src/api-client/types/ticker-data.ts +57 -0
  33. package/src/api-client/types/tweets.ts +59 -0
  34. package/src/api-client/types/world-venues.ts +23 -0
  35. package/src/app/pane-runtime/index.tsx +2 -0
  36. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  37. package/src/app/runtime/desktop-deeplink.ts +41 -6
  38. package/src/app/star-prompt/status-line.tsx +1 -1
  39. package/src/app.tsx +64 -23
  40. package/src/architecture/ui-tokens-allowlist.json +0 -8
  41. package/src/cli/commands/market.ts +149 -10
  42. package/src/cli/commands/search.ts +21 -3
  43. package/src/cli/commands/ticker.ts +90 -36
  44. package/src/cli/desktop-pane-shot-browser.ts +69 -3
  45. package/src/cli/glossary.ts +3 -3
  46. package/src/cli/known-gaps.ts +8 -0
  47. package/src/cli/listing-arg.ts +12 -0
  48. package/src/cli/pane-functions/capabilities.ts +2 -0
  49. package/src/cli/pane-functions/catalog.ts +25 -5
  50. package/src/cli/pane-functions/function-help.ts +8 -5
  51. package/src/cli/pane-functions/headless.ts +4 -3
  52. package/src/cli/pane-functions/resolver.ts +75 -2
  53. package/src/cli/quote-answer.ts +9 -0
  54. package/src/cli/symbol-list.ts +54 -2
  55. package/src/cli/symbol-rows.ts +14 -2
  56. package/src/cli/ticker-resolution.ts +89 -20
  57. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  58. package/src/components/chart/composite/composite-chart.tsx +118 -63
  59. package/src/components/chart/composite/cursor-source.ts +111 -0
  60. package/src/components/chart/composite/format.ts +168 -6
  61. package/src/components/chart/composite/legend.tsx +8 -4
  62. package/src/components/chart/composite/panel-labels.ts +20 -1
  63. package/src/components/chart/composite/panel-surface.tsx +201 -92
  64. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  65. package/src/components/chart/composite/price-series.ts +31 -8
  66. package/src/components/chart/composite/scene.ts +154 -59
  67. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  68. package/src/components/chart/composite/time-axis.ts +13 -5
  69. package/src/components/chart/composite/time-scale.ts +211 -56
  70. package/src/components/chart/composite/types.ts +11 -1
  71. package/src/components/chart/composite/use-composite-chart-keyboard.ts +43 -14
  72. package/src/components/chart/curve/curve-surface.tsx +5 -2
  73. package/src/components/chart/curve/model.ts +4 -1
  74. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  75. package/src/components/chart/static/series.ts +3 -0
  76. package/src/components/command-bar/commands/collection-list.ts +81 -0
  77. package/src/components/command-bar/commands/direct/index.ts +6 -0
  78. package/src/components/command-bar/commands/registry.ts +8 -0
  79. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  80. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  81. package/src/components/command-bar/pane-templates/items.ts +19 -3
  82. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  83. package/src/components/command-bar/routes/root/results.ts +23 -3
  84. package/src/components/command-bar/routes/root/selection.ts +4 -2
  85. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  86. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  87. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  88. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  89. package/src/components/command-bar/surface/environment.ts +2 -0
  90. package/src/components/command-bar/view-model.ts +7 -0
  91. package/src/components/command-bar/workflow/ops.ts +2 -1
  92. package/src/components/command-bar/workflow/tickers.ts +20 -0
  93. package/src/components/data-table/export.ts +4 -1
  94. package/src/components/layout/detached-pane-shell.tsx +10 -37
  95. package/src/components/layout/double-escape-close.ts +90 -0
  96. package/src/components/layout/header.tsx +3 -2
  97. package/src/components/layout/market-summary.ts +6 -3
  98. package/src/components/layout/pane/footer/index.tsx +2 -6
  99. package/src/components/layout/pane/footer/model.ts +6 -12
  100. package/src/components/layout/shell/active-drag.ts +53 -11
  101. package/src/components/layout/shell/drag/magnets.ts +128 -19
  102. package/src/components/layout/shell/menu.ts +15 -1
  103. package/src/components/layout/shell/pane/actions.ts +10 -2
  104. package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
  105. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  106. package/src/components/layout/status-bar.tsx +24 -78
  107. package/src/components/layout/status-widget-space.ts +5 -5
  108. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  109. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  110. package/src/components/onboarding/portfolio-step/positions-panel.tsx +9 -6
  111. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  112. package/src/components/price-sparkline/view.tsx +14 -6
  113. package/src/components/ticker/badge/index.tsx +8 -4
  114. package/src/components/ticker/badge/list.tsx +23 -7
  115. package/src/components/ui/column-grid.tsx +8 -2
  116. package/src/components/ui/data-table/index.tsx +5 -1
  117. package/src/components/ui/data-table/opentui/model.ts +4 -1
  118. package/src/components/ui/data-table/render-cell.ts +19 -0
  119. package/src/components/ui/delayed-mark.tsx +59 -7
  120. package/src/components/ui/icon.tsx +1 -8
  121. package/src/components/ui/menu.tsx +6 -1
  122. package/src/components/ui/tabs.tsx +5 -2
  123. package/src/core/state/app/layout.ts +18 -3
  124. package/src/core/state/app/state.ts +2 -0
  125. package/src/core/state/app/types.ts +5 -0
  126. package/src/data/config/layout.ts +3 -0
  127. package/src/data/config/store/normalize.ts +39 -4
  128. package/src/i18n/es.ts +13 -3
  129. package/src/i18n/ja.ts +13 -3
  130. package/src/i18n/ko.ts +13 -3
  131. package/src/i18n/zh-cn.ts +13 -3
  132. package/src/i18n/zh-tw.ts +13 -3
  133. package/src/layout/pane-manager/floating-placement.ts +7 -4
  134. package/src/layout/pane-manager/floating.ts +5 -2
  135. package/src/market-data/bond-funds.ts +19 -0
  136. package/src/market-data/futures-contract.ts +14 -3
  137. package/src/market-data/market/freshness.ts +18 -0
  138. package/src/market-data/market/status.ts +15 -2
  139. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  140. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  141. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  142. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  143. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  144. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  145. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  146. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  147. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  148. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  149. package/src/plugins/builtin/buildout/format.ts +23 -1
  150. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  151. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  152. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  153. package/src/plugins/builtin/cds/headless.ts +1 -0
  154. package/src/plugins/builtin/cds/index.tsx +1 -1
  155. package/src/plugins/builtin/chat/content/composer.tsx +21 -27
  156. package/src/plugins/builtin/chat/content/index.tsx +31 -3
  157. package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
  158. package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
  159. package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
  160. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  161. package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
  162. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +44 -12
  163. package/src/plugins/builtin/congress-trades/model.ts +2 -1
  164. package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
  165. package/src/plugins/builtin/correlation/headless.ts +3 -2
  166. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  167. package/src/plugins/builtin/custom-view/index.tsx +1 -1
  168. package/src/plugins/builtin/custom-view/loader.ts +85 -8
  169. package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
  170. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  171. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  172. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  173. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  174. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  175. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  176. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +16 -19
  177. package/src/plugins/builtin/equity-screener/headless.ts +37 -3
  178. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  179. package/src/plugins/builtin/equity-screener/model.ts +238 -27
  180. package/src/plugins/builtin/equity-screener/pane.tsx +88 -18
  181. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  182. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  183. package/src/plugins/builtin/executives/format.ts +5 -4
  184. package/src/plugins/builtin/executives/pane.tsx +1 -1
  185. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  186. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  187. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  188. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  189. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  190. package/src/plugins/builtin/help/index.tsx +55 -1
  191. package/src/plugins/builtin/insider/model.ts +30 -2
  192. package/src/plugins/builtin/jobs/model.ts +2 -2
  193. package/src/plugins/builtin/macro-day/client.ts +41 -0
  194. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  195. package/src/plugins/builtin/macro-day/model.ts +3 -1
  196. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  197. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  198. package/src/plugins/builtin/mna/model.ts +2 -2
  199. package/src/plugins/builtin/notes/files.ts +2 -0
  200. package/src/plugins/builtin/notes/owner.tsx +20 -1
  201. package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
  202. package/src/plugins/builtin/notes/store.ts +6 -1
  203. package/src/plugins/builtin/perps/pane.tsx +3 -1
  204. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  205. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  206. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
  208. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  209. package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
  210. package/src/plugins/builtin/research/event-model.ts +10 -3
  211. package/src/plugins/builtin/research/events-headless.ts +20 -2
  212. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  213. package/src/plugins/builtin/sec/index.tsx +1 -1
  214. package/src/plugins/builtin/series-inventory.ts +1 -0
  215. package/src/plugins/builtin/shared/earnings-report.ts +7 -2
  216. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  217. package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
  218. package/src/plugins/builtin/short-interest/headless.ts +1 -1
  219. package/src/plugins/builtin/short-interest/model.ts +15 -6
  220. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  221. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  222. package/src/plugins/builtin/short-interest/types.ts +2 -0
  223. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  224. package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
  225. package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
  226. package/src/plugins/builtin/ticker-detail/overview/model.ts +5 -3
  227. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
  228. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  229. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  230. package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
  231. package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
  232. package/src/plugins/builtin/trace-bonds/history.ts +155 -0
  233. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  234. package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
  235. package/src/plugins/builtin/volatility/client.ts +6 -1
  236. package/src/plugins/builtin/volatility/headless.ts +0 -1
  237. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  238. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  239. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  240. package/src/plugins/host-modules.ts +22 -3
  241. package/src/plugins/host-smoke.ts +6 -3
  242. package/src/plugins/installer.ts +16 -3
  243. package/src/plugins/plugin-names.ts +11 -2
  244. package/src/portfolio/collection-name.ts +19 -0
  245. package/src/remote/controller.ts +9 -2
  246. package/src/remote/schema.ts +2 -1
  247. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  248. package/src/renderers/cloudflare/http-proxy.ts +73 -3
  249. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  250. package/src/renderers/cloudflare/worker.ts +44 -4
  251. package/src/renderers/desktop/geometry.ts +279 -0
  252. package/src/renderers/desktop/screen-setup.ts +246 -0
  253. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  254. package/src/renderers/desktop/test-utils.ts +71 -0
  255. package/src/renderers/desktop/window-controller.ts +433 -0
  256. package/src/renderers/desktop/window-host.ts +70 -0
  257. package/src/renderers/desktop/window-layouts.ts +630 -0
  258. package/src/renderers/dom/data-frames.ts +15 -4
  259. package/src/renderers/dom/desktop/icons.tsx +0 -2
  260. package/src/renderers/dom/styles.css +0 -3
  261. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  262. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  263. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  264. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  265. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  266. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  267. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  268. package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
  269. package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
  270. package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
  271. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  272. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  273. package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
  274. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  275. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  276. package/src/renderers/electrobun/bun/index.ts +22 -109
  277. package/src/renderers/electrobun/bun/window/create.ts +23 -3
  278. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  279. package/src/renderers/electrobun/bun/window/events.ts +4 -4
  280. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  281. package/src/renderers/electrobun/bun/window/frame.ts +2 -1
  282. package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
  283. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  284. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  285. package/src/renderers/electrobun/view/backend-rpc.ts +16 -1
  286. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  287. package/src/renderers/electrobun/view/main.tsx +13 -7
  288. package/src/series/fred-argument.ts +17 -0
  289. package/src/sources/gloomberb-cloud/index.ts +5 -7
  290. package/src/sources/provider-router/batches.ts +18 -3
  291. package/src/sources/provider-router/financial-routes.ts +7 -1
  292. package/src/sources/provider-router/financials.ts +18 -4
  293. package/src/state/app/context/index.tsx +16 -2
  294. package/src/state/desktop-windows.ts +63 -0
  295. package/src/sync/other-window-tabs.ts +62 -0
  296. package/src/tickers/company-name-listing.ts +23 -3
  297. package/src/tickers/listing-fate.ts +147 -1
  298. package/src/tickers/terminal-codes.ts +5 -0
  299. package/src/time-series/types.ts +6 -0
  300. package/src/types/config.ts +10 -1
  301. package/src/types/data-provider.ts +14 -0
  302. package/src/types/desktop-window.ts +71 -2
  303. package/src/types/financials.ts +19 -3
  304. package/src/types/headless.ts +21 -0
  305. package/src/types/plugin.ts +6 -0
  306. package/src/ui/index.tsx +14 -13
  307. package/src/ui/same-props.ts +58 -0
  308. package/src/utils/cli-output.ts +33 -4
  309. package/src/utils/double-escape-close.ts +38 -16
  310. package/src/utils/format.ts +30 -5
  311. package/src/utils/futures-generic.ts +12 -0
  312. package/src/utils/http-proxy-upstream.ts +6 -2
  313. package/src/utils/plugin-proxy-hosts.json +0 -4
  314. package/src/utils/plugin-proxy-hosts.ts +22 -0
  315. package/src/utils/price-earnings.ts +18 -0
  316. package/src/utils/sec-filings.ts +7 -1
  317. package/patches/electrobun@1.18.1.patch +0 -633
  318. package/src/api-client/types.ts +0 -2441
@@ -0,0 +1,322 @@
1
+ import { cc, dlopen, FFIType, type Pointer } from "bun:ffi";
2
+ import { mkdtempSync, rmSync, writeFileSync } from "fs";
3
+ import { tmpdir } from "os";
4
+ import { join } from "path";
5
+ import { logFailure } from "../../../../utils/log-failure";
6
+ import { cString, objcOrNull } from "../desktop/macos-objc";
7
+ import type { WindowMinimumSize } from "./frame";
8
+
9
+ /**
10
+ * Electrobun has no minimum window size (2.0.5 neither), so the app shrank
11
+ * under it at every resize and jumped back once the resize event came. Here
12
+ * each system holds the window to it while it is being resized:
13
+ *
14
+ * - macOS: `NSWindow.contentMinSize`.
15
+ * - Windows: the window's `WM_GETMINMAXINFO` answer, by a window procedure
16
+ * placed before Electrobun's that raises its minimum tracking size to this
17
+ * one, at the window's DPI.
18
+ * - Linux: GTK's geometry hints, which the window manager reads.
19
+ *
20
+ * The app's code runs on a thread of its own, not the one the windows belong
21
+ * to, so each change is handed to that thread: AppKit's
22
+ * `performSelectorOnMainThread:`, GLib's main loop. A Windows window procedure
23
+ * runs on the window's thread and has to answer there and then, which is why
24
+ * Windows and Linux use a few lines of C compiled at runtime (Bun's `cc`).
25
+ *
26
+ * The snap back in events.ts stays as the fallback for a system where this
27
+ * does not apply.
28
+ */
29
+
30
+ /** The C the Windows window procedure is made of. Pointer-sized integers are `long long`: `long` is 32-bit there. */
31
+ const WINDOWS_SOURCE = String.raw`
32
+ typedef long long sptr;
33
+ typedef unsigned long long uptr;
34
+ typedef void *HWND;
35
+ typedef sptr (*WNDPROC)(HWND, unsigned int, uptr, sptr);
36
+ typedef struct { int x; int y; } Pt;
37
+ typedef struct { Pt reserved; Pt max_size; Pt max_position; Pt min_track; Pt max_track; } MinMaxInfo;
38
+
39
+ #define WM_GETMINMAXINFO 0x0024
40
+ #define WM_NCDESTROY 0x0082
41
+ #define GWLP_WNDPROC (-4)
42
+ #define SLOTS 64
43
+
44
+ typedef struct { HWND volatile hwnd; WNDPROC volatile previous; int volatile width; int volatile height; } Slot;
45
+
46
+ static Slot slots[SLOTS];
47
+ static sptr (*call_window_proc)(WNDPROC, HWND, unsigned int, uptr, sptr);
48
+ static sptr (*get_window_long_ptr)(HWND, int);
49
+ static sptr (*set_window_long_ptr)(HWND, int, sptr);
50
+ static sptr (*def_window_proc)(HWND, unsigned int, uptr, sptr);
51
+ static unsigned int (*get_dpi_for_window)(HWND);
52
+
53
+ static Slot *slot_of(HWND hwnd) {
54
+ for (int i = 0; i < SLOTS; i++) if (slots[i].hwnd == hwnd) return &slots[i];
55
+ return 0;
56
+ }
57
+
58
+ static sptr min_size_proc(HWND hwnd, unsigned int message, uptr wparam, sptr lparam) {
59
+ Slot *slot = slot_of(hwnd);
60
+ WNDPROC previous = slot ? slot->previous : 0;
61
+ if (!previous) return def_window_proc(hwnd, message, wparam, lparam);
62
+ if (message == WM_NCDESTROY) {
63
+ set_window_long_ptr(hwnd, GWLP_WNDPROC, (sptr)previous);
64
+ slot->hwnd = 0;
65
+ return call_window_proc(previous, hwnd, message, wparam, lparam);
66
+ }
67
+ sptr result = call_window_proc(previous, hwnd, message, wparam, lparam);
68
+ if (message == WM_GETMINMAXINFO && lparam) {
69
+ MinMaxInfo *info = (MinMaxInfo *)lparam;
70
+ int dpi = get_dpi_for_window ? (int)get_dpi_for_window(hwnd) : 0;
71
+ if (dpi <= 0) dpi = 96;
72
+ int width = (slot->width * dpi + 48) / 96;
73
+ int height = (slot->height * dpi + 48) / 96;
74
+ if (info->min_track.x < width) info->min_track.x = width;
75
+ if (info->min_track.y < height) info->min_track.y = height;
76
+ }
77
+ return result;
78
+ }
79
+
80
+ int gloom_min_size_init(void *call, void *get_long, void *set_long, void *def, void *dpi) {
81
+ call_window_proc = (sptr (*)(WNDPROC, HWND, unsigned int, uptr, sptr))call;
82
+ get_window_long_ptr = (sptr (*)(HWND, int))get_long;
83
+ set_window_long_ptr = (sptr (*)(HWND, int, sptr))set_long;
84
+ def_window_proc = (sptr (*)(HWND, unsigned int, uptr, sptr))def;
85
+ get_dpi_for_window = (unsigned int (*)(HWND))dpi;
86
+ return call && get_long && set_long && def;
87
+ }
88
+
89
+ /* 1 when the window had a minimum already and now has this one, 2 when it is newly held to it, 0 when it cannot be. */
90
+ int gloom_min_size_set(HWND hwnd, int width, int height) {
91
+ Slot *slot = slot_of(hwnd);
92
+ if (slot) {
93
+ slot->width = width;
94
+ slot->height = height;
95
+ return 1;
96
+ }
97
+ for (int i = 0; i < SLOTS && !slot; i++) if (!slots[i].hwnd) slot = &slots[i];
98
+ if (!slot) return 0;
99
+ sptr current = get_window_long_ptr(hwnd, GWLP_WNDPROC);
100
+ if (!current) return 0;
101
+ slot->width = width;
102
+ slot->height = height;
103
+ slot->previous = (WNDPROC)current;
104
+ /* Taken only once the procedure it hands on to is in place. */
105
+ slot->hwnd = hwnd;
106
+ sptr replaced = set_window_long_ptr(hwnd, GWLP_WNDPROC, (sptr)min_size_proc);
107
+ if (!replaced) {
108
+ slot->hwnd = 0;
109
+ return 0;
110
+ }
111
+ if (replaced != current) slot->previous = (WNDPROC)replaced;
112
+ return 2;
113
+ }
114
+ `;
115
+
116
+ /** The C that hands a GTK window's minimum size to GLib's main loop. */
117
+ const LINUX_SOURCE = String.raw`
118
+ typedef struct {
119
+ int min_width; int min_height; int max_width; int max_height;
120
+ int base_width; int base_height; int width_inc; int height_inc;
121
+ double min_aspect; double max_aspect; int win_gravity;
122
+ } Geometry;
123
+
124
+ #define GDK_HINT_MIN_SIZE 2
125
+ #define SLOTS 64
126
+
127
+ typedef struct { void *volatile window; Geometry geometry; } Request;
128
+
129
+ static Request requests[SLOTS];
130
+ static unsigned int next_request;
131
+ static unsigned int (*idle_add)(int (*)(void *), void *);
132
+ static void (*set_geometry_hints)(void *, void *, Geometry *, int);
133
+ static void *(*object_ref)(void *);
134
+ static void (*object_unref)(void *);
135
+
136
+ static int apply(void *data) {
137
+ Request *request = (Request *)data;
138
+ void *window = request->window;
139
+ if (window) {
140
+ set_geometry_hints(window, 0, &request->geometry, GDK_HINT_MIN_SIZE);
141
+ request->window = 0;
142
+ object_unref(window);
143
+ }
144
+ return 0;
145
+ }
146
+
147
+ int gloom_min_size_init(void *idle, void *hints, void *ref, void *unref) {
148
+ idle_add = (unsigned int (*)(int (*)(void *), void *))idle;
149
+ set_geometry_hints = (void (*)(void *, void *, Geometry *, int))hints;
150
+ object_ref = (void *(*)(void *))ref;
151
+ object_unref = (void (*)(void *))unref;
152
+ return idle && hints && ref && unref;
153
+ }
154
+
155
+ int gloom_min_size_set(void *window, int width, int height) {
156
+ Request *request = &requests[next_request++ % SLOTS];
157
+ if (request->window) return 0;
158
+ request->geometry.min_width = width;
159
+ request->geometry.min_height = height;
160
+ request->window = object_ref(window);
161
+ idle_add(apply, request);
162
+ return 2;
163
+ }
164
+ `;
165
+
166
+ const MIN_SIZE_SYMBOLS = {
167
+ gloom_min_size_set: { args: [FFIType.ptr, FFIType.i32, FFIType.i32], returns: FFIType.i32 },
168
+ } as const;
169
+
170
+ type MinSizeSetter = (window: Pointer, width: number, height: number) => number;
171
+
172
+ /** The compiled helper for this system, once; `null` when it could not be made. */
173
+ let compiledSetter: MinSizeSetter | null | undefined;
174
+ /** The compiled code, kept for good: a window procedure in it runs for as long as its window does. */
175
+ const compiledLibraries: unknown[] = [];
176
+
177
+ /**
178
+ * Hands `compile` a file holding `source`, in a folder this process just made
179
+ * for it alone (owner only, under a random name), never a shared name another
180
+ * user could have written first. `cc` reads the file only while it compiles,
181
+ * so the folder goes right after.
182
+ */
183
+ function fromPrivateSource<T>(source: string, compile: (path: string) => T): T {
184
+ const folder = mkdtempSync(join(tmpdir(), "gloom-native-min-size-"));
185
+ try {
186
+ const path = join(folder, "min-size.c");
187
+ writeFileSync(path, source, { flag: "wx", mode: 0o600 });
188
+ return compile(path);
189
+ } finally {
190
+ rmSync(folder, { recursive: true, force: true });
191
+ }
192
+ }
193
+
194
+ function windowsSetter(): MinSizeSetter | null {
195
+ const kernel32 = dlopen("kernel32.dll", {
196
+ GetModuleHandleW: { args: [FFIType.ptr], returns: FFIType.ptr },
197
+ GetProcAddress: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
198
+ }).symbols;
199
+ const user32 = kernel32.GetModuleHandleW(Buffer.from("user32.dll\0", "utf16le"));
200
+ if (!user32) return null;
201
+ const proc = (name: string) => kernel32.GetProcAddress(user32, cString(name));
202
+ const library = fromPrivateSource(WINDOWS_SOURCE, (source) => cc({
203
+ source,
204
+ symbols: {
205
+ ...MIN_SIZE_SYMBOLS,
206
+ gloom_min_size_init: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
207
+ },
208
+ }));
209
+ const ready = library.symbols.gloom_min_size_init(
210
+ proc("CallWindowProcW"),
211
+ proc("GetWindowLongPtrW"),
212
+ proc("SetWindowLongPtrW"),
213
+ proc("DefWindowProcW"),
214
+ proc("GetDpiForWindow"),
215
+ );
216
+ if (!ready) return null;
217
+ compiledLibraries.push(library);
218
+ return library.symbols.gloom_min_size_set;
219
+ }
220
+
221
+ /** The address of `name` in the already loaded library `file`, or null. */
222
+ function linuxSymbol(file: string, name: string): Pointer | null {
223
+ for (const libc of ["libc.so.6", "libdl.so.2"]) {
224
+ try {
225
+ const dl = dlopen(libc, {
226
+ dlopen: { args: [FFIType.ptr, FFIType.i32], returns: FFIType.ptr },
227
+ dlsym: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
228
+ }).symbols;
229
+ // RTLD_LAZY | RTLD_NOLOAD: the library GTK's windows already use, never a second one.
230
+ const handle = dl.dlopen(cString(file), 0x1 | 0x4);
231
+ return handle ? dl.dlsym(handle, cString(name)) : null;
232
+ } catch {
233
+ // No dlopen in this libc: glibc before 2.34 keeps it in libdl.
234
+ }
235
+ }
236
+ return null;
237
+ }
238
+
239
+ function linuxSetter(): MinSizeSetter | null {
240
+ const idleAdd = linuxSymbol("libglib-2.0.so.0", "g_idle_add");
241
+ const geometryHints = linuxSymbol("libgtk-3.so.0", "gtk_window_set_geometry_hints");
242
+ const ref = linuxSymbol("libgobject-2.0.so.0", "g_object_ref");
243
+ const unref = linuxSymbol("libgobject-2.0.so.0", "g_object_unref");
244
+ if (!idleAdd || !geometryHints || !ref || !unref) return null;
245
+ const library = fromPrivateSource(LINUX_SOURCE, (source) => cc({
246
+ source,
247
+ symbols: {
248
+ ...MIN_SIZE_SYMBOLS,
249
+ gloom_min_size_init: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
250
+ },
251
+ }));
252
+ if (!library.symbols.gloom_min_size_init(idleAdd, geometryHints, ref, unref)) return null;
253
+ compiledLibraries.push(library);
254
+ return library.symbols.gloom_min_size_set;
255
+ }
256
+
257
+ function compiledMinSizeSetter(platform: NodeJS.Platform): MinSizeSetter | null {
258
+ if (compiledSetter !== undefined) return compiledSetter;
259
+ try {
260
+ compiledSetter = platform === "win32" ? windowsSetter() : platform === "linux" ? linuxSetter() : null;
261
+ } catch (error) {
262
+ logFailure("desktop-window", "Could not make the native minimum window size")(error);
263
+ compiledSetter = null;
264
+ }
265
+ return compiledSetter;
266
+ }
267
+
268
+ /** Sets an NSWindow's `contentMinSize` on the main thread, through key-value coding, which takes the size boxed. */
269
+ function setMacosContentMinSize(window: Pointer, size: WindowMinimumSize): boolean {
270
+ const objc = objcOrNull();
271
+ if (!objc) return false;
272
+ return objc.withAutoreleasePool(() => {
273
+ const value = objc.sendDoubles(objc.getClass("NSValue"), objc.selector("valueWithSize:"), size.width, size.height);
274
+ const key = objc.sendCString(objc.getClass("NSString"), objc.selector("stringWithUTF8String:"), cString("contentMinSize"));
275
+ const values = objc.sendObjects(objc.getClass("NSDictionary"), objc.selector("dictionaryWithObject:forKey:"), value, key);
276
+ if (!values) return false;
277
+ // Retained by the call until it has run on the main thread.
278
+ objc.sendOnMainThread(
279
+ BigInt(window),
280
+ objc.selector("performSelectorOnMainThread:withObject:waitUntilDone:"),
281
+ objc.selector("setValuesForKeysWithDictionary:"),
282
+ values,
283
+ false,
284
+ );
285
+ return true;
286
+ });
287
+ }
288
+
289
+ /** Holds the native window `ptr` to `size` (in the window frame's points) while it is resized. Resolves whether it took. */
290
+ function setNativeMinimumSize(ptr: Pointer, size: WindowMinimumSize, platform: NodeJS.Platform = process.platform): boolean {
291
+ const width = Math.ceil(size.width);
292
+ const height = Math.ceil(size.height);
293
+ try {
294
+ if (platform === "darwin") return setMacosContentMinSize(ptr, { width, height });
295
+ const set = compiledMinSizeSetter(platform);
296
+ return set ? set(ptr, width, height) > 0 : false;
297
+ } catch (error) {
298
+ logFailure("desktop-window", "Could not set the native minimum window size")(error);
299
+ return false;
300
+ }
301
+ }
302
+
303
+ const HANDLE_ATTEMPTS = 20;
304
+ const HANDLE_RETRY_MS = 100;
305
+
306
+ /**
307
+ * `setNativeMinimumSize` for a window just opened, once its native window
308
+ * exists: Electrobun may make it after the constructor returns.
309
+ */
310
+ export function applyNativeMinimumSize(window: { ptr: Pointer | null }, size: WindowMinimumSize): void {
311
+ let attempts = 0;
312
+ const attempt = () => {
313
+ const handle = window.ptr;
314
+ if (handle) {
315
+ setNativeMinimumSize(handle, size);
316
+ return;
317
+ }
318
+ attempts += 1;
319
+ if (attempts < HANDLE_ATTEMPTS) setTimeout(attempt, HANDLE_RETRY_MS);
320
+ };
321
+ attempt();
322
+ }
@@ -1,12 +1,12 @@
1
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
1
+ import { readFileSync } from "fs";
2
2
  import { dirname, join } from "path";
3
3
  import { getGloomberbDirs } from "../../../../data/config/home";
4
4
  import type { WindowFrame } from "./frame";
5
5
 
6
6
  /**
7
- * The main window's last frame lives beside the config, not in it. Launch
8
- * reads it before config is loaded, and a frame is this machine's screen,
9
- * so it stays out of the synced config.
7
+ * Where builds before the window setup (desktop/screen-setup.ts) kept the
8
+ * main window's last frame. Read once, for the first launch after the
9
+ * update, when the setup has nothing for the main window yet.
10
10
  */
11
11
  const FILE_NAME = "desktop-window.json";
12
12
 
@@ -16,14 +16,6 @@ export interface RememberedDesktopWindow {
16
16
  fullscreen: boolean;
17
17
  }
18
18
 
19
- export interface DisplayWorkArea {
20
- x: number;
21
- y: number;
22
- width: number;
23
- height: number;
24
- primary?: boolean;
25
- }
26
-
27
19
  export function rememberedDesktopWindowPath(env: NodeJS.ProcessEnv = process.env): string {
28
20
  return join(dirname(getGloomberbDirs(env).configFile), FILE_NAME);
29
21
  }
@@ -50,73 +42,3 @@ export function readRememberedDesktopWindow(path: string): RememberedDesktopWind
50
42
  return null;
51
43
  }
52
44
  }
53
-
54
- export function writeRememberedDesktopWindow(path: string, value: RememberedDesktopWindow): void {
55
- mkdirSync(dirname(path), { recursive: true });
56
- const temporary = `${path}.${process.pid}.tmp`;
57
- writeFileSync(temporary, JSON.stringify(value));
58
- renameSync(temporary, path);
59
- }
60
-
61
- function overlapArea(frame: WindowFrame, display: DisplayWorkArea): number {
62
- const width = Math.min(frame.x + frame.width, display.x + display.width) - Math.max(frame.x, display.x);
63
- const height = Math.min(frame.y + frame.height, display.y + display.height) - Math.max(frame.y, display.y);
64
- return width > 0 && height > 0 ? width * height : 0;
65
- }
66
-
67
- function clamp(value: number, min: number, max: number): number {
68
- return Math.min(max, Math.max(min, value));
69
- }
70
-
71
- /**
72
- * Puts a saved frame on a connected display. A window that still intersects
73
- * one stays put. One left on a display that is gone moves onto the display
74
- * with the most overlap, or the primary display.
75
- */
76
- export function fitWindowFrameToDisplays(
77
- frame: WindowFrame,
78
- displays: readonly DisplayWorkArea[],
79
- ): WindowFrame {
80
- const usable = displays.filter((display) => display.width >= 1 && display.height >= 1);
81
- if (usable.length === 0) return frame;
82
- const centerX = frame.x + frame.width / 2;
83
- const centerY = frame.y + frame.height / 2;
84
- const containing = usable.find((display) => (
85
- centerX >= display.x && centerX < display.x + display.width
86
- && centerY >= display.y && centerY < display.y + display.height
87
- ));
88
- let display = containing;
89
- if (!display) {
90
- let best = usable[0]!;
91
- let bestArea = overlapArea(frame, best);
92
- for (const candidate of usable.slice(1)) {
93
- const area = overlapArea(frame, candidate);
94
- if (area > bestArea) {
95
- best = candidate;
96
- bestArea = area;
97
- }
98
- }
99
- display = bestArea > 0 ? best : usable.find((candidate) => candidate.primary) ?? usable[0]!;
100
- }
101
- const width = Math.min(frame.width, display.width);
102
- const height = Math.min(frame.height, display.height);
103
- // A window left on a display that is no longer connected comes back on the
104
- // one that remains, at that display's left edge, keeping its vertical place.
105
- if (overlapArea(frame, display) === 0) {
106
- const minY = display.y;
107
- const maxY = display.y + display.height - height;
108
- return { x: display.x, y: clamp(frame.y, minY, Math.max(minY, maxY)), width, height };
109
- }
110
- const marginX = Math.min(48, width);
111
- const marginY = Math.min(48, height);
112
- const minX = display.x + marginX - width;
113
- const maxX = display.x + display.width - marginX;
114
- const minY = display.y;
115
- const maxY = display.y + display.height - marginY;
116
- return {
117
- x: width === display.width ? display.x : clamp(frame.x, minX, Math.max(minX, maxX)),
118
- y: height === display.height ? display.y : clamp(frame.y, minY, Math.max(minY, maxY)),
119
- width,
120
- height,
121
- };
122
- }
@@ -1,6 +1,12 @@
1
1
  import type { AppSessionSnapshot } from "../../../core/state/session-persistence";
2
2
  import type { PaneRuntimeState } from "../../../core/state/app/state";
3
- import type { DesktopDockPreviewState, DesktopSharedStateSnapshot, DesktopThemePreviewState } from "../../../types/desktop-window";
3
+ import type {
4
+ DesktopDockPreviewState,
5
+ DesktopSharedStateSnapshot,
6
+ DesktopThemePreviewState,
7
+ DesktopWindowInfo,
8
+ OtherWindowTab,
9
+ } from "../../../types/desktop-window";
4
10
  import type { DesktopApplicationMenuCommand } from "../../../types/desktop-menu";
5
11
  import type { AppConfig, UpdateChannel } from "../../../types/config";
6
12
  import type { CachedResourceRecord, ResourceCacheKey } from "../../../data/resource-store";
@@ -29,6 +35,12 @@ export interface ElectrobunBackendInit {
29
35
  hostName?: string;
30
36
  windowKind: "main" | "detached";
31
37
  paneId?: string;
38
+ /** A full window's id: `main`, or an extra window's. Absent for a popped-out pane's window. */
39
+ windowId?: string;
40
+ /** Every full window, for moving a tab or pane between them. */
41
+ windows?: DesktopWindowInfo[];
42
+ /** The main window's: the tabs the other windows hold, for cloud sync. */
43
+ otherWindowTabs?: OtherWindowTab[];
32
44
  /** What the launch's plugin seed could not install, for the main window to say once. */
33
45
  pluginSeedNotice?: { body: string; type: "error" | "info" };
34
46
  /** What the view needs to send crash reports and usage counts the same way the Bun process would. */
@@ -183,7 +195,8 @@ interface DesktopBackendRequestMap {
183
195
  "capability.cancel": { request: { invocationId: string }; response: null };
184
196
  "capability.subscribe": { request: DesktopCapabilitySubscribeRequest; response: null };
185
197
  "capability.unsubscribe": { request: { subscriptionId: string }; response: null };
186
- "desktop.syncMainState": { request: { snapshot: DesktopSharedStateSnapshot }; response: null };
198
+ /** A full window's whole state. `baseSeq` names the last state it took from here; null, its own last sync. */
199
+ "desktop.syncMainState": { request: { snapshot: DesktopSharedStateSnapshot; baseSeq?: number | null }; response: null };
187
200
  "desktop.setThemePreview": { request: { preview: DesktopThemePreviewState }; response: null };
188
201
  "desktop.replaceDetachedPaneState": {
189
202
  request: { paneId: string; paneState: PaneRuntimeState };
@@ -196,6 +209,13 @@ interface DesktopBackendRequestMap {
196
209
  };
197
210
  "desktop.closeDetachedPane": { request: { paneId: string }; response: null };
198
211
  "desktop.focusDetachedPane": { request: { paneId: string }; response: null };
212
+ "desktop.openWindow": { request: null; response: null };
213
+ /** `windowId` null moves it to a new window. False when it cannot go. */
214
+ "desktop.moveLayoutToWindow": { request: { layoutId: string; windowId: string | null }; response: boolean };
215
+ "desktop.movePaneToWindow": { request: { paneId: string; windowId: string | null }; response: boolean };
216
+ "desktop.focusWindow": { request: { windowId: string }; response: null };
217
+ /** Brings forward the full window that shows a pane, on its tab, with the pane focused. False when no window has it. */
218
+ "desktop.focusPane": { request: { paneId: string }; response: boolean };
199
219
  "pluginState.setMany": { request: { entries: DesktopPluginStateSetEntry[] }; response: null };
200
220
  "pluginState.delete": { request: { pluginId: string; key: string }; response: null };
201
221
  "plugins.listExternal": { request: null; response: DesktopExternalPluginBundle[] };
@@ -334,6 +354,24 @@ export interface DesktopDeepLinkMessage {
334
354
  url: string;
335
355
  }
336
356
 
357
+ interface DesktopWindowsMessage {
358
+ windows: DesktopWindowInfo[];
359
+ }
360
+
361
+ interface DesktopOtherWindowTabsMessage {
362
+ /** `OtherWindowTab[]`, encoded as the shared state is. */
363
+ tabs: unknown;
364
+ }
365
+
366
+ interface DesktopFocusPaneMessage {
367
+ paneId: string;
368
+ }
369
+
370
+ /** The window was minimized or brought back; a page cannot always tell by itself. */
371
+ interface DesktopWindowVisibilityMessage {
372
+ visible: boolean;
373
+ }
374
+
337
375
  /** Plugin folders the Bun process updated in the background, for the main window to bring into its session. */
338
376
  interface PluginsUpdatedMessage {
339
377
  directories: string[];
@@ -371,6 +409,10 @@ export interface ElectrobunDesktopRpcSchema {
371
409
  "desktop.dockPreview": DesktopDockPreviewMessage;
372
410
  "desktop.themePreview": DesktopThemePreviewMessage;
373
411
  "desktop.deepLink": DesktopDeepLinkMessage;
412
+ "desktop.windows": DesktopWindowsMessage;
413
+ "desktop.otherWindowTabs": DesktopOtherWindowTabsMessage;
414
+ "desktop.focusPane": DesktopFocusPaneMessage;
415
+ "desktop.windowVisibility": DesktopWindowVisibilityMessage;
374
416
  "plugins.updated": PluginsUpdatedMessage;
375
417
  "update.progress": UpdateProgressMessage;
376
418
  "capability.event": CapabilityEventMessage;
@@ -85,6 +85,21 @@ const rpc = Electroview.defineRPC<ElectrobunDesktopRpcSchema>({
85
85
  "desktop.themePreview": (message) => {
86
86
  emit("desktop.themePreview", { preview: decodeRpcValue<DesktopThemePreviewMessage["preview"]>(message.preview) });
87
87
  },
88
+ "desktop.windows": (message) => {
89
+ if (!Array.isArray(message?.windows)) return;
90
+ emit("desktop.windows", { windows: message.windows });
91
+ },
92
+ "desktop.otherWindowTabs": (message) => {
93
+ const tabs = decodeRpcValue<unknown>(message?.tabs);
94
+ if (Array.isArray(tabs)) emit("desktop.otherWindowTabs", { tabs });
95
+ },
96
+ "desktop.focusPane": (message) => {
97
+ if (typeof message?.paneId !== "string" || !message.paneId) return;
98
+ emit("desktop.focusPane", { paneId: message.paneId });
99
+ },
100
+ "desktop.windowVisibility": (message) => {
101
+ emit("desktop.windowVisibility", { visible: message?.visible !== false });
102
+ },
88
103
  "update.progress": (message) => {
89
104
  emit("update.progress", { progress: decodeRpcValue(message.progress) });
90
105
  },
@@ -114,7 +129,7 @@ const BRIDGE_READY_LIMIT_MS = 5_000;
114
129
  async function waitForBridgeReady(): Promise<void> {
115
130
  const start = Date.now();
116
131
  while (Date.now() - start < BRIDGE_READY_LIMIT_MS) {
117
- if (electroview.bunSocket?.readyState === WebSocket.OPEN) {
132
+ if (electroview.hostSocket?.readyState === WebSocket.OPEN) {
118
133
  return;
119
134
  }
120
135
  await new Promise((resolve) => setTimeout(resolve, 25));
@@ -4,24 +4,84 @@ import type {
4
4
  DesktopSharedStateSnapshot,
5
5
  DesktopThemePreviewState,
6
6
  DesktopWindowBridge,
7
+ DesktopWindowInfo,
8
+ DesktopWindowsBridge,
9
+ DesktopWindowTarget,
10
+ OtherWindowTab,
7
11
  } from "../../../../../types/desktop-window";
8
12
  import { backendRequest, getElectrobunBackendInitSnapshot, onBackendMessage } from "../../backend-rpc";
9
13
  import { createDetachedSnapshotFilter } from "./snapshot";
10
14
 
15
+ const MAIN_WINDOW_ID = "main";
16
+
17
+ function targetWindowId(target: DesktopWindowTarget): string | null {
18
+ return "windowId" in target ? target.windowId : null;
19
+ }
20
+
21
+ /**
22
+ * The full windows as the backend lists them, and for the main window the
23
+ * tabs the others hold, kept current by its `desktop.windows` and
24
+ * `desktop.otherWindowTabs` messages.
25
+ */
26
+ function createDesktopWindowsBridge(
27
+ windowId: string,
28
+ initial: DesktopWindowInfo[],
29
+ initialTabs: readonly OtherWindowTab[],
30
+ ): DesktopWindowsBridge {
31
+ let windows = initial;
32
+ let otherTabs = initialTabs;
33
+ const listeners = new Set<() => void>();
34
+ const changed = () => {
35
+ for (const listener of listeners) listener();
36
+ };
37
+ onBackendMessage("desktop.windows", (message) => {
38
+ windows = message.windows;
39
+ changed();
40
+ });
41
+ onBackendMessage("desktop.otherWindowTabs", (message) => {
42
+ otherTabs = message.tabs as OtherWindowTab[];
43
+ changed();
44
+ });
45
+ return {
46
+ windowId,
47
+ list: () => windows,
48
+ subscribe(listener) {
49
+ listeners.add(listener);
50
+ return () => listeners.delete(listener);
51
+ },
52
+ async openWindow() {
53
+ await backendRequest("desktop.openWindow", null);
54
+ },
55
+ moveLayout: (layoutId, target) => backendRequest("desktop.moveLayoutToWindow", { layoutId, windowId: targetWindowId(target) }),
56
+ movePane: (paneId, target) => backendRequest("desktop.movePaneToWindow", { paneId, windowId: targetWindowId(target) }),
57
+ async focusWindow(targetId) {
58
+ await backendRequest("desktop.focusWindow", { windowId: targetId });
59
+ },
60
+ focusPane: (paneId) => backendRequest("desktop.focusPane", { paneId }),
61
+ subscribeFocusRequests: (listener) => onBackendMessage("desktop.focusPane", (message) => listener(message.paneId)),
62
+ otherWindowTabs: () => otherTabs,
63
+ };
64
+ }
65
+
11
66
  export function createDesktopWindowBridge(kind: "main" | "detached", paneId?: string): DesktopWindowBridge {
12
- const initialDesktopSnapshot = getElectrobunBackendInitSnapshot()?.desktopSnapshot ?? null;
67
+ const init = getElectrobunBackendInitSnapshot();
68
+ const initialDesktopSnapshot = init?.desktopSnapshot ?? null;
13
69
  const takeDetachedSnapshot = kind === "detached" && paneId
14
70
  ? createDetachedSnapshotFilter(paneId, initialDesktopSnapshot)
15
71
  : null;
72
+ const windowId = kind === "main" ? init?.windowId ?? MAIN_WINDOW_ID : null;
16
73
 
17
74
  return {
18
75
  kind,
19
76
  paneId,
77
+ primary: windowId === MAIN_WINDOW_ID,
78
+ windows: windowId ? createDesktopWindowsBridge(windowId, init?.windows ?? [], init?.otherWindowTabs ?? []) : undefined,
20
79
  syncMainState: kind === "main"
21
- ? async (snapshot: DesktopSharedStateSnapshot) => {
22
- await backendRequest("desktop.syncMainState", { snapshot });
80
+ ? async (snapshot: DesktopSharedStateSnapshot, baseSeq?: number | null) => {
81
+ await backendRequest("desktop.syncMainState", { snapshot, baseSeq });
23
82
  }
24
83
  : undefined,
84
+ // The theme preview reaches every window from the one with Settings open.
25
85
  syncThemePreview: kind === "main"
26
86
  ? async (preview: DesktopThemePreviewState) => {
27
87
  await backendRequest("desktop.setThemePreview", { preview });