DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(05): 预设插件可取消勾选/卸载 (#245)
CoderStory70e76b01cad6
diff --git a/src/components/config-close-action.tsx b/src/components/config-close-action.tsxindex 1864924d..f850904d 100644--- a/src/components/config-close-action.tsx+++ b/src/components/config-close-action.tsx@@ -1,6 +1,6 @@import type { AppConfig } from '@/hooks/use-app-config'import { Description, ListBox, Select } from '@heroui/react'-import { useMutation } from '@tanstack/react-query'+import { useMutation, useQueryClient } from '@tanstack/react-query'import { invoke } from '@tauri-apps/api/core'import { useTranslation } from 'react-i18next'import { useAppConfig } from '@/hooks/use-app-config'@@ -14,10 +14,15 @@ const CLOSE_ACTION_LABEL_KEYS = {export function ConfigCloseAction() {const { t } = useTranslation()+ const queryClient = useQueryClient()const { data: config, refetch, isFetching } = useAppConfig()const { mutate: setCloseAction, isPending } = useMutation({mutationFn: async (closeAction: string) => {const next = normalizeCloseAction(closeAction)+ // 先写入成功结果到缓存:即使后续 refetch 失败,UI 仍展示新值,+ // 避免回退到更新前的旧 close_action(refetch 默认不抛错,只保留旧数据)。+ const result = await invoke<AppConfig>('update_app_config', { closeAction: next })+ queryClient.setQueryData(['config'], result)await invoke<AppConfig>('update_app_config', { closeAction: next })await refetch()},diff --git a/src/components/config-plugin.tsx b/src/components/config-plugin.tsxindex 17a9a9f6..84ea89ff 100644--- a/src/components/config-plugin.tsx+++ b/src/components/config-plugin.tsx@@ -189,6 +189,11 @@ export function ConfigPlugin() {{plugin.version}</code></If>+ <If cond={!plugin.internal && plugin.recommended}>+ <Chip size="sm" variant="soft" color="success" className="shrink-0 font-medium">+ {t('plugins.preset')}+ </Chip>+ </If><If cond={plugin.internal}><code className="shrink-0 rounded bg-default px-1.5 py-0.5 font-mono text-[10px] text-muted">{t('plugins.builtin')}diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex e865f6e4..91838778 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -43,6 +43,7 @@"preinstall.settings_hint": "Reopen the preset wizard to re-select or install recommended plugins.","preinstall.restarting_hint": "[harness] Restarting the service, please wait…","preinstall.open_preset": "Open Preset",+ "preinstall.can_uncheck_hint": "You can uncheck plugins you don't want. Unchecked plugins won't be installed.","plugins.title": "Installed Plugins","plugins.empty": "No plugins installed","plugins.loading": "Loading plugins…",@@ -154,10 +155,11 @@"profiles.remove_confirm_desc": "Delete {{name}} permanently? Its plugins and settings will be removed. This cannot be undone.","profiles.remove_confirm": "Delete","profiles.remove_failed": "Failed to delete profile",- "plugins.panel_tooltip": "Installed plugins, read-only. Plugins normally need no management here — upgrade or uninstall one only when it is causing problems.",+ "plugins.panel_tooltip": "Installed plugins. Preset plugins can be uninstalled here.","plugins.uninstall": "Uninstall","plugins.upgrade": "Upgrade","plugins.builtin": "Built-in",+ "plugins.preset": "Preset","plugins.abnormal_tooltip": "This plugin is running abnormally. Click to view details.","plugins.abnormal_desc": "Plugin {{name}} is abnormal and may be corrupted or incompatible with the current environment.","plugins.remove_confirm_title": "Uninstall plugin",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 5981ba49..ad02a205 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -43,6 +43,7 @@"preinstall.settings_hint": "重新打开预设引导,可重新选择或安装推荐的插件。","preinstall.restarting_hint": "[harness] 正在重启服务,请稍候…","preinstall.open_preset": "打开预设",+ "preinstall.can_uncheck_hint": "你可以取消勾选不需要的插件,取消后不会安装。","plugins.title": "已安装插件","plugins.empty": "暂无已安装插件","plugins.loading": "正在读取插件…",@@ -154,10 +155,11 @@"profiles.remove_confirm_desc": "确定删除档案 {{name}} 吗?将同时删除其插件与设置,此操作不可撤销。","profiles.remove_confirm": "删除","profiles.remove_failed": "删除档案失败",- "plugins.panel_tooltip": "该面板只读展示已安装插件。插件通常无需在此管理;仅当某个插件出现问题时,才需要在这里升级或卸载它。",+ "plugins.panel_tooltip": "已安装插件。预设插件可在此卸载。","plugins.uninstall": "卸载","plugins.upgrade": "升级","plugins.builtin": "内置",+ "plugins.preset": "预设","plugins.abnormal_tooltip": "此插件运行异常,点击查看详情。","plugins.abnormal_desc": "插件 {{name}} 运行异常,可能已损坏或与当前环境不兼容。","plugins.remove_confirm_title": "卸载插件",diff --git a/src/layout/components/preinstall-setup.tsx b/src/layout/components/preinstall-setup.tsxindex dacfeca8..5cb0ff9a 100644--- a/src/layout/components/preinstall-setup.tsx+++ b/src/layout/components/preinstall-setup.tsx@@ -4,7 +4,7 @@ import { Button, Checkbox, Chip, Label, Spinner, Typography } from '@heroui/reacimport { invoke } from '@tauri-apps/api/core'import { useEffect, useState } from 'react'import { useTranslation } from 'react-i18next'-import { If } from 'react-if-lite'+import { Else, If, Then } from 'react-if-lite'import { useStore } from 'valtio-define'import { Empty } from '@/components/empty'import { Item } from '@/components/item'@@ -241,20 +241,40 @@ export function PreinstallSetup() {</If></div>- {/* 操作区:跳过 / 确定 */}+ {/* 可取消勾选提示:让用户知道预设插件可减选,取消后不会安装 */}+ <If cond={preinstall.plugins.length > 0 && !installing && preinstall.error === ''}>+ <p className="text-center text-xs text-muted">{t('preinstall.can_uncheck_hint')}</p>+ </If>++ {/* 操作区:跳过 / 确定(空选时主按钮蜕变为「跳过」) */}<div className="flex items-center justify-end gap-2"><Button className="h-8 rounded-md" size="sm" variant="tertiary" onPress={handleSkip} isDisabled={installing}>{t('preinstall.skip')}</Button>- <Button- className="h-8 rounded-md"- size="sm"- variant="primary"- onPress={handleConfirm}- isDisabled={installing || selectedCount === 0 || selectableCount === 0}- >- {t('preinstall.confirm')}- </Button>+ <If cond={selectedCount === 0}>+ <Then>+ <Button+ className="h-8 rounded-md"+ size="sm"+ variant="primary"+ onPress={handleSkip}+ isDisabled={installing || selectableCount === 0}+ >+ {t('preinstall.skip')}+ </Button>+ </Then>+ <Else>+ <Button+ className="h-8 rounded-md"+ size="sm"+ variant="primary"+ onPress={handleConfirm}+ isDisabled={installing || selectableCount === 0}+ >+ {t('preinstall.confirm')}+ </Button>+ </Else>+ </If></div></>)}diff --git a/test/plugin-uninstall.test.ts b/test/plugin-uninstall.test.tsnew file mode 100644index 00000000..ae460e78--- /dev/null+++ b/test/plugin-uninstall.test.ts@@ -0,0 +1,62 @@+import { readFileSync } from 'node:fs'+import { describe, expect, it } from 'vitest'++// ── Suite A — i18n keys exist (source assertion on JSON) ─────────────────────+describe('plugin preset chip i18n keys', () => {+ it('provides plugins.preset in en-US = "Preset"', () => {+ const source = readFileSync(new URL('../src/i18n/locales/en-US.json', import.meta.url), 'utf8')+ const messages = JSON.parse(source) as Record<string, string>+ expect(messages).toHaveProperty('plugins.preset')+ expect(messages['plugins.preset']).toBe('Preset')+ })++ it('provides plugins.preset in zh-CN = "预设"', () => {+ const source = readFileSync(new URL('../src/i18n/locales/zh-CN.json', import.meta.url), 'utf8')+ const messages = JSON.parse(source) as Record<string, string>+ expect(messages).toHaveProperty('plugins.preset')+ expect(messages['plugins.preset']).toBe('预设')+ })++ it('updates plugins.panel_tooltip in en-US to mention uninstall', () => {+ const source = readFileSync(new URL('../src/i18n/locales/en-US.json', import.meta.url), 'utf8')+ const messages = JSON.parse(source) as Record<string, string>+ expect(messages['plugins.panel_tooltip']).toContain('Preset plugins can be uninstalled here')+ })++ it('updates plugins.panel_tooltip in zh-CN to mention uninstall', () => {+ const source = readFileSync(new URL('../src/i18n/locales/zh-CN.json', import.meta.url), 'utf8')+ const messages = JSON.parse(source) as Record<string, string>+ expect(messages['plugins.panel_tooltip']).toContain('预设插件可在此卸载')+ })+})++// ── Suite B — component references the preset key + condition ────────────────+describe('configPlugin preset chip', () => {+ it('renders the plugins.preset key', () => {+ const source = readFileSync(new URL('../src/components/config-plugin.tsx', import.meta.url), 'utf8')+ expect(source).toContain('plugins.preset')+ })++ it('guards the chip on recommended (preset, non-internal)', () => {+ const source = readFileSync(new URL('../src/components/config-plugin.tsx', import.meta.url), 'utf8')+ expect(source).toContain('!plugin.internal && plugin.recommended')+ })+})++// ── Suite C — uninstall flow wires to remove_dsh_plugin + restart ────────────+describe('configPlugin uninstall flow', () => {+ it('calls remove_dsh_plugin', () => {+ const source = readFileSync(new URL('../src/components/config-plugin.tsx', import.meta.url), 'utf8')+ expect(source).toContain('remove_dsh_plugin')+ })++ it('restarts the service after uninstall', () => {+ const source = readFileSync(new URL('../src/components/config-plugin.tsx', import.meta.url), 'utf8')+ expect(source).toContain('store.harness.restart()')+ })++ it('shows a confirm dialog before uninstall', () => {+ const source = readFileSync(new URL('../src/components/config-plugin.tsx', import.meta.url), 'utf8')+ expect(source).toContain('remove_confirm_title')+ })+})diff --git a/test/preinstall-uncheck.test.ts b/test/preinstall-uncheck.test.tsnew file mode 100644index 00000000..b0bdcd09--- /dev/null+++ b/test/preinstall-uncheck.test.ts@@ -0,0 +1,76 @@+import type { Event } from '@tauri-apps/api/event'+import { readFileSync } from 'node:fs'+import { beforeEach, describe, expect, it, vi } from 'vitest'++// ── Suite A — i18n keys exist (source assertion on JSON) ─────────────────────+describe('preinstall can-uncheck hint i18n keys', () => {+ it('provides preinstall.can_uncheck_hint in en-US', () => {+ const source = readFileSync(new URL('../src/i18n/locales/en-US.json', import.meta.url), 'utf8')+ const messages = JSON.parse(source) as Record<string, string>+ expect(messages).toHaveProperty('preinstall.can_uncheck_hint')+ expect(messages['preinstall.can_uncheck_hint']).toContain('Unchecked plugins won\'t be installed')+ })++ it('provides preinstall.can_uncheck_hint in zh-CN', () => {+ const source = readFileSync(new URL('../src/i18n/locales/zh-CN.json', import.meta.url), 'utf8')+ const messages = JSON.parse(source) as Record<string, string>+ expect(messages).toHaveProperty('preinstall.can_uncheck_hint')+ expect(messages['preinstall.can_uncheck_hint']).toContain('取消后不会安装')+ })+})++// ── Suite B — component references the hint key (source assertion) ───────────+describe('preinstallSetup hint text', () => {+ it('renders the can_uncheck_hint key', () => {+ const source = readFileSync(new URL('../src/layout/components/preinstall-setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('preinstall.can_uncheck_hint')+ })+})++// ── Suite C — component has dynamic button label (source assertion) ──────────+describe('preinstallSetup primary button morph', () => {+ it('guards the label switch on selectedCount === 0', () => {+ const source = readFileSync(new URL('../src/layout/components/preinstall-setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('selectedCount === 0')+ })++ it('can render the Skip label', () => {+ const source = readFileSync(new URL('../src/layout/components/preinstall-setup.tsx', import.meta.url), 'utf8')+ expect(source).toContain('preinstall.skip')+ })+})++// ── Suite D — store empty-selection guard (behavior, regression lock) ────────+// vi.mock 工厂会被提升到文件顶部,必须先经 vi.hoisted 声明模块级 mock 状态,+// 否则工厂执行时引用未初始化的绑定(Vitest 4.x 语义)。+const { eventListeners, invoke } = vi.hoisted(() => ({+ eventListeners: new Map<string, (event: Event<unknown>) => void>(),+ invoke: vi.fn(),+}))++vi.mock('@tauri-apps/api/core', () => ({ invoke }))+vi.mock('@tauri-apps/api/event', () => ({+ listen: vi.fn(async (event: string, callback: (payload: Event<unknown>) => void) => {+ eventListeners.set(event, callback)+ return vi.fn()+ }),+}))+vi.mock('@hairy/react-lib', () => ({ emitter: { emit: vi.fn() } }))+vi.mock('@/config/client', () => ({ queryClient: { invalidateQueries: vi.fn() } }))+vi.mock('../src/store/modules/harness-updater', () => ({+ harnessUpdater: { checkForUpdate: vi.fn() },+}))++const { harness } = await import('../src/store/modules/harness/store')++beforeEach(() => {+ eventListeners.clear()+ invoke.mockReset()+})++describe('confirmPreinstall empty-selection guard', () => {+ it('does not invoke the backend when ids is empty', async () => {+ await harness.confirmPreinstall([])+ expect(invoke).not.toHaveBeenCalled()+ })+})