DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
refactor(dialogs): open update/about/config via overlastic instead of always-mounted modals
hairyf8ae1f13ab6fb
diff --git a/src/app.tsx b/src/app.tsxindex 9edee009..9ccf2046 100644--- a/src/app.tsx+++ b/src/app.tsx@@ -1,7 +1,5 @@import { useEffect } from 'react'import { useStore } from 'valtio-define'-import DesktopAboutDialog from './components/desktop-about-dialog'-import DesktopUpdateDialog from './components/desktop-update-dialog'import DesktopUpdater from './components/desktop-updater'import DownloadToast from './components/download-toast'import HarnessUpdater from './components/harness-updater'@@ -13,6 +11,8 @@ import './i18n'* 应用根组件:只负责首次启动与整体布局。* 业务状态与操作方法全部收敛到 valtio-define store,* 各子组件自行订阅 store,不再通过 props 透传回调与状态。+ * 弹出层(关于 / 检查更新 / 应用配置)统一由 overlastic 命令式打开,+ * 仅在需要时挂载,不常驻渲染。*/export default function App() {useDshTheme()@@ -28,8 +28,6 @@ export default function App() {{status === 'ready' && <HarnessUpdater />}{status === 'ready' && <DownloadToast />}<DesktopUpdater />- <DesktopUpdateDialog />- <DesktopAboutDialog /></div>)}diff --git a/src/components/config-dialog.tsx b/src/components/config-dialog.tsxindex 515ae555..079bae88 100644--- a/src/components/config-dialog.tsx+++ b/src/components/config-dialog.tsx@@ -1,52 +1,37 @@+import type { PropsWithOverlays } from '@overlastic/react'import { Cpu, PersonPencil, Puzzle, Wrench } from '@gravity-ui/icons'import { cn, Modal } from '@heroui/react'import { useDisclosure } from '@overlastic/react'import { useState } from 'react'+import { useTranslation } from 'react-i18next'import { Case, Switch } from 'react-if-lite'import { ConfigCore } from './config-core'import { ConfigDebug } from './config-debug'import { ConfigPlugin } from './config-plugin'import { ConfigProfile } from './config-profile'-export function ConfigDialog() {- const disclosure = useDisclosure()+export interface ConfigDialogProps extends PropsWithOverlays {}++export function ConfigDialog(props: ConfigDialogProps) {+ const disclosure = useDisclosure({ props })+ const { t } = useTranslation()const navs = [- {- title: '调试',- label: 'Debug',- value: 'debug',- icon: Wrench,- },- {- title: '档案',- label: 'Profiles',- value: 'profiles',- icon: PersonPencil,- },- {- title: '插件',- label: 'Plugins',- value: 'plugins',- icon: Puzzle,- },- {- title: '核心',- label: 'Harness',- value: 'harness',- icon: Cpu,- },+ { label: t('config.debug'), value: 'debug', icon: Wrench },+ { label: t('config.profiles'), value: 'profiles', icon: PersonPencil },+ { label: t('config.plugins'), value: 'plugins', icon: Puzzle },+ { label: t('config.harness'), value: 'harness', icon: Cpu },]const [activeTab, setActiveTab] = useState('debug')return (- <Modal isOpen={disclosure.visible} onOpenChange={disclosure.confirm}>+ <Modal isOpen={disclosure.visible} onOpenChange={disclosure.cancel}><Modal.Backdrop><Modal.Container size="lg"><Modal.Dialog className="w-[800px] max-w-[calc(100vw-48px)] pr-2.5"><Modal.CloseTrigger /><Modal.Header className="mb-3"><Modal.Heading>- 应用配置+ {t('app.config')}</Modal.Heading></Modal.Header><Modal.Body className="flex gap-6 pr-0">@@ -64,7 +49,7 @@ export function ConfigDialog() {)}><item.icon className="w-5 h-5 mr-2" />- <span>{item.title}</span>+ <span>{item.label}</span></button>)})}diff --git a/src/components/desktop-about-dialog.tsx b/src/components/desktop-about-dialog.tsxindex 36d1bd4c..57d79965 100644--- a/src/components/desktop-about-dialog.tsx+++ b/src/components/desktop-about-dialog.tsx@@ -1,27 +1,33 @@+import type { PropsWithOverlays } from '@overlastic/react'import { ArrowUpRightFromSquare } from '@gravity-ui/icons'-import { Button, Description, Modal, useOverlayState } from '@heroui/react'+import { Button, Description, Modal } from '@heroui/react'+import { useDisclosure } from '@overlastic/react'import { invoke } from '@tauri-apps/api/core'+import { useEffect } from 'react'import { useTranslation } from 'react-i18next'import { useStore } from 'valtio-define'import { desktopUpdate } from '../store/modules/desktop-update'+export interface DesktopAboutDialogProps extends PropsWithOverlays {}+/*** 「关于 Desktop」对话框:展示 Powered by、版本号、发布时间与版权信息。+ *+ * 使用 overlastic 命令式打开(`useOverlay(DesktopAboutDialog)`),+ * 打开时通过 store 的 `loadAbout` 拉取信息,关闭由 `disclosure.cancel` 完成。*/-export default function DesktopAboutDialog() {+export default function DesktopAboutDialog(props: DesktopAboutDialogProps) {+ const disclosure = useDisclosure({ props })const { t } = useTranslation()- const { about, aboutDialogOpen } = useStore(desktopUpdate)+ const { about } = useStore(desktopUpdate)- const state = useOverlayState({- isOpen: aboutDialogOpen,- onOpenChange: (open) => {- if (!open)- desktopUpdate.closeAbout()- },- })+ useEffect(() => {+ if (disclosure.visible)+ void desktopUpdate.loadAbout()+ }, [disclosure.visible])return (- <Modal state={state}>+ <Modal isOpen={disclosure.visible} onOpenChange={disclosure.cancel}><Modal.Backdrop><Modal.Container size="xs"><Modal.Dialog>diff --git a/src/components/desktop-update-dialog.tsx b/src/components/desktop-update-dialog.tsxindex 095a3527..b4c02f68 100644--- a/src/components/desktop-update-dialog.tsx+++ b/src/components/desktop-update-dialog.tsx@@ -1,27 +1,52 @@-import { Button, Description, Modal, ProgressBar, useOverlayState } from '@heroui/react'+import type { PropsWithOverlays } from '@overlastic/react'+import { useWatch } from '@hairy/react-lib'+import { Button, Description, Modal, ProgressBar } from '@heroui/react'+import { useDisclosure } from '@overlastic/react'+import { useRef } from 'react'import { useTranslation } from 'react-i18next'import { If } from 'react-if-lite'import { useStore } from 'valtio-define'import { desktopUpdate } from '../store/modules/desktop-update'+export interface DesktopUpdateDialogProps extends PropsWithOverlays {}+/*** 「检查更新」对话框:展示新版本信息 + 下载进度。* 已下载 → 「打开安装包」直接启动安装器;未下载 → 「立即更新」下载完成后自动打开。+ *+ * 使用 overlastic 命令式打开(`useOverlay(DesktopUpdateDialog)`)。+ * 下载由 store 驱动:对话框内「立即更新」触发 `downloadAndOpen`;+ * 外部触发(右下角 toast)下载完成并打开安装包后,对话框依据 downloading 回落自动关闭。*/-export default function DesktopUpdateDialog() {+export default function DesktopUpdateDialog(props: DesktopUpdateDialogProps) {+ const disclosure = useDisclosure({ props })const { t } = useTranslation()- const { updateInfo, downloading, downloadProgress, updateDialogOpen } = useStore(desktopUpdate)+ const { updateInfo, downloading, downloadProgress } = useStore(desktopUpdate)+ const prevDownloadingRef = useRef(false)++ // 外部触发下载(如右下角 toast「立即更新」)完成并打开安装包后,自动关闭对话框;+ // 仅当 downloading 由 true→false 且已下载(安装包已打开)时才关闭,下载失败保持打开。+ useWatch([downloading, updateInfo], () => {+ if (prevDownloadingRef.current && !downloading && updateInfo?.downloaded)+ disclosure.cancel()+ prevDownloadingRef.current = downloading+ }, { immediate: true })- const state = useOverlayState({- isOpen: updateDialogOpen,- onOpenChange: (open) => {- if (!open)- desktopUpdate.closeUpdateDialog()- },- })+ async function handlePrimary() {+ const info = desktopUpdate.updateInfo+ if (!info)+ return+ if (info.downloaded) {+ await desktopUpdate.openInstaller(info.path)+ disclosure.cancel()+ }+ else {+ await desktopUpdate.downloadAndOpen()+ }+ }return (- <Modal state={state}>+ <Modal isOpen={disclosure.visible} onOpenChange={disclosure.cancel}><Modal.Backdrop isDismissable={!downloading}><Modal.Container size="sm"><Modal.Dialog>@@ -70,7 +95,7 @@ export default function DesktopUpdateDialog() {variant="tertiary"className="rounded-md"isDisabled={downloading}- onPress={desktopUpdate.closeUpdateDialog}+ onPress={disclosure.cancel}>{t('update.later')}</Button>@@ -78,7 +103,7 @@ export default function DesktopUpdateDialog() {variant="primary"className="rounded-md"isDisabled={downloading || updateInfo == null}- onPress={() => desktopUpdate.downloadAndOpen()}+ onPress={handlePrimary}>{updateInfo?.downloaded? t('update.open_installer')diff --git a/src/components/desktop-updater.tsx b/src/components/desktop-updater.tsxindex f831a486..acc06c5a 100644--- a/src/components/desktop-updater.tsx+++ b/src/components/desktop-updater.tsx@@ -1,9 +1,11 @@import { useWatch } from '@hairy/react-lib'+import { useOverlay } from '@overlastic/react'import { useEffect } from 'react'import { useTranslation } from 'react-i18next'import { useStore } from 'valtio-define'import { toast } from '@/utils'import { desktopUpdate } from '../store/modules/desktop-update'+import DesktopUpdateDialog from './desktop-update-dialog'/** 桌面端自更新轮询间隔:Rust 侧不再缓存,改为低频轮询以免触发 GitHub 未认证限流(60 次/小时/IP) */const POLL_INTERVAL = 10 * 60_000@@ -15,7 +17,8 @@ const POLL_INTERVAL = 10 * 60_000*/export default function DesktopUpdater() {const { t } = useTranslation()- const { updateInfo, dismissedTag, downloading, updateDialogOpen } = useStore(desktopUpdate)+ const { updateInfo, dismissedTag, downloading } = useStore(desktopUpdate)+ const openUpdateDialog = useOverlay(DesktopUpdateDialog)// 低频静默检查新版本(实时查询,无本地缓存);后台失败静默,不打扰用户useEffect(() => {@@ -26,8 +29,8 @@ export default function DesktopUpdater() {return () => clearInterval(timer)}, [])- useWatch([updateInfo, dismissedTag, downloading, updateDialogOpen], () => {- if (!updateInfo || downloading || updateDialogOpen)+ useWatch([updateInfo, dismissedTag, downloading], () => {+ if (!updateInfo || downloading)return// 安装包已下载(用户已发起更新)→ 不再重复弹「立即更新」toastif (updateInfo.downloaded)@@ -40,8 +43,9 @@ export default function DesktopUpdater() {children: t('update.now'),onPress: () => {toast.clear()- // 打开更新对话框并开始下载,对话框内展示下载进度- void desktopUpdate.updateNow()+ // 打开更新对话框并开始下载,对话框内展示下载进度(下载完成自动关闭)+ openUpdateDialog()+ void desktopUpdate.downloadAndOpen()},variant: 'tertiary',},diff --git a/src/components/navbar.tsx b/src/components/navbar.tsxindex b41a7cfe..90c9cbec 100644--- a/src/components/navbar.tsx+++ b/src/components/navbar.tsx@@ -20,6 +20,8 @@ import { useDshPlugins } from '../hooks/use-dsh-plugins'import { useIframeTauri } from '../hooks/use-iframe-tauri'import { desktopUpdate } from '../store/modules/desktop-update'import { ConfigDialog } from './config-dialog'+import DesktopAboutDialog from './desktop-about-dialog'+import DesktopUpdateDialog from './desktop-update-dialog'/*** 壳层窗口顶部导航栏(44px,常驻):@@ -59,6 +61,8 @@ export default function Navbar({ iframeRef }: NavbarProps) {const { updateInfo } = useStore(desktopUpdate)const openConfigDialog = useOverlay(ConfigDialog)+ const openAboutDialog = useOverlay(DesktopAboutDialog)+ const openUpdateDialog = useOverlay(DesktopUpdateDialog)// 仅当 dsh-tauri 插件启用(已安装)时显示左侧导航控件const tauriEnabled = plugins.some(plugin => plugin.id === TAURI_PLUGIN_ID)function handleWindowAction(action: 'minimize' | 'maximize' | 'background') {@@ -79,13 +83,28 @@ export default function Navbar({ iframeRef }: NavbarProps) {function handleHelpAction(key: string) {if (key === 'check-update')- void desktopUpdate.openUpdateDialog()+ void handleCheckUpdate()else if (key === 'about')- void desktopUpdate.openAbout()+ openAboutDialog()else if (key === 'copy-run-logs')void copyRunLogs()}+ /** 「检查更新」:先检查,有更新才弹框;检查失败提示错误而非「已是最新」 */+ async function handleCheckUpdate() {+ try {+ const info = await desktopUpdate.check()+ if (info)+ openUpdateDialog()+ else+ toast(t('update.up_to_date'), {})+ }+ catch (err) {+ console.warn('[Navbar] check update failed:', err)+ toast(t('update.check_failed'), { variant: 'danger' })+ }+ }+async function copyRunLogs() {try {const logs = await invoke<string>('read_run_logs')diff --git a/src/store/modules/desktop-update/store.ts b/src/store/modules/desktop-update/store.tsindex ffa866d3..21ff95c2 100644--- a/src/store/modules/desktop-update/store.ts+++ b/src/store/modules/desktop-update/store.ts@@ -37,10 +37,6 @@ export const desktopUpdate = defineStore({downloading: false,/** 下载进度 0-100 */downloadProgress: 0,- /** 更新对话框开关 */- updateDialogOpen: false,- /** 关于对话框开关 */- aboutDialogOpen: false,/** 关于对话框信息 */about: null as DesktopAboutInfo | null,/** 用户已关闭提示的版本 tag(持久化,同版本不再弹 toast) */@@ -88,30 +84,8 @@ export const desktopUpdate = defineStore({}},- /** 打开更新对话框(「检查更新」菜单):先检查,有更新才弹框;检查失败提示错误而非「已是最新」 */- async openUpdateDialog() {- try {- if (!this.updateInfo)- await this.check()- if (this.updateInfo) {- this.updateDialogOpen = true- }- else {- toast(i18next.t('update.up_to_date'), { variant: 'default' })- }- }- catch (err) {- console.warn('[DesktopUpdate] check failed:', err)- toast(i18next.t('update.check_failed'), { variant: 'danger' })- }- },-- closeUpdateDialog() {- this.updateDialogOpen = false- },-- /** 打开关于对话框:拉取信息后展示 */- async openAbout() {+ /** 加载关于信息(缓存到 store,仅首次拉取;打开关于对话框前调用) */+ async loadAbout(): Promise<DesktopAboutInfo | null> {if (!this.about) {try {this.about = await invoke<DesktopAboutInfo>('get_desktop_about')@@ -120,24 +94,7 @@ export const desktopUpdate = defineStore({console.warn('[DesktopUpdate] failed to load about info:', err)}}- this.aboutDialogOpen = true- },-- closeAbout() {- this.aboutDialogOpen = false- },-- /**- * toast「立即更新」:打开更新对话框并开始下载,避免静默下载无反馈。- * 对话框内 `downloading` 状态会展示下载进度条;下载完成自动打开安装器并关闭对话框。- */- async updateNow() {- if (!this.updateInfo)- await this.check()- if (!this.updateInfo)- return- this.updateDialogOpen = true- await this.downloadAndOpen()+ return this.about},/**@@ -178,11 +135,10 @@ export const desktopUpdate = defineStore({}},- /** 打开安装包并收尾(关对话框 + 提示) */+ /** 打开安装包并提示(对话框由调用方 / overlastic 自行关闭) */async openInstaller(path: string) {try {await invoke('open_desktop_installer', { path })- this.closeUpdateDialog()toast(i18next.t('update.desktop_opened'), {variant: 'default',placement: 'bottom end',