Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(plugin): 高级选项收起本地热重载并添加一键升级 (#915)

Mao Mr424b0fbe9b76
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index 2138adee..9598a042 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -274,6 +274,9 @@
"plugins.panel_tooltip": "Installed plugins. Preset plugins can be uninstalled here.",
"plugins.uninstall": "Uninstall",
"plugins.upgrade": "Upgrade",
+ "plugins.upgrade_all": "Upgrade All",
+ "plugins.upgrade_all_hint": "Upgrade or repair all {{count}} available plugins",
+ "plugins.upgrade_all_empty": "No plugins available to upgrade",
"plugins.builtin": "Built-in",
"plugins.builtin_title": "Built-in plugins ({{count}})",
"plugins.preset": "Preset",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index 9c6da5a8..cde43dad 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -274,6 +274,9 @@
"plugins.panel_tooltip": "已安装插件。预设插件可在此卸载。",
"plugins.uninstall": "卸载",
"plugins.upgrade": "升级",
+ "plugins.upgrade_all": "一键升级",
+ "plugins.upgrade_all_hint": "升级或修复全部可操作的插件({{count}})",
+ "plugins.upgrade_all_empty": "暂无可升级的插件",
"plugins.builtin": "内置",
"plugins.builtin_title": "内置插件({{count}})",
"plugins.preset": "预设",
diff --git a/src/ui/config/plugin.test.tsx b/src/ui/config/plugin.test.tsx
index 66bad8e3..006d1d56 100644
--- a/src/ui/config/plugin.test.tsx
+++ b/src/ui/config/plugin.test.tsx
@@ -1,12 +1,12 @@
// @vitest-environment jsdom
import type { ReactNode } from 'react'
-import type { Plugin } from '@/store/modules/plugins'
+import type { Plugin, PluginProcess } from '@/store/modules/plugins'
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ConfigPlugin } from './plugin'
const { manager, openDialog, mocks, hmrStatus } = vi.hoisted(() => ({
- manager: { installed: [] as Plugin[], processes: [], loading: false, error: '', disable: vi.fn(), enable: vi.fn(), search: vi.fn(), install: vi.fn() },
+ manager: { installed: [] as Plugin[], processes: [] as PluginProcess[], loading: false, error: '', disable: vi.fn(), enable: vi.fn(), search: vi.fn(), install: vi.fn(), upgrade: vi.fn() },
openDialog: vi.fn(),
mocks: {
invoke: vi.fn(),
@@ -46,7 +46,10 @@ vi.mock('@/components/item', () => ({ Item: ({ left, right }: { left: ReactNode,
</div>
) }))
vi.mock('@/components/ellipsis', () => ({ Ellipsis: ({ children }: { children: ReactNode }) => <span>{children}</span> }))
-vi.mock('@/components/panel', () => ({ Panel: { Header: () => null, Loadable: ({ children }: { children: ReactNode }) => <div>{children}</div> } }))
+vi.mock('@/components/panel', () => ({ Panel: {
+ Header: ({ action }: { action: ReactNode }) => <div>{action}</div>,
+ Loadable: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+} }))
vi.mock('@heroui/react', () => ({
Chip: ({ children, onClick }: { children: ReactNode, onClick?: () => void }) => <button type="button" onClick={onClick}>{children}</button>,
Button: ({ children, onPress, isDisabled, 'aria-label': ariaLabel }: { 'children': ReactNode, 'onPress'?: () => void, 'isDisabled'?: boolean, 'aria-label'?: string }) => (
@@ -99,8 +102,14 @@ function showBuiltIn() {
fireEvent.click(screen.getByRole('button', { name: 'plugins.builtin_title' }))
}
+function showAdvanced() {
+ fireEvent.click(screen.getByRole('switch', { name: 'plugins.advanced_options' }))
+}
+
beforeEach(() => {
manager.installed = [plugin()]
+ manager.processes = []
+ manager.upgrade.mockReset().mockResolvedValue([])
manager.disable.mockReset().mockResolvedValue(undefined)
manager.enable.mockReset().mockResolvedValue(undefined)
manager.search.mockReset().mockResolvedValue([])
@@ -174,6 +183,113 @@ describe('built-in plugin toggles', () => {
})
})
+describe('one-click plugin upgrade', () => {
+ it('shows the bulk upgrade immediately after open preset without enabling advanced options', () => {
+ render(<ConfigPlugin />)
+ const preset = screen.getByRole('button', { name: 'preinstall.open_preset' })
+ const upgradeAll = screen.getByRole('button', { name: 'plugins.upgrade_all' })
+ expect(preset.nextElementSibling).toBe(upgradeAll)
+ expect(screen.getByRole('switch', { name: 'plugins.advanced_options' }).getAttribute('aria-checked')).toBe('false')
+ })
+
+ it.each([
+ ['no plugins', []],
+ ['only current managed plugins', [plugin({ internal: false })]],
+ ['only built-in updates', [plugin({ updateAvailable: true, latest: '2.0.0' })]],
+ ] as const)('disables bulk upgrade with %s', (_case, installed) => {
+ manager.installed = [...installed]
+ render(<ConfigPlugin />)
+ const upgradeAll = screen.getByRole('button', { name: 'plugins.upgrade_all' }) as HTMLButtonElement
+ expect(upgradeAll.disabled).toBe(true)
+ fireEvent.click(upgradeAll)
+ expect(manager.upgrade).not.toHaveBeenCalled()
+ })
+
+ it('submits managed updates and repairs as one group with the displayed target versions', async () => {
+ manager.installed = [
+ plugin({ id: 'updated', internal: false, updateAvailable: true, latest: '2.0.0' }),
+ plugin({ id: 'unresolved', internal: false, updateAvailable: true }),
+ plugin({ id: 'broken', internal: false, error: { message: 'broken', action: 'runtime', at: '1' } }),
+ plugin({ id: 'current', internal: false }),
+ plugin({ id: 'built-in', updateAvailable: true, latest: '2.0.0' }),
+ ]
+ render(<ConfigPlugin />)
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.upgrade_all' })))
+ expect(manager.upgrade).toHaveBeenCalledExactlyOnceWith([
+ { spec: 'updated', version: '2.0.0' },
+ 'unresolved',
+ 'broken',
+ ])
+ expect(mocks.toast).not.toHaveBeenCalled()
+ expect(mocks.restart).not.toHaveBeenCalled()
+ })
+
+ it('prevents duplicate bulk and row submissions until the group settles', async () => {
+ let settle: () => void = () => {}
+ manager.upgrade.mockImplementationOnce(() => new Promise<void>((resolve) => {
+ settle = resolve
+ }))
+ manager.installed = [plugin({ id: 'updated', internal: false, updateAvailable: true, latest: '2.0.0' })]
+ render(<ConfigPlugin />)
+ const upgradeAll = screen.getByRole('button', { name: 'plugins.upgrade_all' }) as HTMLButtonElement
+ fireEvent.click(upgradeAll)
+ expect(upgradeAll.disabled).toBe(true)
+ fireEvent.click(upgradeAll)
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.upgrade 2.0.0' })))
+ expect(manager.upgrade).toHaveBeenCalledExactlyOnceWith([{ spec: 'updated', version: '2.0.0' }])
+
+ await act(async () => settle())
+ expect(upgradeAll.disabled).toBe(false)
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.upgrade 2.0.0' })))
+ expect(manager.upgrade).toHaveBeenCalledTimes(2)
+ expect(manager.upgrade).toHaveBeenLastCalledWith({ spec: 'updated', version: '2.0.0' })
+ })
+
+ it('excludes plugins already queued while allowing other updates', async () => {
+ manager.installed = [
+ plugin({ id: 'queued', internal: false, updateAvailable: true, latest: '2.0.0' }),
+ plugin({ id: 'available', internal: false, updateAvailable: true, latest: '3.0.0' }),
+ ]
+ manager.processes = [{ id: 'p1', groupId: 'g1', name: 'queued', spec: '[email protected]', type: 'upgrade', status: 'unauthorized' }]
+ const { rerender } = render(<ConfigPlugin />)
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.upgrade_all' })))
+ expect(manager.upgrade).toHaveBeenCalledExactlyOnceWith([{ spec: 'available', version: '3.0.0' }])
+
+ manager.installed = [plugin({ id: 'queued', internal: false, updateAvailable: true })]
+ rerender(<ConfigPlugin />)
+ expect((screen.getByRole('button', { name: 'plugins.upgrade_all' }) as HTMLButtonElement).disabled).toBe(true)
+ })
+
+ it('excludes a row whose local action is still pending', async () => {
+ let settle: () => void = () => {}
+ manager.disable.mockImplementationOnce(() => new Promise<void>((resolve) => {
+ settle = resolve
+ }))
+ manager.installed = [plugin({ id: 'updated', internal: false, updateAvailable: true, latest: '2.0.0' })]
+ render(<ConfigPlugin />)
+ fireEvent.click(screen.getByRole('button', { name: 'plugins.disable' }))
+ const upgradeAll = screen.getByRole('button', { name: 'plugins.upgrade_all' }) as HTMLButtonElement
+ expect(upgradeAll.disabled).toBe(true)
+ fireEvent.click(upgradeAll)
+ expect(manager.upgrade).not.toHaveBeenCalled()
+ await act(async () => settle())
+ expect(upgradeAll.disabled).toBe(false)
+ })
+
+ it('releases the bulk and row guards after a manager failure without duplicating its toast', async () => {
+ vi.spyOn(console, 'warn').mockImplementation(() => {})
+ manager.upgrade.mockRejectedValueOnce(new Error('UPGRADE_FAILED'))
+ manager.installed = [plugin({ id: 'updated', internal: false, updateAvailable: true })]
+ render(<ConfigPlugin />)
+ const upgradeAll = screen.getByRole('button', { name: 'plugins.upgrade_all' }) as HTMLButtonElement
+ await act(async () => fireEvent.click(upgradeAll))
+ expect(upgradeAll.disabled).toBe(false)
+ expect(mocks.toast).not.toHaveBeenCalled()
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.upgrade' })))
+ expect(manager.upgrade.mock.calls).toEqual([[['updated']], ['updated']])
+ })
+})
+
describe('local plugin folder picking', () => {
/** 目录选择器由宿主在三平台各用原生实现,这里让 get_local_plugin_hmr 与 pick 各自返回固定值。 */
function mockLocalCommands(picked: string | null) {
@@ -226,6 +342,27 @@ describe('local plugin folder picking', () => {
})
describe('local plugin hot reload switch', () => {
+ it('hides the whole hot reload block unless advanced options are enabled', () => {
+ hmrStatus.data = { enabled: true, watching: false, patchPath: null, roots: [] }
+ render(<ConfigPlugin />)
+ expect(screen.getByRole('switch', { name: 'plugins.advanced_options' }).getAttribute('aria-checked')).toBe('false')
+ expect(screen.queryByRole('switch', { name: 'plugins.hmr' })).toBeNull()
+ expect(screen.queryByText('plugins.hmr')).toBeNull()
+ expect(screen.queryByText('plugins.hmr_hint')).toBeNull()
+ expect(screen.queryByText('plugins.hmr_idle')).toBeNull()
+
+ showAdvanced()
+ expect(screen.getByRole('switch', { name: 'plugins.hmr' }).getAttribute('aria-checked')).toBe('true')
+ expect(screen.getByText('plugins.hmr_hint').textContent).toBe('plugins.hmr_hint')
+ expect(screen.getByText('plugins.hmr_idle').textContent).toBe('plugins.hmr_idle')
+
+ showAdvanced()
+ expect(screen.queryByRole('switch', { name: 'plugins.hmr' })).toBeNull()
+ expect(screen.queryByText('plugins.hmr_hint')).toBeNull()
+ expect(screen.queryByText('plugins.hmr_idle')).toBeNull()
+ expect(mocks.invoke).not.toHaveBeenCalledWith('set_local_plugin_hmr', expect.anything())
+ })
+
it('sends the new value to the host and offers a restart', async () => {
hmrStatus.data = { enabled: false, watching: false, patchPath: null, roots: [] }
mocks.invoke.mockImplementation(async (command: string) => {
@@ -236,6 +373,7 @@ describe('local plugin hot reload switch', () => {
throw new Error(`Unexpected command: ${command}`)
})
render(<ConfigPlugin />)
+ showAdvanced()
await act(async () => fireEvent.click(screen.getByRole('switch', { name: 'plugins.hmr' })))
await waitFor(() => expect(mocks.invoke).toHaveBeenCalledWith('set_local_plugin_hmr', { enabled: true }))
expect(mocks.setQueryData).toHaveBeenCalledWith(['local_plugin_hmr'], expect.objectContaining({ enabled: true }))
@@ -251,6 +389,7 @@ describe('local plugin hot reload switch', () => {
throw new Error(`Unexpected command: ${command}`)
})
render(<ConfigPlugin />)
+ showAdvanced()
await act(async () => fireEvent.click(screen.getByRole('switch', { name: 'plugins.hmr' })))
await waitFor(() => expect(mocks.toast).toHaveBeenCalledWith('plugins.hmr_save_failed', { variant: 'danger' }))
expect(mocks.toast).not.toHaveBeenCalledWith('plugins.hmr_restart_hint', expect.anything())
diff --git a/src/ui/config/plugin.tsx b/src/ui/config/plugin.tsx
index 99a68e33..71e66537 100644
--- a/src/ui/config/plugin.tsx
+++ b/src/ui/config/plugin.tsx
@@ -77,7 +77,6 @@ export function ConfigPlugin() {
const managedPlugins = plugins.filter(plugin => !plugin.internal)
const [showInternal, toggleShowInternal] = useToggle()
- /** 高级选项:默认关闭,快照(创建/还原/删除)属于低频维护操作,不常驻每行 */
const [advanced, toggleAdvanced] = useToggle()
/** 行内动作标记 `<id>:<action>`:按行独立,某行的动作不阻塞其他行继续入队 */
const [busy, setBusy] = useState<string[]>([])
@@ -86,6 +85,8 @@ export function ConfigPlugin() {
const [installing, setInstalling] = useState(false)
/** 兼容性预检结果:安装前先经 manager.search 展示解析到的版本与兼容性 */
const [searchResults, setSearchResults] = useState<PluginSearchResult[] | null>(null)
+ const [upgradingAll, toggleUpgradingAll] = useToggle()
+ const upgradable = managedPlugins.filter(plugin => (plugin.updateAvailable || plugin.error != null) && !rowBusy(plugin.id))
const [dialogHolder, openDialog] = useOverlay(Modal, { type: 'holder' })
@@ -233,6 +234,28 @@ export function ConfigPlugin() {
await runAction(id, 'update', () => manager.upgrade(ref))
}
+ async function onUpgradeAll() {
+ if (upgradingAll || upgradable.length === 0)
+ return
+ toggleUpgradingAll(true)
+ const targets = upgradable
+ for (const plugin of targets)
+ markBusy(plugin.id, 'update')
+ try {
+ await manager.upgrade(targets.map(plugin => (
+ plugin.latest === null ? plugin.id : { spec: plugin.id, version: plugin.latest }
+ )))
+ }
+ catch (e) {
+ silence(e, 'plugin upgrade all: error already reported by the manager')
+ }
+ finally {
+ for (const plugin of targets)
+ clearBusy(plugin.id, 'update')
+ toggleUpgradingAll(false)
+ }
+ }
+
async function onRemove(id: string, name: string) {
if (rowBusy(id))
return
@@ -648,6 +671,28 @@ export function ConfigPlugin() {
<p>{t('preinstall.settings_hint')}</p>
</Tooltip.Content>
</Tooltip>
+ <Tooltip delay={0}>
+ <Button
+ size="sm"
+ variant="tertiary"
+ onPress={() => void onUpgradeAll()}
+ isDisabled={upgradingAll || upgradable.length === 0}
+ >
+ <span className="flex items-center gap-1">
+ <If cond={upgradingAll} then={<Spinner size="sm" color="current" />} />
+ {t('plugins.upgrade_all')}
+ </span>
+ </Button>
+ <Tooltip.Content>
+ <p>
+ <If
+ cond={upgradable.length > 0}
+ then={t('plugins.upgrade_all_hint', { count: upgradable.length })}
+ else={t('plugins.upgrade_all_empty')}
+ />
+ </p>
+ </Tooltip.Content>
+ </Tooltip>
</div>
)}
description={t('plugins.panel_tooltip')}
@@ -725,28 +770,30 @@ export function ConfigPlugin() {
</If>
</div>
- <div className="flex flex-col gap-1 px-1">
- <div className="flex items-center justify-between gap-2">
- <span className="text-xs font-medium text-ink">{t('plugins.hmr')}</span>
- <Switch
- size="sm"
- isSelected={hmr.data?.enabled ?? false}
- isDisabled={hmr.isFetching || setHmr.isPending}
- onChange={enabled => setHmr.mutate(enabled)}
- aria-label={t('plugins.hmr')}
- >
- <Switch.Content>
- <Switch.Control>
- <Switch.Thumb />
- </Switch.Control>
- </Switch.Content>
- </Switch>
+ <If cond={advanced}>
+ <div className="flex flex-col gap-1 px-1">
+ <div className="flex items-center justify-between gap-2">
+ <span className="text-xs font-medium text-ink">{t('plugins.hmr')}</span>
+ <Switch
+ size="sm"
+ isSelected={hmr.data?.enabled ?? false}
+ isDisabled={hmr.isFetching || setHmr.isPending}
+ onChange={enabled => setHmr.mutate(enabled)}
+ aria-label={t('plugins.hmr')}
+ >
+ <Switch.Content>
+ <Switch.Control>
+ <Switch.Thumb />
+ </Switch.Control>
+ </Switch.Content>
+ </Switch>
+ </div>
+ <Description className="text-[10px] text-muted/70">{t('plugins.hmr_hint')}</Description>
+ <If cond={hmr.data != null && !hmr.data.watching}>
+ <Description className="text-[10px] text-warning">{t('plugins.hmr_idle')}</Description>
+ </If>
</div>
- <Description className="text-[10px] text-muted/70">{t('plugins.hmr_hint')}</Description>
- <If cond={hmr.data != null && !hmr.data.watching}>
- <Description className="text-[10px] text-warning">{t('plugins.hmr_idle')}</Description>
- </If>
- </div>
+ </If>
<If cond={managedPlugins.length > 0} else={<Empty>{t('plugins.empty')}</Empty>}>
{managedPlugins.map(plugin => renderPluginRow(plugin))}
diff --git a/test/plugin-uninstall.test.ts b/test/plugin-uninstall.test.ts
index 7479b907..adce842f 100644
--- a/test/plugin-uninstall.test.ts
+++ b/test/plugin-uninstall.test.ts
@@ -30,6 +30,21 @@ describe('plugin preset chip i18n keys', () => {
})
})
+describe('one-click plugin upgrade messages', () => {
+ it.each([
+ ['en-US', 'Upgrade All', 'Upgrade or repair all {{count}} available plugins', 'No plugins available to upgrade'],
+ ['zh-CN', '一键升级', '升级或修复全部可操作的插件({{count}})', '暂无可升级的插件'],
+ ] as const)('provides the %s bulk upgrade label and hints', (locale, label, hint, empty) => {
+ const source = readFileSync(new URL(`../src/i18n/locales/${locale}.json`, import.meta.url), 'utf8')
+ const messages = JSON.parse(source) as Record<string, string>
+ expect(messages).toMatchObject({
+ 'plugins.upgrade_all': label,
+ 'plugins.upgrade_all_hint': hint,
+ 'plugins.upgrade_all_empty': empty,
+ })
+ })
+})
+
// ── Suite B — component references the preset key + condition ────────────────
describe('configPlugin preset chip', () => {
it('renders the plugins.preset key', () => {