DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(plugin): add hook to list installed plugins in the shell
hairyfe85fc5e57768
diff --git a/src/components/debug-sidebar.tsx b/src/components/debug-sidebar.tsxindex 12f5e847..8e85ed92 100644--- a/src/components/debug-sidebar.tsx+++ b/src/components/debug-sidebar.tsx@@ -1,4 +1,5 @@import type { ReactNode } from 'react'+// import type { DshPlugin } from '../hooks/use-dsh-plugins'import { ArrowRotateRight, ArrowsRotateRight, ArrowUpRightFromSquare, Copy, Folder, Power } from '@gravity-ui/icons'import {Button,@@ -14,7 +15,9 @@ import {import { invoke } from '@tauri-apps/api/core'import { useEffect, useState } from 'react'import { useTranslation } from 'react-i18next'+// import { If } from 'react-if-lite'import { useStore } from 'valtio-define'+// import { useDshPlugins } from '../hooks/use-dsh-plugins'import { harness } from '../store/modules/harness'import { setting } from '../store/modules/setting'import { toast } from '../utils/toast'@@ -78,6 +81,7 @@ export default function DebugSidebar() {const { t, i18n } = useTranslation()const { sidebarOpen } = useStore(setting)const { serviceRunning, busyAction, preinstall } = useStore(harness)+ // const { plugins, loading: pluginsLoading, error: pluginsError, refresh: refreshPlugins } = useDshPlugins()const [info, setInfo] = useState<RuntimeInfo | null>(null)const [cliLinkEnabled, setCliLinkEnabled] = useState(true)const [port, setPort] = useState(3080)@@ -243,6 +247,22 @@ export default function DebugSidebar() {}}+ // /** 打开插件仓库:URL 由 Rust 侧从解析结果解析(不信任前端入参) */+ // async function openPluginRepo(plugin: DshPlugin) {+ // if (busy)+ // return+ // setBusy('openPluginRepo')+ // try {+ // await invoke('open_plugin_repo', { id: plugin.id })+ // }+ // catch (err) {+ // console.error('[DebugSidebar] failed to open plugin repo:', err)+ // }+ // finally {+ // setBusy(null)+ // }+ // }+return (<Drawer.Root><Drawer.Backdrop@@ -481,6 +501,81 @@ export default function DebugSidebar() {</Button></SectionCard>+ {/* 已安装插件(Rust 侧文件监控,变化时实时同步) */}+ {/* <SectionCard>+ <SectionTitle+ action={(+ <Button+ size="sm"+ variant="ghost"+ isIconOnly+ className="size-6 min-w-6"+ aria-label={t('app.refresh')}+ onPress={refreshPlugins}+ isDisabled={pluginsLoading}+ >+ {pluginsLoading ? <Spinner size="sm" color="current" /> : <ArrowsRotateRight className="size-3.5" />}+ </Button>+ )}+ >+ {t('plugins.title')}+ </SectionTitle>++ <If cond={pluginsLoading && plugins.length === 0}>+ <p className="text-xs text-muted">{t('plugins.loading')}</p>+ </If>+ <If cond={pluginsError}>+ <p className="text-xs text-danger">{t('plugins.error')}</p>+ </If>+ <If cond={!pluginsLoading && !pluginsError && plugins.length === 0}>+ <p className="text-xs text-muted">{t('plugins.empty')}</p>+ </If>++ <ul className="space-y-0.5">+ {plugins.map(plugin => (+ <li+ key={plugin.id}+ className="flex items-center justify-between gap-2 border-b border-line/30 py-1 text-xs last:border-b-0"+ >+ <span className="min-w-0">+ <span className="block truncate font-medium text-ink">{plugin.name}</span>+ <If cond={plugin.version}>+ <span className="block truncate font-mono text-[10px] text-muted/70">+ v+ {plugin.version}+ </span>+ </If>+ </span>+ <span className="flex shrink-0 items-center gap-1">+ <If cond={plugin.bundled}>+ <Chip size="sm" variant="soft" color="accent" className="font-medium">+ {t('plugins.bundled')}+ </Chip>+ </If>+ <If cond={plugin.recommended}>+ <Chip size="sm" variant="soft" color="success" className="font-medium">+ {t('preinstall.recommend')}+ </Chip>+ </If>+ <If cond={Boolean(plugin.repo_url)}>+ <Button+ isIconOnly+ size="sm"+ variant="ghost"+ className="size-6 min-w-6 rounded-md"+ aria-label={t('preinstall.open_repo', { name: plugin.name })}+ onPress={() => openPluginRepo(plugin)}+ isDisabled={busy === 'openPluginRepo'}+ >+ <CircleInfo className="size-3.5" />+ </Button>+ </If>+ </span>+ </li>+ ))}+ </ul>+ </SectionCard> */}+{/* 日志 */}<SectionCard><SectionTitlediff --git a/src/hooks/use-dsh-plugins.ts b/src/hooks/use-dsh-plugins.tsnew file mode 100644index 00000000..5ada633e--- /dev/null+++ b/src/hooks/use-dsh-plugins.ts@@ -0,0 +1,103 @@+import type { UnlistenFn } from '@tauri-apps/api/event'+import { invoke } from '@tauri-apps/api/core'+import { listen } from '@tauri-apps/api/event'+import { useEffect, useState } from 'react'++/** Rust 侧 service::plugin::watch::DshPlugin 的序列化形态(camelCase) */+export interface DshPlugin {+ /** 依赖键(npm 包名),列表主键 */+ id: string+ /** 展示名:插件自身 package.json 的 name,缺失时回落预设清单 */+ name: string+ /** 已安装版本(解析失败时为空字符串) */+ version: string+ description: string+ /** 仓库地址(repository.url / homepage) */+ repo_url: string+ /** 是否在 dsh.profile.bundles 中(启动时自动加载) */+ bundled: boolean+ /** 预设清单中的「推荐」标记 */+ recommended: boolean+ /** 预设清单中的「修复」标记 */+ fix: boolean+}++export interface UseDshPluginsResult {+ plugins: DshPlugin[]+ loading: boolean+ error: string+ /** 手动重新拉取(Rust 侧也会在插件文件变化时实时推送) */+ refresh: () => Promise<void>+}++/**+ * 已安装 dsh 插件列表(实时同步)。+ *+ * 后端(`service/plugin/watch`)秒级监控 profile 插件文件(package.json ++ * node_modules 下各直接依赖清单),解析出插件元信息;首次加载走+ * `get_dsh_plugins` 命令,之后插件安装/卸载/升级时通过+ * `dsh-plugins-updated` 事件增量推送,无需轮询。+ */+export function useDshPlugins(): UseDshPluginsResult {+ const [plugins, setPlugins] = useState<DshPlugin[]>([])+ const [loading, setLoading] = useState(true)+ const [error, setError] = useState('')++ useEffect(() => {+ let unlisten: UnlistenFn | null = null+ let disposed = false++ function apply(list: DshPlugin[]) {+ if (disposed)+ return+ setPlugins(list)+ setLoading(false)+ setError('')+ }++ function fail(err: unknown) {+ if (disposed)+ return+ console.error('[useDshPlugins] failed to load plugins:', err)+ setError(String(err))+ setLoading(false)+ }++ // 先订阅事件再拉取初始值,避免两者之间的插件变化丢失+ listen<DshPlugin[]>('dsh-plugins-updated', (event) => {+ apply(event.payload)+ }).then((fn) => {+ if (disposed)+ fn()+ else+ unlisten = fn+ }).catch((err) => {+ console.error('[useDshPlugins] failed to listen dsh-plugins-updated:', err)+ })++ invoke<DshPlugin[]>('get_dsh_plugins').then(apply).catch(fail)++ return () => {+ disposed = true+ unlisten?.()+ }+ }, [])++ async function refresh() {+ setLoading(true)+ try {+ const list = await invoke<DshPlugin[]>('get_dsh_plugins')+ setPlugins(list)+ setError('')+ }+ catch (err) {+ console.error('[useDshPlugins] refresh failed:', err)+ setError(String(err))+ }+ finally {+ setLoading(false)+ }+ }++ return { plugins, loading, error, refresh }+}diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex aa2aa3f5..436a165c 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -41,6 +41,12 @@"preinstall.settings_hint": "Reopen the preset wizard to re-select or install recommended plugins.","preinstall.open_preset": "Open Preset",+ "plugins.title": "Installed Plugins",+ "plugins.empty": "No plugins installed",+ "plugins.loading": "Loading plugins…",+ "plugins.error": "Failed to load plugins",+ "plugins.bundled": "Loaded",+"update.available": "A new version {{tag}} is available. Update now?","update.now": "Update Now","update.later": "Later",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex eaa0753b..fe41fb38 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -41,6 +41,12 @@"preinstall.settings_hint": "重新打开预设引导,可重新选择或安装推荐的插件。","preinstall.open_preset": "打开预设",+ "plugins.title": "已安装插件",+ "plugins.empty": "暂无已安装插件",+ "plugins.loading": "正在读取插件…",+ "plugins.error": "插件读取失败",+ "plugins.bundled": "已加载",+"update.available": "发现新版本 {{tag}},是否立即更新?","update.now": "立即更新","update.later": "稍后",