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.
- package/package.json +3 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
- package/src/api-client/equity-screener.ts +23 -0
- package/src/app/pane-runtime/index.tsx +2 -0
- package/src/app/pane-runtime/plugin-bindings.ts +10 -1
- package/src/app.tsx +63 -16
- package/src/cli/commands/command-utils.ts +4 -0
- package/src/cli/commands/market.ts +264 -33
- package/src/cli/commands/search.ts +22 -4
- package/src/cli/commands/ticker.ts +84 -39
- package/src/cli/currency-name-hint.ts +60 -0
- package/src/cli/glossary.ts +3 -3
- package/src/cli/history-rows.ts +18 -1
- package/src/cli/known-gaps.ts +25 -2
- package/src/cli/listing-arg.ts +12 -0
- package/src/cli/not-a-ticker.ts +5 -3
- package/src/cli/pane-functions/capabilities.ts +2 -0
- package/src/cli/pane-functions/catalog.ts +31 -5
- package/src/cli/pane-functions/function-help.ts +8 -5
- package/src/cli/pane-functions/headless.ts +11 -6
- package/src/cli/pane-functions/market-session.ts +6 -7
- package/src/cli/pane-functions/resolver.ts +75 -2
- package/src/cli/quote-answer.ts +9 -0
- package/src/cli/series-search.ts +4 -5
- package/src/cli/symbol-list.ts +54 -2
- package/src/cli/symbol-rows.ts +14 -2
- package/src/cli/ticker-resolution.ts +89 -20
- package/src/components/chart/composite/axis-overlays.tsx +60 -27
- package/src/components/chart/composite/composite-chart.tsx +118 -63
- package/src/components/chart/composite/cursor-source.ts +111 -0
- package/src/components/chart/composite/format.ts +168 -6
- package/src/components/chart/composite/legend.tsx +8 -4
- package/src/components/chart/composite/panel-bitmap.ts +28 -2
- package/src/components/chart/composite/panel-labels.ts +20 -1
- package/src/components/chart/composite/panel-surface.tsx +201 -92
- package/src/components/chart/composite/price-axis-labels.tsx +92 -46
- package/src/components/chart/composite/price-series.ts +31 -8
- package/src/components/chart/composite/scene.ts +154 -59
- package/src/components/chart/composite/series-axis-tags.tsx +4 -2
- package/src/components/chart/composite/time-axis.ts +30 -7
- package/src/components/chart/composite/time-scale.ts +211 -56
- package/src/components/chart/composite/types.ts +11 -1
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
- package/src/components/chart/curve/curve-surface.tsx +5 -2
- package/src/components/chart/curve/model.ts +4 -1
- package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
- package/src/components/chart/static/series.ts +3 -0
- package/src/components/command-bar/commands/collection-list.ts +81 -0
- package/src/components/command-bar/commands/direct/index.ts +6 -0
- package/src/components/command-bar/commands/registry.ts +8 -0
- package/src/components/command-bar/layout-items/current-layout.ts +22 -1
- package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
- package/src/components/command-bar/pane-templates/items.ts +19 -3
- package/src/components/command-bar/pane-templates/workflow.ts +5 -0
- package/src/components/command-bar/routes/root/results.ts +23 -3
- package/src/components/command-bar/routes/root/selection.ts +4 -2
- package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
- package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
- package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
- package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
- package/src/components/command-bar/surface/environment.ts +2 -0
- package/src/components/command-bar/view-model.ts +7 -0
- package/src/components/command-bar/workflow/ops.ts +2 -1
- package/src/components/command-bar/workflow/tickers.ts +20 -0
- package/src/components/layout/shell/active-drag.ts +38 -7
- package/src/components/layout/shell/drag/magnets.ts +106 -0
- package/src/components/layout/shell/menu.ts +15 -1
- package/src/components/layout/shell/pane/actions.ts +4 -0
- package/src/components/layout/shell/ticker-link-menu.ts +12 -3
- package/src/components/layout/status-bar.tsx +20 -0
- package/src/components/layout/window-controls.tsx +96 -35
- package/src/components/layout/window-fullscreen.ts +20 -0
- package/src/components/onboarding/onboarding-keyboard.ts +5 -1
- package/src/components/onboarding/onboarding-wizard.tsx +15 -4
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
- package/src/components/onboarding/use-onboarding-progress.ts +20 -1
- package/src/components/price-sparkline/view.tsx +14 -6
- package/src/components/quote-flash.ts +36 -32
- package/src/components/ticker/badge/index.tsx +8 -4
- package/src/components/ticker/badge/list.tsx +23 -7
- package/src/components/ui/column-grid.tsx +8 -2
- package/src/components/ui/data-table/opentui/model.ts +4 -1
- package/src/components/ui/tabs.tsx +5 -2
- package/src/core/state/app/layout.ts +18 -3
- package/src/core/state/app/state.ts +2 -0
- package/src/core/state/app/types.ts +5 -0
- package/src/data/config/layout.ts +3 -0
- package/src/data/config/store/normalize.ts +39 -4
- package/src/i18n/es.ts +10 -0
- package/src/i18n/ja.ts +10 -0
- package/src/i18n/ko.ts +10 -0
- package/src/i18n/zh-cn.ts +10 -0
- package/src/i18n/zh-tw.ts +10 -0
- package/src/layout/pane-manager/floating-placement.ts +7 -4
- package/src/layout/pane-manager/floating.ts +5 -2
- package/src/market-data/bond-funds.ts +19 -0
- package/src/market-data/coordinator/events.ts +17 -1
- package/src/market-data/frame-scheduler.ts +47 -10
- package/src/market-data/frame-wake.ts +74 -0
- package/src/market-data/futures-board.ts +7 -6
- package/src/market-data/futures-contract.ts +14 -3
- package/src/market-data/hooks.tsx +12 -3
- package/src/market-data/market/freshness.ts +18 -0
- package/src/market-data/market/status.ts +15 -2
- package/src/market-data/performance.ts +78 -9
- package/src/market-data/request-types.ts +6 -3
- package/src/plugins/builtin/alerts/cli.ts +2 -1
- package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
- package/src/plugins/builtin/attention/evidence.ts +1 -1
- package/src/plugins/builtin/awards/client.ts +1 -1
- package/src/plugins/builtin/awards/evidence.ts +1 -1
- package/src/plugins/builtin/awards/pane.tsx +2 -1
- package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
- package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
- package/src/plugins/builtin/bond-calculator/math.ts +1 -1
- package/src/plugins/builtin/bond-calculator/model.ts +14 -5
- package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
- package/src/plugins/builtin/broker-manager/footer.ts +3 -2
- package/src/plugins/builtin/broker-manager/index.tsx +2 -1
- package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
- package/src/plugins/builtin/buildout/cells.tsx +25 -45
- package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
- package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
- package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
- package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
- package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
- package/src/plugins/builtin/buildout/format.ts +23 -1
- package/src/plugins/builtin/buildout/model/types.ts +1 -0
- package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
- package/src/plugins/builtin/buildout/table-model.ts +12 -4
- package/src/plugins/builtin/catalysts/evidence.ts +1 -1
- package/src/plugins/builtin/catalysts/pane.tsx +2 -1
- package/src/plugins/builtin/cds/headless.ts +1 -0
- package/src/plugins/builtin/cds/index.tsx +1 -1
- package/src/plugins/builtin/chart-composer/headless.ts +40 -1
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
- package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
- package/src/plugins/builtin/comment-letters/client.ts +2 -1
- package/src/plugins/builtin/company-kpis/client.ts +1 -1
- package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
- package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
- package/src/plugins/builtin/correlation/headless.ts +3 -2
- package/src/plugins/builtin/cot/headless.ts +9 -3
- package/src/plugins/builtin/cot/model.ts +44 -3
- package/src/plugins/builtin/credit-documents/client.ts +1 -1
- package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
- package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
- package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
- package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
- package/src/plugins/builtin/debt-maturities/model.ts +66 -0
- package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
- package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
- package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
- package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
- package/src/plugins/builtin/econ/calendar-model.ts +30 -6
- package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
- package/src/plugins/builtin/econ/print-watch.ts +3 -1
- package/src/plugins/builtin/equity-screener/client.ts +1 -1
- package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
- package/src/plugins/builtin/equity-screener/headless.ts +4 -2
- package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
- package/src/plugins/builtin/equity-screener/model.ts +180 -12
- package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
- package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
- package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
- package/src/plugins/builtin/futures/series.ts +16 -1
- package/src/plugins/builtin/futures-curve/client.ts +19 -0
- package/src/plugins/builtin/futures-curve/headless.ts +52 -13
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +77 -6
- package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
- package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
- package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
- package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
- package/src/plugins/builtin/gpu/headless.ts +2 -1
- package/src/plugins/builtin/help/function-card.tsx +2 -1
- package/src/plugins/builtin/help/index.tsx +2 -1
- package/src/plugins/builtin/insider/display.ts +45 -6
- package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
- package/src/plugins/builtin/iv-history/client.ts +2 -1
- package/src/plugins/builtin/iv-history/headless.ts +2 -1
- package/src/plugins/builtin/jobs/pages.ts +4 -4
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
- package/src/plugins/builtin/macro-day/client.ts +41 -0
- package/src/plugins/builtin/macro-day/headless.ts +19 -9
- package/src/plugins/builtin/macro-day/model.ts +3 -1
- package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
- package/src/plugins/builtin/market-movers/index.tsx +4 -3
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/mna/distress/client.ts +1 -0
- package/src/plugins/builtin/mna/distress/headless.ts +1 -0
- package/src/plugins/builtin/mna/pane.tsx +4 -1
- package/src/plugins/builtin/options/market-reference.ts +1 -1
- package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
- package/src/plugins/builtin/options/view.tsx +2 -1
- package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
- package/src/plugins/builtin/options-scenario/csp.ts +28 -9
- package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/client.ts +1 -1
- package/src/plugins/builtin/perps/pane.tsx +3 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
- package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
- package/src/plugins/builtin/rate-path/headless.ts +24 -10
- package/src/plugins/builtin/research/analyst-model.ts +1 -0
- package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
- package/src/plugins/builtin/research/event-model.ts +10 -3
- package/src/plugins/builtin/research/events-headless.ts +20 -2
- package/src/plugins/builtin/research/index.tsx +1 -0
- package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
- package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
- package/src/plugins/builtin/research-search/snippet.ts +1 -0
- package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
- package/src/plugins/builtin/seasonality/headless.ts +2 -1
- package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
- package/src/plugins/builtin/sec/fund-facts.ts +17 -1
- package/src/plugins/builtin/sec/index.tsx +8 -5
- package/src/plugins/builtin/sec/row-summaries.ts +28 -12
- package/src/plugins/builtin/shared/members-menu.tsx +103 -38
- package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
- package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
- package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
- package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
- package/src/plugins/builtin/social-mentions/client.ts +2 -1
- package/src/plugins/builtin/supply-chain/client.ts +1 -1
- package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
- package/src/plugins/builtin/time-sales/client.ts +1 -0
- package/src/plugins/builtin/time-sales/pane.tsx +3 -2
- package/src/plugins/builtin/trace-bonds/client.ts +7 -4
- package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
- package/src/plugins/builtin/vol-surface/client.ts +2 -1
- package/src/plugins/builtin/volatility/client.ts +6 -1
- package/src/plugins/builtin/volatility/headless.ts +0 -1
- package/src/plugins/builtin/yield-curve/curves.ts +15 -0
- package/src/plugins/builtin/yield-curve/headless.ts +9 -2
- package/src/plugins/builtin/yield-curve/index.tsx +5 -8
- package/src/plugins/host-modules.ts +22 -3
- package/src/plugins/host-smoke.ts +6 -3
- package/src/portfolio/collection-name.ts +19 -0
- package/src/portfolio/column-values.ts +76 -10
- package/src/renderers/browser/http-proxy-transport.ts +78 -8
- package/src/renderers/cloudflare/http-proxy.ts +13 -2
- package/src/renderers/cloudflare/proxy-session.ts +47 -24
- package/src/renderers/cloudflare/worker.ts +15 -2
- package/src/renderers/desktop/geometry.ts +279 -0
- package/src/renderers/desktop/screen-setup.ts +246 -0
- package/src/renderers/desktop/sequential-window-host.ts +179 -0
- package/src/renderers/desktop/test-utils.ts +71 -0
- package/src/renderers/desktop/window-controller.ts +433 -0
- package/src/renderers/desktop/window-host.ts +70 -0
- package/src/renderers/desktop/window-layouts.ts +630 -0
- package/src/renderers/dom/data-frames.ts +15 -4
- package/src/renderers/dom/host/box.tsx +204 -176
- package/src/renderers/dom/host/style.ts +49 -20
- package/src/renderers/dom/host/text.tsx +3 -2
- package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
- package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
- package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
- package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
- package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
- package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
- package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
- package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
- package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
- package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
- package/src/renderers/electrobun/bun/index.ts +4 -97
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
- package/src/renderers/electrobun/bun/window/focus.ts +0 -25
- package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
- package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
- package/src/renderers/electrobun/shared/protocol.ts +50 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
- package/src/renderers/electrobun/view/main.tsx +13 -7
- package/src/renderers/electrobun/view/ui-host.tsx +7 -0
- package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
- package/src/series/fred-argument.ts +17 -0
- package/src/sources/provider-router/financial-routes.ts +7 -1
- package/src/sources/provider-router/index.ts +7 -1
- package/src/state/app/context/index.tsx +16 -2
- package/src/state/desktop-windows.ts +63 -0
- package/src/sync/other-window-tabs.ts +62 -0
- package/src/tickers/company-name-listing.ts +23 -3
- package/src/tickers/listing-fate.ts +147 -1
- package/src/tickers/terminal-codes.ts +5 -0
- package/src/time-series/price-units.ts +11 -0
- package/src/time-series/types.ts +6 -0
- package/src/types/config.ts +10 -1
- package/src/types/desktop-window.ts +71 -2
- package/src/types/financials.ts +4 -0
- package/src/types/headless.ts +19 -0
- package/src/types/plugin.ts +6 -0
- package/src/ui/host.tsx +2 -0
- package/src/ui/index.tsx +14 -13
- package/src/ui/same-props.ts +58 -0
- package/src/utils/cli-output.ts +33 -4
- package/src/utils/currency-names.ts +20 -0
- package/src/utils/currency-pair.ts +6 -0
- package/src/utils/exchange-rate-snapshot.ts +20 -2
- package/src/utils/format.ts +7 -2
- package/src/utils/futures-generic.ts +12 -0
- package/src/utils/fx-market-hours.ts +43 -0
- package/src/utils/http-proxy-upstream.ts +6 -2
- package/src/utils/plugin-proxy-hosts.json +0 -4
- package/src/utils/plugin-proxy-hosts.ts +22 -0
- package/src/utils/sec-filings.ts +7 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Electrobun, { ApplicationMenu,
|
|
1
|
+
import Electrobun, { ApplicationMenu, Utils } from "electrobun/bun";
|
|
2
2
|
import { homedir } from "os";
|
|
3
3
|
import { debugLog } from "../../../utils/debug-log";
|
|
4
4
|
import { setConfigStoreHost } from "../../../data/config/store";
|
|
@@ -8,24 +8,7 @@ import { contextMenuSelectionMessage } from "./context-menu/click";
|
|
|
8
8
|
import { applicationMenuCommand, createApplicationMenuGate } from "./application-menu/click";
|
|
9
9
|
import { DesktopBackend } from "./desktop/backend";
|
|
10
10
|
import { startDesktopBackend } from "./desktop/initialization";
|
|
11
|
-
import {
|
|
12
|
-
MAIN_WINDOW_MIN_SIZE,
|
|
13
|
-
defaultMainWindowFrame,
|
|
14
|
-
normalizeWindowFrameWithMinimum,
|
|
15
|
-
} from "./window/frame";
|
|
16
|
-
import { MAIN_WINDOW_RPC_KEY } from "./window/focus";
|
|
17
|
-
import { createAppWindow } from "./window/create";
|
|
18
|
-
import { desktopBootFramePath, desktopBootFramePreload, readDesktopBootFrame } from "./window/boot-frame";
|
|
19
|
-
import { getWindowFrame } from "./window/events";
|
|
20
|
-
import {
|
|
21
|
-
fitWindowFrameToDisplays,
|
|
22
|
-
readRememberedDesktopWindow,
|
|
23
|
-
rememberedDesktopWindowPath,
|
|
24
|
-
writeRememberedDesktopWindow,
|
|
25
|
-
type RememberedDesktopWindow,
|
|
26
|
-
} from "./window/remembered-frame";
|
|
27
11
|
import { reapStaleTerminalMedia } from "../../opentui/terminal-media";
|
|
28
|
-
import { quitWindowsEventLoopOnItsThread } from "./window/windows-quit";
|
|
29
12
|
import { installProcessCrashListeners } from "../../../telemetry/crash-reports-node";
|
|
30
13
|
import { renameLegacyMacApp } from "./desktop/app-name";
|
|
31
14
|
import { scheduleDesktopRelaunch } from "./desktop/relaunch";
|
|
@@ -123,87 +106,11 @@ backend.installApplicationMenu();
|
|
|
123
106
|
// started from. Cleaning up here is what makes the stray actually die.
|
|
124
107
|
reapStaleTerminalMedia();
|
|
125
108
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const fallbackMainWindowFrame = defaultMainWindowFrame();
|
|
130
|
-
const initialMainWindowFrame = fitWindowFrameToDisplays(
|
|
131
|
-
normalizeWindowFrameWithMinimum(rememberedWindow?.frame, fallbackMainWindowFrame, MAIN_WINDOW_MIN_SIZE),
|
|
132
|
-
readDisplayWorkAreas(),
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
let windowedFrame = initialMainWindowFrame;
|
|
136
|
-
let rememberTimer: ReturnType<typeof setTimeout> | null = null;
|
|
137
|
-
|
|
138
|
-
function readDisplayWorkAreas() {
|
|
139
|
-
try {
|
|
140
|
-
return Screen.getAllDisplays().map((display) => ({
|
|
141
|
-
x: display.workArea?.x ?? display.bounds.x,
|
|
142
|
-
y: display.workArea?.y ?? display.bounds.y,
|
|
143
|
-
width: display.workArea?.width ?? display.bounds.width,
|
|
144
|
-
height: display.workArea?.height ?? display.bounds.height,
|
|
145
|
-
primary: display.isPrimary,
|
|
146
|
-
}));
|
|
147
|
-
} catch {
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function rememberedFromWindow(): RememberedDesktopWindow | null {
|
|
153
|
-
const window = backend.mainWindow;
|
|
154
|
-
const live = getWindowFrame(window) ?? windowedFrame;
|
|
155
|
-
let minimized = false;
|
|
156
|
-
let fullscreen = false;
|
|
157
|
-
let maximized = false;
|
|
158
|
-
try { minimized = window?.isMinimized() === true; } catch { minimized = false; }
|
|
159
|
-
if (minimized) return null;
|
|
160
|
-
try { fullscreen = window?.isFullScreen() === true; } catch { fullscreen = false; }
|
|
161
|
-
try { maximized = !fullscreen && window?.isMaximized() === true; } catch { maximized = false; }
|
|
162
|
-
if (!fullscreen && !maximized) windowedFrame = live;
|
|
163
|
-
return { frame: windowedFrame, maximized, fullscreen };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function flushRememberedWindow(): void {
|
|
167
|
-
if (rememberTimer) {
|
|
168
|
-
clearTimeout(rememberTimer);
|
|
169
|
-
rememberTimer = null;
|
|
170
|
-
}
|
|
171
|
-
const next = rememberedFromWindow();
|
|
172
|
-
if (next) writeRememberedDesktopWindow(rememberedWindowPath, next);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function scheduleRememberedWindow(): void {
|
|
176
|
-
if (rememberTimer) clearTimeout(rememberTimer);
|
|
177
|
-
rememberTimer = setTimeout(() => {
|
|
178
|
-
rememberTimer = null;
|
|
179
|
-
const next = rememberedFromWindow();
|
|
180
|
-
if (next) writeRememberedDesktopWindow(rememberedWindowPath, next);
|
|
181
|
-
}, 300);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const mainWindow = createAppWindow({
|
|
185
|
-
title: "Gloom",
|
|
186
|
-
frame: initialMainWindowFrame,
|
|
187
|
-
rpc: mainRpc,
|
|
188
|
-
minSize: MAIN_WINDOW_MIN_SIZE,
|
|
189
|
-
onFrameChange: scheduleRememberedWindow,
|
|
190
|
-
// The layout the window last drew, which its page draws before its script
|
|
191
|
-
// has loaded (dom/boot-frame.ts).
|
|
192
|
-
preload: desktopBootFramePreload(readDesktopBootFrame(desktopBootFramePath())),
|
|
193
|
-
});
|
|
194
|
-
backend.mainWindow = mainWindow;
|
|
195
|
-
quitWindowsEventLoopOnItsThread(mainWindow);
|
|
109
|
+
// The main window opens where it was left on these screens; extra windows
|
|
110
|
+
// follow once it has its data (desktop/window-controller.ts).
|
|
111
|
+
backend.startWindows();
|
|
196
112
|
// The window is loading its view; the services it will ask for start now
|
|
197
113
|
// rather than when it asks. Its `init` reports a failure, and retries.
|
|
198
114
|
startDesktopBackend(backend).catch((error) => {
|
|
199
115
|
console.error("[desktop] startup failed", error instanceof Error ? error.stack ?? error.message : String(error));
|
|
200
116
|
});
|
|
201
|
-
// Windows has no way into fullscreen here, and builds whose frameless window
|
|
202
|
-
// Windows took for fullscreen saved every window as fullscreen.
|
|
203
|
-
if (rememberedWindow?.fullscreen && process.platform !== "win32") {
|
|
204
|
-
try { mainWindow.setFullScreen(true); } catch { /* the framed window is still the one they sized */ }
|
|
205
|
-
} else if (rememberedWindow?.maximized) {
|
|
206
|
-
try { mainWindow.maximize(); } catch { /* the framed window is still the one they sized */ }
|
|
207
|
-
}
|
|
208
|
-
(mainWindow as { on?: (event: "close", listener: () => void) => void }).on?.("close", flushRememberedWindow);
|
|
209
|
-
backend.detachedWindows.focusWindowForRpcKey(MAIN_WINDOW_RPC_KEY);
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import type { BrowserWindow, Screen } from "electrobun/bun";
|
|
2
|
+
import { arrangementKey, type DesktopDisplay, type Rect } from "../../../desktop/geometry";
|
|
3
|
+
import type {
|
|
4
|
+
DesktopWindowHost,
|
|
5
|
+
NativeWindowEvent,
|
|
6
|
+
NativeWindowState,
|
|
7
|
+
OpenWindowSpec,
|
|
8
|
+
} from "../../../desktop/window-host";
|
|
9
|
+
import { getWindowFrame, updateWindowFrameCache } from "./events";
|
|
10
|
+
import type { FocusableElectrobunWindow } from "./focus";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Electrobun 1.18 has no event for displays coming and going, nor for a window
|
|
14
|
+
* being minimized: both are read on a timer, this often while there is more
|
|
15
|
+
* than one window...
|
|
16
|
+
*/
|
|
17
|
+
const POLL_MS = 3_000;
|
|
18
|
+
/**
|
|
19
|
+
* ...and this often with one, which reads the displays only: its page's own
|
|
20
|
+
* visibility says when it is hidden, as it did before there were more windows.
|
|
21
|
+
*/
|
|
22
|
+
const QUIET_POLL_MS = 10_000;
|
|
23
|
+
/**
|
|
24
|
+
* A window's own events read whether it is minimized at once, so one coming
|
|
25
|
+
* back redraws without waiting for the timer: a focus, a move or a resize
|
|
26
|
+
* (a restore on Windows). A blur reads it again this long after, once the
|
|
27
|
+
* minimize animation has run.
|
|
28
|
+
*/
|
|
29
|
+
const AFTER_BLUR_MS = 600;
|
|
30
|
+
|
|
31
|
+
export interface ElectrobunWindowHostOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Makes the native window: the view it loads, its RPC channel and preload
|
|
34
|
+
* are the backend's. `onFrameChange` runs after each move or resize.
|
|
35
|
+
*/
|
|
36
|
+
create(spec: OpenWindowSpec, hooks: { onFrameChange: () => void }): BrowserWindow;
|
|
37
|
+
platform?: NodeJS.Platform;
|
|
38
|
+
env?: NodeJS.ProcessEnv;
|
|
39
|
+
/** The displays as Electrobun lists them: `Screen.getAllDisplays`. */
|
|
40
|
+
readDisplays: () => ElectrobunDisplay[];
|
|
41
|
+
pollMs?: number;
|
|
42
|
+
quietPollMs?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type ElectrobunDisplay = ReturnType<typeof Screen.getAllDisplays>[number];
|
|
46
|
+
|
|
47
|
+
function toRect(value: Partial<Rect> | undefined, fallback: Rect): Rect {
|
|
48
|
+
return {
|
|
49
|
+
x: typeof value?.x === "number" ? value.x : fallback.x,
|
|
50
|
+
y: typeof value?.y === "number" ? value.y : fallback.y,
|
|
51
|
+
width: typeof value?.width === "number" ? value.width : fallback.width,
|
|
52
|
+
height: typeof value?.height === "number" ? value.height : fallback.height,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readElectrobunDisplays(read: () => ElectrobunDisplay[]): DesktopDisplay[] {
|
|
57
|
+
try {
|
|
58
|
+
return read().map((display) => {
|
|
59
|
+
const bounds = toRect(display.bounds, { x: 0, y: 0, width: 0, height: 0 });
|
|
60
|
+
return {
|
|
61
|
+
id: String(display.id),
|
|
62
|
+
bounds,
|
|
63
|
+
workArea: toRect(display.workArea, bounds),
|
|
64
|
+
scaleFactor: typeof display.scaleFactor === "number" && display.scaleFactor > 0 ? display.scaleFactor : 1,
|
|
65
|
+
primary: display.isPrimary === true,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
} catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether windows can place themselves. Under a Wayland session GTK talks to
|
|
75
|
+
* the compositor, which ignores a window's own position; run through XWayland
|
|
76
|
+
* (GDK_BACKEND=x11) they can.
|
|
77
|
+
*/
|
|
78
|
+
function canPlaceWindowsOn(platform: NodeJS.Platform, env: NodeJS.ProcessEnv): boolean {
|
|
79
|
+
if (platform !== "linux") return true;
|
|
80
|
+
const wayland = env.XDG_SESSION_TYPE === "wayland" || !!env.WAYLAND_DISPLAY;
|
|
81
|
+
return !wayland || env.GDK_BACKEND === "x11";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A native yes or no; false when the window cannot answer. */
|
|
85
|
+
function read(call: () => boolean): boolean {
|
|
86
|
+
try {
|
|
87
|
+
return call() === true;
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The desktop window host on Electrobun 1.18: windows, their frames and events, and the displays. */
|
|
94
|
+
export class ElectrobunWindowHost implements DesktopWindowHost {
|
|
95
|
+
readonly canPlaceWindows: boolean;
|
|
96
|
+
/** Windows has no way into full screen with Electrobun's frameless windows. */
|
|
97
|
+
readonly canFullscreen: boolean;
|
|
98
|
+
private readonly windows = new Map<string, BrowserWindow>();
|
|
99
|
+
private readonly minimized = new Map<string, boolean>();
|
|
100
|
+
/** Each window's maximized and full screen state as last read: a closed window cannot be asked. */
|
|
101
|
+
private readonly modes = new Map<string, { maximized: boolean; fullscreen: boolean }>();
|
|
102
|
+
/** A window closed from outside, as last known, while its close is being reported. */
|
|
103
|
+
private readonly closing = new Map<string, NativeWindowState>();
|
|
104
|
+
private readonly displayListeners = new Set<(displays: DesktopDisplay[]) => void>();
|
|
105
|
+
private readonly windowListeners = new Set<(event: NativeWindowEvent) => void>();
|
|
106
|
+
private poll: ReturnType<typeof setTimeout> | null = null;
|
|
107
|
+
private lastArrangement: string;
|
|
108
|
+
|
|
109
|
+
constructor(private readonly options: ElectrobunWindowHostOptions) {
|
|
110
|
+
const platform = options.platform ?? process.platform;
|
|
111
|
+
this.canPlaceWindows = canPlaceWindowsOn(platform, options.env ?? process.env);
|
|
112
|
+
this.canFullscreen = platform !== "win32";
|
|
113
|
+
this.lastArrangement = arrangementKey(this.listDisplays());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The Electrobun window, for the few calls only this shell makes (its native handle, devtools). */
|
|
117
|
+
browserWindow(id: string): BrowserWindow | null {
|
|
118
|
+
return this.windows.get(id) ?? null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
listDisplays(): DesktopDisplay[] {
|
|
122
|
+
return readElectrobunDisplays(this.options.readDisplays);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
openWindow(spec: OpenWindowSpec): void {
|
|
126
|
+
if (this.windows.has(spec.id)) return;
|
|
127
|
+
const window = this.options.create(spec, {
|
|
128
|
+
onFrameChange: () => {
|
|
129
|
+
this.checkMinimized(spec.id);
|
|
130
|
+
this.readModes(spec.id);
|
|
131
|
+
this.emit({ type: "frame", id: spec.id });
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
this.windows.set(spec.id, window);
|
|
135
|
+
this.minimized.set(spec.id, false);
|
|
136
|
+
const on = (window as { on?: (name: string, handler: (event: unknown) => void) => void }).on;
|
|
137
|
+
on?.call(window, "focus", () => {
|
|
138
|
+
this.checkMinimized(spec.id);
|
|
139
|
+
this.emit({ type: "focus", id: spec.id });
|
|
140
|
+
});
|
|
141
|
+
on?.call(window, "blur", () => {
|
|
142
|
+
this.checkMinimized(spec.id);
|
|
143
|
+
setTimeout(() => this.checkMinimized(spec.id), AFTER_BLUR_MS);
|
|
144
|
+
});
|
|
145
|
+
on?.call(window, "close", () => {
|
|
146
|
+
// Only the person's closes are reported: `closeWindow` forgets the window first.
|
|
147
|
+
if (this.windows.get(spec.id) !== window) return;
|
|
148
|
+
// The native window is gone: what is known of it answers while its close is reported.
|
|
149
|
+
const frame = getWindowFrame(window);
|
|
150
|
+
const modes = this.modes.get(spec.id) ?? { maximized: false, fullscreen: false };
|
|
151
|
+
if (frame) this.closing.set(spec.id, { frame, ...modes, minimized: this.minimized.get(spec.id) === true });
|
|
152
|
+
this.forget(spec.id);
|
|
153
|
+
try {
|
|
154
|
+
this.emit({ type: "close", id: spec.id });
|
|
155
|
+
} finally {
|
|
156
|
+
this.closing.delete(spec.id);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
// A second window reads sooner than the timer one window left.
|
|
160
|
+
this.schedulePoll(true);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
closeWindow(id: string): void {
|
|
164
|
+
const window = this.windows.get(id);
|
|
165
|
+
if (!window) return;
|
|
166
|
+
this.forget(id);
|
|
167
|
+
window.close();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private forget(id: string): void {
|
|
171
|
+
this.windows.delete(id);
|
|
172
|
+
this.minimized.delete(id);
|
|
173
|
+
this.modes.delete(id);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
hasWindow(id: string): boolean {
|
|
177
|
+
return this.windows.has(id);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
getWindowState(id: string): NativeWindowState | null {
|
|
181
|
+
const window = this.windows.get(id);
|
|
182
|
+
if (!window) return this.closing.get(id) ?? null;
|
|
183
|
+
const frame = getWindowFrame(window);
|
|
184
|
+
if (!frame) return null;
|
|
185
|
+
return { frame, ...this.readModes(id), minimized: read(() => window.isMinimized()) };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private readModes(id: string): { maximized: boolean; fullscreen: boolean } {
|
|
189
|
+
const window = this.windows.get(id);
|
|
190
|
+
if (!window) return { maximized: false, fullscreen: false };
|
|
191
|
+
const fullscreen = this.canFullscreen && read(() => window.isFullScreen());
|
|
192
|
+
const modes = { maximized: !fullscreen && read(() => window.isMaximized()), fullscreen };
|
|
193
|
+
this.modes.set(id, modes);
|
|
194
|
+
return modes;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
setFrame(id: string, frame: Rect): void {
|
|
198
|
+
const window = this.windows.get(id);
|
|
199
|
+
if (!window) return;
|
|
200
|
+
window.setFrame(frame.x, frame.y, frame.width, frame.height);
|
|
201
|
+
updateWindowFrameCache(window, frame);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
setMaximized(id: string, maximized: boolean): void {
|
|
205
|
+
const window = this.windows.get(id);
|
|
206
|
+
try {
|
|
207
|
+
if (maximized) window?.maximize();
|
|
208
|
+
else window?.unmaximize();
|
|
209
|
+
} catch {
|
|
210
|
+
// The window keeps the frame it has.
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
setFullscreen(id: string, fullscreen: boolean): void {
|
|
215
|
+
if (!this.canFullscreen) return;
|
|
216
|
+
try {
|
|
217
|
+
this.windows.get(id)?.setFullScreen(fullscreen);
|
|
218
|
+
} catch {
|
|
219
|
+
// The window keeps the frame it has.
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setTitle(id: string, title: string): void {
|
|
224
|
+
(this.windows.get(id) as { setTitle?: (title: string) => void } | undefined)?.setTitle?.(title);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
focusWindow(id: string): void {
|
|
228
|
+
const window = this.windows.get(id) as FocusableElectrobunWindow | undefined;
|
|
229
|
+
if (!window) return;
|
|
230
|
+
if (this.minimized.get(id)) {
|
|
231
|
+
try {
|
|
232
|
+
(window as unknown as BrowserWindow).unminimize();
|
|
233
|
+
} catch {
|
|
234
|
+
// Focusing it still brings it forward where the system allows.
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (window.activate) window.activate();
|
|
238
|
+
else window.focus?.();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
onDisplaysChanged(listener: (displays: DesktopDisplay[]) => void): () => void {
|
|
242
|
+
this.displayListeners.add(listener);
|
|
243
|
+
this.schedulePoll(false);
|
|
244
|
+
return () => {
|
|
245
|
+
this.displayListeners.delete(listener);
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
onWindowEvent(listener: (event: NativeWindowEvent) => void): () => void {
|
|
250
|
+
this.windowListeners.add(listener);
|
|
251
|
+
return () => {
|
|
252
|
+
this.windowListeners.delete(listener);
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
dispose(): void {
|
|
257
|
+
if (this.poll) clearTimeout(this.poll);
|
|
258
|
+
this.poll = null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private emit(event: NativeWindowEvent): void {
|
|
262
|
+
for (const listener of [...this.windowListeners]) listener(event);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private pollInterval(): number {
|
|
266
|
+
return this.windows.size > 1 ? this.options.pollMs ?? POLL_MS : this.options.quietPollMs ?? QUIET_POLL_MS;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Sets the next read; `sooner` moves one already set closer when there are now more windows. */
|
|
270
|
+
private schedulePoll(sooner: boolean): void {
|
|
271
|
+
if (this.poll && !sooner) return;
|
|
272
|
+
if (this.poll) clearTimeout(this.poll);
|
|
273
|
+
this.poll = setTimeout(() => {
|
|
274
|
+
this.poll = null;
|
|
275
|
+
this.check();
|
|
276
|
+
this.schedulePoll(false);
|
|
277
|
+
}, this.pollInterval());
|
|
278
|
+
(this.poll as { unref?: () => void }).unref?.();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private check(): void {
|
|
282
|
+
const displays = this.listDisplays();
|
|
283
|
+
const arrangement = arrangementKey(displays);
|
|
284
|
+
if (displays.length > 0 && arrangement !== this.lastArrangement) {
|
|
285
|
+
this.lastArrangement = arrangement;
|
|
286
|
+
for (const listener of [...this.displayListeners]) listener(displays);
|
|
287
|
+
}
|
|
288
|
+
if (this.windows.size > 1) {
|
|
289
|
+
for (const id of this.windows.keys()) this.checkMinimized(id);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private checkMinimized(id: string): void {
|
|
294
|
+
const window = this.windows.get(id);
|
|
295
|
+
if (!window) return;
|
|
296
|
+
let minimized: boolean;
|
|
297
|
+
try {
|
|
298
|
+
minimized = window.isMinimized() === true;
|
|
299
|
+
} catch {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (this.minimized.get(id) === minimized) return;
|
|
303
|
+
this.minimized.set(id, minimized);
|
|
304
|
+
this.emit({ type: "visibility", id, visible: !minimized });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -15,28 +15,3 @@ export function paneIdFromDetachedRpcKey(rpcKey: string | undefined): string | n
|
|
|
15
15
|
if (!rpcKey?.startsWith(DETACHED_WINDOW_RPC_PREFIX)) return null;
|
|
16
16
|
return rpcKey.slice(DETACHED_WINDOW_RPC_PREFIX.length) || null;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
function resolveWindowForRpcKey<T>(
|
|
20
|
-
rpcKey: string | undefined,
|
|
21
|
-
mainWindow: T | null,
|
|
22
|
-
detachedWindows: ReadonlyMap<string, T>,
|
|
23
|
-
): T | null {
|
|
24
|
-
if (rpcKey === MAIN_WINDOW_RPC_KEY) return mainWindow;
|
|
25
|
-
const paneId = paneIdFromDetachedRpcKey(rpcKey);
|
|
26
|
-
return paneId ? detachedWindows.get(paneId) ?? null : null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function focusWindowForRpcKey(
|
|
30
|
-
rpcKey: string | undefined,
|
|
31
|
-
mainWindow: FocusableElectrobunWindow | null,
|
|
32
|
-
detachedWindows: ReadonlyMap<string, FocusableElectrobunWindow>,
|
|
33
|
-
): boolean {
|
|
34
|
-
const window = resolveWindowForRpcKey(rpcKey, mainWindow, detachedWindows);
|
|
35
|
-
if (window?.activate) {
|
|
36
|
-
window.activate();
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
if (!window?.focus) return false;
|
|
40
|
-
window.focus();
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { dlopen, FFIType, ptr, type Pointer } from "bun:ffi";
|
|
2
|
+
import type { DesktopWindowResizeEdge } from "../../shared/protocol";
|
|
2
3
|
|
|
3
4
|
const WINDOWS_HANDLE_MAX_ATTEMPTS = 20;
|
|
4
5
|
const WINDOWS_HANDLE_RETRY_DELAY_MS = 100;
|
|
@@ -57,6 +58,10 @@ function loadWin32() {
|
|
|
57
58
|
args: [FFIType.u32, FFIType.ptr],
|
|
58
59
|
returns: FFIType.bool,
|
|
59
60
|
},
|
|
61
|
+
IsZoomed: {
|
|
62
|
+
args: [FFIType.ptr],
|
|
63
|
+
returns: FFIType.bool,
|
|
64
|
+
},
|
|
60
65
|
});
|
|
61
66
|
}
|
|
62
67
|
|
|
@@ -93,6 +98,8 @@ export function fitPageToClientArea(windowHandle: Pointer): boolean {
|
|
|
93
98
|
const WM_NCLBUTTONDOWN = 0x00a1;
|
|
94
99
|
const WM_CANCELMODE = 0x001f;
|
|
95
100
|
const HTCAPTION = 2;
|
|
101
|
+
/** HTTOP, HTTOPLEFT, HTTOPRIGHT. */
|
|
102
|
+
const TOP_EDGE_HIT_TESTS: Record<DesktopWindowResizeEdge, number> = { top: 12, "top-left": 13, "top-right": 14 };
|
|
96
103
|
/** GUITHREADINFO on 64-bit Windows: two DWORDs, six window handles, a RECT. */
|
|
97
104
|
const GUI_THREAD_INFO_SIZE = 72;
|
|
98
105
|
const GUI_THREAD_INFO_CAPTURE_OFFSET = 24;
|
|
@@ -126,12 +133,30 @@ function mouseCaptureOnThreadOf(win32: Win32, windowHandle: Pointer): Pointer |
|
|
|
126
133
|
export function startSystemWindowMove(windowHandle: Pointer): boolean {
|
|
127
134
|
const win32 = win32OrNull();
|
|
128
135
|
if (!win32) return false;
|
|
136
|
+
return pressNonClientArea(win32, windowHandle, HTCAPTION);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Hands a press on the page's top edge to Windows as a press on the frame's
|
|
141
|
+
* top edge, which the page covers: its size loop then resizes the window until
|
|
142
|
+
* the button comes up. A maximized window has no edge to pull, so the press
|
|
143
|
+
* moves it, as one at the top of a maximized title bar does. False off Windows.
|
|
144
|
+
*/
|
|
145
|
+
export function startSystemWindowResize(windowHandle: Pointer, edge: DesktopWindowResizeEdge): boolean {
|
|
146
|
+
const win32 = win32OrNull();
|
|
147
|
+
if (!win32) return false;
|
|
148
|
+
const hitTest = win32.symbols.IsZoomed(windowHandle) ? HTCAPTION : TOP_EDGE_HIT_TESTS[edge];
|
|
149
|
+
return pressNonClientArea(win32, windowHandle, hitTest);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Presses the window's frame at `hitTest` where the pointer is, after the page lets go of the mouse. */
|
|
153
|
+
function pressNonClientArea(win32: Win32, windowHandle: Pointer, hitTest: number): boolean {
|
|
129
154
|
const point = new Int32Array(2);
|
|
130
155
|
if (!win32.symbols.GetCursorPos(ptr(point))) return false;
|
|
131
156
|
const capture = mouseCaptureOnThreadOf(win32, windowHandle);
|
|
132
157
|
if (capture && capture !== windowHandle) win32.symbols.PostMessageW(capture, WM_CANCELMODE, 0n, 0n);
|
|
133
158
|
const position = ((point[1]! & 0xffff) << 16) | (point[0]! & 0xffff);
|
|
134
|
-
return win32.symbols.PostMessageW(windowHandle, WM_NCLBUTTONDOWN, BigInt(
|
|
159
|
+
return win32.symbols.PostMessageW(windowHandle, WM_NCLBUTTONDOWN, BigInt(hitTest), BigInt(position >>> 0));
|
|
135
160
|
}
|
|
136
161
|
|
|
137
162
|
export function wideString(value: string): Uint8Array {
|