Issue #611 asked for file-type icons like the official explorer's, and #429 built a colored theme for them. DSH 0.1.5-rc.2 makes most of that work unnecessary: `@deepseek-ai/dsh-client-ui-primitives` now exports `FileTypeIcon` / `CodeFileIcon` with the host's own 48-type full-color code artwork plus category-colored sheet glyphs (and its classifier behind them). So the plugin renders the host's icons instead of shipping a color table, and color becomes the only behaviour rather than an opt-in theme. File icons (src/client/file-icons.tsx) - `builtinFileIcon(path, size)` → `<FileTypeIcon path size />`; folders use the host's folder category. The plugin's own per-extension VSCodicon map is gone. - The public `registerFileIcon` API from #531 is unchanged and still outranks the built-ins, so an external plugin can take over any row. One semantic consequence, now documented and tested: because the host classifier covers every path, a registered catch-all (`exts: []`) claims rows it used to lose to the built-in map. An unregistered catch-all (the old icon theme's shape) is unaffected. - Nothing is lazy any more: the artwork lives in a platform module the client already holds, so `lib/client-file-icons.js` and its 563-entry dataset (255 kB) are deleted outright — the core bundle grew by 10 kB (0.85 → 0.86 MB). - `src/client/file-icon-theme.ts`, the `fileIconTheme` pref (prefs-shared / config / client prefs), the settings-page select row and the six `settingsFileIconTheme*` keys in all 20 dictionaries are removed with it. Tab glyphs (src/client/builtins/tab-icons.tsx) - Every built-in tab type now declares a colored glyph: files (the host's folder artwork), changes/diff (commit), tasks (checklist), side chat (discussion), terminal (shell), browser (globe). - The color comes from a `--dsw-alias-*` token through a wrapper class, never from a literal — the skin contract (§12) holds and `tests/theme.spec.ts` enforces both halves (no literals in the module, every color declaration in the stylesheet resolves to a token). Native right Sidebar chips (src/client/native/tab-adapter.tsx) - The host's tab definition has no icon field, but the `sidebar.right.pane.tab.title` slot IS the chip's content, so the plugin draws the glyph itself: an editor tab with a path shows that file's icon, every other tab shows its descriptor's icon — the same `descriptor.icon` the workbench strip and the guide capsules already render, so the three cannot drift. The glyph is `aria-hidden`, which keeps the chip's accessible name exactly the title the mount lane matches on. Gates: typecheck / lint / check:consumer-types green; pnpm test 127 files / 1342 passed / 9 skipped (3 new chip cases, 1 rewritten built-in case).
225 lines
10 KiB
TypeScript
225 lines
10 KiB
TypeScript
/**
|
|
* Client-side read of the user-facing "Side card" preferences. The host owns
|
|
* the namespace through the settings seam (in-process); the DSH settings RPC
|
|
* domain only serves allowlisted namespaces to configuration clients, so the
|
|
* client reads and writes THIS namespace through the plugin's own fenced
|
|
* /sidebar routes instead (api.settingsGet/settingsUpdate). Any failure
|
|
* (route rejected, namespace absent, a field of the wrong type, a value out
|
|
* of the contract range) falls back to the schema defaults — the side card
|
|
* must keep working exactly as composed when the settings surface is missing.
|
|
*/
|
|
import type { api } from './api.ts'
|
|
import {
|
|
clampTerminalFontSize,
|
|
clampTitleBarStrip,
|
|
SIDEBAR_PREFS_DEFAULTS,
|
|
TITLE_BAR_SCHEMES,
|
|
TITLE_BAR_STRIP_DEFAULT,
|
|
type SidebarPrefs,
|
|
type TitleBarScheme,
|
|
} from '../prefs-shared.ts'
|
|
|
|
export {
|
|
SIDEBAR_PREFS_DEFAULTS,
|
|
TITLE_BAR_SCHEMES,
|
|
TITLE_BAR_STRIP_DEFAULT,
|
|
clampTerminalFontSize,
|
|
clampTitleBarStrip,
|
|
}
|
|
export type { SidebarPrefs, TitleBarScheme }
|
|
|
|
/** The settings wire face the preferences need (a subset of the plugin api). */
|
|
export type SidebarSettingsClient = Pick<typeof api, 'settingsGet' | 'settingsUpdate'>
|
|
|
|
/** Validate one raw resolved value into {@link SidebarPrefs}. Used for the
|
|
* settings.get payload AND the settings.update response (both carry the
|
|
* layered resolved value); any malformed field falls back to its default.
|
|
* @param value - the raw resolved section from the settings wire.
|
|
* @returns validated prefs (always well-formed).
|
|
*/
|
|
export function parsePrefs(value: unknown): SidebarPrefs {
|
|
if (value === null || typeof value !== 'object') return { ...SIDEBAR_PREFS_DEFAULTS }
|
|
const record = value as Record<string, unknown>
|
|
return {
|
|
autoOpenSubagent: typeof record.autoOpenSubagent === 'boolean'
|
|
? record.autoOpenSubagent
|
|
: SIDEBAR_PREFS_DEFAULTS.autoOpenSubagent,
|
|
autoOpenJobs: typeof record.autoOpenJobs === 'boolean'
|
|
? record.autoOpenJobs
|
|
: SIDEBAR_PREFS_DEFAULTS.autoOpenJobs,
|
|
agentTerminalTools: typeof record.agentTerminalTools === 'boolean'
|
|
? record.agentTerminalTools
|
|
: SIDEBAR_PREFS_DEFAULTS.agentTerminalTools,
|
|
agentOpenTools: typeof record.agentOpenTools === 'boolean'
|
|
? record.agentOpenTools
|
|
: SIDEBAR_PREFS_DEFAULTS.agentOpenTools,
|
|
bottomPanelAutoTerminal: typeof record.bottomPanelAutoTerminal === 'boolean'
|
|
? record.bottomPanelAutoTerminal
|
|
: SIDEBAR_PREFS_DEFAULTS.bottomPanelAutoTerminal,
|
|
terminalFontFamily: typeof record.terminalFontFamily === 'string'
|
|
? record.terminalFontFamily
|
|
: SIDEBAR_PREFS_DEFAULTS.terminalFontFamily,
|
|
terminalShell: typeof record.terminalShell === 'string'
|
|
? record.terminalShell
|
|
: SIDEBAR_PREFS_DEFAULTS.terminalShell,
|
|
terminalShellArgs: typeof record.terminalShellArgs === 'string'
|
|
? record.terminalShellArgs
|
|
: SIDEBAR_PREFS_DEFAULTS.terminalShellArgs,
|
|
terminalFontSize: typeof record.terminalFontSize === 'number' && Number.isFinite(record.terminalFontSize)
|
|
? clampTerminalFontSize(record.terminalFontSize)
|
|
: SIDEBAR_PREFS_DEFAULTS.terminalFontSize,
|
|
editorExplorer: typeof record.editorExplorer === 'boolean'
|
|
? record.editorExplorer
|
|
: SIDEBAR_PREFS_DEFAULTS.editorExplorer,
|
|
workspaceFence: typeof record.workspaceFence === 'boolean'
|
|
? record.workspaceFence
|
|
: SIDEBAR_PREFS_DEFAULTS.workspaceFence,
|
|
// The title-bar scheme (auto | web | preset | custom). The schema
|
|
// declares the field WITHOUT a default, so documents written by older
|
|
// plugin versions resolve without it — migrate from the legacy fields:
|
|
// a document that ALREADY HAS VALUES (the manual compat flag on, or a
|
|
// non-default strip px — both only reachable through the old gear
|
|
// popup) maps to the `custom` scheme so the user's numbers keep
|
|
// working; a pristine document keeps the conservative `auto` scheme.
|
|
titleBarScheme: isTitleBarScheme(record.titleBarScheme)
|
|
? record.titleBarScheme
|
|
: (record.titleBarCompat === true || hasLegacyStripValue(record.titleBarStripPx) ? 'custom' : 'auto'),
|
|
titleBarPresetId: typeof record.titleBarPresetId === 'string'
|
|
? record.titleBarPresetId
|
|
: SIDEBAR_PREFS_DEFAULTS.titleBarPresetId,
|
|
customCss: typeof record.customCss === 'string'
|
|
? record.customCss
|
|
: SIDEBAR_PREFS_DEFAULTS.customCss,
|
|
titleBarCompat: typeof record.titleBarCompat === 'boolean'
|
|
? record.titleBarCompat
|
|
: SIDEBAR_PREFS_DEFAULTS.titleBarCompat,
|
|
titleBarStripPx: typeof record.titleBarStripPx === 'number' && Number.isFinite(record.titleBarStripPx)
|
|
? clampTitleBarStrip(record.titleBarStripPx)
|
|
: SIDEBAR_PREFS_DEFAULTS.titleBarStripPx,
|
|
htmlViewerNoSandbox: typeof record.htmlViewerNoSandbox === 'boolean'
|
|
? record.htmlViewerNoSandbox
|
|
: SIDEBAR_PREFS_DEFAULTS.htmlViewerNoSandbox,
|
|
htmlViewerDefaultUnsafe: typeof record.htmlViewerDefaultUnsafe === 'boolean'
|
|
? record.htmlViewerDefaultUnsafe
|
|
: SIDEBAR_PREFS_DEFAULTS.htmlViewerDefaultUnsafe,
|
|
browserNoSandbox: typeof record.browserNoSandbox === 'boolean'
|
|
? record.browserNoSandbox
|
|
: SIDEBAR_PREFS_DEFAULTS.browserNoSandbox,
|
|
browserInterceptLinks: typeof record.browserInterceptLinks === 'boolean'
|
|
? record.browserInterceptLinks
|
|
: SIDEBAR_PREFS_DEFAULTS.browserInterceptLinks,
|
|
browserInterceptHttp: typeof record.browserInterceptHttp === 'boolean'
|
|
? record.browserInterceptHttp
|
|
: SIDEBAR_PREFS_DEFAULTS.browserInterceptHttp,
|
|
browserInterceptHttps: typeof record.browserInterceptHttps === 'boolean'
|
|
? record.browserInterceptHttps
|
|
: SIDEBAR_PREFS_DEFAULTS.browserInterceptHttps,
|
|
browserAllowedLoopback: typeof record.browserAllowedLoopback === 'string'
|
|
? record.browserAllowedLoopback
|
|
: SIDEBAR_PREFS_DEFAULTS.browserAllowedLoopback,
|
|
tabsEnabled: booleanMapOf(record.tabsEnabled),
|
|
viewersEnabled: booleanMapOf(record.viewersEnabled),
|
|
pluginSettings: pluginSettingsMapOf(record.pluginSettings),
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validate the plugin-owned settings map (v0.12.0+): `{ descriptorId: { key:
|
|
* value } }`, nested open maps. Any non-object value (or a malformed whole)
|
|
* falls back to the empty map — the schema defaults already guard the wire
|
|
* shape, this is the client's second line.
|
|
*/
|
|
function pluginSettingsMapOf(value: unknown): Record<string, Record<string, unknown>> {
|
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) return {}
|
|
const out: Record<string, Record<string, unknown>> = {}
|
|
for (const [id, blob] of Object.entries(value as Record<string, unknown>)) {
|
|
if (blob !== null && typeof blob === 'object' && !Array.isArray(blob)) {
|
|
out[id] = blob as Record<string, unknown>
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
/**
|
|
* Validate one enable-switch map (per-tab / per-viewer). Only boolean values
|
|
* survive; a non-object or a non-boolean entry falls back to the empty map /
|
|
* drops the entry — an absent key means the feature stays enabled.
|
|
*/
|
|
function booleanMapOf(value: unknown): Record<string, boolean> {
|
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) return {}
|
|
const out: Record<string, boolean> = {}
|
|
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
if (typeof item === 'boolean') out[key] = item
|
|
}
|
|
return out
|
|
}
|
|
|
|
/** Type guard for the title-bar scheme union (anything else falls back). */
|
|
function isTitleBarScheme(value: unknown): value is TitleBarScheme {
|
|
return typeof value === 'string' && (TITLE_BAR_SCHEMES as readonly string[]).includes(value)
|
|
}
|
|
|
|
/**
|
|
* Whether the legacy document carries an explicit strip value (only
|
|
* reachable through the old gear popup): a stored number different from the
|
|
* default counts as "the user already configured something" and migrates to
|
|
* the `custom` scheme.
|
|
*/
|
|
function hasLegacyStripValue(value: unknown): boolean {
|
|
return typeof value === 'number' && Number.isFinite(value) && value !== TITLE_BAR_STRIP_DEFAULT
|
|
}
|
|
|
|
/**
|
|
* Read the resolved side card preferences through the plugin's settings route.
|
|
* @param settings - the settings wire face (the plugin api by default).
|
|
* @returns validated prefs, or the schema defaults when the route rejects,
|
|
* the namespace is absent, or a stored value violates the contract.
|
|
*/
|
|
export async function loadPrefs(settings: SidebarSettingsClient): Promise<SidebarPrefs> {
|
|
try {
|
|
const view = await settings.settingsGet()
|
|
return parsePrefs(view.value)
|
|
} catch {
|
|
// Transport/fence rejection or a malformed response: keep the defaults.
|
|
return { ...SIDEBAR_PREFS_DEFAULTS }
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Read the external-disable flag from the same settings route: the
|
|
* dsh-web-ui family's aionui-panel provider choice. True only when the host
|
|
* resolved `aionui-panel.rightPanel` to 'aionui-panel' — while true the
|
|
* sidebar must not mount (the two right panels are mutually exclusive). Any
|
|
* failure (route rejected, aionui absent, malformed response) reads false,
|
|
* so a missing family never hides the sidebar.
|
|
* @param settings - the settings wire face (the plugin api by default).
|
|
* @returns the external-disable flag (false on any failure).
|
|
*/
|
|
export async function loadExternalDisable(settings: SidebarSettingsClient): Promise<boolean> {
|
|
try {
|
|
const view = await settings.settingsGet()
|
|
return view.externalDisable === true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
/** The boot decision both the prefs and the external-disable flag need:
|
|
* ONE settings fetch answers both (the boot path used to await
|
|
* {@link loadPrefs} and {@link loadExternalDisable} serially — two round
|
|
* trips of the same document before the first paint, and the second had no
|
|
* timeout, so a stalled wire could keep the sidebar unmounted forever). */
|
|
export interface BootDecision {
|
|
prefs: SidebarPrefs
|
|
suspended: boolean
|
|
}
|
|
|
|
export async function loadBootDecision(settings: SidebarSettingsClient): Promise<BootDecision> {
|
|
try {
|
|
const view = await settings.settingsGet()
|
|
return { prefs: parsePrefs(view.value), suspended: view.externalDisable === true }
|
|
} catch {
|
|
return { prefs: { ...SIDEBAR_PREFS_DEFAULTS }, suspended: false }
|
|
}
|
|
}
|