@gloom-sh/terminal 0.19.5 → 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 (208) hide show
  1. package/package.json +1 -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/market.ts +149 -10
  8. package/src/cli/commands/search.ts +21 -3
  9. package/src/cli/commands/ticker.ts +74 -33
  10. package/src/cli/glossary.ts +3 -3
  11. package/src/cli/known-gaps.ts +8 -0
  12. package/src/cli/listing-arg.ts +12 -0
  13. package/src/cli/pane-functions/capabilities.ts +2 -0
  14. package/src/cli/pane-functions/catalog.ts +22 -4
  15. package/src/cli/pane-functions/function-help.ts +8 -5
  16. package/src/cli/pane-functions/headless.ts +4 -3
  17. package/src/cli/pane-functions/resolver.ts +75 -2
  18. package/src/cli/quote-answer.ts +9 -0
  19. package/src/cli/symbol-list.ts +54 -2
  20. package/src/cli/symbol-rows.ts +14 -2
  21. package/src/cli/ticker-resolution.ts +89 -20
  22. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  23. package/src/components/chart/composite/composite-chart.tsx +118 -63
  24. package/src/components/chart/composite/cursor-source.ts +111 -0
  25. package/src/components/chart/composite/format.ts +168 -6
  26. package/src/components/chart/composite/legend.tsx +8 -4
  27. package/src/components/chart/composite/panel-labels.ts +20 -1
  28. package/src/components/chart/composite/panel-surface.tsx +201 -92
  29. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  30. package/src/components/chart/composite/price-series.ts +31 -8
  31. package/src/components/chart/composite/scene.ts +154 -59
  32. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  33. package/src/components/chart/composite/time-axis.ts +13 -5
  34. package/src/components/chart/composite/time-scale.ts +211 -56
  35. package/src/components/chart/composite/types.ts +11 -1
  36. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  37. package/src/components/chart/curve/curve-surface.tsx +5 -2
  38. package/src/components/chart/curve/model.ts +4 -1
  39. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  40. package/src/components/chart/static/series.ts +3 -0
  41. package/src/components/command-bar/commands/collection-list.ts +81 -0
  42. package/src/components/command-bar/commands/direct/index.ts +6 -0
  43. package/src/components/command-bar/commands/registry.ts +8 -0
  44. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  45. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  46. package/src/components/command-bar/pane-templates/items.ts +19 -3
  47. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  48. package/src/components/command-bar/routes/root/results.ts +23 -3
  49. package/src/components/command-bar/routes/root/selection.ts +4 -2
  50. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  51. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  52. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  53. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  54. package/src/components/command-bar/surface/environment.ts +2 -0
  55. package/src/components/command-bar/view-model.ts +7 -0
  56. package/src/components/command-bar/workflow/ops.ts +2 -1
  57. package/src/components/command-bar/workflow/tickers.ts +20 -0
  58. package/src/components/layout/shell/menu.ts +15 -1
  59. package/src/components/layout/shell/pane/actions.ts +4 -0
  60. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  61. package/src/components/layout/status-bar.tsx +20 -0
  62. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  63. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  64. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  65. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  66. package/src/components/price-sparkline/view.tsx +14 -6
  67. package/src/components/ticker/badge/index.tsx +8 -4
  68. package/src/components/ticker/badge/list.tsx +23 -7
  69. package/src/components/ui/column-grid.tsx +8 -2
  70. package/src/components/ui/data-table/opentui/model.ts +4 -1
  71. package/src/components/ui/tabs.tsx +5 -2
  72. package/src/core/state/app/layout.ts +18 -3
  73. package/src/core/state/app/state.ts +2 -0
  74. package/src/core/state/app/types.ts +5 -0
  75. package/src/data/config/layout.ts +3 -0
  76. package/src/data/config/store/normalize.ts +39 -4
  77. package/src/i18n/es.ts +10 -0
  78. package/src/i18n/ja.ts +10 -0
  79. package/src/i18n/ko.ts +10 -0
  80. package/src/i18n/zh-cn.ts +10 -0
  81. package/src/i18n/zh-tw.ts +10 -0
  82. package/src/layout/pane-manager/floating-placement.ts +7 -4
  83. package/src/layout/pane-manager/floating.ts +5 -2
  84. package/src/market-data/bond-funds.ts +19 -0
  85. package/src/market-data/futures-contract.ts +14 -3
  86. package/src/market-data/market/freshness.ts +18 -0
  87. package/src/market-data/market/status.ts +15 -2
  88. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  89. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  90. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  91. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  92. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  93. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  94. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  95. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  96. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  97. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  98. package/src/plugins/builtin/buildout/format.ts +23 -1
  99. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  100. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  101. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  102. package/src/plugins/builtin/cds/headless.ts +1 -0
  103. package/src/plugins/builtin/cds/index.tsx +1 -1
  104. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  105. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  106. package/src/plugins/builtin/correlation/headless.ts +3 -2
  107. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  108. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  109. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  110. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  111. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  112. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  113. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  114. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  115. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  116. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  117. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  118. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  119. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  120. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  121. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  122. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  123. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  124. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  125. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  126. package/src/plugins/builtin/macro-day/client.ts +41 -0
  127. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  128. package/src/plugins/builtin/macro-day/model.ts +3 -1
  129. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  130. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  131. package/src/plugins/builtin/perps/pane.tsx +3 -1
  132. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  133. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  134. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  135. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  136. package/src/plugins/builtin/research/event-model.ts +10 -3
  137. package/src/plugins/builtin/research/events-headless.ts +20 -2
  138. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  139. package/src/plugins/builtin/sec/index.tsx +1 -1
  140. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  141. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  142. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  143. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  144. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  145. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  146. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  147. package/src/plugins/builtin/volatility/client.ts +6 -1
  148. package/src/plugins/builtin/volatility/headless.ts +0 -1
  149. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  150. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  151. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  152. package/src/plugins/host-modules.ts +22 -3
  153. package/src/plugins/host-smoke.ts +6 -3
  154. package/src/portfolio/collection-name.ts +19 -0
  155. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  156. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  157. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  158. package/src/renderers/cloudflare/worker.ts +15 -2
  159. package/src/renderers/desktop/geometry.ts +279 -0
  160. package/src/renderers/desktop/screen-setup.ts +246 -0
  161. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  162. package/src/renderers/desktop/test-utils.ts +71 -0
  163. package/src/renderers/desktop/window-controller.ts +433 -0
  164. package/src/renderers/desktop/window-host.ts +70 -0
  165. package/src/renderers/desktop/window-layouts.ts +630 -0
  166. package/src/renderers/dom/data-frames.ts +15 -4
  167. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  168. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  169. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  170. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  171. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  172. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  173. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  174. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  175. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  176. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  177. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  178. package/src/renderers/electrobun/bun/index.ts +4 -97
  179. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  180. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  181. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  182. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  183. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  184. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  185. package/src/renderers/electrobun/view/main.tsx +13 -7
  186. package/src/series/fred-argument.ts +17 -0
  187. package/src/sources/provider-router/financial-routes.ts +7 -1
  188. package/src/state/app/context/index.tsx +16 -2
  189. package/src/state/desktop-windows.ts +63 -0
  190. package/src/sync/other-window-tabs.ts +62 -0
  191. package/src/tickers/company-name-listing.ts +23 -3
  192. package/src/tickers/listing-fate.ts +147 -1
  193. package/src/tickers/terminal-codes.ts +5 -0
  194. package/src/time-series/types.ts +6 -0
  195. package/src/types/config.ts +10 -1
  196. package/src/types/desktop-window.ts +71 -2
  197. package/src/types/financials.ts +4 -0
  198. package/src/types/headless.ts +19 -0
  199. package/src/types/plugin.ts +6 -0
  200. package/src/ui/index.tsx +14 -13
  201. package/src/ui/same-props.ts +58 -0
  202. package/src/utils/cli-output.ts +33 -4
  203. package/src/utils/format.ts +7 -2
  204. package/src/utils/futures-generic.ts +12 -0
  205. package/src/utils/http-proxy-upstream.ts +6 -2
  206. package/src/utils/plugin-proxy-hosts.json +0 -4
  207. package/src/utils/plugin-proxy-hosts.ts +22 -0
  208. package/src/utils/sec-filings.ts +7 -1
@@ -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
 
@@ -38,9 +38,7 @@ function playNotificationSound(sound: string | undefined): void {
38
38
  }
39
39
 
40
40
  function windowForRpcKey(backend: DesktopBackend, windowKey: string | undefined): BrowserWindow | null {
41
- return windowKey === MAIN_WINDOW_RPC_KEY
42
- ? backend.mainWindow
43
- : backend.detachedWindows.getWindowForRpcKey(windowKey);
41
+ return backend.nativeWindow(windowKey);
44
42
  }
45
43
 
46
44
  /**
@@ -78,17 +76,9 @@ function controlWindow(
78
76
  return true;
79
77
  }
80
78
 
81
- /** Exiting closes the popped-out windows, services and main window; with no main window it quits directly. */
79
+ /** Exiting closes every window and the services, then quits. */
82
80
  function exitDesktopApp(backend: DesktopBackend): void {
83
- backend.detachedWindows.closeAll();
84
- backend.teardownServices();
85
- const mainWindow = backend.mainWindow;
86
- if (mainWindow) {
87
- mainWindow.close();
88
- backend.mainWindow = null;
89
- return;
90
- }
91
- Utils.quit();
81
+ backend.quit();
92
82
  }
93
83
 
94
84
  function normalizeWindowResizeEdge(edge: unknown): DesktopWindowResizeEdge {
@@ -155,7 +145,7 @@ export async function handleDesktopHostRequest(
155
145
  return null;
156
146
  case "host.focusWindow": {
157
147
  const windowKey = backend.rpcs.getRpcWindowKey(rpc);
158
- if (windowKey) backend.detachedWindows.focusWindowForRpcKey(windowKey);
148
+ backend.focusWindow(windowKey);
159
149
  return null;
160
150
  }
161
151
  case "host.copyPngImage": {
@@ -31,13 +31,15 @@ import { markStartupComplete } from "../../../../utils/main-thread-stall";
31
31
  interface DesktopWindowTarget {
32
32
  kind: "main" | "detached";
33
33
  paneId?: string;
34
+ /** A full window's id: the main window's, or an extra window's. */
35
+ windowId?: string;
34
36
  }
35
37
 
36
38
  function normalizeInitWindowTarget(
37
39
  rpcKey: string | undefined,
38
40
  payload: DesktopBackendRequestPayload<"init">,
39
41
  ): DesktopWindowTarget {
40
- if (rpcKey === MAIN_WINDOW_RPC_KEY) return { kind: "main" };
42
+ if (rpcKey === MAIN_WINDOW_RPC_KEY) return { kind: "main", windowId: MAIN_WINDOW_RPC_KEY };
41
43
 
42
44
  const detachedPaneId = paneIdFromDetachedRpcKey(rpcKey);
43
45
  if (detachedPaneId) {
@@ -46,6 +48,8 @@ function normalizeInitWindowTarget(
46
48
  paneId: detachedPaneId,
47
49
  };
48
50
  }
51
+ // Every other window the backend opens is a full window with its own tabs.
52
+ if (rpcKey) return { kind: "main", windowId: rpcKey };
49
53
 
50
54
  const kind = payload.kind === "detached" ? "detached" : "main";
51
55
  return {
@@ -75,13 +79,21 @@ function buildInitializationPayload(
75
79
  config: AppConfig,
76
80
  services: AppServices,
77
81
  windowTarget: DesktopWindowTarget,
82
+ windowKey: string | undefined,
78
83
  ): ElectrobunBackendInit {
84
+ const mainWindow = windowTarget.windowId === MAIN_WINDOW_RPC_KEY;
79
85
  // The main window says once what the launch's seed could not install.
80
- const pluginSeedNotice = windowTarget.kind === "main" ? takePluginSeedNotice() : null;
86
+ const pluginSeedNotice = mainWindow ? takePluginSeedNotice() : null;
87
+ // Each full window draws its own tabs; a popped-out pane's draws the main
88
+ // window's. Numbered like every state sent, so the window's first sync is
89
+ // merged against it.
90
+ const projected = backend.workspace?.getWindowSnapshot(windowTarget.windowId ?? MAIN_WINDOW_RPC_KEY) ?? null;
91
+ const desktopSnapshot = projected ? backend.stateBroadcaster.stamp(projected) : null;
92
+ if (desktopSnapshot && windowKey) backend.workspace?.noteDelivered(windowKey, desktopSnapshot.stateSeq!, desktopSnapshot);
81
93
  return {
82
- config,
94
+ config: desktopSnapshot?.config ?? config,
83
95
  sessionSnapshot: backend.getSessionSnapshot(),
84
- desktopSnapshot: backend.workspace?.getSnapshot() ?? null,
96
+ desktopSnapshot,
85
97
  desktopThemePreview: backend.stateBroadcaster.currentThemePreview,
86
98
  pluginState: loadDesktopPluginState(services.pluginRegistry),
87
99
  savedResources: loadSavedResources(services, config),
@@ -90,6 +102,8 @@ function buildInitializationPayload(
90
102
  hostName: hostname(),
91
103
  windowKind: windowTarget.kind,
92
104
  paneId: windowTarget.paneId,
105
+ ...(windowTarget.windowId ? { windowId: windowTarget.windowId, windows: backend.windowInfos() } : {}),
106
+ ...(mainWindow ? { otherWindowTabs: backend.otherWindowTabsForInit() } : {}),
93
107
  ...(pluginSeedNotice ? { pluginSeedNotice } : {}),
94
108
  telemetry: {
95
109
  installId: readOrCreateInstallId(config.dataDir),
@@ -185,23 +199,28 @@ export async function initializeDesktopBackend(
185
199
  rpc: DesktopRpc,
186
200
  payload: DesktopBackendRequestPayload<"init">,
187
201
  ): Promise<ElectrobunBackendInit> {
188
- const windowTarget = normalizeInitWindowTarget(backend.rpcs.getRpcWindowKey(rpc), payload);
202
+ const windowKey = backend.rpcs.getRpcWindowKey(rpc);
203
+ const windowTarget = normalizeInitWindowTarget(windowKey, payload);
189
204
  backend.rpcs.markWindowRpcReady(rpc);
190
205
  backend.stateBroadcaster.forgetWindowState(rpc);
206
+ // Its page loaded and runs: the next window waiting to open may.
207
+ if (windowKey) backend.windowHost?.windowDrawn(windowKey);
191
208
 
192
209
  await startDesktopBackend(backend);
193
210
  const config = backend.requireConfig();
194
211
  const services = backend.requireServices();
195
212
  if (!backend.workspace) {
196
- backend.workspace = createDesktopWorkspace(config, backend.getSessionSnapshot());
197
- backend.detachedWindows.reconcile();
213
+ backend.workspace = createDesktopWorkspace(config, backend.getSessionSnapshot(), backend.windowController?.screenSetup.windows);
214
+ backend.reconcileWindows();
198
215
  }
199
- const init = buildInitializationPayload(backend, config, services, windowTarget);
216
+ // A window that loads again starts from this state: nothing sent before counts.
217
+ if (windowKey) backend.workspace.forgetWindow(windowKey);
218
+ const init = buildInitializationPayload(backend, config, services, windowTarget, windowKey);
200
219
  // The main window has what it needs to draw: this process is up, and the
201
- // popped-out windows open next.
202
- if (windowTarget.kind === "main") {
220
+ // popped-out panes and extra windows open next.
221
+ if (windowTarget.windowId === MAIN_WINDOW_RPC_KEY) {
203
222
  markStartupComplete();
204
- backend.detachedWindows.openAfterMainWindow();
223
+ backend.openWindowsAfterMainWindow();
205
224
  }
206
225
  return init;
207
226
  }
@@ -0,0 +1,55 @@
1
+ import { copyFileSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
2
+ import { dirname, join } from "path";
3
+ import { getGloomberbDirs } from "../../../../data/config/home";
4
+ import { emptyScreenSetup, parseScreenSetup, type ScreenSetup } from "../../../desktop/screen-setup";
5
+ import type { ScreenSetupStore } from "../../../desktop/window-controller";
6
+
7
+ /**
8
+ * The windows and where they sit, per monitor arrangement, beside the config
9
+ * and never in it: launch reads it before the config, and it describes this
10
+ * machine's screens, so it stays out of the synced config.
11
+ */
12
+ const FILE_NAME = "desktop-windows.json";
13
+
14
+ function desktopScreenSetupPath(env: NodeJS.ProcessEnv = process.env): string {
15
+ return join(dirname(getGloomberbDirs(env).configFile), FILE_NAME);
16
+ }
17
+
18
+ export function desktopScreenSetupStore(path: string = desktopScreenSetupPath()): ScreenSetupStore {
19
+ return {
20
+ load(): ScreenSetup {
21
+ let text: string;
22
+ try {
23
+ text = readFileSync(path, "utf8");
24
+ } catch {
25
+ // Intentional ignore: no file yet; the windows start from the defaults.
26
+ return emptyScreenSetup();
27
+ }
28
+ try {
29
+ const raw: unknown = JSON.parse(text);
30
+ if (raw && typeof raw === "object" && !Array.isArray(raw)) return parseScreenSetup(raw);
31
+ } catch {
32
+ // Not JSON: kept below.
33
+ }
34
+ // The next save would replace a file this build cannot read: a copy stays beside it.
35
+ try {
36
+ copyFileSync(path, `${path}.bak`);
37
+ } catch {
38
+ // Intentional ignore: the windows start from the defaults either way.
39
+ }
40
+ console.error("[desktop] the window setup could not be read; a copy was kept as desktop-windows.json.bak");
41
+ return emptyScreenSetup();
42
+ },
43
+ save(setup: ScreenSetup): void {
44
+ const temporary = `${path}.${process.pid}.tmp`;
45
+ try {
46
+ mkdirSync(dirname(path), { recursive: true });
47
+ writeFileSync(temporary, JSON.stringify(setup));
48
+ renameSync(temporary, path);
49
+ } catch (error) {
50
+ rmSync(temporary, { force: true });
51
+ console.error("[desktop] could not save the window setup", error instanceof Error ? error.message : String(error));
52
+ }
53
+ },
54
+ };
55
+ }
@@ -15,6 +15,21 @@ export interface DesktopStateRpc {
15
15
 
16
16
  interface DesktopStateBroadcasterOptions<Rpc extends DesktopStateRpc> {
17
17
  forEachReadyWindowRpc: (callback: (rpc: Rpc) => void) => void;
18
+ /**
19
+ * Which state a window draws: windows with the same view share one key.
20
+ * Without it every window gets the shared state.
21
+ */
22
+ viewKey?: (rpc: Rpc) => string;
23
+ /** The state for a view key, from the shared one; null sends that window nothing. */
24
+ project?: (viewKey: string, shared: DesktopSharedStateSnapshot) => DesktopSharedStateSnapshot | null;
25
+ /** Each state sent to a window, with the number it carries, which the window's next sync names as its base. */
26
+ delivered?: (rpc: Rpc, snapshot: DesktopSharedStateSnapshot) => void;
27
+ }
28
+
29
+ interface ProjectedState {
30
+ snapshot: DesktopSharedStateSnapshot | null;
31
+ key?: string;
32
+ encoded?: DesktopSharedStateSnapshot;
18
33
  }
19
34
 
20
35
  /**
@@ -29,6 +44,7 @@ function desktopStateKey(snapshot: DesktopSharedStateSnapshot): string {
29
44
  focusedPaneId: snapshot.focusedPaneId,
30
45
  statusBarVisible: snapshot.statusBarVisible,
31
46
  brokerSyncErrors: snapshot.brokerSyncErrors ?? {},
47
+ linkedTickers: snapshot.linkedTickers ?? {},
32
48
  });
33
49
  }
34
50
 
@@ -37,6 +53,7 @@ export class DesktopStateBroadcaster<Rpc extends DesktopStateRpc> {
37
53
  private themePreview: DesktopThemePreviewState = { theme: null };
38
54
  /** The state held by each window that sends its whole state: what it last sent here or was sent. */
39
55
  private readonly heldStateKeys = new WeakMap<Rpc, string>();
56
+ private seq = 0;
40
57
 
41
58
  constructor(private readonly options: DesktopStateBroadcasterOptions<Rpc>) {}
42
59
 
@@ -52,6 +69,12 @@ export class DesktopStateBroadcaster<Rpc extends DesktopStateRpc> {
52
69
  this.dockPreview = { paneId: null, edge: null };
53
70
  }
54
71
 
72
+ /** Numbers a state handed to a window outside a broadcast (its `init`), in the same series. */
73
+ stamp(snapshot: DesktopSharedStateSnapshot): DesktopSharedStateSnapshot {
74
+ this.seq += 1;
75
+ return { ...snapshot, stateSeq: this.seq };
76
+ }
77
+
55
78
  /** A window that sent its whole state holds it, and is not sent it back. */
56
79
  noteWindowState(rpc: Rpc, snapshot: DesktopSharedStateSnapshot): void {
57
80
  this.heldStateKeys.set(rpc, desktopStateKey(snapshot));
@@ -72,18 +95,29 @@ export class DesktopStateBroadcaster<Rpc extends DesktopStateRpc> {
72
95
  */
73
96
  sendDesktopState(snapshot: DesktopSharedStateSnapshot | null): void {
74
97
  if (!snapshot) return;
75
- let encodedSnapshot: DesktopSharedStateSnapshot | null = null;
76
- let snapshotKey: string | null = null;
98
+ this.seq += 1;
99
+ const seq = this.seq;
100
+ const views = new Map<string, ProjectedState>();
101
+ const { viewKey, project, delivered } = this.options;
77
102
  this.options.forEachReadyWindowRpc((rpc) => {
103
+ const view = viewKey?.(rpc) ?? "";
104
+ let projected = views.get(view);
105
+ if (!projected) {
106
+ const shown = project ? project(view, snapshot) : snapshot;
107
+ projected = { snapshot: shown ? { ...shown, stateSeq: seq } : null };
108
+ views.set(view, projected);
109
+ }
110
+ if (!projected.snapshot) return;
78
111
  const heldKey = this.heldStateKeys.get(rpc);
79
112
  if (heldKey !== undefined) {
80
- snapshotKey ??= desktopStateKey(snapshot);
81
- if (heldKey === snapshotKey) return;
82
- this.heldStateKeys.set(rpc, snapshotKey);
113
+ projected.key ??= desktopStateKey(projected.snapshot);
114
+ if (heldKey === projected.key) return;
115
+ this.heldStateKeys.set(rpc, projected.key);
83
116
  }
84
- encodedSnapshot ??= encodeRpcValue(snapshot) as DesktopSharedStateSnapshot;
117
+ projected.encoded ??= encodeRpcValue(projected.snapshot) as DesktopSharedStateSnapshot;
118
+ delivered?.(rpc, projected.snapshot);
85
119
  rpc.send["desktop.state"]({
86
- snapshot: encodedSnapshot,
120
+ snapshot: projected.encoded,
87
121
  });
88
122
  });
89
123
  }
@@ -101,11 +135,13 @@ export class DesktopStateBroadcaster<Rpc extends DesktopStateRpc> {
101
135
  });
102
136
  }
103
137
 
104
- sendThemePreview(preview: DesktopThemePreviewState): void {
138
+ /** Every window but the one previewing (`fromRpc`) previews the theme too. */
139
+ sendThemePreview(preview: DesktopThemePreviewState, fromRpc?: Rpc): void {
105
140
  if (this.themePreview.theme === preview.theme) return;
106
141
  this.themePreview = preview;
107
142
  const encodedPreview = encodeRpcValue(preview) as DesktopThemePreviewState;
108
143
  this.options.forEachReadyWindowRpc((rpc) => {
144
+ if (rpc === fromRpc) return;
109
145
  rpc.send["desktop.themePreview"]({
110
146
  preview: encodedPreview,
111
147
  });