dsh-bash-terminal-ts 0.7.2-compat.2 → 0.8.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/README.de.md +3 -2
- package/README.en.md +102 -3
- package/README.es.md +3 -2
- package/README.fr.md +3 -2
- package/README.it.md +3 -2
- package/README.md +198 -4
- package/README.ru.md +3 -2
- package/cordis.patch.yml +66 -0
- package/dist/client.core.js +7888 -79
- package/dist/client.js +7888 -79
- package/dsh.plugin.json +22 -22
- package/lib/browser-i18n.d.ts +4 -0
- package/lib/browser-i18n.js +23 -0
- package/lib/client.js +7888 -79
- package/lib/dsh-types.d.ts +10 -0
- package/lib/dsh.d.ts +2 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.js +176 -91
- package/lib/locales.d.ts +4 -0
- package/lib/locales.js +422 -0
- package/lib/settings-surface.d.ts +20 -0
- package/lib/settings-surface.js +49 -0
- package/lib/shell-id.d.ts +2 -0
- package/lib/shell-id.js +9 -0
- package/lib/shells.d.ts +114 -0
- package/lib/shells.js +187 -0
- package/lib/terminal.d.ts +30 -1
- package/lib/terminal.js +18 -5
- package/lib/webterminals/catalog.d.ts +36 -0
- package/lib/webterminals/catalog.js +93 -0
- package/lib/webterminals/host.d.ts +67 -0
- package/lib/webterminals/host.js +278 -0
- package/lib/webterminals/mount.d.ts +46 -0
- package/lib/webterminals/mount.js +171 -0
- package/lib/webterminals/protocol.d.ts +94 -0
- package/lib/webterminals/protocol.js +9 -0
- package/lib/webterminals/pty.d.ts +42 -0
- package/lib/webterminals/pty.js +64 -0
- package/lib/webterminals/registry.d.ts +139 -0
- package/lib/webterminals/registry.js +353 -0
- package/lib/webterminals/ws.d.ts +54 -0
- package/lib/webterminals/ws.js +140 -0
- package/locale/de.json +4 -0
- package/locale/en.json +4 -0
- package/locale/es.json +4 -0
- package/locale/fr.json +4 -0
- package/locale/it.json +4 -0
- package/locale/ja.json +4 -0
- package/locale/ko.json +4 -0
- package/locale/ru.json +4 -0
- package/locale/zh.json +4 -0
- package/package.json +131 -121
- package/scripts/build-browser-tests.mjs +36 -0
- package/scripts/build-client.mjs +10 -0
- package/scripts/check-artifacts.mjs +93 -0
- package/scripts/link-shells.mjs +75 -0
- package/src/browser-i18n.ts +27 -0
- package/src/client.tsx +539 -134
- package/src/dsh-types.ts +6 -0
- package/src/dsh.ts +2 -0
- package/src/index.ts +146 -35
- package/src/locales.ts +434 -0
- package/src/settings-surface.ts +59 -0
- package/src/shell-id.ts +11 -0
- package/src/shells.ts +250 -0
- package/src/terminal.ts +34 -5
- package/src/webterminals/browser/api.ts +212 -0
- package/src/webterminals/browser/bridge.ts +188 -0
- package/src/webterminals/browser/css.d.ts +16 -0
- package/src/webterminals/browser/face.ts +151 -0
- package/src/webterminals/browser/shell-picker.tsx +98 -0
- package/src/webterminals/browser/store.ts +40 -0
- package/src/webterminals/browser/tab.tsx +136 -0
- package/src/webterminals/browser/testkit.ts +21 -0
- package/src/webterminals/browser/url.ts +70 -0
- package/src/webterminals/browser/view.ts +381 -0
- package/src/webterminals/browser/xterm.ts +269 -0
- package/src/webterminals/catalog.ts +114 -0
- package/src/webterminals/host.ts +361 -0
- package/src/webterminals/mount.ts +227 -0
- package/src/webterminals/protocol.ts +78 -0
- package/src/webterminals/pty.ts +90 -0
- package/src/webterminals/registry.ts +447 -0
- package/src/webterminals/ws.ts +166 -0
- package/tsconfig.client.json +9 -1
- package/tsconfig.json +1 -1
package/src/client.tsx
CHANGED
|
@@ -1,25 +1,49 @@
|
|
|
1
1
|
// dsh-bash-terminal-ts client plugin (compat-legacy): a "Default terminal"
|
|
2
|
-
// preference row
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// preference row plus the bottom-terminal shell section, surfaced on the bundle
|
|
3
|
+
// detail card and on this plugin's OWN top-level settings section (it left the
|
|
4
|
+
// dsh-family tab in 2026-10-14 — it keeps a first-class nav row, so it no longer
|
|
5
|
+
// needs the family container), with a shell.overlay floating-gear fallback for
|
|
6
|
+
// hosts without any settings surface (0.1.0/0.1.1).
|
|
5
7
|
//
|
|
6
8
|
// compat-legacy rewiring vs upstream 0.7.1:
|
|
7
9
|
// - no @deepseek-ai/dsh-client-store / dsh-client-ui-primitives requires:
|
|
8
10
|
// 0.1.0/0.1.1 have no browser module table and 0.1.2 is unverified; the
|
|
9
|
-
// row reads/writes
|
|
10
|
-
//
|
|
11
|
+
// row reads/writes through the host config bridge (GET/POST
|
|
12
|
+
// /api/bash-terminal/config) and the terminal through /api/bash-terminal/terminals,
|
|
13
|
+
// both of which work on every line.
|
|
11
14
|
// - ui-primitives Menu/Icon replaced by a native select (same capsule CSS).
|
|
12
15
|
// - every surface registration is independently guarded (one unknown slot
|
|
13
16
|
// name on one line must not take down the rest).
|
|
17
|
+
//
|
|
18
|
+
// 0.8.0 adds two surfaces and removes one idea:
|
|
19
|
+
// - the shell activation section (Git Bash / MSYS2 / WSL switches with a
|
|
20
|
+
// per-row availability badge, and a default-shell choice restricted to the
|
|
21
|
+
// activated-and-available set), all state coming from the HOST's catalog so the
|
|
22
|
+
// browser never decides twice;
|
|
23
|
+
// - a bottom-dock tab of our own (`ctx.betterSidebar.registerTab`, bottomOnly), which
|
|
24
|
+
// is what makes Git Bash and MSYS2 reachable side by side - the host's own terminal
|
|
25
|
+
// menu de-duplicates shells by executable file name and both are `bash.exe`;
|
|
26
|
+
// - NO `ctx.provide('webTerminals')`. That was the bridge plugin's approach and it is
|
|
27
|
+
// fatal on any host that ships its terminal controller: see the webTerminals block
|
|
28
|
+
// near the bottom of this file.
|
|
14
29
|
|
|
15
30
|
import { useEffect, useState } from "react";
|
|
31
|
+
import { setTranslator, tr as translate } from "./browser-i18n";
|
|
32
|
+
import { dictionaries } from "./locales";
|
|
33
|
+
import { BridgeTerminals } from "./webterminals/browser/bridge";
|
|
34
|
+
import { looksLikeTerminals } from "./webterminals/browser/face";
|
|
35
|
+
import { MultiShellTerminal } from "./webterminals/browser/tab";
|
|
36
|
+
import { ShellPicker } from "./webterminals/browser/shell-picker";
|
|
37
|
+
import { switchableRows } from "./webterminals/browser/xterm";
|
|
38
|
+
import { post, readConfig, readLegacyConfig, writeDefaultShell, writeLegacyDefault } from "./webterminals/browser/api";
|
|
39
|
+
import type { CatalogEntry, ConfigSnapshot } from "./webterminals/browser/api";
|
|
16
40
|
|
|
17
41
|
const SETTINGS_NS = "settings.bash-terminal";
|
|
18
42
|
const SHELLS = ["powershell", "gitbash", "msys2", "wsl"] as const;
|
|
19
43
|
|
|
20
44
|
// Injected once when the browser loads the bundle (node tests guard on document).
|
|
21
45
|
const ROW_CSS =
|
|
22
|
-
".btRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.btRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}.btTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.btDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.btSelector{background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;border-radius:18px;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.btSelector:hover{background:var(--dsw-alias-interactive-bg-hover)}.btGear{position:fixed;right:16px;bottom:110px;z-index:10000;width:40px;height:40px;border-radius:50%;border:1px solid rgba(127,127,127,.4);background:rgba(30,30,32,.85);color:inherit;cursor:pointer;font-size:17px;box-shadow:0 4px 16px rgba(0,0,0,.35)}.btOverlay{position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,.45)}.btPanel{position:fixed;top:6vh;left:50%;transform:translateX(-50%);width:min(760px,92vw);max-height:84vh;overflow-y:auto;z-index:10001;background:var(--dsw-alias-bg-module-platform,rgba(30,30,32,.92));border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.3));border-radius:14px;padding:20px;color:var(--dsw-alias-label-primary)}";
|
|
46
|
+
".btRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.btRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}.btTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.btDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.btSelector{background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;border-radius:18px;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.btSelector:hover{background:var(--dsw-alias-interactive-bg-hover)}.btGear{position:fixed;right:16px;bottom:110px;z-index:10000;width:40px;height:40px;border-radius:50%;border:1px solid rgba(127,127,127,.4);background:rgba(30,30,32,.85);color:inherit;cursor:pointer;font-size:17px;box-shadow:0 4px 16px rgba(0,0,0,.35)}.btOverlay{position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,.45)}.btPanel{position:fixed;top:6vh;left:50%;transform:translateX(-50%);width:min(760px,92vw);max-height:84vh;overflow-y:auto;z-index:10001;background:var(--dsw-alias-bg-module-platform,rgba(30,30,32,.92));border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.3));border-radius:14px;padding:20px;color:var(--dsw-alias-label-primary)}.btBadge{border-radius:10px;padding:2px 8px;font-size:11px;line-height:16px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-tertiary);white-space:nowrap}.btBadgeOk{color:var(--dsw-alias-label-primary)}.btNotice{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;padding:8px 0}.btWarn{color:var(--dsw-status-warning-default,#b8860b)}.btRowSwitch{padding-right:0}.btSwitch{width:40px;height:24px;border-radius:12px;border:none;cursor:pointer;background:var(--dsw-alias-bg-module-platform);position:relative;flex:none;transition:background .15s ease;box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l2)}.btSwitch::after{content:'';position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;background:var(--dsw-alias-label-tertiary);transition:transform .15s ease,background .15s ease}.btSwitchOn{background:var(--dsw-alias-interactive-brand,#2f6fed)}.btSwitchOn::after{transform:translateX(16px);background:#fff}.btSwitch:disabled{cursor:not-allowed;opacity:.4}.btSwitch:disabled::after{background:var(--dsw-alias-label-quaternary,#8a8a8a)}.btInput{background:var(--dsw-alias-bg-module-platform);height:32px;border:none;border-radius:8px;color:var(--dsw-alias-label-primary);padding:0 10px;font:inherit;min-width:0;flex:1}.btPick{position:relative;display:inline-block}.btPickBtn{gap:6px}.btPickSm{height:28px;padding:0 10px;border-radius:14px;font-size:12px;line-height:18px}.btPickBtn:disabled{opacity:.4;cursor:not-allowed}.btPickText{max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.btPickCaret{color:var(--dsw-alias-label-tertiary);font-size:10px;line-height:1}.btPickList{position:absolute;z-index:1000;top:calc(100% + 4px);left:0;min-width:100%;max-height:260px;overflow-y:auto;padding:4px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-overlay);box-shadow:0 8px 24px rgba(0,0,0,.28)}.btPickOpt{padding:6px 10px;font-size:12px;line-height:18px;border-radius:6px;color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap}.btPickOpt:hover{background:var(--dsw-alias-interactive-bg-hover)}.btPickOptOn{color:var(--dsw-alias-interactive-brand);font-weight:600}";
|
|
23
47
|
if (typeof document !== "undefined" && document.querySelector('style[data-plugin-css="bash-terminal-row"]') === null) {
|
|
24
48
|
const tag = document.createElement("style");
|
|
25
49
|
tag.dataset.plugin = "dsh-bash-terminal-ts";
|
|
@@ -28,107 +52,74 @@ if (typeof document !== "undefined" && document.querySelector('style[data-plugin
|
|
|
28
52
|
document.head.appendChild(tag);
|
|
29
53
|
}
|
|
30
54
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"shell.unavailable": "Einstellungen nicht verfügbar: Die Konfigurationsbrücke des Hosts hat nicht geantwortet"
|
|
66
|
-
};
|
|
67
|
-
const it: Record<string, string> = {
|
|
68
|
-
"shell.title": "Terminale predefinito",
|
|
69
|
-
"shell.description": "Terminale usato dal comando shell",
|
|
70
|
-
"shell.powershell": "PowerShell",
|
|
71
|
-
"shell.gitbash": "Git Bash",
|
|
72
|
-
"shell.msys2": "MSYS2",
|
|
73
|
-
"shell.wsl": "WSL",
|
|
74
|
-
"shell.unavailable": "Impostazioni non disponibili: il bridge di configurazione dell'host non ha risposto"
|
|
75
|
-
};
|
|
76
|
-
const ru: Record<string, string> = {
|
|
77
|
-
"shell.title": "Терминал по умолчанию",
|
|
78
|
-
"shell.description": "Терминал для команд оболочки",
|
|
79
|
-
"shell.powershell": "PowerShell",
|
|
80
|
-
"shell.gitbash": "Git Bash",
|
|
81
|
-
"shell.msys2": "MSYS2",
|
|
82
|
-
"shell.wsl": "WSL",
|
|
83
|
-
"shell.unavailable": "Настройки недоступны: мост конфигурации хоста не ответил"
|
|
84
|
-
};
|
|
85
|
-
const es: Record<string, string> = {
|
|
86
|
-
"shell.title": "Terminal predeterminada",
|
|
87
|
-
"shell.description": "Terminal usada por el comando shell",
|
|
88
|
-
"shell.powershell": "PowerShell",
|
|
89
|
-
"shell.gitbash": "Git Bash",
|
|
90
|
-
"shell.msys2": "MSYS2",
|
|
91
|
-
"shell.wsl": "WSL",
|
|
92
|
-
"shell.unavailable": "Configuración no disponible: el puente de configuración del host no respondió"
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const zhDictTitle = (): string => zh["shell.title"] ?? "Terminal";
|
|
96
|
-
|
|
97
|
-
async function bridgeConfig(): Promise<{ defaultShell?: string } | null> {
|
|
55
|
+
/**
|
|
56
|
+
* Whether the host itself owns `webTerminals` (the normal case on a DSH build that
|
|
57
|
+
* mounts its terminal controller). Set once by `apply()`; the dock section states it,
|
|
58
|
+
* because without that line a user cannot tell why the official terminal row and this
|
|
59
|
+
* plugin's coexist - or which one their switches are affecting.
|
|
60
|
+
*
|
|
61
|
+
* A getter rather than a cached boolean: the controller may activate after our apply
|
|
62
|
+
* runs, and a snapshot taken at apply time would be a permanent false negative. Every
|
|
63
|
+
* render asks again, so the notice cannot go stale.
|
|
64
|
+
*/
|
|
65
|
+
let hostOwnsTerminals: () => boolean = () => false;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Claim `webTerminals` for dsh-better-sidebar's OFFICIAL bottom terminal row - the one
|
|
69
|
+
* thing this plugin can only do on a host that has no terminal controller. Returns what
|
|
70
|
+
* actually happened so the settings row can say it, because the honest answer depends on
|
|
71
|
+
* a live read of the service, not on the switch's own value.
|
|
72
|
+
*
|
|
73
|
+
* Replacing this stub is how `apply()` hands the component the real context. It stays a
|
|
74
|
+
* function rather than a `ctx` global so the component never has to know that the apply
|
|
75
|
+
* context is a Proxy which throws on undeclared property reads.
|
|
76
|
+
*/
|
|
77
|
+
let tryPublishShim: () => "published" | "host-provides" = () => "host-provides";
|
|
78
|
+
|
|
79
|
+
/** The published instance, kept so a later disable can dispose it. */
|
|
80
|
+
let shimInstance: BridgeTerminals | undefined;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Read the current shell and, when the terminal route answers, its catalog.
|
|
84
|
+
* The op route is preferred (it carries the catalog and validates choices); the
|
|
85
|
+
* legacy bridge is the fallback so the row still works on a host where only the
|
|
86
|
+
* preference channel exists.
|
|
87
|
+
*/
|
|
88
|
+
async function bridgeConfig(): Promise<ConfigSnapshot | null> {
|
|
98
89
|
try {
|
|
99
|
-
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: { "content-type": "application/json" },
|
|
102
|
-
body: "{}",
|
|
103
|
-
});
|
|
104
|
-
const d = await r.json();
|
|
105
|
-
return d && d.ok ? (d.value as { defaultShell?: string }) : null;
|
|
90
|
+
return await readConfig();
|
|
106
91
|
} catch {
|
|
107
|
-
return
|
|
92
|
+
return await readLegacyConfig();
|
|
108
93
|
}
|
|
109
94
|
}
|
|
110
95
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
headers: { "content-type": "application/json" },
|
|
116
|
-
body: JSON.stringify({ defaultShell: value }),
|
|
117
|
-
});
|
|
118
|
-
const d = await r.json();
|
|
119
|
-
return !!(d && d.ok);
|
|
120
|
-
} catch {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
96
|
+
/** The catalog if the terminal routes answered, else null (the old bridge shape). */
|
|
97
|
+
function catalogOf(snapshot: ConfigSnapshot | null): CatalogEntry[] | null {
|
|
98
|
+
if (!Array.isArray(snapshot?.catalog)) return null;
|
|
99
|
+
return snapshot.catalog as CatalogEntry[];
|
|
123
100
|
}
|
|
124
101
|
|
|
125
|
-
/**
|
|
126
|
-
function
|
|
102
|
+
/** The availability badge for one catalog row. */
|
|
103
|
+
function badgeKey(row: CatalogEntry): string {
|
|
104
|
+
// The floor row gets its own word: the lock EXPLANATION belongs in the row's
|
|
105
|
+
// description, and putting it in both places reads as a rendering bug.
|
|
106
|
+
if (!row.togglable) return "dock.state.floor";
|
|
107
|
+
if (row.available) return "dock.state.available";
|
|
108
|
+
return row.reason === "no-distro"
|
|
109
|
+
? "dock.state.noDistro"
|
|
110
|
+
: row.reason === "launcher-only"
|
|
111
|
+
? "dock.state.launcherOnly"
|
|
112
|
+
: "dock.state.notInstalled";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 默认终端选择行:读写全部走宿主 bridge(六线统一)。 */
|
|
116
|
+
function ShellPreferenceRow({ snapshot }: { snapshot?: ConfigSnapshot | null }) {
|
|
127
117
|
const [shell, setShell] = useState("powershell");
|
|
128
118
|
const [status, setStatus] = useState<"loading" | "ready" | "unavailable">("loading");
|
|
129
119
|
useEffect(() => {
|
|
130
120
|
let alive = true;
|
|
131
|
-
|
|
121
|
+
const load = async (): Promise<void> => {
|
|
122
|
+
const v = snapshot ?? (await bridgeConfig());
|
|
132
123
|
if (!alive) return;
|
|
133
124
|
if (v && v.defaultShell) {
|
|
134
125
|
setShell(v.defaultShell);
|
|
@@ -136,21 +127,29 @@ function ShellPreferenceRow() {
|
|
|
136
127
|
} else {
|
|
137
128
|
setStatus("unavailable");
|
|
138
129
|
}
|
|
139
|
-
}
|
|
130
|
+
};
|
|
131
|
+
void load();
|
|
140
132
|
return () => {
|
|
141
133
|
alive = false;
|
|
142
134
|
};
|
|
143
|
-
}, []);
|
|
135
|
+
}, [snapshot]);
|
|
144
136
|
const change = (value: string): void => {
|
|
145
137
|
setShell(value);
|
|
146
|
-
|
|
138
|
+
// Validated write first; the legacy channel only if the op route is absent.
|
|
139
|
+
void writeDefaultShell(value).catch(async () => {
|
|
140
|
+
try {
|
|
141
|
+
await writeLegacyDefault(value);
|
|
142
|
+
} catch {
|
|
143
|
+
/* the row keeps its optimistic value; the next read reconciles */
|
|
144
|
+
}
|
|
145
|
+
});
|
|
147
146
|
};
|
|
148
147
|
if (status === "unavailable") {
|
|
149
148
|
return (
|
|
150
149
|
<div className="btRow">
|
|
151
150
|
<div className="btRowText">
|
|
152
|
-
<div className="btTitle">{
|
|
153
|
-
<div className="btDesc">{
|
|
151
|
+
<div className="btTitle">{translate("shell.title")}</div>
|
|
152
|
+
<div className="btDesc">{translate("shell.unavailable")}</div>
|
|
154
153
|
</div>
|
|
155
154
|
</div>
|
|
156
155
|
);
|
|
@@ -158,36 +157,316 @@ function ShellPreferenceRow() {
|
|
|
158
157
|
return (
|
|
159
158
|
<div className="btRow">
|
|
160
159
|
<div className="btRowText">
|
|
161
|
-
<div className="btTitle">{
|
|
162
|
-
<div className="btDesc">{
|
|
160
|
+
<div className="btTitle">{translate("shell.title")}</div>
|
|
161
|
+
<div className="btDesc">{translate("shell.description")}</div>
|
|
163
162
|
</div>
|
|
164
|
-
<
|
|
165
|
-
|
|
163
|
+
<ShellPicker
|
|
164
|
+
rows={SHELLS.map((id) => ({ id, label: translate("shell." + id) }))}
|
|
166
165
|
value={shell}
|
|
167
|
-
onChange={(
|
|
168
|
-
|
|
169
|
-
{SHELLS.map((id) => (
|
|
170
|
-
<option key={id} value={id}>
|
|
171
|
-
{zh["shell." + id] ?? id}
|
|
172
|
-
</option>
|
|
173
|
-
))}
|
|
174
|
-
</select>
|
|
166
|
+
onChange={(next) => change(next)}
|
|
167
|
+
/>
|
|
175
168
|
</div>
|
|
176
169
|
);
|
|
177
170
|
}
|
|
178
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Whether the master switch is on, as last seen by the settings row. The bottom tab's
|
|
174
|
+
* `available()` is synchronous, so it reads this cache instead of fetching: the
|
|
175
|
+
* section refreshes on mount and after every write, and the tab re-reads the catalog
|
|
176
|
+
* itself before allocating, so a stale value here can only grey out a menu entry.
|
|
177
|
+
*/
|
|
178
|
+
let bottomTerminalEnabled = true;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The bottom-terminal section: a MASTER switch, then one child switch per shell the
|
|
182
|
+
* machine actually has.
|
|
183
|
+
*
|
|
184
|
+
* Two levels because the two decisions are different in kind: whether this plugin
|
|
185
|
+
* offers a terminal at all, versus which shells it may start. And every state string
|
|
186
|
+
* comes from the host's catalog - the browser probes nothing, because two discovery
|
|
187
|
+
* implementations drift (that is how an MSYS2 `bash.exe` ended up labelled "Git Bash"
|
|
188
|
+
* in the sibling plugin).
|
|
189
|
+
*/
|
|
190
|
+
function ShellDockSection() {
|
|
191
|
+
const [snapshot, setSnapshot] = useState<ConfigSnapshot | null>(null);
|
|
192
|
+
const [pending, setPending] = useState(false);
|
|
193
|
+
const [error, setError] = useState("");
|
|
194
|
+
|
|
195
|
+
/** Read the catalog once, reporting an absent route as an error rather than a blank. */
|
|
196
|
+
const reload = (): void => {
|
|
197
|
+
bridgeConfig().then((v) => {
|
|
198
|
+
setSnapshot(v);
|
|
199
|
+
if (v === null) setError("no-route");
|
|
200
|
+
else {
|
|
201
|
+
bottomTerminalEnabled = v.enabled !== false;
|
|
202
|
+
hostSettingsSurface = v.settingsSurface ?? "unknown";
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
// The read is a `.then`, not an awaited body: the effect itself must not set
|
|
208
|
+
// state synchronously (the host's own hook lint forbids it, and a synchronous
|
|
209
|
+
// first paint would flash the unmounted state).
|
|
210
|
+
reload();
|
|
211
|
+
}, []);
|
|
212
|
+
|
|
213
|
+
const rows = catalogOf(snapshot);
|
|
214
|
+
const [shimNote, setShimNote] = useState("");
|
|
215
|
+
/**
|
|
216
|
+
* Flip the official-row opt-in. The config write comes first (so the choice survives a
|
|
217
|
+
* restart), then - only when turning ON - a live check of the service: if the host (or
|
|
218
|
+
* a previous activation) already publishes `webTerminals`, we must not add a second
|
|
219
|
+
* provider, because cordis refuses it and the loser's entry fails.
|
|
220
|
+
*/
|
|
221
|
+
const writeShim = async (next: boolean): Promise<void> => {
|
|
222
|
+
setPending(true);
|
|
223
|
+
setError("");
|
|
224
|
+
try {
|
|
225
|
+
const v = await post<ConfigSnapshot>({ op: "shim", shim: next });
|
|
226
|
+
setSnapshot(v);
|
|
227
|
+
setShimNote(next && v.shimOfficialTerminal === true ? tryPublishShim() : "");
|
|
228
|
+
} catch (e) {
|
|
229
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
230
|
+
} finally {
|
|
231
|
+
setPending(false);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const write = async (body: Record<string, unknown>): Promise<void> => {
|
|
235
|
+
setPending(true);
|
|
236
|
+
setError("");
|
|
237
|
+
try {
|
|
238
|
+
const v = await post<ConfigSnapshot>(body);
|
|
239
|
+
setSnapshot(v);
|
|
240
|
+
if (typeof v.enabled === "boolean") bottomTerminalEnabled = v.enabled;
|
|
241
|
+
hostSettingsSurface = v.settingsSurface ?? hostSettingsSurface;
|
|
242
|
+
} catch (e) {
|
|
243
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
244
|
+
} finally {
|
|
245
|
+
setPending(false);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
if (rows === null) {
|
|
250
|
+
// The terminal route never answered (the legacy bridge may have). Say so and
|
|
251
|
+
// offer a re-check: silence here is the "settings row exists but does nothing"
|
|
252
|
+
// failure mode.
|
|
253
|
+
return (
|
|
254
|
+
<div className="btNotice">
|
|
255
|
+
{translate("dock.unavailable.notInstalled")}{" "}
|
|
256
|
+
<button type="button" className="btSelector" style={{ height: 28, fontSize: 12 }} onClick={() => reload()}>
|
|
257
|
+
{translate("dock.refresh")}
|
|
258
|
+
</button>
|
|
259
|
+
</div>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const enabled = snapshot?.enabled !== false;
|
|
264
|
+
const usable = rows.filter((row) => row.activated && row.available);
|
|
265
|
+
// One source of truth for "this row deserves a switch", shared with the tab's own
|
|
266
|
+
// picker and asserted in test/browser.mjs (a render assertion cannot reach it, since
|
|
267
|
+
// the catalog arrives in an effect).
|
|
268
|
+
const switchable = new Set(switchableRows(rows).map((row) => row.id));
|
|
269
|
+
const unavailableReason = snapshot?.unavailable ?? "ok";
|
|
270
|
+
const notice = snapshot?.effective;
|
|
271
|
+
return (
|
|
272
|
+
<div>
|
|
273
|
+
<div className="btRow" style={{ borderBottom: "none", paddingBottom: 4 }}>
|
|
274
|
+
<div className="btRowText">
|
|
275
|
+
<div className="btTitle">{translate("dock.title")}</div>
|
|
276
|
+
<div className="btDesc">{translate("dock.hint")}</div>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
{unavailableReason !== "ok" && unavailableReason !== "disabled" ? (
|
|
280
|
+
<div className="btNotice btWarn">
|
|
281
|
+
{unavailableReason === "no-pty-backend"
|
|
282
|
+
? translate("dock.unavailable.noPty")
|
|
283
|
+
: unavailableReason === "no-websocket-route"
|
|
284
|
+
? translate("dock.unavailable.noSocket")
|
|
285
|
+
: translate("dock.unavailable.notInstalled")}
|
|
286
|
+
</div>
|
|
287
|
+
) : null}
|
|
288
|
+
{/* Which terminal surface the user is looking at: the host's own, or ours. */}
|
|
289
|
+
{hostOwnsTerminals() ? <div className="btNotice">{translate("dock.hostProvided")}</div> : null}
|
|
290
|
+
{/* ── level 1: the master switch ───────────────────────────────────── */}
|
|
291
|
+
<div className="btRow btRowSwitch">
|
|
292
|
+
<div className="btRowText">
|
|
293
|
+
<div className="btTitle">{translate("dock.enabled.title")}</div>
|
|
294
|
+
<div className="btDesc">{translate("dock.enabled.description")}</div>
|
|
295
|
+
</div>
|
|
296
|
+
<button
|
|
297
|
+
type="button"
|
|
298
|
+
className={"btSwitch" + (enabled ? " btSwitchOn" : "")}
|
|
299
|
+
disabled={pending}
|
|
300
|
+
aria-pressed={enabled}
|
|
301
|
+
onClick={() => void write({ op: "enabled", enabled: !enabled })}
|
|
302
|
+
/>
|
|
303
|
+
</div>
|
|
304
|
+
{/* ── level 2: one switch per shell the machine actually has ───────── */}
|
|
305
|
+
{!enabled ? (
|
|
306
|
+
<div className="btNotice">{translate("dock.enabled.off")}</div>
|
|
307
|
+
) : (
|
|
308
|
+
<>
|
|
309
|
+
{rows.map((row) => (
|
|
310
|
+
<div className="btRow btRowSwitch" key={row.id}>
|
|
311
|
+
<div className="btRowText">
|
|
312
|
+
<div className="btTitle">{row.label}</div>
|
|
313
|
+
{/* The path when a shell was found, the lock rule for the floor, and
|
|
314
|
+
the reason when there is nothing to switch on. */}
|
|
315
|
+
<div className="btDesc">
|
|
316
|
+
{!row.togglable
|
|
317
|
+
? translate("dock.powershell.locked")
|
|
318
|
+
: row.available
|
|
319
|
+
? (row.path ?? translate("dock.state.notInstalled"))
|
|
320
|
+
: translate(badgeKey(row))}
|
|
321
|
+
</div>
|
|
322
|
+
</div>
|
|
323
|
+
<span className={"btBadge" + (row.available ? " btBadgeOk" : "")}>{translate(badgeKey(row))}</span>
|
|
324
|
+
{/* No control where a choice cannot be honoured: an absent shell gets a
|
|
325
|
+
reason, not a switch that would do nothing. */}
|
|
326
|
+
{switchable.has(row.id) ? (
|
|
327
|
+
<button
|
|
328
|
+
type="button"
|
|
329
|
+
className={"btSwitch" + (row.activated ? " btSwitchOn" : "")}
|
|
330
|
+
disabled={pending}
|
|
331
|
+
aria-pressed={row.activated}
|
|
332
|
+
onClick={() => void write({ op: "switches", switches: { [row.id]: !row.activated } })}
|
|
333
|
+
/>
|
|
334
|
+
) : null}
|
|
335
|
+
</div>
|
|
336
|
+
))}
|
|
337
|
+
<div className="btRow btRowSwitch">
|
|
338
|
+
<div className="btRowText">
|
|
339
|
+
<div className="btTitle">{translate("dock.defaultChoice")}</div>
|
|
340
|
+
<div className="btDesc">{translate("shell.description")}</div>
|
|
341
|
+
</div>
|
|
342
|
+
<ShellPicker
|
|
343
|
+
rows={usable.map((row) => ({ id: row.id, label: row.label }))}
|
|
344
|
+
value={usable.some((row) => row.id === (snapshot?.defaultShell ?? "")) ? (snapshot?.defaultShell ?? usable[0]?.id ?? "powershell") : (usable[0]?.id ?? "powershell")}
|
|
345
|
+
onChange={(next) => void write({ op: "default", defaultShell: next })}
|
|
346
|
+
/>
|
|
347
|
+
</div>
|
|
348
|
+
<div className="btRow">
|
|
349
|
+
<div className="btRowText">
|
|
350
|
+
<div className="btTitle">{translate("dock.wslDistro")}</div>
|
|
351
|
+
</div>
|
|
352
|
+
<input
|
|
353
|
+
className="btInput"
|
|
354
|
+
type="text"
|
|
355
|
+
defaultValue={snapshot?.wslDistro ?? ""}
|
|
356
|
+
key={snapshot?.wslDistro ?? ""}
|
|
357
|
+
disabled={pending}
|
|
358
|
+
onBlur={(e) => {
|
|
359
|
+
const value = (e.target as HTMLInputElement).value.trim();
|
|
360
|
+
void write({ op: "switches", switches: {}, wslDistro: value });
|
|
361
|
+
}}
|
|
362
|
+
/>
|
|
363
|
+
</div>
|
|
364
|
+
{notice?.floor === true ? (
|
|
365
|
+
<div className="btNotice btWarn">{translate("dock.floor.notice", { to: notice.id })}</div>
|
|
366
|
+
) : notice?.fellBack === true ? (
|
|
367
|
+
<div className="btNotice btWarn">{translate("dock.fallback.notice", { from: notice.from ?? "", to: notice.id })}</div>
|
|
368
|
+
) : null}
|
|
369
|
+
{typeof snapshot?.terminals === "number" && snapshot.terminals > 0 ? (
|
|
370
|
+
<div className="btNotice">{translate("dock.terminals", { count: snapshot.terminals })}</div>
|
|
371
|
+
) : null}
|
|
372
|
+
{/* ── the official-row opt-in (off by default; see the description) ──── */}
|
|
373
|
+
<div className="btRow btRowSwitch">
|
|
374
|
+
<div className="btRowText">
|
|
375
|
+
<div className="btTitle">{translate("dock.shim.title")}</div>
|
|
376
|
+
<div className="btDesc">{translate("dock.shim.description")}</div>
|
|
377
|
+
</div>
|
|
378
|
+
<button
|
|
379
|
+
type="button"
|
|
380
|
+
className={"btSwitch" + (snapshot?.shimOfficialTerminal === true ? " btSwitchOn" : "")}
|
|
381
|
+
disabled={pending}
|
|
382
|
+
aria-pressed={snapshot?.shimOfficialTerminal === true}
|
|
383
|
+
onClick={() => void writeShim(snapshot?.shimOfficialTerminal !== true)}
|
|
384
|
+
/>
|
|
385
|
+
</div>
|
|
386
|
+
{shimNote === "published" ? <div className="btNotice">{translate("dock.shim.published")}</div> : null}
|
|
387
|
+
{shimNote === "host-provides" ? <div className="btNotice btWarn">{translate("dock.shim.hostProvides")}</div> : null}
|
|
388
|
+
</>
|
|
389
|
+
)}
|
|
390
|
+
{pending ? <div className="btNotice">{translate("dock.applying")}</div> : null}
|
|
391
|
+
{error !== "" && error !== "no-route" ? (
|
|
392
|
+
<div className="btNotice btWarn">{translate("dock.failed", { message: error })}</div>
|
|
393
|
+
) : null}
|
|
394
|
+
</div>
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** dsh-better-sidebar's extension service - optional, because that plugin may be absent. */
|
|
399
|
+
interface BetterSidebarService {
|
|
400
|
+
registerTab(descriptor: Record<string, unknown>): () => void;
|
|
401
|
+
}
|
|
402
|
+
|
|
179
403
|
interface ClientContext {
|
|
180
404
|
effect(fn: () => unknown, name?: string): unknown;
|
|
181
|
-
|
|
405
|
+
/** Soft read: the ONLY legal way to look at a service missing from `inject`. */
|
|
406
|
+
get?(name: string): unknown;
|
|
407
|
+
/**
|
|
408
|
+
* Publish a service. Exactly one call site, and it is gated: the official-row opt-in
|
|
409
|
+
* re-reads `webTerminals` through `get` first, because providing a name the host's own
|
|
410
|
+
* controller already claimed fails THAT entry (findings D15-1). Never call this from
|
|
411
|
+
* `apply()` unconditionally.
|
|
412
|
+
*/
|
|
413
|
+
provide?(name: string, service: unknown): unknown;
|
|
414
|
+
locale: {
|
|
415
|
+
register(ns: string, dicts: Record<string, Record<string, string>>): unknown;
|
|
416
|
+
bind?(ns: string): (key: string, params?: Record<string, string | number>) => string;
|
|
417
|
+
};
|
|
182
418
|
slots: {
|
|
183
419
|
inject(slot: string, fn: () => unknown, name?: string): void;
|
|
184
420
|
register(options: Record<string, unknown>, Component: unknown): Record<string, unknown>;
|
|
421
|
+
/** Read the ledger of a slot: the only way to ask whether another plugin claimed it. */
|
|
422
|
+
entries?(slot: string): { options: { id?: string; key?: string } }[];
|
|
185
423
|
};
|
|
424
|
+
/**
|
|
425
|
+
* Service-arrival callback. Optional because the oldest hosts have no browser module
|
|
426
|
+
* table at all; where it exists it is the reliable way to find `betterSidebar`.
|
|
427
|
+
*
|
|
428
|
+
* Note what is NOT here: a `betterSidebar` property. Cordis exposes requested services
|
|
429
|
+
* as properties on the ARRIVAL context only - on the apply context the same read
|
|
430
|
+
* throws "cannot get property 'betterSidebar' without inject". Keeping the key out of
|
|
431
|
+
* this type is what turns that runtime trap into a compile error.
|
|
432
|
+
*/
|
|
433
|
+
inject?(deps: string[], callback: (arrived: { betterSidebar?: BetterSidebarService }) => void): void;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* The settings body. ONE component, rendered by whichever surface carries this plugin's
|
|
438
|
+
* controls - the bundle detail card, the family tab and the fallback section must not be
|
|
439
|
+
* three copies that can drift (the family contract's "one source of truth" rule).
|
|
440
|
+
*/
|
|
441
|
+
function SettingsBody() {
|
|
442
|
+
return (
|
|
443
|
+
<>
|
|
444
|
+
<ShellPreferenceRow />
|
|
445
|
+
<ShellDockSection />
|
|
446
|
+
</>
|
|
447
|
+
);
|
|
186
448
|
}
|
|
187
449
|
|
|
188
|
-
/**
|
|
450
|
+
/**
|
|
451
|
+
* Whether the host renders a settings page, as the host half reported it (`page` /
|
|
452
|
+
* `none` / `unknown`). Only `none` - 0.1.0 and 0.1.1, which declare the `settings.*` slot
|
|
453
|
+
* map but ship no page that renders it - unlocks the floating panel below.
|
|
454
|
+
*/
|
|
455
|
+
let hostSettingsSurface = "unknown";
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The 0.1.0/0.1.1 way in, and nothing more.
|
|
459
|
+
*
|
|
460
|
+
* Those two lines declare the whole `settings.*` slot map but ship no settings page, so a
|
|
461
|
+
* registered card there is a card nobody can open - the only surface that renders is a
|
|
462
|
+
* shell-level overlay the plugin brings itself. Everywhere else this returns null, which
|
|
463
|
+
* is why the arm can be registered unconditionally at apply time (the family contract's
|
|
464
|
+
* rule) while the DECISION stays data-driven: the host half probes the first-generation
|
|
465
|
+
* seam and the row obeys the answer.
|
|
466
|
+
*/
|
|
189
467
|
function SettingsOverlayEntry() {
|
|
190
468
|
const [open, setOpen] = useState(false);
|
|
469
|
+
if (hostSettingsSurface !== "none") return null;
|
|
191
470
|
return (
|
|
192
471
|
<div style={{ position: "fixed", right: "16px", bottom: "110px", zIndex: 10000 }}>
|
|
193
472
|
{open ? <div className="btOverlay" onClick={() => setOpen(false)} /> : null}
|
|
@@ -201,16 +480,29 @@ function SettingsOverlayEntry() {
|
|
|
201
480
|
>
|
|
202
481
|
✕
|
|
203
482
|
</button>
|
|
204
|
-
<
|
|
483
|
+
<SettingsBody />
|
|
205
484
|
</div>
|
|
206
485
|
) : null}
|
|
207
|
-
<button type="button" className="btGear" title={
|
|
486
|
+
<button type="button" className="btGear" title={translate("shell.title")} onClick={() => setOpen(!open)}>
|
|
208
487
|
⚙
|
|
209
488
|
</button>
|
|
210
489
|
</div>
|
|
211
490
|
);
|
|
212
491
|
}
|
|
213
492
|
|
|
493
|
+
/**
|
|
494
|
+
* The services this client half consumes. Declared, not guessed: the loader hands
|
|
495
|
+
* `apply` a context carrying exactly these.
|
|
496
|
+
*
|
|
497
|
+
* What the declaration list really controls (learned by being wrong about it on
|
|
498
|
+
* 0.2.0-rc.2): the context is a Proxy, and `ctx.someService` THROWS
|
|
499
|
+
* "cannot get property 'someService' without inject" for any name absent from this
|
|
500
|
+
* list. `ctx.get(name)` and `ctx.inject(names, cb)` are the two legal ways to reach an
|
|
501
|
+
* undeclared or optional service - and optional is exactly what `betterSidebar` and
|
|
502
|
+
* `webTerminals` are, so neither may ever appear as a property read.
|
|
503
|
+
*/
|
|
504
|
+
export const inject: string[] = ["slots", "locale"];
|
|
505
|
+
|
|
214
506
|
export function apply(ctx: ClientContext): void {
|
|
215
507
|
const safe = (tag: string, fn: () => void): void => {
|
|
216
508
|
try {
|
|
@@ -220,36 +512,149 @@ export function apply(ctx: ClientContext): void {
|
|
|
220
512
|
}
|
|
221
513
|
};
|
|
222
514
|
safe("locale", () => {
|
|
223
|
-
ctx.effect(
|
|
224
|
-
|
|
225
|
-
|
|
515
|
+
ctx.effect(() => ctx.locale.register(SETTINGS_NS, dictionaries), "bash-terminal: settings dictionaries");
|
|
516
|
+
// bind() exists on 0.1.2+; the oldest lines have no locale service at all, and
|
|
517
|
+
// the module fallback (zh) is then the honest answer.
|
|
518
|
+
const bound = ctx.locale.bind?.call(ctx.locale, SETTINGS_NS);
|
|
519
|
+
if (typeof bound === "function") setTranslator(bound);
|
|
520
|
+
});
|
|
521
|
+
/**
|
|
522
|
+
* This plugin NEVER provides `webTerminals`. Measured on 0.2.0-rc.2: the host's
|
|
523
|
+
* `dsh-api-terminal-controller` provides the same service name and its `provide`
|
|
524
|
+
* is unguarded, so whichever entry wins the boot race decides who dies - and ours
|
|
525
|
+
* won, taking down the first-party terminal and the whole web boot with
|
|
526
|
+
* `service "webTerminals" has been registered`. The bottom-dock feature does not
|
|
527
|
+
* need the service either: this plugin ships its own tab, which works whether or
|
|
528
|
+
* not the host has a controller. All that is left here is the read that drives the
|
|
529
|
+
* notice above.
|
|
530
|
+
*/
|
|
531
|
+
safe("webTerminals", () => {
|
|
532
|
+
hostOwnsTerminals = () => looksLikeTerminals(ctx.get?.("webTerminals"));
|
|
533
|
+
tryPublishShim = () => {
|
|
534
|
+
if (shimInstance !== undefined) return "published";
|
|
535
|
+
// The check is the whole point of making this opt-in: "the operator said so" is
|
|
536
|
+
// not evidence that the name is free, and taking it anyway would fail the host's
|
|
537
|
+
// own controller entry.
|
|
538
|
+
if (looksLikeTerminals(ctx.get?.("webTerminals"))) return "host-provides";
|
|
539
|
+
const terminals = new BridgeTerminals();
|
|
540
|
+
ctx.effect(() => () => {
|
|
541
|
+
terminals.disposeAll();
|
|
542
|
+
shimInstance = undefined;
|
|
543
|
+
}, "bash-terminal: official-row shim");
|
|
544
|
+
ctx.provide?.("webTerminals", terminals);
|
|
545
|
+
shimInstance = terminals;
|
|
546
|
+
return "published";
|
|
547
|
+
};
|
|
548
|
+
});
|
|
549
|
+
// ── settings surfaces ────────────────────────────────────────────────────────
|
|
550
|
+
//
|
|
551
|
+
// Two landing points plus a fallback that keeps the controls reachable when
|
|
552
|
+
// neither has a host:
|
|
553
|
+
//
|
|
554
|
+
// 1. the bundle detail page (`plugins.bundle.config`, keyed by the package name) -
|
|
555
|
+
// the host's own per-plugin configuration card, present on 0.1.7+/0.2.0; on
|
|
556
|
+
// 0.1.2/0.1.5 the era-equivalent dispatch is `settings.plugin.item`, keyed by the
|
|
557
|
+
// settings namespace, so both are declared;
|
|
558
|
+
// 2. this plugin's OWN top-level `settings.section` (id `bash-terminal`), registered
|
|
559
|
+
// unconditionally. It used to stand down while a `dsh-family` row existed and
|
|
560
|
+
// contribute a family tab instead; that coupling made the family container a
|
|
561
|
+
// single point of failure for these settings, and the tab is gone now (2026-10-14).
|
|
562
|
+
// Registering under our own id — never shadowing `dsh-family` — is what keeps the
|
|
563
|
+
// family contract intact: two nav rows, no double-rendered section.
|
|
564
|
+
// 3. `shell.overlay` for the lines with no settings page at all.
|
|
565
|
+
//
|
|
566
|
+
// Every arm is registered at apply-time top level (registering from inside an inject
|
|
567
|
+
// callback is the two-generation accident this family keeps re-learning), each is
|
|
568
|
+
// wrapped on its own so one unknown slot name cannot take the rest down, and an inject
|
|
569
|
+
// into a slot the host does not declare simply idles - an undischarged wait never
|
|
570
|
+
// blocks the client half.
|
|
571
|
+
safe("plugins.bundle.config", () => {
|
|
572
|
+
ctx.slots.inject(
|
|
573
|
+
"plugins.bundle.config",
|
|
574
|
+
() => ctx.slots.register({ name: "plugins.bundle.config", key: "dsh-bash-terminal-ts", locale: SETTINGS_NS, inject: () => ({}) }, SettingsBody),
|
|
575
|
+
"bash-terminal: bundle config card",
|
|
226
576
|
);
|
|
227
577
|
});
|
|
228
|
-
safe("
|
|
578
|
+
safe("settings.plugin.item", () => {
|
|
229
579
|
ctx.slots.inject(
|
|
230
|
-
"
|
|
231
|
-
() =>
|
|
232
|
-
|
|
580
|
+
"settings.plugin.item",
|
|
581
|
+
() => ctx.slots.register({ name: "settings.plugin.item", key: SETTINGS_NS, locale: SETTINGS_NS, inject: () => ({}) }, SettingsBody),
|
|
582
|
+
"bash-terminal: legacy plugin settings card",
|
|
583
|
+
);
|
|
584
|
+
});
|
|
585
|
+
safe("settings.section", () => {
|
|
586
|
+
ctx.slots.inject(
|
|
587
|
+
"settings.section",
|
|
588
|
+
function* () {
|
|
589
|
+
// Unconditional since the family tab was dropped: this plugin owns a nav row,
|
|
590
|
+
// so it must not depend on another plugin's container existing. The register
|
|
591
|
+
// still happens at the declaration event (the generator runs when the host
|
|
592
|
+
// declares the slot), which is what kept the old probe honest about bundle order.
|
|
593
|
+
yield ctx.slots.register(
|
|
233
594
|
{
|
|
234
|
-
name: "
|
|
235
|
-
id: "bash-terminal
|
|
236
|
-
order:
|
|
237
|
-
label:
|
|
595
|
+
name: "settings.section",
|
|
596
|
+
id: "bash-terminal",
|
|
597
|
+
order: 45,
|
|
598
|
+
label: () => translate("shell.title"),
|
|
238
599
|
locale: SETTINGS_NS,
|
|
239
600
|
inject: () => ({}),
|
|
240
601
|
},
|
|
241
|
-
|
|
242
|
-
)
|
|
243
|
-
|
|
602
|
+
SettingsBody,
|
|
603
|
+
);
|
|
604
|
+
},
|
|
605
|
+
"bash-terminal: own settings section",
|
|
244
606
|
);
|
|
245
607
|
});
|
|
246
608
|
safe("shell.overlay", () => {
|
|
609
|
+
// Registered always, rendered only on the two lines with no settings page (the
|
|
610
|
+
// component itself returns null). Registering conditionally would mean deciding at
|
|
611
|
+
// apply time, before the host's probe has answered.
|
|
247
612
|
ctx.slots.inject(
|
|
248
613
|
"shell.overlay",
|
|
614
|
+
() => ctx.slots.register({ name: "shell.overlay", id: "bash-terminal-settings" }, SettingsOverlayEntry),
|
|
615
|
+
"bash-terminal: last-resort panel for hosts with no settings page",
|
|
616
|
+
);
|
|
617
|
+
});
|
|
618
|
+
// The multi-shell bottom tab. Reached through `ctx.inject` rather than a one-shot
|
|
619
|
+
// `ctx.get`: reading once would make this depend on dsh-better-sidebar's client
|
|
620
|
+
// happening to run first in the bundle order, and a silently missing tab is exactly
|
|
621
|
+
// the failure nobody notices until it is not there. `inject` fires when the service
|
|
622
|
+
// arrives; if that plugin is not installed the callback simply never runs - which is
|
|
623
|
+
// also why `betterSidebar` stays out of the declared `inject` list: without it this
|
|
624
|
+
// plugin's settings row and terminal shim must still load.
|
|
625
|
+
let tabRegistered = false;
|
|
626
|
+
const registerMultiShellTab = (service: BetterSidebarService | undefined): void => {
|
|
627
|
+
if (service?.registerTab === undefined || tabRegistered) return;
|
|
628
|
+
tabRegistered = true;
|
|
629
|
+
ctx.effect(
|
|
249
630
|
() =>
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
631
|
+
service.registerTab({
|
|
632
|
+
id: "dsh-bash-terminal-ts:multi",
|
|
633
|
+
title: () => translate("tab.title"),
|
|
634
|
+
description: () => translate("tab.description"),
|
|
635
|
+
// Bottom workbench only: without this the type also becomes a capsule in
|
|
636
|
+
// DSH's native right sidebar, i.e. a second "Terminal" next to the host's.
|
|
637
|
+
bottomOnly: true,
|
|
638
|
+
order: 41,
|
|
639
|
+
single: false,
|
|
640
|
+
// Reads the cached master switch: the + menu asks synchronously, and a
|
|
641
|
+
// greyed-out entry is a far better answer than a tab that refuses to open.
|
|
642
|
+
available: () => bottomTerminalEnabled,
|
|
643
|
+
component: (props: unknown) => <MultiShellTerminal {...(props as object)} />,
|
|
644
|
+
}),
|
|
645
|
+
"bash-terminal: multi-shell bottom tab",
|
|
253
646
|
);
|
|
647
|
+
};
|
|
648
|
+
safe("betterSidebar.registerTab", () => {
|
|
649
|
+
// Arrival-driven: dsh-better-sidebar's client may run after ours, and a one-shot
|
|
650
|
+
// read would then leave the tab silently absent.
|
|
651
|
+
if (typeof ctx.inject === "function") {
|
|
652
|
+
ctx.inject(["betterSidebar"], (arrived) => registerMultiShellTab(arrived.betterSidebar));
|
|
653
|
+
}
|
|
654
|
+
// Soft read for the case where the service is already published. `ctx.get` is the
|
|
655
|
+
// ONLY legal way to look at an undeclared service: the client context is a Proxy
|
|
656
|
+
// and `ctx.betterSidebar` throws "cannot get property \"betterSidebar\" without
|
|
657
|
+
// inject" (measured on 0.2.0-rc.2), which used to kill this whole block.
|
|
658
|
+
registerMultiShellTab(ctx.get?.("betterSidebar") as BetterSidebarService | undefined);
|
|
254
659
|
});
|
|
255
660
|
}
|