gloomberb 0.19.4 → 0.19.6

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 (321) hide show
  1. package/package.json +3 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  3. package/src/api-client/equity-screener.ts +23 -0
  4. package/src/app/pane-runtime/index.tsx +2 -0
  5. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  6. package/src/app.tsx +63 -16
  7. package/src/cli/commands/command-utils.ts +4 -0
  8. package/src/cli/commands/market.ts +264 -33
  9. package/src/cli/commands/search.ts +22 -4
  10. package/src/cli/commands/ticker.ts +84 -39
  11. package/src/cli/currency-name-hint.ts +60 -0
  12. package/src/cli/glossary.ts +3 -3
  13. package/src/cli/history-rows.ts +18 -1
  14. package/src/cli/known-gaps.ts +25 -2
  15. package/src/cli/listing-arg.ts +12 -0
  16. package/src/cli/not-a-ticker.ts +5 -3
  17. package/src/cli/pane-functions/capabilities.ts +2 -0
  18. package/src/cli/pane-functions/catalog.ts +31 -5
  19. package/src/cli/pane-functions/function-help.ts +8 -5
  20. package/src/cli/pane-functions/headless.ts +11 -6
  21. package/src/cli/pane-functions/market-session.ts +6 -7
  22. package/src/cli/pane-functions/resolver.ts +75 -2
  23. package/src/cli/quote-answer.ts +9 -0
  24. package/src/cli/series-search.ts +4 -5
  25. package/src/cli/symbol-list.ts +54 -2
  26. package/src/cli/symbol-rows.ts +14 -2
  27. package/src/cli/ticker-resolution.ts +89 -20
  28. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  29. package/src/components/chart/composite/composite-chart.tsx +118 -63
  30. package/src/components/chart/composite/cursor-source.ts +111 -0
  31. package/src/components/chart/composite/format.ts +168 -6
  32. package/src/components/chart/composite/legend.tsx +8 -4
  33. package/src/components/chart/composite/panel-bitmap.ts +28 -2
  34. package/src/components/chart/composite/panel-labels.ts +20 -1
  35. package/src/components/chart/composite/panel-surface.tsx +201 -92
  36. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  37. package/src/components/chart/composite/price-series.ts +31 -8
  38. package/src/components/chart/composite/scene.ts +154 -59
  39. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  40. package/src/components/chart/composite/time-axis.ts +30 -7
  41. package/src/components/chart/composite/time-scale.ts +211 -56
  42. package/src/components/chart/composite/types.ts +11 -1
  43. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  44. package/src/components/chart/curve/curve-surface.tsx +5 -2
  45. package/src/components/chart/curve/model.ts +4 -1
  46. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  47. package/src/components/chart/static/series.ts +3 -0
  48. package/src/components/command-bar/commands/collection-list.ts +81 -0
  49. package/src/components/command-bar/commands/direct/index.ts +6 -0
  50. package/src/components/command-bar/commands/registry.ts +8 -0
  51. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  52. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  53. package/src/components/command-bar/pane-templates/items.ts +19 -3
  54. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  55. package/src/components/command-bar/routes/root/results.ts +23 -3
  56. package/src/components/command-bar/routes/root/selection.ts +4 -2
  57. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  58. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  59. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  60. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  61. package/src/components/command-bar/surface/environment.ts +2 -0
  62. package/src/components/command-bar/view-model.ts +7 -0
  63. package/src/components/command-bar/workflow/ops.ts +2 -1
  64. package/src/components/command-bar/workflow/tickers.ts +20 -0
  65. package/src/components/layout/shell/active-drag.ts +38 -7
  66. package/src/components/layout/shell/drag/magnets.ts +106 -0
  67. package/src/components/layout/shell/menu.ts +15 -1
  68. package/src/components/layout/shell/pane/actions.ts +4 -0
  69. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  70. package/src/components/layout/status-bar.tsx +20 -0
  71. package/src/components/layout/window-controls.tsx +96 -35
  72. package/src/components/layout/window-fullscreen.ts +20 -0
  73. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  74. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  75. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  76. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  77. package/src/components/price-sparkline/view.tsx +14 -6
  78. package/src/components/quote-flash.ts +36 -32
  79. package/src/components/ticker/badge/index.tsx +8 -4
  80. package/src/components/ticker/badge/list.tsx +23 -7
  81. package/src/components/ui/column-grid.tsx +8 -2
  82. package/src/components/ui/data-table/opentui/model.ts +4 -1
  83. package/src/components/ui/tabs.tsx +5 -2
  84. package/src/core/state/app/layout.ts +18 -3
  85. package/src/core/state/app/state.ts +2 -0
  86. package/src/core/state/app/types.ts +5 -0
  87. package/src/data/config/layout.ts +3 -0
  88. package/src/data/config/store/normalize.ts +39 -4
  89. package/src/i18n/es.ts +10 -0
  90. package/src/i18n/ja.ts +10 -0
  91. package/src/i18n/ko.ts +10 -0
  92. package/src/i18n/zh-cn.ts +10 -0
  93. package/src/i18n/zh-tw.ts +10 -0
  94. package/src/layout/pane-manager/floating-placement.ts +7 -4
  95. package/src/layout/pane-manager/floating.ts +5 -2
  96. package/src/market-data/bond-funds.ts +19 -0
  97. package/src/market-data/coordinator/events.ts +17 -1
  98. package/src/market-data/frame-scheduler.ts +47 -10
  99. package/src/market-data/frame-wake.ts +74 -0
  100. package/src/market-data/futures-board.ts +7 -6
  101. package/src/market-data/futures-contract.ts +14 -3
  102. package/src/market-data/hooks.tsx +12 -3
  103. package/src/market-data/market/freshness.ts +18 -0
  104. package/src/market-data/market/status.ts +15 -2
  105. package/src/market-data/performance.ts +78 -9
  106. package/src/market-data/request-types.ts +6 -3
  107. package/src/plugins/builtin/alerts/cli.ts +2 -1
  108. package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
  109. package/src/plugins/builtin/attention/evidence.ts +1 -1
  110. package/src/plugins/builtin/awards/client.ts +1 -1
  111. package/src/plugins/builtin/awards/evidence.ts +1 -1
  112. package/src/plugins/builtin/awards/pane.tsx +2 -1
  113. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  114. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  115. package/src/plugins/builtin/bond-calculator/math.ts +1 -1
  116. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  117. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  118. package/src/plugins/builtin/broker-manager/footer.ts +3 -2
  119. package/src/plugins/builtin/broker-manager/index.tsx +2 -1
  120. package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
  121. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  122. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  123. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  124. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  125. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  126. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  127. package/src/plugins/builtin/buildout/format.ts +23 -1
  128. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  129. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  130. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  131. package/src/plugins/builtin/catalysts/evidence.ts +1 -1
  132. package/src/plugins/builtin/catalysts/pane.tsx +2 -1
  133. package/src/plugins/builtin/cds/headless.ts +1 -0
  134. package/src/plugins/builtin/cds/index.tsx +1 -1
  135. package/src/plugins/builtin/chart-composer/headless.ts +40 -1
  136. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  137. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  138. package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
  139. package/src/plugins/builtin/comment-letters/client.ts +2 -1
  140. package/src/plugins/builtin/company-kpis/client.ts +1 -1
  141. package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
  142. package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
  143. package/src/plugins/builtin/correlation/headless.ts +3 -2
  144. package/src/plugins/builtin/cot/headless.ts +9 -3
  145. package/src/plugins/builtin/cot/model.ts +44 -3
  146. package/src/plugins/builtin/credit-documents/client.ts +1 -1
  147. package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
  148. package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
  149. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  150. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  151. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  152. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  153. package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
  154. package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
  155. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  156. package/src/plugins/builtin/econ/calendar-model.ts +30 -6
  157. package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
  158. package/src/plugins/builtin/econ/print-watch.ts +3 -1
  159. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  160. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  161. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  162. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  163. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  164. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  165. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  166. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  167. package/src/plugins/builtin/futures/series.ts +16 -1
  168. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  169. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  170. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  171. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  172. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  173. package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
  174. package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
  175. package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
  176. package/src/plugins/builtin/gpu/headless.ts +2 -1
  177. package/src/plugins/builtin/help/function-card.tsx +2 -1
  178. package/src/plugins/builtin/help/index.tsx +2 -1
  179. package/src/plugins/builtin/insider/display.ts +45 -6
  180. package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
  181. package/src/plugins/builtin/iv-history/client.ts +2 -1
  182. package/src/plugins/builtin/iv-history/headless.ts +2 -1
  183. package/src/plugins/builtin/jobs/pages.ts +4 -4
  184. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
  185. package/src/plugins/builtin/macro-day/client.ts +41 -0
  186. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  187. package/src/plugins/builtin/macro-day/model.ts +3 -1
  188. package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
  189. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  190. package/src/plugins/builtin/members/client.ts +1 -1
  191. package/src/plugins/builtin/mna/distress/client.ts +1 -0
  192. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  193. package/src/plugins/builtin/mna/pane.tsx +4 -1
  194. package/src/plugins/builtin/options/market-reference.ts +1 -1
  195. package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
  196. package/src/plugins/builtin/options/view.tsx +2 -1
  197. package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
  198. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  199. package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
  200. package/src/plugins/builtin/options-scenario/csp.ts +28 -9
  201. package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
  202. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  203. package/src/plugins/builtin/perps/client.ts +1 -1
  204. package/src/plugins/builtin/perps/pane.tsx +3 -1
  205. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  206. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
  208. package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
  209. package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
  210. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  211. package/src/plugins/builtin/research/analyst-model.ts +1 -0
  212. package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
  213. package/src/plugins/builtin/research/event-model.ts +10 -3
  214. package/src/plugins/builtin/research/events-headless.ts +20 -2
  215. package/src/plugins/builtin/research/index.tsx +1 -0
  216. package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
  217. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
  218. package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
  219. package/src/plugins/builtin/research-search/snippet.ts +1 -0
  220. package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
  221. package/src/plugins/builtin/seasonality/headless.ts +2 -1
  222. package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
  223. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  224. package/src/plugins/builtin/sec/index.tsx +8 -5
  225. package/src/plugins/builtin/sec/row-summaries.ts +28 -12
  226. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  227. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  228. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  229. package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
  230. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  231. package/src/plugins/builtin/social-mentions/client.ts +2 -1
  232. package/src/plugins/builtin/supply-chain/client.ts +1 -1
  233. package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
  234. package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
  235. package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
  236. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
  237. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
  238. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
  239. package/src/plugins/builtin/time-sales/client.ts +1 -0
  240. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  241. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  242. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  243. package/src/plugins/builtin/vol-surface/client.ts +2 -1
  244. package/src/plugins/builtin/volatility/client.ts +6 -1
  245. package/src/plugins/builtin/volatility/headless.ts +0 -1
  246. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  247. package/src/plugins/builtin/yield-curve/headless.ts +9 -2
  248. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  249. package/src/plugins/host-modules.ts +22 -3
  250. package/src/plugins/host-smoke.ts +6 -3
  251. package/src/portfolio/collection-name.ts +19 -0
  252. package/src/portfolio/column-values.ts +76 -10
  253. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  254. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  255. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  256. package/src/renderers/cloudflare/worker.ts +15 -2
  257. package/src/renderers/desktop/geometry.ts +279 -0
  258. package/src/renderers/desktop/screen-setup.ts +246 -0
  259. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  260. package/src/renderers/desktop/test-utils.ts +71 -0
  261. package/src/renderers/desktop/window-controller.ts +433 -0
  262. package/src/renderers/desktop/window-host.ts +70 -0
  263. package/src/renderers/desktop/window-layouts.ts +630 -0
  264. package/src/renderers/dom/data-frames.ts +15 -4
  265. package/src/renderers/dom/host/box.tsx +204 -176
  266. package/src/renderers/dom/host/style.ts +49 -20
  267. package/src/renderers/dom/host/text.tsx +3 -2
  268. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  269. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  270. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  271. package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
  272. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  273. package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
  274. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  275. package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
  276. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  277. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  278. package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
  279. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  280. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  281. package/src/renderers/electrobun/bun/index.ts +4 -97
  282. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  283. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  284. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  285. package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
  286. package/src/renderers/electrobun/shared/protocol.ts +50 -2
  287. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  288. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  289. package/src/renderers/electrobun/view/main.tsx +13 -7
  290. package/src/renderers/electrobun/view/ui-host.tsx +7 -0
  291. package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
  292. package/src/series/fred-argument.ts +17 -0
  293. package/src/sources/provider-router/financial-routes.ts +7 -1
  294. package/src/sources/provider-router/index.ts +7 -1
  295. package/src/state/app/context/index.tsx +16 -2
  296. package/src/state/desktop-windows.ts +63 -0
  297. package/src/sync/other-window-tabs.ts +62 -0
  298. package/src/tickers/company-name-listing.ts +23 -3
  299. package/src/tickers/listing-fate.ts +147 -1
  300. package/src/tickers/terminal-codes.ts +5 -0
  301. package/src/time-series/price-units.ts +11 -0
  302. package/src/time-series/types.ts +6 -0
  303. package/src/types/config.ts +10 -1
  304. package/src/types/desktop-window.ts +71 -2
  305. package/src/types/financials.ts +4 -0
  306. package/src/types/headless.ts +19 -0
  307. package/src/types/plugin.ts +6 -0
  308. package/src/ui/host.tsx +2 -0
  309. package/src/ui/index.tsx +14 -13
  310. package/src/ui/same-props.ts +58 -0
  311. package/src/utils/cli-output.ts +33 -4
  312. package/src/utils/currency-names.ts +20 -0
  313. package/src/utils/currency-pair.ts +6 -0
  314. package/src/utils/exchange-rate-snapshot.ts +20 -2
  315. package/src/utils/format.ts +7 -2
  316. package/src/utils/futures-generic.ts +12 -0
  317. package/src/utils/fx-market-hours.ts +43 -0
  318. package/src/utils/http-proxy-upstream.ts +6 -2
  319. package/src/utils/plugin-proxy-hosts.json +0 -4
  320. package/src/utils/plugin-proxy-hosts.ts +22 -0
  321. package/src/utils/sec-filings.ts +7 -1
@@ -1,4 +1,4 @@
1
- import { ApplicationMenu, BrowserView, Utils, type BrowserWindow } from "electrobun/bun";
1
+ import Electrobun, { ApplicationMenu, BrowserView, Screen, Utils, type BrowserWindow } from "electrobun/bun";
2
2
  import { homedir } from "os";
3
3
  import { createAppServices, type AppServices } from "../../../../core/app-services";
4
4
  import { syncConfigActiveLayoutState, type PaneRuntimeState } from "../../../../core/state/app/state";
@@ -45,8 +45,20 @@ import {
45
45
  prefetchExternalPluginBundles,
46
46
  takeExternalPluginBundles,
47
47
  } from "../external-plugins";
48
- import { MAIN_WINDOW_RPC_KEY } from "../window/focus";
48
+ import { MAIN_WINDOW_RPC_KEY, paneIdFromDetachedRpcKey } from "../window/focus";
49
49
  import { measureNativeWindowCalls } from "../window/native-timing";
50
+ import { createAppWindow } from "../window/create";
51
+ import { desktopBootFramePath, desktopBootFramePreload, readDesktopBootFrame } from "../window/boot-frame";
52
+ import { MAIN_WINDOW_MIN_SIZE, defaultMainWindowFrame } from "../window/frame";
53
+ import { ElectrobunWindowHost } from "../window/electrobun-window-host";
54
+ import { quitWindowsEventLoopOnItsThread } from "../window/windows-quit";
55
+ import { readRememberedDesktopWindow, rememberedDesktopWindowPath } from "../window/remembered-frame";
56
+ import { DesktopWindowController } from "../../../desktop/window-controller";
57
+ import { SequentialWindowHost } from "../../../desktop/sequential-window-host";
58
+ import { createExtraWindowId, MAIN_WINDOW_ID } from "../../../desktop/screen-setup";
59
+ import type { OpenWindowSpec } from "../../../desktop/window-host";
60
+ import type { DesktopWindowInfo, OtherWindowTab } from "../../../../types/desktop-window";
61
+ import { desktopScreenSetupStore } from "./screen-setup-file";
50
62
  import { handleDesktopBackendRequest } from "./backend-requests";
51
63
  import { detectDesktopInstallKind, removeUpdateAsides } from "./update";
52
64
  import { removeLegacyMacApp } from "./app-name";
@@ -107,11 +119,35 @@ export class DesktopBackend {
107
119
  config: AppConfig | null = null;
108
120
  services: AppServices | null = null;
109
121
  workspace: DesktopWorkspace | null = null;
110
- mainWindow: BrowserWindow | null = null;
122
+ /**
123
+ * Every window and screen goes through these: the host, which opens
124
+ * native windows one at a time, and the full windows' placement on the
125
+ * screens. `nativeWindows` is the Electrobun host under it, for the calls
126
+ * only this shell makes.
127
+ */
128
+ windowHost: SequentialWindowHost | null = null;
129
+ windowController: DesktopWindowController | null = null;
130
+ private nativeWindows: ElectrobunWindowHost | null = null;
111
131
 
112
132
  readonly rpcs = createDesktopRpcRegistry<DesktopRpc>();
113
133
  readonly stateBroadcaster = new DesktopStateBroadcaster<DesktopRpc>({
114
134
  forEachReadyWindowRpc: this.rpcs.forEachReadyWindowRpc,
135
+ // A full window draws its own tabs; a popped-out pane's window draws the main window's.
136
+ viewKey: (rpc) => {
137
+ const key = this.rpcs.getRpcWindowKey(rpc) ?? MAIN_WINDOW_ID;
138
+ return paneIdFromDetachedRpcKey(key) ? MAIN_WINDOW_ID : key;
139
+ },
140
+ // With one window its view is the shared state: nothing to project or keep.
141
+ project: (viewKey, shared) => {
142
+ const workspace = this.workspace;
143
+ return workspace && workspace.windowIds().length > 1 ? workspace.peekWindowSnapshot(viewKey) ?? shared : shared;
144
+ },
145
+ delivered: (rpc, snapshot) => {
146
+ const workspace = this.workspace;
147
+ const key = this.rpcs.getRpcWindowKey(rpc);
148
+ if (!workspace || !key || typeof snapshot.stateSeq !== "number" || workspace.windowIds().length <= 1) return;
149
+ workspace.noteDelivered(key, snapshot.stateSeq, snapshot);
150
+ },
115
151
  });
116
152
  readonly capabilityBridge = new DesktopCapabilityBridge<DesktopRpc>({
117
153
  getRegistry: () => this.requireServices().pluginRegistry.capabilities,
@@ -131,6 +167,244 @@ export class DesktopBackend {
131
167
  private remoteControlServer: RemoteControlServer | null = null;
132
168
  private readonly pendingDeepLinks: string[] = [];
133
169
  private readonly contextMenuRequestRpcs = new Map<string, DesktopRpc>();
170
+ /** Extra windows open once the main window has drawn, like popped-out panes. */
171
+ private extraWindowsAllowed = false;
172
+ private lastWindowList = "";
173
+ /** What the main window was last told the other windows' tabs are. */
174
+ private lastOtherWindowTabs = "[]";
175
+ private quitting = false;
176
+
177
+ /**
178
+ * Makes the window host, opens the main window where it was left on these
179
+ * screens, and starts watching them. Extra windows open once the main
180
+ * window has its data.
181
+ */
182
+ startWindows(): void {
183
+ if (this.windowHost) return;
184
+ const shell = new ElectrobunWindowHost({
185
+ create: (spec, hooks) => this.createNativeWindow(spec, hooks.onFrameChange),
186
+ readDisplays: () => Screen.getAllDisplays(),
187
+ });
188
+ const host = new SequentialWindowHost(shell, {
189
+ canReopen: (spec) => spec.id !== MAIN_WINDOW_ID,
190
+ onNeverDrew: (id) => console.error("[desktop] a window never drew", { kind: paneIdFromDetachedRpcKey(id) ? "pane" : "app" }),
191
+ });
192
+ this.nativeWindows = shell;
193
+ this.windowHost = host;
194
+ const legacy = readRememberedDesktopWindow(rememberedDesktopWindowPath());
195
+ this.windowController = new DesktopWindowController({
196
+ host,
197
+ store: desktopScreenSetupStore(),
198
+ minSize: MAIN_WINDOW_MIN_SIZE,
199
+ defaultMainFrame: defaultMainWindowFrame(),
200
+ // Windows saved every window as full screen in builds whose frameless
201
+ // window it took for full screen; it has no way into full screen here.
202
+ legacyMainPlacement: legacy ? { ...legacy, fullscreen: legacy.fullscreen && process.platform !== "win32" } : null,
203
+ onWindowClosed: (windowId) => this.handleExtraWindowClosed(windowId),
204
+ onMainWindowClosed: () => this.quit(),
205
+ });
206
+ host.onWindowEvent((event) => {
207
+ this.detachedWindows.handleWindowEvent(event);
208
+ // A page that has not started yet draws as shown; it is told once it hides again.
209
+ if (event.type !== "visibility" || !this.rpcs.isWindowRpcReady(event.id)) return;
210
+ this.rpcs.getWindowRpc(event.id)?.send["desktop.windowVisibility"]({ visible: event.visible });
211
+ });
212
+ // A quit from outside the app (the Dock, logging out) does not come
213
+ // through `quit`: where the windows are is written here. Registered
214
+ // before the main window opens, so it runs before the shell's own
215
+ // handlers wait for the windows to go.
216
+ Electrobun.events.on("before-quit", () => {
217
+ if (!this.quitting) this.windowController?.flush();
218
+ });
219
+ this.windowController.openWindow(MAIN_WINDOW_ID);
220
+ this.windowController.focus(MAIN_WINDOW_ID);
221
+ }
222
+
223
+ /** The native window behind a full window or a popped-out pane, with its own RPC channel. */
224
+ private createNativeWindow(spec: OpenWindowSpec, onFrameChange: () => void): BrowserWindow {
225
+ const rpc = this.createWindowRpc(spec.id);
226
+ const main = spec.id === MAIN_WINDOW_ID;
227
+ const window = createAppWindow({
228
+ title: spec.title,
229
+ frame: spec.frame,
230
+ rpc,
231
+ minSize: spec.minSize,
232
+ onFrameChange,
233
+ // A full window's page draws a frame before its script has loaded: the
234
+ // main window the layout it last drew (dom/boot-frame.ts), another the
235
+ // bare shell. A popped-out pane's draws none.
236
+ ...(spec.kind === "app"
237
+ ? { preload: desktopBootFramePreload(main ? readDesktopBootFrame(desktopBootFramePath()) : null) }
238
+ : {}),
239
+ });
240
+ if (main) quitWindowsEventLoopOnItsThread(window);
241
+ return window;
242
+ }
243
+
244
+ /** Brings a window forward by its RPC key: a full window's or a popped-out pane's. False when there is none. */
245
+ focusWindow(windowKey: string | undefined): boolean {
246
+ const host = this.windowHost;
247
+ if (!windowKey || !host?.hasWindow(windowKey)) return false;
248
+ if (this.windowController?.isOpen(windowKey)) this.windowController.focus(windowKey);
249
+ else host.focusWindow(windowKey);
250
+ return true;
251
+ }
252
+
253
+ /** The Electrobun window for an RPC key, for the calls only this shell makes. */
254
+ nativeWindow(windowKey: string | undefined): BrowserWindow | null {
255
+ return windowKey ? this.nativeWindows?.browserWindow(windowKey) ?? null : null;
256
+ }
257
+
258
+ /** The main window has its data: popped-out panes and extra windows open shortly after. */
259
+ openWindowsAfterMainWindow(): void {
260
+ this.detachedWindows.openAfterMainWindow(() => {
261
+ this.extraWindowsAllowed = true;
262
+ this.reconcileWindows();
263
+ });
264
+ }
265
+
266
+ /** Opens and closes windows to match the workspace: popped-out panes, and full windows. */
267
+ reconcileWindows(): void {
268
+ this.detachedWindows.reconcile();
269
+ const controller = this.windowController;
270
+ const workspace = this.workspace;
271
+ if (!controller || !workspace) return;
272
+ const wanted = workspace.windowIds();
273
+ if (this.extraWindowsAllowed) {
274
+ for (const windowId of wanted) {
275
+ if (windowId !== MAIN_WINDOW_ID && !controller.isOpen(windowId)) controller.openWindow(windowId);
276
+ }
277
+ }
278
+ for (const windowId of controller.openWindowIds()) {
279
+ if (windowId === MAIN_WINDOW_ID || wanted.includes(windowId)) continue;
280
+ controller.closeWindow(windowId, { forget: true });
281
+ this.releaseWindow(windowId);
282
+ }
283
+ controller.rememberWindows(workspace.extraWindows());
284
+ this.sendWindowList();
285
+ }
286
+
287
+ /** Every full window, labelled in the order they opened. */
288
+ windowInfos(): DesktopWindowInfo[] {
289
+ const workspace = this.workspace;
290
+ if (!workspace) return [];
291
+ return workspace.windowIds().map((id, index) => {
292
+ const tabs = workspace.windowTabNames(id);
293
+ return {
294
+ id,
295
+ number: index + 1,
296
+ activeLayoutName: tabs?.active ?? "",
297
+ tabCount: tabs?.count ?? 0,
298
+ };
299
+ });
300
+ }
301
+
302
+ /** Tells every full window which windows there are, when that changed. */
303
+ private sendWindowList(): void {
304
+ this.sendOtherWindowTabs();
305
+ const windows = this.windowInfos();
306
+ const key = JSON.stringify(windows);
307
+ if (key === this.lastWindowList) return;
308
+ this.lastWindowList = key;
309
+ for (const { id } of windows) {
310
+ if (!this.rpcs.isWindowRpcReady(id)) continue;
311
+ this.rpcs.getWindowRpc(id)?.send["desktop.windows"]({ windows });
312
+ }
313
+ }
314
+
315
+ /** The tabs the other windows hold, for the main window's init; later changes come as messages. */
316
+ otherWindowTabsForInit(): OtherWindowTab[] {
317
+ const tabs = this.workspace?.otherWindowTabs() ?? [];
318
+ this.lastOtherWindowTabs = JSON.stringify(tabs);
319
+ return tabs;
320
+ }
321
+
322
+ /** Tells the main window when the tabs the other windows hold changed: its cloud sync pushes every window's tabs. */
323
+ private sendOtherWindowTabs(): void {
324
+ const workspace = this.workspace;
325
+ if (!workspace || !this.rpcs.isWindowRpcReady(MAIN_WINDOW_ID)) return;
326
+ const tabs = workspace.otherWindowTabs();
327
+ // One window: none, as the main window already knows.
328
+ if (tabs.length === 0 && this.lastOtherWindowTabs === "[]") return;
329
+ const key = JSON.stringify(tabs);
330
+ if (key === this.lastOtherWindowTabs) return;
331
+ this.lastOtherWindowTabs = key;
332
+ this.rpcs.getWindowRpc(MAIN_WINDOW_ID)?.send["desktop.otherWindowTabs"]({ tabs: encodeRpcValue(tabs) });
333
+ }
334
+
335
+ /** A full window's id for a request, or null for a popped-out pane's window. */
336
+ fullWindowKey(rpc: DesktopRpc): string | null {
337
+ const key = this.rpcs.getRpcWindowKey(rpc);
338
+ if (!key || paneIdFromDetachedRpcKey(key)) return null;
339
+ return key;
340
+ }
341
+
342
+ /** Opens a new full window, on `layoutId` or an empty tab. Null when that tab cannot leave its window. */
343
+ async openExtraWindow(holding?: { layoutId?: string; paneId?: string }): Promise<string | null> {
344
+ const workspace = this.requireWorkspace();
345
+ const windowId = createExtraWindowId();
346
+ const snapshot = workspace.openWindow(windowId, holding);
347
+ if (!snapshot) return null;
348
+ this.extraWindowsAllowed = true;
349
+ await this.commitDesktopSnapshot(snapshot);
350
+ this.windowController?.focus(windowId);
351
+ return windowId;
352
+ }
353
+
354
+ /**
355
+ * Shows a pane wherever it is: brings its window forward, on its tab, and
356
+ * has that window focus it. False when no window holds it.
357
+ */
358
+ async focusPaneAnywhere(paneId: string): Promise<boolean> {
359
+ const workspace = this.requireWorkspace();
360
+ const config = this.config;
361
+ if (config && config.layout.detached.some((entry) => entry.instanceId === paneId)) {
362
+ return this.detachedWindows.focusDetachedPane(paneId);
363
+ }
364
+ const located = workspace.locatePane(paneId);
365
+ if (!located) return false;
366
+ const before = workspace.getWindowSnapshot(located.windowId);
367
+ const shown = before?.config.layouts[before.config.activeLayoutIndex]?.id;
368
+ if (shown !== located.layoutId) {
369
+ await this.commitDesktopSnapshot(workspace.activateLayout(located.windowId, located.layoutId), { persistConfig: false });
370
+ }
371
+ this.windowController?.focus(located.windowId);
372
+ this.rpcs.getWindowRpc(located.windowId)?.send["desktop.focusPane"]({ paneId });
373
+ return true;
374
+ }
375
+
376
+ private handleExtraWindowClosed(windowId: string): void {
377
+ this.releaseWindow(windowId);
378
+ // Closed by the quit itself: it opens again with its tabs at the next launch.
379
+ if (this.quitting) return;
380
+ const workspace = this.workspace;
381
+ if (!workspace || !workspace.windowIds().includes(windowId)) return;
382
+ void this.commitDesktopSnapshot(workspace.closeWindow(windowId));
383
+ }
384
+
385
+ /** What a closed full window held: its streams, its channel. */
386
+ private releaseWindow(windowId: string): void {
387
+ this.disposeWindowResources(windowId);
388
+ this.rpcs.unregisterWindowRpc(windowId);
389
+ this.workspace?.forgetWindow(windowId);
390
+ }
391
+
392
+ /**
393
+ * Closes every window but the main one, without forgetting the extra
394
+ * ones, which open again at the next launch or session. Where each window
395
+ * is, the main one included, is written first.
396
+ */
397
+ closeAllWindows(): void {
398
+ this.detachedWindows.closeAll();
399
+ const controller = this.windowController;
400
+ if (!controller) return;
401
+ controller.flush();
402
+ for (const windowId of controller.openWindowIds()) {
403
+ if (windowId === MAIN_WINDOW_ID) continue;
404
+ controller.closeWindow(windowId);
405
+ this.releaseWindow(windowId);
406
+ }
407
+ }
134
408
 
135
409
  requireConfig(): AppConfig {
136
410
  if (!this.config) throw new Error("Backend config has not been initialized.");
@@ -207,8 +481,8 @@ export class DesktopBackend {
207
481
  getConfig: () => this.requireConfig(),
208
482
  getServices: () => this.requireServices(),
209
483
  });
210
- this.workspace = createDesktopWorkspace(config, this.getSessionSnapshot());
211
- this.detachedWindows.reconcile();
484
+ this.workspace = createDesktopWorkspace(config, this.getSessionSnapshot(), this.windowController?.screenSetup.windows);
485
+ this.reconcileWindows();
212
486
  return { config, services };
213
487
  }
214
488
 
@@ -236,9 +510,10 @@ export class DesktopBackend {
236
510
  await saveConfig(nextConfig);
237
511
  }
238
512
  if (options.reconcileWindows !== false) {
239
- this.detachedWindows.reconcile();
513
+ this.reconcileWindows();
240
514
  }
241
515
  this.stateBroadcaster.sendDesktopState(this.requireWorkspace().getSnapshot());
516
+ this.sendWindowList();
242
517
  return this.requireWorkspace().getSnapshot();
243
518
  }
244
519
 
@@ -291,7 +566,7 @@ export class DesktopBackend {
291
566
  if (this.pendingDeepLinks.length > MAX_PENDING_DEEP_LINKS) this.pendingDeepLinks.shift();
292
567
  return;
293
568
  }
294
- this.detachedWindows.focusWindowForRpcKey(MAIN_WINDOW_RPC_KEY);
569
+ this.focusWindow(MAIN_WINDOW_RPC_KEY);
295
570
  rpc.send["desktop.deepLink"]({ url: rawUrl });
296
571
  }
297
572
 
@@ -313,13 +588,29 @@ export class DesktopBackend {
313
588
  });
314
589
  }
315
590
 
591
+ /** The full window the person used last, ready for messages; the main window otherwise. */
592
+ private focusedFullWindow(): { key: string; rpc: DesktopRpc } | null {
593
+ const focused = this.windowController?.focusedWindowId ?? MAIN_WINDOW_ID;
594
+ for (const key of [focused, MAIN_WINDOW_RPC_KEY]) {
595
+ const rpc = this.rpcs.getWindowRpc(key);
596
+ if (rpc && this.rpcs.isWindowRpcReady(key)) return { key, rpc };
597
+ }
598
+ return null;
599
+ }
600
+
316
601
  runApplicationMenuCommand(command: ElectrobunApplicationMenuCommand): void {
317
602
  if (command.type === "open-devtools") {
318
- this.mainWindow?.webview.openDevTools();
603
+ this.nativeWindow(this.focusedFullWindow()?.key ?? MAIN_WINDOW_ID)?.webview.openDevTools();
604
+ return;
605
+ }
606
+ if (command.type === "new-window") {
607
+ if (this.workspace) void this.openExtraWindow().catch((error: unknown) => {
608
+ console.error("[desktop] could not open a window", summarizeError(error));
609
+ });
319
610
  return;
320
611
  }
321
- const rpc = this.readyMainWindowRpc();
322
612
  if (command.type === "quit") {
613
+ const rpc = this.readyMainWindowRpc();
323
614
  if (!rpc) {
324
615
  this.quit();
325
616
  return;
@@ -330,21 +621,26 @@ export class DesktopBackend {
330
621
  setTimeout(() => this.quit(), QUIT_FALLBACK_MS);
331
622
  return;
332
623
  }
333
- if (!rpc) return;
334
- // The bar and every form open in the main window; with a detached window
335
- // key, the keys would go there instead.
624
+ // Menu commands go to the full window in front, or the one used last.
625
+ const target = this.focusedFullWindow();
626
+ if (!target) return;
627
+ // The bar and every form open in that window; with a popped-out pane's
628
+ // window in front, the keys would go there instead.
336
629
  if (command.type === "open-command-bar" || command.type === "open-builtin-workflow" || command.type === "open-plugin-workflow") {
337
- this.detachedWindows.focusWindowForRpcKey(MAIN_WINDOW_RPC_KEY);
630
+ this.windowController?.focus(target.key);
338
631
  }
339
- rpc.send["application-menu.select"]({ command });
632
+ target.rpc.send["application-menu.select"]({ command });
340
633
  }
341
634
 
342
- private quit(): void {
343
- this.detachedWindows.closeAll();
635
+ quit(): void {
636
+ if (this.quitting) return;
637
+ this.quitting = true;
638
+ // The order a quit had with one window: the other windows close, the
639
+ // services stop while the main window can still hear from them, and
640
+ // the main window goes last.
641
+ this.closeAllWindows();
344
642
  this.teardownServices();
345
- const window = this.mainWindow;
346
- this.mainWindow = null;
347
- window?.close();
643
+ this.windowController?.closeWindow(MAIN_WINDOW_ID);
348
644
  Utils.quit();
349
645
  }
350
646
 
@@ -543,6 +839,11 @@ export class DesktopBackend {
543
839
  case "desktop.dockDetachedPane":
544
840
  case "desktop.closeDetachedPane":
545
841
  case "desktop.focusDetachedPane":
842
+ case "desktop.openWindow":
843
+ case "desktop.moveLayoutToWindow":
844
+ case "desktop.movePaneToWindow":
845
+ case "desktop.focusWindow":
846
+ case "desktop.focusPane":
546
847
  return handleDesktopWorkspaceRequest(this, rpc, request);
547
848
  case "pluginState.setMany":
548
849
  case "pluginState.delete":
@@ -570,7 +871,9 @@ export class DesktopBackend {
570
871
  case "host.exit":
571
872
  case "host.windowControl":
572
873
  case "host.windowFullscreen":
874
+ case "host.windowMaximized":
573
875
  case "host.startWindowDrag":
876
+ case "host.startWindowResize":
574
877
  case "host.openExternal":
575
878
  case "host.copyText":
576
879
  case "host.focusWindow":
@@ -1,4 +1,7 @@
1
1
  import type { BrowserWindow } from "electrobun/bun";
2
+ import type { NativeWindowEvent } from "../../../desktop/window-host";
3
+ import { clampFrameToScreens, sameRect } from "../../../desktop/geometry";
4
+ import { MAIN_WINDOW_ID } from "../../../desktop/screen-setup";
2
5
  import { findPaneInstance } from "../../../../types/config";
3
6
  import { isPaneDetached } from "../../../../layout/pane-manager";
4
7
  import {
@@ -7,13 +10,7 @@ import {
7
10
  normalizeWindowFrameWithMinimum,
8
11
  type WindowFrame,
9
12
  } from "../window/frame";
10
- import {
11
- detachedRpcKey,
12
- focusWindowForRpcKey,
13
- paneIdFromDetachedRpcKey,
14
- } from "../window/focus";
15
- import { getWindowFrame } from "../window/events";
16
- import { createAppWindow } from "../window/create";
13
+ import { detachedRpcKey, paneIdFromDetachedRpcKey } from "../window/focus";
17
14
  import type { DesktopBackend } from "./backend";
18
15
 
19
16
  const INITIAL_DOCK_SUPPRESSION_MS = 800;
@@ -21,11 +18,16 @@ const WINDOW_CONTROL_DOCK_SUPPRESSION_MS = 5_000;
21
18
  /** How long after the main window has its data the popped-out windows of the last session open. */
22
19
  const LAUNCH_WINDOWS_DELAY_MS = 300;
23
20
 
21
+ /**
22
+ * The windows that hold one popped-out pane each, opened and moved through
23
+ * the window host like every other window. Their frames live in the config's
24
+ * layout, which is how they reopen where they were.
25
+ */
24
26
  export class DesktopDetachedWindowManager {
25
- private readonly windows = new Map<string, BrowserWindow>();
27
+ /** The panes with a window open. */
28
+ private readonly windows = new Set<string>();
26
29
  private readonly frameTimers = new Map<string, ReturnType<typeof setTimeout>>();
27
30
  private readonly dockTimers = new Map<string, ReturnType<typeof setTimeout>>();
28
- private readonly closingPanes = new Set<string>();
29
31
  private readonly pendingMoveFlush = new Set<string>();
30
32
  private readonly suppressDockUntil = new Map<string, number>();
31
33
  private readonly windowControlDockSuppressed = new Set<string>();
@@ -41,28 +43,58 @@ export class DesktopDetachedWindowManager {
41
43
 
42
44
  /**
43
45
  * The main window has its data: the popped-out windows open shortly
44
- * after, once it has had a moment to draw and ask for what it shows.
46
+ * after, once it has had a moment to draw and ask for what it shows, and
47
+ * then `onOpen` runs (the extra full windows open there).
45
48
  */
46
- openAfterMainWindow(): void {
49
+ openAfterMainWindow(onOpen?: () => void): void {
47
50
  if (this.windowsAllowed || this.windowsTimer) return;
48
51
  this.windowsTimer = setTimeout(() => {
49
52
  this.windowsTimer = null;
50
53
  this.windowsAllowed = true;
51
54
  this.reconcile();
55
+ onOpen?.();
52
56
  }, LAUNCH_WINDOWS_DELAY_MS);
53
57
  }
54
58
 
55
59
  focusDetachedPane(instanceId: string): boolean {
56
- return this.focusWindowForRpcKey(detachedRpcKey(instanceId));
57
- }
58
-
59
- focusWindowForRpcKey(rpcKey: string | undefined): boolean {
60
- return focusWindowForRpcKey(rpcKey, this.backend.mainWindow, this.windows);
60
+ return this.backend.focusWindow(detachedRpcKey(instanceId));
61
61
  }
62
62
 
63
63
  getWindowForRpcKey(rpcKey: string | undefined): BrowserWindow | null {
64
64
  const paneId = paneIdFromDetachedRpcKey(rpcKey);
65
- return paneId ? this.windows.get(paneId) ?? null : null;
65
+ return paneId && this.windows.has(paneId) ? this.backend.nativeWindow(rpcKey) : null;
66
+ }
67
+
68
+ /** A popped-out pane's window moved or closed. */
69
+ handleWindowEvent(event: NativeWindowEvent): void {
70
+ const instanceId = paneIdFromDetachedRpcKey(event.id);
71
+ // A window this side closed says nothing (the host only reports the
72
+ // person's closes), and its state went with the close.
73
+ if (!instanceId || !this.windows.has(instanceId)) return;
74
+ if (event.type === "frame") {
75
+ this.scheduleMove(instanceId);
76
+ return;
77
+ }
78
+ if (event.type !== "close") return;
79
+ this.cleanupState(instanceId);
80
+ const workspace = this.backend.workspace;
81
+ const config = this.backend.config;
82
+ if (!workspace || !config || !isPaneDetached(config.layout, instanceId)) return;
83
+ void this.backend.commitDesktopSnapshot(workspace.closeDetachedPane(instanceId));
84
+ }
85
+
86
+ /**
87
+ * A popped-out pane's saved frame, on a screen that is connected: one
88
+ * saved on a monitor since unplugged or at another resolution opens on
89
+ * screen, as the shell would leave it where it was asked.
90
+ */
91
+ private onScreen(frame: WindowFrame): WindowFrame {
92
+ const host = this.backend.windowHost;
93
+ return host?.canPlaceWindows ? clampFrameToScreens(frame, host.listDisplays()) : frame;
94
+ }
95
+
96
+ private frameOf(rpcKey: string): WindowFrame | null {
97
+ return this.backend.windowHost?.getWindowState(rpcKey)?.frame ?? null;
66
98
  }
67
99
 
68
100
  suppressAutoDockForRpcKey(rpcKey: string | undefined): void {
@@ -82,7 +114,7 @@ export class DesktopDetachedWindowManager {
82
114
  if (remembered) {
83
115
  return normalizeWindowFrameWithMinimum(remembered, DEFAULT_WINDOW_FRAME, DETACHED_WINDOW_MIN_SIZE);
84
116
  }
85
- const mainFrame = getWindowFrame(this.backend.mainWindow) ?? DEFAULT_WINDOW_FRAME;
117
+ const mainFrame = this.frameOf(MAIN_WINDOW_ID) ?? DEFAULT_WINDOW_FRAME;
86
118
  return normalizeWindowFrameWithMinimum({
87
119
  x: mainFrame.x + 72,
88
120
  y: mainFrame.y + 72,
@@ -107,20 +139,26 @@ export class DesktopDetachedWindowManager {
107
139
  const desiredEntries = new Map(config.layout.detached
108
140
  .filter((entry) => !hidden(entry.instanceId))
109
141
  .map((entry) => [entry.instanceId, entry] as const));
142
+ const host = this.backend.windowHost;
110
143
  for (const [instanceId, entry] of desiredEntries) {
111
- const existingWindow = this.windows.get(instanceId);
112
- if (!existingWindow) {
144
+ if (!this.windows.has(instanceId)) {
113
145
  if (this.windowsAllowed) this.createWindow(instanceId, entry);
114
146
  continue;
115
147
  }
116
148
 
117
- const currentFrame = getWindowFrame(existingWindow);
149
+ const key = detachedRpcKey(instanceId);
150
+ const currentFrame = this.frameOf(key);
118
151
  const hasLiveFrameUpdate = this.pendingMoveFlush.has(instanceId)
119
152
  || this.frameTimers.has(instanceId)
120
153
  || this.dockTimers.has(instanceId);
121
- const nextFrame = currentFrame
154
+ const savedFrame = currentFrame
122
155
  ? normalizeWindowFrameWithMinimum(entry, currentFrame, DETACHED_WINDOW_MIN_SIZE)
123
156
  : null;
157
+ // Where the person left the window stays, even part off screen; a
158
+ // frame from elsewhere (or one saved off screen) lands on one.
159
+ const nextFrame = savedFrame && currentFrame && !sameRect(savedFrame, currentFrame)
160
+ ? this.onScreen(savedFrame)
161
+ : savedFrame;
124
162
  if (!hasLiveFrameUpdate
125
163
  && currentFrame
126
164
  && nextFrame
@@ -128,28 +166,27 @@ export class DesktopDetachedWindowManager {
128
166
  || currentFrame.y !== nextFrame.y
129
167
  || currentFrame.width !== nextFrame.width
130
168
  || currentFrame.height !== nextFrame.height)) {
131
- existingWindow.setFrame(nextFrame.x, nextFrame.y, nextFrame.width, nextFrame.height);
169
+ host?.setFrame(key, nextFrame);
132
170
  }
133
- (existingWindow as any).setTitle?.(this.resolveTitle(instanceId));
171
+ host?.setTitle(key, this.resolveTitle(instanceId));
134
172
  }
135
173
 
136
- for (const [instanceId, window] of this.windows) {
174
+ for (const instanceId of [...this.windows]) {
137
175
  if (desiredEntries.has(instanceId)) continue;
138
- this.closingPanes.add(instanceId);
139
- this.cleanupState(instanceId);
140
- (window as any).close?.();
176
+ this.closePaneWindow(instanceId);
141
177
  }
142
178
  }
143
179
 
144
180
  closeAll(): void {
145
- for (const [instanceId, window] of this.windows) {
146
- this.closingPanes.add(instanceId);
147
- this.cleanupState(instanceId);
148
- (window as any).close?.();
149
- }
181
+ for (const instanceId of [...this.windows]) this.closePaneWindow(instanceId);
150
182
  this.backend.stateBroadcaster.resetDockPreview();
151
183
  }
152
184
 
185
+ private closePaneWindow(instanceId: string): void {
186
+ this.cleanupState(instanceId);
187
+ this.backend.windowHost?.closeWindow(detachedRpcKey(instanceId));
188
+ }
189
+
153
190
  private resolveTitle(instanceId: string): string {
154
191
  const config = this.backend.config;
155
192
  const instance = config ? findPaneInstance(config.layout, instanceId) : null;
@@ -158,7 +195,7 @@ export class DesktopDetachedWindowManager {
158
195
  }
159
196
 
160
197
  private resolveDockEdge(frame: WindowFrame): "left" | "right" | "top" | "bottom" | null {
161
- const mainFrame = getWindowFrame(this.backend.mainWindow);
198
+ const mainFrame = this.frameOf(MAIN_WINDOW_ID);
162
199
  if (!mainFrame) return null;
163
200
  const threshold = 72;
164
201
  const headerMidX = frame.x + (frame.width / 2);
@@ -187,32 +224,18 @@ export class DesktopDetachedWindowManager {
187
224
  private createWindow(
188
225
  instanceId: string,
189
226
  frame: Partial<WindowFrame>,
190
- ): BrowserWindow {
191
- const rpc = this.backend.createWindowRpc(detachedRpcKey(instanceId));
192
- const initialFrame = normalizeWindowFrameWithMinimum(frame, DEFAULT_WINDOW_FRAME, DETACHED_WINDOW_MIN_SIZE);
193
- const title = this.resolveTitle(instanceId);
194
- const window = createAppWindow({
195
- title,
196
- frame: initialFrame,
197
- rpc: rpc as never,
198
- minSize: DETACHED_WINDOW_MIN_SIZE,
199
- onFrameChange: () => this.scheduleMove(instanceId),
200
- });
201
- this.windows.set(instanceId, window);
227
+ ): void {
228
+ const host = this.backend.windowHost;
229
+ if (!host) return;
230
+ this.windows.add(instanceId);
202
231
  this.suppressDockUntil.set(instanceId, Date.now() + INITIAL_DOCK_SUPPRESSION_MS);
203
-
204
- (window as any).on?.("close", () => {
205
- const shouldIgnore = this.closingPanes.delete(instanceId);
206
- this.cleanupState(instanceId);
207
- const workspace = this.backend.workspace;
208
- const config = this.backend.config;
209
- if (shouldIgnore || !workspace || !config || !isPaneDetached(config.layout, instanceId)) {
210
- return;
211
- }
212
- void this.backend.commitDesktopSnapshot(this.backend.requireWorkspace().closeDetachedPane(instanceId));
232
+ host.openWindow({
233
+ id: detachedRpcKey(instanceId),
234
+ kind: "pane",
235
+ title: this.resolveTitle(instanceId),
236
+ frame: this.onScreen(normalizeWindowFrameWithMinimum(frame, DEFAULT_WINDOW_FRAME, DETACHED_WINDOW_MIN_SIZE)),
237
+ minSize: DETACHED_WINDOW_MIN_SIZE,
213
238
  });
214
-
215
- return window;
216
239
  }
217
240
 
218
241
  private scheduleMove(instanceId: string): void {
@@ -225,14 +248,13 @@ export class DesktopDetachedWindowManager {
225
248
  }
226
249
 
227
250
  private handleMove(instanceId: string): void {
228
- const window = this.windows.get(instanceId);
229
251
  const workspace = this.backend.workspace;
230
252
  const config = this.backend.config;
231
- if (!window || !workspace || !config || !isPaneDetached(config.layout, instanceId)) {
253
+ if (!this.windows.has(instanceId) || !workspace || !config || !isPaneDetached(config.layout, instanceId)) {
232
254
  return;
233
255
  }
234
256
 
235
- const frame = getWindowFrame(window);
257
+ const frame = this.frameOf(detachedRpcKey(instanceId));
236
258
  if (!frame) return;
237
259
  const edge = this.resolveDockEdge(frame);
238
260