@gloom-sh/terminal 0.19.6 → 0.20.1
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/electrobun-devkit@2.0.5.patch +408 -0
- package/src/api-client/bond-trades.ts +59 -0
- package/src/api-client/crypto-markets.ts +20 -2
- package/src/api-client/data.ts +21 -0
- package/src/api-client/fund-facts.ts +23 -1
- 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 +356 -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/runtime/desktop-deeplink.ts +41 -6
- package/src/app/runtime/plugin-seed.ts +119 -0
- package/src/app/runtime/startup.ts +45 -9
- package/src/app/star-prompt/status-line.tsx +1 -1
- package/src/app.tsx +2 -7
- package/src/architecture/ui-tokens-allowlist.json +0 -8
- package/src/cli/board-coins.ts +38 -5
- package/src/cli/commands/crypto-hints.ts +8 -1
- package/src/cli/commands/market.ts +29 -26
- package/src/cli/commands/overview.ts +13 -6
- package/src/cli/commands/ticker.ts +78 -18
- package/src/cli/company-name-hint.ts +19 -0
- package/src/cli/desktop-pane-shot-browser.ts +69 -3
- package/src/cli/entry.ts +10 -4
- package/src/cli/glossary.ts +25 -0
- package/src/cli/helpers.ts +4 -2
- package/src/cli/not-a-ticker.ts +26 -1
- package/src/cli/pane-functions/catalog.ts +3 -1
- package/src/cli/pane-functions/freshness.ts +45 -29
- package/src/cli/pane-functions/market-session.ts +14 -5
- package/src/cli/restore-plugins.ts +164 -51
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +11 -2
- package/src/components/chart-table/header.tsx +10 -1
- package/src/components/chart-table/layout.ts +14 -5
- package/src/components/command-bar/panel/index.tsx +13 -0
- package/src/components/command-bar/panel/layout.ts +7 -0
- package/src/components/command-bar/panel/runtime.ts +1 -0
- package/src/components/command-bar/panel/types.ts +2 -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/pane/actions.ts +6 -2
- package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
- package/src/components/layout/status-bar.tsx +4 -78
- package/src/components/layout/status-widget-space.ts +5 -5
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +1 -1
- package/src/components/ui/data-table/index.tsx +5 -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/i18n/es.ts +6 -3
- package/src/i18n/ja.ts +6 -3
- package/src/i18n/ko.ts +6 -3
- package/src/i18n/zh-cn.ts +6 -3
- package/src/i18n/zh-tw.ts +6 -3
- package/src/market-data/fund-facts.ts +7 -1
- package/src/market-data/market/change-basis.ts +20 -0
- package/src/market-data/market/format.ts +62 -2
- package/src/market-data/market/futures-week.ts +3 -1
- package/src/plugins/builtin/chart-composer/headless.ts +57 -17
- package/src/plugins/builtin/chart-composer/session-range.ts +82 -3
- 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/trial-offer-status-widget.tsx +3 -3
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +32 -25
- 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/compute.ts +8 -2
- package/src/plugins/builtin/correlation/headless.ts +10 -9
- package/src/plugins/builtin/correlation/history.ts +30 -0
- package/src/plugins/builtin/correlation/matrix/model.ts +10 -10
- package/src/plugins/builtin/correlation/relationship/model.ts +3 -6
- package/src/plugins/builtin/correlation/relationship/pane.tsx +1 -2
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/defi-view.tsx +12 -1
- package/src/plugins/builtin/crypto-board/defi.ts +44 -7
- package/src/plugins/builtin/crypto-board/headless.ts +83 -12
- package/src/plugins/builtin/crypto-board/model.ts +30 -6
- package/src/plugins/builtin/crypto-board/pane.tsx +13 -2
- 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/equity-screener/criterion-editor.tsx +13 -4
- package/src/plugins/builtin/equity-screener/headless.ts +33 -1
- package/src/plugins/builtin/equity-screener/model.ts +58 -15
- package/src/plugins/builtin/equity-screener/pane.tsx +36 -6
- package/src/plugins/builtin/executives/format.ts +5 -4
- package/src/plugins/builtin/executives/pane.tsx +1 -1
- 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/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/headless.ts +8 -2
- package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
- package/src/plugins/builtin/risk-factors/index.tsx +2 -28
- package/src/plugins/builtin/risk-factors/lock-note.ts +58 -0
- package/src/plugins/builtin/risk-factors/pane.tsx +10 -3
- package/src/plugins/builtin/scanner/hilo-model.ts +4 -3
- package/src/plugins/builtin/sec/fund-facts.ts +45 -11
- package/src/plugins/builtin/sec/headless.ts +30 -1
- package/src/plugins/builtin/sec/index.tsx +26 -5
- package/src/plugins/builtin/series-inventory.ts +1 -0
- package/src/plugins/builtin/shared/earnings-report.ts +7 -2
- package/src/plugins/builtin/shared/pro-lock-note.ts +5 -1
- 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/types.ts +2 -0
- 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 +19 -9
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
- package/src/plugins/builtin/time-sales/headless.ts +23 -7
- package/src/plugins/builtin/time-sales/index.tsx +2 -2
- 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/pane.tsx +64 -5
- package/src/plugins/extracted-plugins.ts +49 -24
- package/src/plugins/installer.ts +234 -32
- package/src/plugins/plugin-names.ts +11 -2
- package/src/plugins/running-installs.ts +34 -0
- package/src/plugins/seed-progress.ts +72 -0
- package/src/remote/controller.ts +9 -2
- package/src/remote/schema.ts +2 -1
- package/src/renderers/cloudflare/http-proxy.ts +67 -8
- package/src/renderers/cloudflare/proxy-session.ts +1 -1
- package/src/renderers/cloudflare/worker.ts +29 -2
- package/src/renderers/dom/desktop/icons.tsx +0 -2
- package/src/renderers/dom/styles.css +0 -3
- package/src/renderers/electrobun/bun/desktop/backend.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +14 -7
- package/src/renderers/electrobun/bun/desktop/initialization.ts +24 -14
- 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/update.ts +1 -1
- package/src/renderers/electrobun/bun/index.ts +24 -13
- package/src/renderers/electrobun/bun/window/context-menu-thread.ts +84 -0
- package/src/renderers/electrobun/bun/window/create.ts +23 -3
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +4 -4
- package/src/renderers/electrobun/bun/window/events.ts +4 -4
- package/src/renderers/electrobun/bun/window/frame.ts +2 -1
- package/src/renderers/electrobun/bun/window/native-call-thread.ts +224 -0
- package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
- package/src/renderers/electrobun/bun/window/native-timing.ts +10 -0
- package/src/renderers/electrobun/bun/window/script-for-webview.ts +15 -0
- package/src/renderers/electrobun/bun/window/webview-script-thread.ts +82 -0
- package/src/renderers/electrobun/shared/protocol.ts +13 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +8 -1
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +1 -1
- package/src/renderers/electrobun/view/main.tsx +4 -3
- package/src/renderers/opentui/start.tsx +3 -0
- package/src/sources/gloomberb-cloud/index.ts +5 -7
- package/src/sources/provider-router/batches.ts +18 -3
- package/src/sources/provider-router/financials.ts +18 -4
- package/src/telemetry/stall-reports.ts +21 -4
- package/src/types/data-provider.ts +14 -0
- package/src/types/financials.ts +15 -3
- package/src/types/headless.ts +2 -0
- package/src/utils/double-escape-close.ts +38 -16
- package/src/utils/format.ts +23 -3
- package/src/utils/main-thread-stall.ts +21 -5
- package/src/utils/perf-marks.ts +88 -9
- package/src/utils/price-earnings.ts +18 -0
- package/src/utils/reported-money.ts +9 -2
- package/src/utils/sec.ts +34 -3
- package/patches/electrobun@1.18.1.patch +0 -633
- package/src/api-client/types.ts +0 -2441
- package/src/plugins/seed-notice.ts +0 -20
|
@@ -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
|
+
}
|
|
@@ -46,3 +46,13 @@ export function measureNativeWindowCalls(): void {
|
|
|
46
46
|
measureCalls(BrowserWindow.prototype, "native.window", WINDOW_CALLS);
|
|
47
47
|
measureCalls(BrowserView.prototype, "native.view", VIEW_CALLS);
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Measures one of Electrobun's other native calls (a menu, the clipboard, a
|
|
52
|
+
* notification) as `native.<name>`: on Windows each waits for the thread that
|
|
53
|
+
* runs the windows, as the window calls do. `waitsOnPerson`: the call returns
|
|
54
|
+
* when a person chooses (a menu), so its time is not a freeze.
|
|
55
|
+
*/
|
|
56
|
+
export function measureNativeCall<T>(name: string, call: () => T, options?: { waitsOnPerson?: boolean }): T {
|
|
57
|
+
return measurePerf(`native.${name}`, call, undefined, { waitedOnPerson: options?.waitsOnPerson });
|
|
58
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `js`, made to run only in the page of the webview it was sent to.
|
|
3
|
+
*
|
|
4
|
+
* Off the app's thread a script reaches its webview by the webview's native
|
|
5
|
+
* pointer, taken when it was sent. A webview opened after that one closed
|
|
6
|
+
* can reuse the pointer, and the script would run there: its RPC answers
|
|
7
|
+
* could settle the other page's requests. The page knows its own webview id
|
|
8
|
+
* (Electrobun's preload sets it), and ids are never reused, so anywhere else
|
|
9
|
+
* the script does nothing. The scripts are Electrobun's message calls; a
|
|
10
|
+
* block around them changes nothing where they run.
|
|
11
|
+
*/
|
|
12
|
+
export function scriptForWebview(webviewId: number, js: string): string {
|
|
13
|
+
if (!Number.isSafeInteger(webviewId)) throw new Error(`Not a webview id: ${webviewId}`);
|
|
14
|
+
return `if (window.__electrobunWebviewId === ${webviewId}) {\n${js}\n}`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BrowserView } from "electrobun/bun";
|
|
2
|
+
import { reportCrash } from "../../../../telemetry/crash-reports";
|
|
3
|
+
import { nativeWrapperLibraryPath, startNativeCallThread, type NativeCallThread, type NativeCallThreadFailure } from "./native-call-thread";
|
|
4
|
+
import { scriptForWebview } from "./script-for-webview";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Past this a script's call counts as stuck: the thread that runs the
|
|
8
|
+
* windows takes one in milliseconds, and keeps taking them while a menu is
|
|
9
|
+
* open or a window is held mid-move. The app's own freeze watchdog waits
|
|
10
|
+
* as long.
|
|
11
|
+
*/
|
|
12
|
+
const SCRIPT_CALL_LIMIT_MS = 30_000;
|
|
13
|
+
/** After this many stuck threads in a row, scripts run on the app's thread. */
|
|
14
|
+
const MAX_STUCK_THREADS = 3;
|
|
15
|
+
|
|
16
|
+
let installed = false;
|
|
17
|
+
let reported = false;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Once per process, and only once it happens: scripts waiting on the app's
|
|
21
|
+
* thread again, or piling up behind a call that does not return, is the
|
|
22
|
+
* freeze this thread removes, so error tracking hears of it.
|
|
23
|
+
*/
|
|
24
|
+
function reportScriptThreadFailure(failure: NativeCallThreadFailure | "unavailable"): void {
|
|
25
|
+
if (reported) return;
|
|
26
|
+
reported = true;
|
|
27
|
+
reportCrash(
|
|
28
|
+
{ name: "WebviewScriptThread", message: `Messages to windows could not go off the app's thread: ${failure}` },
|
|
29
|
+
{ kind: "plugin", plugin: "stall-monitor" },
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* On Windows every message the app sends a window goes as a script (it has
|
|
35
|
+
* no socket there), and the script's native call waits until the thread
|
|
36
|
+
* that runs the windows takes it, so the app stood still whenever that
|
|
37
|
+
* thread was busy. Scripts go to a thread of their own, started with the
|
|
38
|
+
* first one, and run there in the order they were sent, each only in the
|
|
39
|
+
* page it was sent to (script-for-webview.ts).
|
|
40
|
+
*
|
|
41
|
+
* A call that does not return within the limit gives the thread up: the
|
|
42
|
+
* scripts behind it go to a new thread, in order, so they neither pile up
|
|
43
|
+
* behind it for good nor wait on this thread. After three stuck threads in
|
|
44
|
+
* a row, or where no thread can run, scripts run on this thread as before,
|
|
45
|
+
* the ones a thread took and never began first, so none is lost or
|
|
46
|
+
* overtaken.
|
|
47
|
+
*/
|
|
48
|
+
export function runWebviewScriptsOffThread(platform: string = process.platform): void {
|
|
49
|
+
if (platform !== "win32" || installed) return;
|
|
50
|
+
installed = true;
|
|
51
|
+
/** Undefined: started with the next script. Null: scripts run on this thread. */
|
|
52
|
+
let thread: NativeCallThread | null | undefined;
|
|
53
|
+
let stuckThreads = 0;
|
|
54
|
+
const encoder = new TextEncoder();
|
|
55
|
+
|
|
56
|
+
const start = (): NativeCallThread | null => {
|
|
57
|
+
const started = startNativeCallThread(nativeWrapperLibraryPath(), "evaluateJavaScriptWithNoCompletion", {
|
|
58
|
+
pointerFirst: true,
|
|
59
|
+
callLimitMs: SCRIPT_CALL_LIMIT_MS,
|
|
60
|
+
onCallDone: () => {
|
|
61
|
+
stuckThreads = 0;
|
|
62
|
+
},
|
|
63
|
+
onFailure: (failure, unstarted) => {
|
|
64
|
+
reportScriptThreadFailure(failure);
|
|
65
|
+
stuckThreads += failure === "stuck" ? 1 : 0;
|
|
66
|
+
thread = failure === "stuck" && stuckThreads < MAX_STUCK_THREADS ? undefined : null;
|
|
67
|
+
for (const call of unstarted) call.replay();
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
if (!started) reportScriptThreadFailure("unavailable");
|
|
71
|
+
return started;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const run = (js: string, webviewId: number, webview: number, runHere: () => void): boolean => {
|
|
75
|
+
if (thread === undefined) thread = start();
|
|
76
|
+
if (!thread) return false;
|
|
77
|
+
return thread.call(encoder.encode(`${scriptForWebview(webviewId, js)}\0`), webview, () => {
|
|
78
|
+
if (!run(js, webviewId, webview, runHere)) runHere();
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
BrowserView.setScriptRunner(run);
|
|
82
|
+
}
|
|
@@ -14,6 +14,7 @@ import type { TickerRecord } from "../../../types/ticker";
|
|
|
14
14
|
import type { ReleaseInfo, UpdateCheckResult, UpdateProgress } from "../../../updater";
|
|
15
15
|
import type { CapabilityManifest } from "../../../capabilities";
|
|
16
16
|
import type { PluginOperationResult, PluginPin } from "../../../plugins/marketplace/store";
|
|
17
|
+
import type { PluginSeedProgress } from "../../../plugins/seed-progress";
|
|
17
18
|
import type { RemoteControlRequest, RemoteControlResponse } from "../../../remote/types";
|
|
18
19
|
import type { HttpProxyRequestEnvelope, HttpProxyResponseEnvelope } from "../../../utils/http-proxy-response";
|
|
19
20
|
import type { StallEvent } from "../../../utils/main-thread-stall";
|
|
@@ -41,8 +42,12 @@ export interface ElectrobunBackendInit {
|
|
|
41
42
|
windows?: DesktopWindowInfo[];
|
|
42
43
|
/** The main window's: the tabs the other windows hold, for cloud sync. */
|
|
43
44
|
otherWindowTabs?: OtherWindowTab[];
|
|
44
|
-
/**
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The main window's: the plugins the launch is restoring in the background,
|
|
47
|
+
* to bring into its session as they land and to say what could not be
|
|
48
|
+
* installed. Later changes arrive as `plugins.seedProgress`.
|
|
49
|
+
*/
|
|
50
|
+
pluginSeed?: PluginSeedProgress;
|
|
46
51
|
/** What the view needs to send crash reports and usage counts the same way the Bun process would. */
|
|
47
52
|
telemetry: ElectrobunTelemetryInit;
|
|
48
53
|
/** The copy on disk of the ids the view keeps in its own storage (view/view-ids.ts). */
|
|
@@ -377,6 +382,11 @@ interface PluginsUpdatedMessage {
|
|
|
377
382
|
directories: string[];
|
|
378
383
|
}
|
|
379
384
|
|
|
385
|
+
/** The launch's restore of plugins that moved into their own repositories, after a change. */
|
|
386
|
+
interface PluginSeedProgressMessage {
|
|
387
|
+
seed: PluginSeedProgress;
|
|
388
|
+
}
|
|
389
|
+
|
|
380
390
|
export interface RemoteControlRequestMessage {
|
|
381
391
|
request: RemoteControlRequest;
|
|
382
392
|
}
|
|
@@ -414,6 +424,7 @@ export interface ElectrobunDesktopRpcSchema {
|
|
|
414
424
|
"desktop.focusPane": DesktopFocusPaneMessage;
|
|
415
425
|
"desktop.windowVisibility": DesktopWindowVisibilityMessage;
|
|
416
426
|
"plugins.updated": PluginsUpdatedMessage;
|
|
427
|
+
"plugins.seedProgress": PluginSeedProgressMessage;
|
|
417
428
|
"update.progress": UpdateProgressMessage;
|
|
418
429
|
"capability.event": CapabilityEventMessage;
|
|
419
430
|
"http.stream.chunk": HttpStreamChunkMessage;
|
|
@@ -18,6 +18,7 @@ import { RpcTimeoutError } from "../../../utils/rpc-timeout-error";
|
|
|
18
18
|
import { nameRpcTimeout, RPC_MAX_REQUEST_TIME_MS } from "./rpc-timeout";
|
|
19
19
|
import type { RemoteControlRequest, RemoteControlResponse } from "../../../remote/types";
|
|
20
20
|
import type { StallEvent } from "../../../utils/main-thread-stall";
|
|
21
|
+
import { publishPluginSeedProgress } from "../../../plugins/seed-progress";
|
|
21
22
|
|
|
22
23
|
type BackendMessages = ElectrobunDesktopRpcSchema["webview"]["messages"];
|
|
23
24
|
type BackendMessageName = keyof BackendMessages;
|
|
@@ -108,6 +109,12 @@ const rpc = Electroview.defineRPC<ElectrobunDesktopRpcSchema>({
|
|
|
108
109
|
const directories = message.directories.filter((directory): directory is string => typeof directory === "string");
|
|
109
110
|
emit("plugins.updated", { directories });
|
|
110
111
|
},
|
|
112
|
+
// Kept, not handed to a listener: it can arrive before the app is up,
|
|
113
|
+
// and the app reads the latest whenever it looks.
|
|
114
|
+
"plugins.seedProgress": (message) => {
|
|
115
|
+
if (typeof message?.seed?.seq !== "number" || !Array.isArray(message.seed.plugins)) return;
|
|
116
|
+
publishPluginSeedProgress(message.seed);
|
|
117
|
+
},
|
|
111
118
|
"capability.event": (message) => {
|
|
112
119
|
emit("capability.event", {
|
|
113
120
|
subscriptionId: message.subscriptionId,
|
|
@@ -129,7 +136,7 @@ const BRIDGE_READY_LIMIT_MS = 5_000;
|
|
|
129
136
|
async function waitForBridgeReady(): Promise<void> {
|
|
130
137
|
const start = Date.now();
|
|
131
138
|
while (Date.now() - start < BRIDGE_READY_LIMIT_MS) {
|
|
132
|
-
if (electroview.
|
|
139
|
+
if (electroview.hostSocket?.readyState === WebSocket.OPEN) {
|
|
133
140
|
return;
|
|
134
141
|
}
|
|
135
142
|
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
@@ -135,7 +135,7 @@ function useShotStatusLine(enabled: boolean, hasAsOf: () => boolean): ShotStatus
|
|
|
135
135
|
/**
|
|
136
136
|
* Static captures retain warnings, what a filter leaves out (`capture`) and
|
|
137
137
|
* optional source status without action shortcuts. With `statusLine` the footer also carries the capture's dated
|
|
138
|
-
* status line (`Fri 9 Oct close · 15 min delayed · markets closed
|
|
138
|
+
* status line (`Fri 9 Oct close · 15 min delayed · markets closed · regular session opens Mon 13:30 UTC, 09:30 ET`),
|
|
139
139
|
* inside the requested size: the body gives up the footer row for it. The
|
|
140
140
|
* pane's own text that says the same goes, so the date is said once: its `as
|
|
141
141
|
* of` (a footer segment or a query bar's) when the line dates the pane's data,
|
|
@@ -49,7 +49,7 @@ import { getMarketplaceHost, setPluginManager, type PluginManager } from "../../
|
|
|
49
49
|
import { remoteNotesFilesIO, setNotesFilesIO } from "../../../plugins/builtin/notes/files";
|
|
50
50
|
import { NOTES_FILES_CAPABILITY_ID } from "../../../capabilities";
|
|
51
51
|
import { loadOfficialPluginIds } from "../../../plugins/marketplace/feed";
|
|
52
|
-
import {
|
|
52
|
+
import { publishPluginSeedProgress } from "../../../plugins/seed-progress";
|
|
53
53
|
import { crashReportsEnabled, installCrashReporter, reportCrash } from "../../../telemetry/crash-reports";
|
|
54
54
|
import { browserDoNotTrack, installWindowCrashListeners } from "../../../telemetry/crash-reports-dom";
|
|
55
55
|
import { forwardAttendedStalls } from "../../../telemetry/stall-reports-dom";
|
|
@@ -183,8 +183,9 @@ async function boot() {
|
|
|
183
183
|
: init.desktopSnapshot;
|
|
184
184
|
const config = desktopSnapshot?.config ?? init.config;
|
|
185
185
|
applyLanguageFromConfig(config);
|
|
186
|
-
//
|
|
187
|
-
|
|
186
|
+
// The plugins the launch is restoring, which the app brings in as they
|
|
187
|
+
// land, as the terminal does; later changes come as messages.
|
|
188
|
+
if (init.pluginSeed) publishPluginSeedProgress(init.pluginSeed);
|
|
188
189
|
const desktopWindowBridge = createDesktopWindowBridge(init.windowKind, init.paneId);
|
|
189
190
|
// Menus and the command bar offer the other windows from here.
|
|
190
191
|
setDesktopWindows(desktopWindowBridge.windows ?? null);
|
|
@@ -12,6 +12,7 @@ import { startNodePluginAutoUpdates } from "../../plugins/auto-update-node";
|
|
|
12
12
|
import { activateUpdatedPlugins } from "../../plugins/marketplace/activation";
|
|
13
13
|
import { getMarketplaceHost, setPluginManager } from "../../plugins/marketplace/store";
|
|
14
14
|
import { createNodePluginManager } from "../../plugins/manager-node";
|
|
15
|
+
import { stopInstallCommands } from "../../plugins/running-installs";
|
|
15
16
|
import { setCurrentPluginTarget } from "../../plugins/current-target";
|
|
16
17
|
import { getLoadablePlugins } from "../../plugins/catalog";
|
|
17
18
|
import { OpenTuiInputHostProvider } from "./input-host";
|
|
@@ -104,6 +105,8 @@ export async function startOpenTuiApp({ externalPlugins, cliLaunchRequest }: Sta
|
|
|
104
105
|
let exitTimer: ReturnType<typeof setTimeout> | null = null;
|
|
105
106
|
const finishProcessExit = () => {
|
|
106
107
|
if (exitTimer) return;
|
|
108
|
+
// Plugin installs still running in the background end with the app.
|
|
109
|
+
stopInstallCommands();
|
|
107
110
|
exitTimer = setTimeout(() => {
|
|
108
111
|
void Promise.allSettled([
|
|
109
112
|
flushPendingPersistence(),
|
|
@@ -618,13 +618,11 @@ export class GloomberbCloudProvider implements AssetDataProvider {
|
|
|
618
618
|
const { matched, missing } = matchCloudBatchItems(submitted, payload.items);
|
|
619
619
|
return [...rejected, ...matched.map(({ target, item }) => {
|
|
620
620
|
// A successful batch can contain an expired cache fallback for only
|
|
621
|
-
// one listing
|
|
622
|
-
//
|
|
623
|
-
//
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return { target, quote: null, error: createProviderMiss(`Cloud quotes are stale for ${target.symbol}`) };
|
|
627
|
-
}
|
|
621
|
+
// one listing: the last price the service has, flagged stale as the
|
|
622
|
+
// single-quote route flags it. No freshness check passes it, so the
|
|
623
|
+
// router asks for that listing alone and keeps this price only when
|
|
624
|
+
// that read brings none. A listing that no longer trades has only
|
|
625
|
+
// that last quote too.
|
|
628
626
|
if ((item.status === "success" || item.status === "partial") && item.data) {
|
|
629
627
|
const answered = mapQuote(item.data);
|
|
630
628
|
if (pricesOtherListing(answered, cloudInstrumentTarget(target.symbol, target.exchange))) {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
hasRecentFinancialProfileAttempt,
|
|
22
22
|
hasDetailedStatementRows,
|
|
23
23
|
isProviderQuoteUsableForCurrentSession,
|
|
24
|
+
lastKnownProviderQuote,
|
|
24
25
|
providerFinancialsMatchTarget,
|
|
25
26
|
quoteWithFreshnessExchange,
|
|
26
27
|
type CachedFinancialsSelection,
|
|
@@ -58,6 +59,8 @@ export class ProviderRouterBatchRoutes {
|
|
|
58
59
|
const providerOptions = { forceRefresh: options.forceRefresh };
|
|
59
60
|
const forceRefresh = options.forceRefresh === true;
|
|
60
61
|
const results = new Array<QuoteBatchResult | null>(targets.length).fill(null);
|
|
62
|
+
// A dated price the batch answered that is not current: shown, flagged stale, when asking alone brings none.
|
|
63
|
+
const lastKnown = new Array<Quote | null>(targets.length).fill(null);
|
|
61
64
|
const misses: Array<{ index: number; target: QuoteSubscriptionTarget }> = [];
|
|
62
65
|
|
|
63
66
|
targets.forEach((target, index) => {
|
|
@@ -104,8 +107,12 @@ export class ProviderRouterBatchRoutes {
|
|
|
104
107
|
return logFailure("sources.provider-router.batches", "Loading batch quotes failed", [] as QuoteBatchResult[])(error);
|
|
105
108
|
});
|
|
106
109
|
for (const item of batchResults) {
|
|
107
|
-
if (!isProviderQuoteUsableForCurrentSession(item.quote, item.target.exchange, item.target.symbol, { recentAnswer: true })) continue;
|
|
108
110
|
const key = this.quoteBatchKey(item.target);
|
|
111
|
+
if (!isProviderQuoteUsableForCurrentSession(item.quote, item.target.exchange, item.target.symbol, { recentAnswer: true })) {
|
|
112
|
+
const fallback = lastKnownProviderQuote(item.quote, item.target.exchange, item.target.symbol);
|
|
113
|
+
if (fallback) for (const entry of providerIndexes.get(key) ?? []) lastKnown[entry.index] = fallback;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
109
116
|
const sourceKey = this.deps.providerSourceKey(batchProvider);
|
|
110
117
|
for (const entry of providerIndexes.get(key) ?? []) {
|
|
111
118
|
const entityKey = this.deps.getEntityKey(entry.target.symbol, entry.target.context?.instrument);
|
|
@@ -119,16 +126,24 @@ export class ProviderRouterBatchRoutes {
|
|
|
119
126
|
// The batch never reached the data service: a copy saved a moment ago is still a saved copy, not the
|
|
120
127
|
// service's answer, so each is asked for as a refresh, which fails at once and says it answers from that copy.
|
|
121
128
|
const unreached = isNetworkFailure(batchFailure) ? new Set(providerMisses.map(({ index }) => index)) : null;
|
|
129
|
+
const followUp = (index: number): "default" | "refresh" => (forceRefresh || unreached?.has(index) ? "refresh" : "default");
|
|
130
|
+
if (options.deferFollowUps) {
|
|
131
|
+
for (const { index, target } of misses) {
|
|
132
|
+
results[index] ??= { target, quote: lastKnown[index] ?? null, followUp: followUp(index) };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
122
135
|
await Promise.all(misses.map(async ({ index, target }) => {
|
|
123
136
|
if (results[index]) return;
|
|
124
137
|
try {
|
|
125
138
|
const quote = await this.deps.getQuote(target.symbol, target.exchange, {
|
|
126
139
|
...target.context,
|
|
127
|
-
cacheMode:
|
|
140
|
+
cacheMode: followUp(index),
|
|
128
141
|
});
|
|
129
142
|
results[index] = { target, quote };
|
|
130
143
|
} catch (error) {
|
|
131
|
-
|
|
144
|
+
// Asked alone it brought nothing: the batch's dated price, flagged stale, rather than none, as the quote route answers.
|
|
145
|
+
const fallback = lastKnown[index];
|
|
146
|
+
results[index] = fallback ? { target, quote: fallback } : { target, quote: null, error };
|
|
132
147
|
}
|
|
133
148
|
}));
|
|
134
149
|
|