Skip to content

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

feat(store): introduce valtio-define global stores

hairyf523af611cd62
diff --git a/package.json b/package.json
index 005fc81e..7e3333fa 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,9 @@
"@tauri-apps/api": "^2.11.1",
"lucide-react": "^1.31.0",
"react": "^18.3.1",
- "react-dom": "^18.3.1"
+ "react-dom": "^18.3.1",
+ "tailwind-variants": "^3.3.1",
+ "valtio-define": "^1.4.1"
},
"devDependencies": {
"@antfu/eslint-config": "^9.3.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 88d635db..049ca123 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -25,6 +25,12 @@ importers:
react-dom:
specifier: ^18.3.1
version: 18.3.1([email protected])
+ tailwind-variants:
+ specifier: ^3.3.1
+ version: 3.3.1([email protected])
+ valtio-define:
+ specifier: ^1.4.1
+ version: 1.4.1(@types/[email protected])([email protected])
devDependencies:
'@antfu/eslint-config':
specifier: ^9.3.0
@@ -525,6 +531,9 @@ packages:
resolution: {integrity: sha512-+CNAzxglkrpNf/kKywqQfk74QjtceuOE7Qm+AF8miRvPF/wmmK5+OJOgVh3AVTT3RP2mH3+FOaxlE5v72owk0A==}
engines: {node: ^20.19.0 || ^22.13.0 || >=24}
+ '@hairy/[email protected]':
+ resolution: {integrity: sha512-KF3rVUeYGdjjQ0VBYwhH7BplmUXE4kgq6UpMecYHxL2ujP230iC0nKjA+SiBv25ycpmdCyVRcsYZdRbn+lZ6Gg==}
+
'@humanfs/[email protected]':
resolution: {integrity: sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==}
engines: {node: '>=18.18.0'}
@@ -940,6 +949,12 @@ packages:
resolution: {integrity: sha512-trgaNyfU+Xh2Tc+ABIb44a5AYUpicB3uwirOioeOkNPPbmgRNtcWyDeeFRzjPZENO9Vq8gvVqfhaaXWLlevVwg==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==}
+
+ '@types/[email protected]':
+ resolution: {integrity: sha512-+K1NIO8I+F9/wNulfVvu23QYd0Pe9/OCqRrim4NoYIf1VoEDL90Ve4ClzpyqBLc7NpGGWRvYNCKZ1BE/Jpf8dQ==}
+
resolution: {integrity: sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==}
@@ -1092,6 +1107,9 @@ packages:
engines: {node: '>=6.0.0'}
hasBin: true
+ resolution: {integrity: sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==}
+
resolution: {integrity: sha512-5PAPTTmMpMEb+GuMb5DebfBkipRGyIW9+gtwEBSoDA9xkhHILm04+hZQ702pMksu3d8YAuGkmgTzQWcKqTPScA==}
@@ -1172,6 +1190,11 @@ packages:
resolution: {integrity: sha512-XGpFGbMLHwSt74YLTKho7Ib242qi6O8MSX+sRokV4oz7iKXvQWGYZthjIhjRGMxjzVkAubBO512dKGYcefmX3Q==}
engines: {node: '>=6.4.0'}
+ resolution: {integrity: sha512-BMenSpH81lr/eRQp5ABPIfmBL1wqcIfM3iPnbPROtHn79KwtR9KVnQnFN/skTN/YLJPXJmXDM/R1CGhAWnEg1w==}
+ peerDependencies:
+ react: '>=18.0.0'
+
resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
engines: {node: '>= 8'}
@@ -1206,6 +1229,9 @@ packages:
resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==}
engines: {node: '>=6'}
+ resolution: {integrity: sha512-ugFTXCtDZunbzasqBxrK93Ik/DRYsO6S/fedkWEMKqt04xZ4csmnmwGDBAb07QWNaGMAmnTIemsYZCksjATwsA==}
+
resolution: {integrity: sha512-y+8xyqdGLL+6sh0tVeHcfP/QDd8gUgbasolJJpY7NgeQGSZ739bDtSiaiDgtoicy+mtYB81dKLxO9xRhCyIB3A==}
engines: {node: '>=12.20'}
@@ -1988,6 +2014,10 @@ packages:
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
engines: {node: '>=10'}
+ resolution: {integrity: sha512-HkPfFklpZQPUKBFXzKFB6ihLriIHxnmuQdK9WmLDwe4hf2PdhhfWT/FJa+pc3bA1ywvKXtedxIRmd4Y7BTXE4w==}
+ engines: {node: '>=12'}
+
resolution: {integrity: sha512-MyIV3ZA/PmyBN/ud8vV9XzwTrNtR4jFrObymZYnZqMmW0zA8Z17vnT0rBgFE/TlohB+YCHqXMgZzb3Csp49vqg==}
engines: {node: '>=14.16'}
@@ -2048,6 +2078,9 @@ packages:
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
engines: {node: '>= 0.8.0'}
+ resolution: {integrity: sha512-V9plBAt3qjMlS1+nC8771KNf6oJ12gExvaxnNzN/9yVRLdTv/lc+oJlnSzrdYDAvBfTStPCoiaCOTmTs0adv7Q==}
+
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
engines: {node: '>=6'}
@@ -2146,6 +2179,9 @@ packages:
resolution: {integrity: sha512-SlyRoSkdh1dYP0PzclLE7r0M9sgbFKKMFXpFRUMNuKhQSbC6VQIGzq3E0qsfvGJaUFJPGv6Ws1NZ/haTAjfbMA==}
engines: {node: '>=12'}
+ resolution: {integrity: sha512-JXpm4DZLQqcioH+wooEc3jCFRlwu/pJvemuuNUv37gOWTVzdYgw1khGWPYulMxdkK7rlsi0pIc5gDFTw+pF8+A==}
+
resolution: {integrity: sha512-WHkws2ZflZe41zj6AolvvmaTrWds/VuyeYr9iPVv/oQeaIoVxMKaushfFWpOGDT+GuBrM/sVqF8KUCYQlSSTdQ==}
engines: {node: '>=18'}
@@ -2154,6 +2190,18 @@ packages:
resolution: {integrity: sha512-eNRKgb3z66Yp3D2CixVujOUvXLFUTij/zVnV8KRyvFdQwpz7I5DS8UfRkTeLzb64u+dkzDSdelE24izu+zSSUg==}
engines: {node: ^14.18.0 || >=16.0.0}
+ resolution: {integrity: sha512-4pAvwUtM4HKBiRZftncAbpn6V9Hhwoa5Fl7O2u5zbp7Z5Cvu+/o/6+176WY3WCEES209543quG8zFIcXCsc5Jw==}
+ engines: {node: '>=16.9.x', pnpm: '>=7.x'}
+ peerDependencies:
+ tailwind-merge: '>=3.0.0'
+ tailwindcss: '*'
+ peerDependenciesMeta:
+ tailwind-merge:
+ optional: true
+ tailwindcss:
+ optional: true
+
resolution: {integrity: sha512-2E9TBm6MDD/xKYe+dvJZAmg3yxIEDNRc0jwlNyDg/4Fil2QcSLjFKGVff0lAf1jjeaArlG/M75Ey/EYr/OJtBA==}
@@ -2246,6 +2294,34 @@ packages:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
+ resolution: {integrity: sha512-6pcyIDqXWcWWl51GWoVTwkGszFsBDFLd7DPwKx9SSzIMhzolgG0U1tlkl2YWJAdEIOOMb05wzhyMkRIKDnh4Vg==}
+ peerDependencies:
+ react: ^19.2.4
+
+ resolution: {integrity: sha512-Zl1vr0w2S33QP9wBRX60p1LczyHrX+AWLB3iRl1doCdUTKaCziSj9GZIyrEIMykfjd0b3t27+X44phKOplcyfg==}
+ peerDependencies:
+ valtio: '>=2.0.0'
+
+ resolution: {integrity: sha512-cQE85SG8VjXYIuxWmvw1iZt41icrMVcCQgsoleIAPgnP8vTk0xXNUPDzfS8y6m4ZFJQpHUvQjZznGwts7cKgJA==}
+ peerDependencies:
+ react: '>=18.0.0'
+ valtio: '>=2.0.0-rc.0'
+
+ resolution: {integrity: sha512-YXhWQei9IN/ZDce9rhL3trCq9+vVq8M1gWmKVdP3YSZ2gxsmmNWVbxXwf9yG6ffu/dAvAD91nevg8xirGr4Dhg==}
+ engines: {node: '>=12.20.0'}
+ peerDependencies:
+ '@types/react': '>=18.0.0'
+ react: '>=18.0.0'
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ react:
+ optional: true
+
resolution: {integrity: sha512-zj/ob3UsvJGN0whEAKFp53REA5X66hvffVqoCtVQAakJKnKlH+/PcOfMoFwIG/o4rElqLv/ycAFlx8ZlXUorCg==}
engines: {node: '>=18.12.0'}
@@ -2786,6 +2862,12 @@ snapshots:
'@eslint/core': 1.2.1
levn: 0.4.1
+ '@hairy/[email protected]':
+ dependencies:
+ '@types/lodash-es': 4.17.12
+ bignumber.js: 9.3.1
+ p-pipe: 4.0.0
+
'@humanfs/[email protected]':
dependencies:
'@humanfs/types': 0.15.0
@@ -3090,6 +3172,12 @@ snapshots:
'@types/[email protected]': {}
+ '@types/[email protected]':
+ dependencies:
+ '@types/lodash': 4.17.25
+
+ '@types/[email protected]': {}
+
dependencies:
'@types/unist': 3.0.3
@@ -3282,6 +3370,8 @@ snapshots:
+
@@ -3346,6 +3436,10 @@ snapshots:
dependencies:
browserslist: 4.28.8
+ dependencies:
+ react: 18.3.1
+
dependencies:
path-key: 3.1.1
@@ -3370,6 +3464,8 @@ snapshots:
+
@@ -4425,6 +4521,8 @@ snapshots:
dependencies:
p-limit: 3.1.0
+
@@ -4478,6 +4576,8 @@ snapshots:
+
@@ -4584,6 +4684,8 @@ snapshots:
+
dependencies:
function-timeout: 1.0.2
@@ -4594,6 +4696,10 @@ snapshots:
dependencies:
'@pkgr/core': 0.3.6
+ optionalDependencies:
+ tailwindcss: 4.1.11
+
@@ -4693,6 +4799,35 @@ snapshots:
+ dependencies:
+ '@hairy/utils': 1.52.0
+ destr: 2.0.5
+ react: 18.3.1
+ structure-id: 1.2.9
+ valtio: 2.3.2(@types/[email protected])([email protected])
+ valtio-reactive: 0.2.0([email protected](@types/[email protected])([email protected]))
+ transitivePeerDependencies:
+ - '@types/react'
+
+ dependencies:
+ valtio: 2.3.2(@types/[email protected])([email protected])
+
+ dependencies:
+ create-react-signals: 0.8.0([email protected])
+ react: 18.3.1
+ valtio: 2.3.2(@types/[email protected])([email protected])
+
+ dependencies:
+ proxy-compare: 3.0.1
+ optionalDependencies:
+ '@types/react': 18.3.31
+ react: 18.3.1
+
diff --git a/src/store/index.ts b/src/store/index.ts
new file mode 100644
index 00000000..70e16f4a
--- /dev/null
+++ b/src/store/index.ts
@@ -0,0 +1,25 @@
+import { download } from './modules/download'
+import { harness } from './modules/harness'
+import { setting } from './modules/setting'
+import { updater } from './modules/updater'
+
+/** 全局 store 聚合(参考 damn-reports 的组织方式:模块各自独立,聚合统一出口) */
+export const store = {
+ harness,
+ updater,
+ download,
+ setting,
+}
+
+export { download } from './modules/download'
+export type { DownloadFinishedPayload } from './modules/download'
+export { harness } from './modules/harness'
+export type {
+ InstallerState,
+ InstallProgress,
+ SetupStatus,
+ SidebarBusyAction,
+} from './modules/harness'
+export { setting, useI18n } from './modules/setting'
+export { updater } from './modules/updater'
+export type { DshUpdateInfo } from './modules/updater'
diff --git a/src/store/modules/download/index.ts b/src/store/modules/download/index.ts
new file mode 100644
index 00000000..e7d8de7a
--- /dev/null
+++ b/src/store/modules/download/index.ts
@@ -0,0 +1,2 @@
+export { download } from './store'
+export type { DownloadFinishedPayload } from './types'
diff --git a/src/store/modules/download/store.ts b/src/store/modules/download/store.ts
new file mode 100644
index 00000000..206f68a0
--- /dev/null
+++ b/src/store/modules/download/store.ts
@@ -0,0 +1,25 @@
+import type { DownloadFinishedPayload } from './types'
+import { listen } from '@tauri-apps/api/event'
+import { defineStore } from 'valtio-define'
+
+/**
+ * 下载完成提示模块:dsh iframe 内的下载在 WebView2 中是静默保存的
+ * (用户零感知),由外壳监听 Rust 侧完成事件,弹出"已保存 + 打开文件夹"提示。
+ */
+export const download = defineStore({
+ state: () => ({
+ notice: null as DownloadFinishedPayload | null,
+ }),
+ actions: {
+ dismiss() {
+ this.notice = null
+ },
+ },
+})
+
+// 模块级监听 Rust 侧下载完成事件(应用生命周期内常驻,无需手动清理)
+listen<DownloadFinishedPayload>('harness-download-finished', (e) => {
+ download.notice = e.payload
+}).catch((err) => {
+ console.error('[Download] failed to listen harness-download-finished:', err)
+})
diff --git a/src/store/modules/download/types.ts b/src/store/modules/download/types.ts
new file mode 100644
index 00000000..76a80e76
--- /dev/null
+++ b/src/store/modules/download/types.ts
@@ -0,0 +1,6 @@
+/** Rust 侧 on_download 接管下载后 emit 的完成事件载荷 */
+export interface DownloadFinishedPayload {
+ url: string
+ path: string | null
+ success: boolean
+}
diff --git a/src/store/modules/harness/index.ts b/src/store/modules/harness/index.ts
new file mode 100644
index 00000000..6f4366ec
--- /dev/null
+++ b/src/store/modules/harness/index.ts
@@ -0,0 +1,2 @@
+export { harness } from './store'
+export type { InstallerState, InstallProgress, SetupStatus, SidebarBusyAction } from './types'
diff --git a/src/store/modules/harness/store.ts b/src/store/modules/harness/store.ts
new file mode 100644
index 00000000..32fe3378
--- /dev/null
+++ b/src/store/modules/harness/store.ts
@@ -0,0 +1,318 @@
+import type { UnlistenFn } from '@tauri-apps/api/event'
+import type { InstallerState, InstallProgress, SetupStatus, SidebarBusyAction } from './types'
+import { invoke } from '@tauri-apps/api/core'
+import { listen } from '@tauri-apps/api/event'
+import { defineStore } from 'valtio-define'
+import { setting } from '../setting'
+import { updater } from '../updater'
+
+const MAX_RETRIES = 8
+const IFRAME_LOAD_TIMEOUT = 20000
+
+const initialInstaller: InstallerState = {
+ title: '',
+ detail: '',
+ percentage: 0,
+ logs: [],
+}
+
+/** 启动流程令牌:boot 并发/重复调用时只采纳最后一次的结果 */
+let bootToken = 0
+/** 首次自动启动去重(React StrictMode 会重复挂载 effect) */
+let bootStarted = false
+
+/** 构建带时间戳的 iframe URL,避免 WebView2 缓存旧页面 */
+function generateTimestampedUrl(baseUrl: string): string {
+ const timestamp = Date.now()
+ const separator = baseUrl.includes('?') ? '&' : '?'
+ return `${baseUrl}${separator}t=${timestamp}`
+}
+
+/** 通过 Rust 代理探测服务健康状态(超时 8s,网络抖动时重试) */
+async function checkHealthViaProxy(): Promise<boolean> {
+ try {
+ const timeoutPromise = new Promise<never>((_, reject) => {
+ setTimeout(() => reject(new Error('health check timeout')), 8000)
+ })
+ const resultPromise = invoke<string>('proxy_health_check')
+ const result = await Promise.race([resultPromise, timeoutPromise])
+
+ const lower = result.toLowerCase()
+ if (
+ lower.includes('healthy')
+ || lower.includes('ready')
+ || result.includes('200')
+ || result.includes('201')
+ || lower.includes('ok')
+ ) {
+ console.warn('[Harness] health check passed:', result)
+ return true
+ }
+ console.warn('[Harness] health check returned:', result)
+ return false
+ }
+ catch (err) {
+ const message = String(err)
+ if (message.includes('502') || message.includes('Bad Gateway')) {
+ console.warn('[Harness] transient 502 during health check, retrying')
+ }
+ else {
+ console.error('[Harness] health check failed:', err)
+ }
+ return false
+ }
+}
+
+/**
+ * 桌面外壳核心业务模块:安装/启动流程、服务生命周期(启动/健康检查/重启/停止)、
+ * iframe 加载状态与挂起兜底。
+ *
+ * 拆分说明(参考 damn-reports 的 store 组织方式):
+ * 版本更新与下载完成提示分别收敛到 updater / download 模块,
+ * 本模块专注服务生命周期与页面加载状态。
+ */
+export const harness = defineStore({
+ state: () => ({
+ status: 'ready' as SetupStatus,
+ installer: initialInstaller,
+ errorMsg: '',
+ serviceUrl: 'http://127.0.0.1:3080',
+ /** 带时间戳的 iframe 地址(boot 时生成一次,避免缓存) */
+ iframeSrc: '',
+ iframeLoaded: false,
+ iframeError: false,
+ iframeKey: 0,
+ serviceHealthy: false,
+ serviceRunning: false,
+ busyAction: null as SidebarBusyAction,
+ }),
+ actions: {
+ /** 首次挂载时自动启动(StrictMode 重复挂载下保证只执行一次) */
+ startup() {
+ if (bootStarted)
+ return
+ bootStarted = true
+ void this.boot()
+ },
+
+ /** 刷新 iframe:清除加载态并延迟重新挂载 */
+ refreshIframe() {
+ this.iframeLoaded = false
+ this.iframeError = false
+ setTimeout(() => {
+ this.iframeKey++
+ }, 800)
+ },
+
+ /** iframe 加载成功/失败时由视图回调更新状态 */
+ markIframeLoaded() {
+ this.iframeLoaded = true
+ this.iframeError = false
+ },
+
+ markIframeError() {
+ this.iframeError = true
+ this.iframeLoaded = false
+ },
+
+ /** 安装进度流:只前进不后退,供首次安装/手动更新共用 */
+ async listenInstallProgress(): Promise<UnlistenFn> {
+ return listen<InstallProgress>('install-progress', (e) => {
+ const payload = e.payload
+ if (payload.percentage < this.installer.percentage) {
+ return
+ }
+ const logs = payload.log
+ ? [...this.installer.logs, payload.log].slice(-5)
+ : this.installer.logs
+ this.installer = {
+ title: payload.title || this.installer.title,
+ detail: payload.detail || this.installer.detail,
+ percentage: payload.percentage,
+ logs,
+ }
+ })
+ },
+
+ /** 拉起服务并等待健康检查通过,通过后才允许挂载 iframe */
+ async launchAndWait() {
+ this.status = 'ready'
+ this.installer = initialInstaller
+ this.serviceHealthy = false
+ this.iframeLoaded = false
+ this.iframeError = false
+ await invoke('launch_harness')
+ this.serviceRunning = true
+
+ let healthy = false
+ for (let attempt = 0; attempt < MAX_RETRIES && !healthy; attempt++) {
+ healthy = await checkHealthViaProxy()
+ if (!healthy) {
+ await new Promise(resolve => setTimeout(resolve, 2000))
+ }
+ }
+ if (!healthy) {
+ throw new Error(
+ setting.t('errors.service_start_timeout', { port: new URL(this.serviceUrl).port || '3080' }),
+ )
+ }
+ this.serviceHealthy = true
+ },
+
+ /** 启动流程:检测环境/安装依赖 → 拉起服务 → 已安装时后台检查更新 */
+ async boot() {
+ const token = ++bootToken
+ // 回到加载态:已安装时不再显示检测/启动界面,直接进入页面加载状态
+ this.serviceHealthy = false
+ this.iframeLoaded = false
+ this.iframeError = false
+ let unlistenInstall: UnlistenFn | null = null
+
+ try {
+ // 事件监听失败(例如 IPC 自定义协议被 CSP 拦截、回退 postMessage 也异常)
+ // 不应阻断启动流程,因此容错跳过。
+ try {
+ unlistenInstall = await this.listenInstallProgress()
+ }
+ catch (err) {
+ console.error('[Harness] failed to listen install-progress:', err)
+ }
+ const runtimeInfo = await invoke<{ service_url: string }>('get_runtime_info')
+ this.serviceUrl = runtimeInfo.service_url
+ this.iframeSrc = generateTimestampedUrl(runtimeInfo.service_url)
+
+ // 已安装过则跳过安装界面,避免每次启动都闪现"正在安装依赖..."
+ const config = await invoke<{ installed: boolean }>('get_app_config')
+
+ // 仅首次使用需要检测环境/安装依赖;之后直接进入页面
+ if (!config.installed) {
+ this.status = 'installing'
+ this.installer = { ...initialInstaller, title: setting.t('status.installing') }
+ await invoke('install_dependencies')
+ }
+
+ await this.launchAndWait()
+
+ if (token !== bootToken)
+ return
+ // 已安装时后台静默检查新版,发现后提示用户
+ if (config.installed) {
+ void updater.checkForUpdate()
+ }
+ }
+ catch (err) {
+ if (token !== bootToken)
+ return
+ console.error('[Harness] startup failed:', err)
+ this.fail(String(err))
+ }
+ finally {
+ unlistenInstall?.()
+ }
+ },
+
+ /** 进入安装态(手动更新前复用,标题区分"安装/更新") */
+ prepareInstall(title: string) {
+ this.status = 'installing'
+ this.installer = { ...initialInstaller, title }
+ },
+
+ /** 进入错误态(供本模块与 updater 模块共用) */
+ fail(message: string) {
+ this.errorMsg = message
+ this.status = 'error'
+ this.serviceRunning = false
+ },
+
+ /** 重启服务:先强杀再拉起,最终回到就绪/错误态 */
+ async restart() {
+ if (this.busyAction)
+ return
+ this.busyAction = 'restart'
+ try {
+ await invoke('shutdown_harness')
+ }
+ catch (err) {
+ console.error('[Harness] shutdown during restart failed:', err)
+ }
+ this.serviceRunning = false
+ this.iframeLoaded = false
+ try {
+ await this.boot()
+ }
+ finally {
+ this.busyAction = null
+ }
+ },
+
+ /** 停止服务并回到停止态界面 */
+ async shutdown() {
+ if (this.busyAction)
+ return
+ this.busyAction = 'shutdown'
+ try {
+ await invoke('shutdown_harness')
+ }
+ catch (err) {
+ console.error('[Harness] shutdown failed:', err)
+ }
+ finally {
+ this.busyAction = null
+ }
+ this.serviceRunning = false
+ this.status = 'error'
+ this.errorMsg = setting.t('ui.stopped')
+ },
+
+ /** 服务未运行时点击"重试":重新拉起服务并等待健康检查 */
+ async start() {
+ if (this.busyAction)
+ return
+ this.busyAction = 'start'
+ try {
+ await this.boot()
+ }
+ finally {
+ this.busyAction = null
+ }
+ },
+
+ /** 在系统浏览器中打开服务地址 */
+ async openBrowser() {
+ if (this.busyAction)
+ return
+ this.busyAction = 'openBrowser'
+ try {
+ await invoke('open_in_browser')
+ }
+ catch (err) {
+ console.error('[Harness] open in browser failed:', err)
+ }
+ finally {
+ this.busyAction = null
+ }
+ },
+ },
+})
+
+// 进入 ready 后 iframe 长时间未加载(dsh 未就绪/挂起)→ 转为错误界面,
+// 避免一直停在黑色加载遮罩
+let iframeLoadTimer: ReturnType<typeof setTimeout> | null = null
+harness.$subscribe(() => {
+ const { status, serviceHealthy, iframeLoaded, iframeError } = harness.$state
+ if (status === 'ready' && serviceHealthy && !iframeLoaded && !iframeError) {
+ if (!iframeLoadTimer) {
+ iframeLoadTimer = setTimeout(() => {
+ iframeLoadTimer = null
+ harness.iframeLoaded = false
+ harness.iframeError = true
+ }, IFRAME_LOAD_TIMEOUT)
+ }
+ }
+ else {
+ if (iframeLoadTimer) {
+ clearTimeout(iframeLoadTimer)
+ iframeLoadTimer = null
+ }
+ }
+})
diff --git a/src/store/modules/harness/types.ts b/src/store/modules/harness/types.ts
new file mode 100644
index 00000000..8c325aa0
--- /dev/null
+++ b/src/store/modules/harness/types.ts
@@ -0,0 +1,23 @@
+/** 安装/启动流程阶段状态 */
+export type SetupStatus = 'checking' | 'installing' | 'starting' | 'ready' | 'error'
+
+/** 侧边栏忙碌标记:标识当前正在执行的服务操作 */
+export type SidebarBusyAction = 'restart' | 'shutdown' | 'start' | 'openBrowser' | null
+
+/** 安装器展示状态 */
+export interface InstallerState {
+ title: string
+ detail: string
+ percentage: number
+ logs: string[]
+}
+
+/** Rust 侧 install-progress 事件载荷 */
+export interface InstallProgress {
+ title: string
+ detail: string
+ log: string
+ type: string
+ percentage: number
+ progress: number
+}
diff --git a/src/store/modules/setting/index.ts b/src/store/modules/setting/index.ts
new file mode 100644
index 00000000..eb463b49
--- /dev/null
+++ b/src/store/modules/setting/index.ts
@@ -0,0 +1,97 @@
+import type { Language, Translations } from '../../../i18n'
+import { invoke } from '@tauri-apps/api/core'
+import { defineStore, useStore } from 'valtio-define'
+import { translations } from '../../../i18n'
+
+const STORAGE_KEY = 'deepseek-harness-desktop-language'
+
+/** 初始语言:优先取 localStorage,其次浏览器语言 */
+function getInitialLanguage(): Language {
+ const saved = localStorage.getItem(STORAGE_KEY) as Language | null
+ if (saved === 'en' || saved === 'zh') {
+ return saved
+ }
+ return navigator.language.toLowerCase().startsWith('zh') ? 'zh' : 'en'
+}
+
+/** 按 keyPath(如 'ui.running')取翻译文案,支持 {{param}} 插值 */
+function getTranslation(obj: Translations, keyPath: string, params?: Record<string, string | number>): string {
+ const keys = keyPath.split('.')
+ let value: unknown = obj
+
+ for (const key of keys) {
+ if (value && typeof value === 'object' && key in value) {
+ value = (value as Record<string, unknown>)[key]
+ }
+ else {
+ return keyPath
+ }
+ }
+
+ if (typeof value !== 'string') {
+ return keyPath
+ }
+
+ if (params) {
+ return value.replace(/\{\{(\w+)\}\}/g, (match, paramName: string) => {
+ return params[paramName]?.toString() ?? match
+ })
+ }
+ return value
+}
+
+/** 从 localStorage 恢复侧边栏开关状态 */
+function getInitialSidebarOpen(): boolean {
+ const saved = localStorage.getItem('sidebarOpen')
+ return saved === null ? false : saved === 'true'
+}
+
+/**
+ * 设置模块:语言偏好与文案翻译 + 侧边栏开关等纯 UI 状态(由原 i18n / ui 模块合并而来)。
+ * 组件通过 useI18n() 订阅语言变化;store 内部动作直接调用 setting.t(...)。
+ */
+export const setting = defineStore({
+ state: () => ({
+ language: getInitialLanguage() as Language,
+ sidebarOpen: getInitialSidebarOpen(),
+ }),
+ actions: {
+ setLanguage(lang: Language) {
+ this.language = lang
+ localStorage.setItem(STORAGE_KEY, lang)
+ // 后端语言设置仅尽力而为
+ invoke('set_language', { lang }).catch(() => {})
+ },
+ t(key: string, params?: Record<string, string | number>): string {
+ return getTranslation(translations[this.language], key, params)
+ },
+ toggleSidebar() {
+ this.sidebarOpen = !this.sidebarOpen
+ localStorage.setItem('sidebarOpen', String(this.sidebarOpen))
+ },
+ closeSidebar() {
+ this.sidebarOpen = false
+ localStorage.setItem('sidebarOpen', 'false')
+ },
+ },
+})
+
+// 语言变化时同步 <html lang> 与方向(首次加载也立即生效)
+function applyDocumentLanguage(language: Language) {
+ document.documentElement.lang = language
+ document.documentElement.dir = 'ltr'
+}
+applyDocumentLanguage(setting.language)
+setting.$subscribeKey('language', (language) => {
+ applyDocumentLanguage(language)
+})
+
+/** 订阅 setting store,返回语言与翻译函数(语言切换时自动重渲染) */
+export function useI18n() {
+ const { language } = useStore(setting)
+ return {
+ language,
+ setLanguage: setting.setLanguage,
+ t: setting.t,
+ }
+}
diff --git a/src/store/modules/updater/index.ts b/src/store/modules/updater/index.ts
new file mode 100644
index 00000000..22de3ee8
--- /dev/null
+++ b/src/store/modules/updater/index.ts
@@ -0,0 +1,2 @@
+export { updater } from './store'
+export type { DshUpdateInfo } from './types'
diff --git a/src/store/modules/updater/store.ts b/src/store/modules/updater/store.ts
new file mode 100644
index 00000000..0136a805
--- /dev/null
+++ b/src/store/modules/updater/store.ts
@@ -0,0 +1,62 @@
+import type { UnlistenFn } from '@tauri-apps/api/event'
+import type { DshUpdateInfo } from './types'
+import { invoke } from '@tauri-apps/api/core'
+import { defineStore } from 'valtio-define'
+import { harness } from '../harness'
+import { setting } from '../setting'
+
+/**
+ * 版本更新模块:后台静默检查 + 手动更新安装。
+ * 安装进度与启动等待复用 harness 模块的能力,本模块只负责"有没有新版本"的决策。
+ */
+export const updater = defineStore({
+ state: () => ({
+ /** 发现的新版本信息(null 表示暂无/已被忽略) */
+ updateInfo: null as DshUpdateInfo | null,
+ /** 是否正在安装更新 */
+ updating: false,
+ }),
+ actions: {
+ /** 后台静默检查是否有新版 Harness(网络失败/API 限流时静默跳过) */
+ async checkForUpdate() {
+ try {
+ const info = await invoke<DshUpdateInfo | null>('check_dsh_update')
+ if (info) {
+ this.updateInfo = info
+ }
+ }
+ catch (err) {
+ console.warn('[Harness] update check skipped:', err)
+ }
+ },
+
+ /** 手动更新:重新下载安装新版并重启服务 */
+ async handleUpdate() {
+ if (this.updating)
+ return
+ this.updating = true
+ this.updateInfo = null
+ let unlistenInstall: UnlistenFn | null = null
+ try {
+ unlistenInstall = await harness.listenInstallProgress()
+ harness.prepareInstall(setting.t('status.updating'))
+ await invoke('install_dependencies')
+ await harness.launchAndWait()
+ this.updateInfo = null
+ }
+ catch (err) {
+ console.error('[Harness] update failed:', err)
+ harness.fail(String(err))
+ }
+ finally {
+ unlistenInstall?.()
+ this.updating = false
+ }
+ },
+
+ /** 忽略本次更新提示 */
+ dismissUpdate() {
+ this.updateInfo = null
+ },
+ },
+})
diff --git a/src/store/modules/updater/types.ts b/src/store/modules/updater/types.ts
new file mode 100644
index 00000000..8cf4319e
--- /dev/null
+++ b/src/store/modules/updater/types.ts
@@ -0,0 +1,5 @@
+/** Rust 侧 check_dsh_update 返回的版本信息 */
+export interface DshUpdateInfo {
+ tag: string
+ commit: string
+}