Skip to content

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

fix(update): 下载安装包期间隐藏更新对话框底部按钮 (#884)

Mao Mr82319bbe8a2e
diff --git a/src/ui/dialog/update.test.tsx b/src/ui/dialog/update.test.tsx
new file mode 100644
index 00000000..6078ea73
--- /dev/null
+++ b/src/ui/dialog/update.test.tsx
@@ -0,0 +1,84 @@
+// @vitest-environment jsdom
+import { OverlaysProvider, useOverlay } from '@overlastic/react'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { StrictMode } from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { DesktopUpdateDialog } from './update'
+
+const { desktopUpdater } = vi.hoisted(() => ({
+ desktopUpdater: {
+ updateInfo: null as null | { currentVersion: string, version: string, tag: string, downloaded: boolean, path: string },
+ downloading: false,
+ downloadProgress: 0,
+ downloadAndOpen: vi.fn(),
+ openInstaller: vi.fn(),
+ },
+}))
+
+vi.mock('@/store', () => ({ store: { desktopUpdater } }))
+vi.mock('valtio-define', () => ({ useStore: (value: unknown) => value }))
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }))
+
+function Launcher() {
+ const open = useOverlay(DesktopUpdateDialog)
+ function handleOpen() {
+ void open().catch(() => {})
+ }
+ return <button onClick={handleOpen}>Open update</button>
+}
+
+function openDialog() {
+ render(<StrictMode><OverlaysProvider><Launcher /></OverlaysProvider></StrictMode>)
+ fireEvent.click(screen.getByText('Open update'))
+}
+
+beforeEach(() => {
+ desktopUpdater.updateInfo = {
+ currentVersion: '0.21.1',
+ version: '0.21.2',
+ tag: 'v0.21.2',
+ downloaded: false,
+ path: 'C:/installer.exe',
+ }
+ desktopUpdater.downloading = false
+ desktopUpdater.downloadProgress = 0
+ desktopUpdater.downloadAndOpen.mockReset()
+ desktopUpdater.openInstaller.mockReset()
+})
+
+afterEach(() => {
+ cleanup()
+ vi.restoreAllMocks()
+})
+
+describe('desktop update dialog', () => {
+ it('hides the footer actions while downloading and keeps the progress visible', async () => {
+ desktopUpdater.downloading = true
+ desktopUpdater.downloadProgress = 42
+ openDialog()
+ await screen.findByText('update.desktop_downloading')
+ expect(screen.queryByRole('button', { name: 'update.later' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'update.now' })).toBeNull()
+ expect(screen.queryByRole('button', { name: 'update.open_installer' })).toBeNull()
+ })
+
+ it('offers the download action once no download is in flight', async () => {
+ openDialog()
+ expect((await screen.findByRole('button', { name: 'update.now' })).textContent).toBe('update.now')
+ expect(screen.queryByRole('button', { name: 'update.later' })).not.toBeNull()
+ })
+
+ it('offers the installer action once the package is downloaded', async () => {
+ desktopUpdater.updateInfo!.downloaded = true
+ openDialog()
+ expect((await screen.findByRole('button', { name: 'update.open_installer' })).textContent).toBe('update.open_installer')
+ })
+
+ it('opens the installer instead of downloading when the package already exists', async () => {
+ desktopUpdater.updateInfo!.downloaded = true
+ openDialog()
+ fireEvent.click(await screen.findByRole('button', { name: 'update.open_installer' }))
+ expect(desktopUpdater.openInstaller).toHaveBeenCalledExactlyOnceWith('C:/installer.exe')
+ expect(desktopUpdater.downloadAndOpen).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/ui/dialog/update.tsx b/src/ui/dialog/update.tsx
index 75e371ac..c0d7cac3 100644
--- a/src/ui/dialog/update.tsx
+++ b/src/ui/dialog/update.tsx
@@ -23,6 +23,9 @@ export interface DesktopUpdateDialogProps extends PropsWithOverlays {}
*
* 对话框在下载中同样可关闭:下载由 store 驱动、与对话框生命周期无关,锁住弹窗
* 只会让「打开看进度」的用户无法退出(更新入口 chip 常驻,随时能再打开)。
+ *
+ * 下载中隐藏底部按钮(「稍后」/「立即更新」):此阶段主按钮只会阻塞等待同一次下载,
+ * 点击无意义;关闭仍可用右上角 X。
*/
export function DesktopUpdateDialog(props: DesktopUpdateDialogProps) {
const disclosure = useDisclosure({ props })
@@ -85,23 +88,25 @@ export function DesktopUpdateDialog(props: DesktopUpdateDialogProps) {
</div>
</If>
</AlertDialog.Body>
- <AlertDialog.Footer>
- <Button
- variant="tertiary"
- onPress={disclosure.cancel}
- >
- {t('update.later')}
- </Button>
- <Button
- variant="primary"
- isDisabled={updateInfo == null}
- onPress={handlePrimary}
- >
- {updateInfo?.downloaded
- ? t('update.open_installer')
- : t('update.now')}
- </Button>
- </AlertDialog.Footer>
+ <If cond={!downloading}>
+ <AlertDialog.Footer>
+ <Button
+ variant="tertiary"
+ onPress={disclosure.cancel}
+ >
+ {t('update.later')}
+ </Button>
+ <Button
+ variant="primary"
+ isDisabled={updateInfo == null}
+ onPress={handlePrimary}
+ >
+ {updateInfo?.downloaded
+ ? t('update.open_installer')
+ : t('update.now')}
+ </Button>
+ </AlertDialog.Footer>
+ </If>
</AlertDialog.Dialog>
</AlertDialog.Container>
</AlertDialog.Backdrop>