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