Files
Menghuan1918 fa301da29e feat(i18n): localize plugin catalog names and shell preset desc
Catalog entry names (15 tab + 4 viewer) and the dsh-desktop shell preset
desc were raw hardcoded zh strings rendered straight into the add-plugin
modals and the title-bar scheme dropdown. Mirror the existing desc
pattern exactly: PluginEntry.name / ShellPreset.desc widen to the
i18n-friendly string-or-() =>-string union, the catalogs carry lazy
t('pluginXxxName') / t('presetDshDesktopDesc') lookups, and the
add-plugin modal (render, search filter, aria-labels) plus the scheme
SelectMenu resolve them like every other copy. The plain-string arm of
the union stays as the raw-name fallback, and t() itself never yields
empty text (missing keys render the key), so a dict gap can never blank
a name.

20 new dictionary keys added to zh/en (locales.ts), ja (locales-ja.ts),
and all 18 third-language dictionaries — tests/locales.spec.ts enforces
key-set equality against zh for every shipped dict (precedent: 9cc642b),
so the 'leave other locales-* untouched' shortcut would fail the hard
parity gate; real translations are provided instead.

Spec follow-ups (behavior change: names/descs now render through t()):
- plugin-list.spec.ts: name non-empty assertion resolves the union.
- add-plugin-modal.spec.tsx: sentinel/office name assertions resolve
  from the catalog (en locale in tests) instead of pinning zh literals.
- shell-presets.spec.ts: desc non-empty assertion resolves the union.
2026-09-03 19:59:00 +08:00

87 lines
3.5 KiB
TypeScript

/**
* Built-in desktop-shell presets for the "位置兼容模式" secondary setting
* (scheme `preset`). DATA-DRIVEN by design: each shell's adaptation lives
* in one entry (strip values / optional CSS), the core applies it through
* the SAME generic strip variable and CSS-injection mechanism — adding a
* shell is adding data, never a code path.
*
* Inclusion rule (maintained in docs/external-plugin-guide.md §12): only shells that (a) appear
* in this repo's issues/PRs (a user actually hit a problem) and (b) have
* 100+ GitHub stars (a real user base). The mechanism is opt-in: auto
* detection never applies a preset — the settings badge only SUGGESTS it.
*/
import { t } from './locales.ts'
import type { DesktopEnv } from './desktop-env.ts'
export interface ShellPreset {
/** Stable preset id (persisted in `titleBarPresetId`). */
readonly id: string
/** User-facing name of the shell. */
readonly title: string
/** One-line description shown in the settings popup (i18n friendly:
* string or () => string — the plain string form is the raw-text
* fallback when no dictionary key covers the preset). */
readonly desc: string | (() => string)
/**
* The top strip (px) this shell reserves over web content, per
* environment — the fallback used when neither the standard WCO API nor
* the `dsh-desktop-titlebar-inset` contract parameter is available.
* Return undefined when the shell needs no strip in that environment.
* MUST be pure (called during render).
*/
readonly stripFor?: (env: DesktopEnv) => number | undefined
/**
* Extra CSS applied while the preset is enabled (injected last, after the
* plugin's own styles). Targets the plugin's stable data attributes and
* shell-declared body/URL markers only — never other shells' class names.
* Empty for presets fully covered by the strip variable.
*/
readonly css?: string
/**
* Whether this shell's marker is currently visible (URL stamps / preload
* markers — see desktop-env.ts). Used ONLY for the settings "已检测"
* badge; never auto-applies anything. MUST be pure.
*/
readonly detect?: (env: DesktopEnv) => boolean
}
/**
* DeepSeek Harness Desktop (anywhere-labs, Electron, 16k+ stars — the most
* reported shell in this repo's issues/PRs). Advanced mode: macOS reserves
* a 20px caption row (traffic lights top-left), win32 draws the native
* window controls in a ~32px overlay (WCO reports the real height when
* available, which the auto scheme already consumes; the 32 is the
* no-WCO fallback). Compatibility mode keeps the native frame — nothing.
*/
const DSH_DESKTOP: ShellPreset = {
id: 'dsh-desktop',
title: 'DeepSeek Harness Desktop',
desc: () => t('presetDshDesktopDesc'),
stripFor: (env) => {
if (env.mode !== 'advanced') return undefined
if (env.platform === 'darwin') return 20
if (env.platform === 'win32') return 32
return undefined
},
detect: (env) => env.mode === 'advanced',
}
const PRESETS: readonly ShellPreset[] = [
DSH_DESKTOP,
]
/** All built-in shell presets (registration order = settings list order). */
export function getShellPresets(): readonly ShellPreset[] {
return PRESETS
}
/** One preset by id, or undefined for an unknown/empty id. */
export function getShellPreset(id: string): ShellPreset | undefined {
return PRESETS.find(preset => preset.id === id)
}
/** The strip the active preset contributes for the given environment. */
export function presetStripFor(preset: ShellPreset | undefined, env: DesktopEnv): number | undefined {
return preset?.stripFor?.(env)
}