Skip to content

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

feat(core): warn before downloading core versions above rc.2 (#323)

Mao Mr62a67603eedf
diff --git a/src/components/config-core.tsx b/src/components/config-core.tsx
index 5e4aba1d..0f818930 100644
--- a/src/components/config-core.tsx
+++ b/src/components/config-core.tsx
@@ -6,7 +6,9 @@ import { invoke } from '@tauri-apps/api/core'
import { Fragment, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { If } from 'react-if-lite'
+import { useCoreBreakingConfirm } from '@/hooks/use-core-breaking-confirm'
import { store } from '@/store'
+import { compareVersions } from '@/utils/core-version'
import { toast } from '@/utils/toast'
import { useDshCores } from '../hooks/use-dsh-cores'
import { DownloadCoreDialog } from './download-core-dialog'
@@ -31,9 +33,11 @@ import { PanelState } from './panel-state'
* - 本地核心更新:通过用户包管理器 CLI(npm install -g @latest / pnpm add -g @latest)。
* - 每行展示核心入口(cli path,超长省略号 + 限制宽度)。
*/
+
export function ConfigCore() {
const [dialogHolder, openDialog] = useOverlay(Modal, { type: 'holder' })
const [downloadDialogHolder, openDownloadDialog] = useOverlay(DownloadCoreDialog, { type: 'holder' })
+ const { holder: coreBreakingHolder, confirmCoreBreaking } = useCoreBreakingConfirm()
const { t } = useTranslation()
const { cores, loading, error, setActiveCore, updateLocalCore, downloadCore, removeCore, refreshCores, busy } = useDshCores()
@@ -131,6 +135,10 @@ export function ConfigCore() {
async function onDownload(core: HarnessCore) {
if (busy)
return
+ // rc.2 以上版本引入破坏性更改,可能影响第三方插件 → 下载前先弹出确认。
+ // 取消则中止,确认后继续;该提示与推荐版本逻辑无关,仅告知用户可随时切回 rc.2。
+ if (!(await confirmCoreBreaking(core.version)))
+ return
// 下载过程在对话框内展示进度 + 日志(复用 install-progress 事件流);
// 对话框 confirm(下载成功)或 cancel(失败后点关闭)都会结束本次等待。
try {
@@ -382,6 +390,7 @@ export function ConfigCore() {
{dialogHolder}
{downloadDialogHolder}
+ {coreBreakingHolder}
</div>
)
}
@@ -390,60 +399,3 @@ export function ConfigCore() {
function displayVersion(version: HarnessCore): string {
return version.version || (version.source === 'local' ? 'local' : 'app')
}
-
-/**
- * 简化 semver 比较(不引入额外依赖),可处理 `0.1.1-rc.2` / `0.1.1` 格式。
- * 返回值:负数 a < b,0 相等,正数 a > b。
- */
-function compareVersions(a: string, b: string): number {
- const parse = (value: string) => {
- let v = value
- while (v.startsWith('dsh-') || v.startsWith('src-'))
- v = v.replace(/^(?:src|dsh)-/, '')
- if (v.includes('-')) {
- const candidate = v.slice(0, v.lastIndexOf('-'))
- if (/^\d+\.\d+\.\d+(?:-[0-9A-Z.-]+)?$/i.test(candidate))
- v = candidate
- }
- const [core, pre = ''] = v.split('-', 2)
- const nums = core.split('.').map(n => parseInt(n, 10) || 0)
- return { nums, pre }
- }
- const pa = parse(a)
- const pb = parse(b)
- for (let i = 0; i < 3; i++) {
- const x = pa.nums[i] ?? 0
- const y = pb.nums[i] ?? 0
- if (x !== y)
- return x < y ? -1 : 1
- }
- // 无预发布号 > 有预发布号
- if (!pa.pre && !pb.pre)
- return 0
- if (!pa.pre)
- return 1
- if (!pb.pre)
- return -1
- // 预发布号按点分段比较:数字按数值、非数字按字典序
- const paParts = pa.pre.split('.').map(p => (Number.isNaN(Number(p)) ? p : Number(p)))
- const pbParts = pb.pre.split('.').map(p => (Number.isNaN(Number(p)) ? p : Number(p)))
- const len = Math.max(paParts.length, pbParts.length)
- for (let i = 0; i < len; i++) {
- const x = paParts[i]
- const y = pbParts[i]
- if (x === undefined)
- return -1
- if (y === undefined)
- return 1
- if (x === y)
- continue
- if (typeof x === 'number' && typeof y === 'number')
- return x < y ? -1 : 1
- if (typeof x === 'number')
- return -1
- if (typeof y === 'number')
- return 1
- return x < y ? -1 : 1
- }
- return 0
-}
diff --git a/src/components/config-debug.tsx b/src/components/config-debug.tsx
index 3a0431e4..f0e840d8 100644
--- a/src/components/config-debug.tsx
+++ b/src/components/config-debug.tsx
@@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next'
import { If } from 'react-if-lite'
import { useStore } from 'valtio-define'
import { useAppConfig } from '@/hooks/use-app-config'
+import { useCoreBreakingConfirm } from '@/hooks/use-core-breaking-confirm'
import { store } from '@/store'
import { writeClipboardText } from '@/utils/clipboard'
import { toast } from '@/utils/toast'
@@ -42,6 +43,7 @@ export function ConfigDebug() {
const { t, i18n } = useTranslation()
const { serviceRunning, busyAction } = useStore(store.harness)
const { updateInfo } = useStore(store.harnessUpdater)
+ const { holder: coreBreakingHolder, confirmCoreBreaking } = useCoreBreakingConfirm()
// 端口编辑态:用户尚未输入时为 undefined,由 `data?.port ?? 3080` 提供初值。
// 初值不写入 state(避免 queryFn 副作用 / effect 同步),渲染与保存时统一
@@ -95,6 +97,13 @@ export function ConfigDebug() {
}
}
+ /** 「存在新版本」:先按 rc.2 破坏性更改确认(高于 rc.2 则先拦截),再展示更新提示 */
+ async function handleShowNewVersion() {
+ if (updateInfo && !(await confirmCoreBreaking(updateInfo.tag)))
+ return
+ store.harnessUpdater.showToast()
+ }
+
const { mutate: onClearLogs } = useMutation({
mutationFn: async () => {
await invoke('clear_service_logs')
@@ -182,6 +191,7 @@ export function ConfigDebug() {
return (
<div className="space-y-3">
+ {coreBreakingHolder}
<div className="space-y-1.5">
<div className="flex items-center justify-between">
<span className="text-xs font-semibold uppercase tracking-wider text-muted">
@@ -261,7 +271,7 @@ export function ConfigDebug() {
<Info term={t('ui.dsh_version')}>
<span>{info?.dsh_version ?? '-'}</span>
<If cond={updateInfo}>
- <Link className="ml-2 text-[10px] text-accent" onClick={store.harnessUpdater.showToast}>
+ <Link className="ml-2 text-[10px] text-accent" onClick={handleShowNewVersion}>
{t('menu.new_version')}
<ChevronRight className="scale-75" />
</Link>
diff --git a/src/hooks/use-core-breaking-confirm.tsx b/src/hooks/use-core-breaking-confirm.tsx
new file mode 100644
index 00000000..a1669cf7
--- /dev/null
+++ b/src/hooks/use-core-breaking-confirm.tsx
@@ -0,0 +1,40 @@
+import { useOverlay } from '@overlastic/react'
+import { useTranslation } from 'react-i18next'
+import { Modal } from '@/components/modal'
+import { CORE_BREAKING_BASELINE, isCoreBreakingVersion } from '@/utils/core-version'
+
+/**
+ * rc.2 以上版本的下载前确认:若目标核心版本高于 rc.2 基准(引入破坏性更改、
+ * 可能影响第三方插件),先弹出确认对话框;取消则中止,确认后继续。
+ *
+ * 该逻辑与「推荐版本」逻辑无关,仅用于提示用户,提示可随时在核心中切回 rc.2。
+ * 三个入口(核心面板下载、核心「发现新版本」toast、debug「存在新版本」链接)
+ * 共用此一份逻辑。
+ */
+export function useCoreBreakingConfirm() {
+ const [holder, openDialog] = useOverlay(Modal, { type: 'holder' })
+ const { t } = useTranslation()
+
+ /** 返回 true=继续下载,false=用户取消。版本高于 rc.2 时弹确认框,否则直接放行 */
+ async function confirmCoreBreaking(version: string): Promise<boolean> {
+ if (!isCoreBreakingVersion(version))
+ return true
+ try {
+ await openDialog({
+ status: 'warning',
+ title: t('core.above_rc2_warning_title'),
+ description: (
+ <p>
+ {t('core.above_rc2_warning_desc', { version: CORE_BREAKING_BASELINE })}
+ </p>
+ ),
+ })
+ return true
+ }
+ catch {
+ return false
+ }
+ }
+
+ return { holder, confirmCoreBreaking }
+}
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index d077d7d5..9c43a529 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -251,6 +251,8 @@
"core.switch_confirm_desc": "Switch to the {{version}} version? The running engine will change to this copy.",
"core.recommended_warning_title": "Warning",
"core.recommended_warning_desc": "The current recommended version is “{{version}}”. Switching to this version may cause software errors. Continue switching?",
+ "core.above_rc2_warning_title": "Warning",
+ "core.above_rc2_warning_desc": "Versions above {{version}} contain breaking changes that may cause third-party plugin errors. Confirm the update? You can switch back to {{version}} in the core at any time.",
"core.activate_toast": "Switched to {{version}}",
"core.uninstalled_toast": "Uninstalled {{version}}",
"core.remove_confirm_title": "Uninstall version",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index c4d0263f..140dda62 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -251,6 +251,8 @@
"core.switch_confirm_desc": "切换至 {{version}} 版本吗?运行中的引擎将切换为该副本。",
"core.recommended_warning_title": "警告",
"core.recommended_warning_desc": "当前推荐版本是 “{{version}}”,切换到该版本可能导致软件异常,确定切换吗?",
+ "core.above_rc2_warning_title": "警告",
+ "core.above_rc2_warning_desc": "{{version}} 以上的版本引入破坏性更改,可能导致第三方插件异常,确定更新吗?你可随时在核心中切换回 {{version}}。",
"core.activate_toast": "已切换到 {{version}}",
"core.uninstalled_toast": "已卸载 {{version}}",
"core.remove_confirm_title": "卸载版本",
diff --git a/src/layout/components/harness-updater.tsx b/src/layout/components/harness-updater.tsx
index 9c53f413..54329af8 100644
--- a/src/layout/components/harness-updater.tsx
+++ b/src/layout/components/harness-updater.tsx
@@ -1,16 +1,25 @@
import { useWatch } from '@hairy/react-lib'
import { useStore } from 'valtio-define'
+import { useCoreBreakingConfirm } from '@/hooks/use-core-breaking-confirm'
import { store } from '@/store'
-/** 右下角"发现新版本"提示条:状态与操作直接来自 updater store */
+/** 右下角“发现新版本”提示条:状态与操作直接来自 updater store */
export function HarnessUpdater() {
const { updateInfo, updating } = useStore(store.harnessUpdater)
+ const { holder, confirmCoreBreaking } = useCoreBreakingConfirm()
useWatch([updateInfo, updating], () => {
if (!updateInfo || updating)
- return null
- store.harnessUpdater.showToast()
+ return
+ // 高于 rc.2 时先弹破坏性更改确认,取消则不提示更新(不进入下载)
+ void showAfterConfirm(updateInfo.tag)
}, { immediate: true })
- return null
+ async function showAfterConfirm(tag: string) {
+ if (!(await confirmCoreBreaking(tag)))
+ return
+ store.harnessUpdater.showToast()
+ }
+
+ return holder
}
diff --git a/src/utils/core-version.ts b/src/utils/core-version.ts
new file mode 100644
index 00000000..25d3f64f
--- /dev/null
+++ b/src/utils/core-version.ts
@@ -0,0 +1,68 @@
+/**
+ * 核心(dsh)版本判断:以 rc.2 为硬编码基准,高于该基准的版本引入破坏性更改、
+ * 可能影响第三方插件。该判断与「推荐版本」逻辑无关,仅作为用户提示的阈值。
+ */
+export const CORE_BREAKING_BASELINE = '0.1.1-rc.2'
+
+/**
+ * 简化 semver 比较(不引入额外依赖),可处理 `0.1.1-rc.2` / `0.1.1` 以及
+ * release tag(`dsh-`/`src-` 前缀、末尾 `-<commit>` 后缀)。
+ * 返回值:负数 a < b,0 相等,正数 a > b。
+ */
+export function compareVersions(a: string, b: string): number {
+ const parse = (value: string) => {
+ let v = value
+ while (v.startsWith('dsh-') || v.startsWith('src-'))
+ v = v.replace(/^(?:src|dsh)-/, '')
+ if (v.includes('-')) {
+ const candidate = v.slice(0, v.lastIndexOf('-'))
+ if (/^\d+\.\d+\.\d+(?:-[0-9A-Z.-]+)?$/i.test(candidate))
+ v = candidate
+ }
+ const [core, pre = ''] = v.split('-', 2)
+ const nums = core.split('.').map(n => parseInt(n, 10) || 0)
+ return { nums, pre }
+ }
+ const pa = parse(a)
+ const pb = parse(b)
+ for (let i = 0; i < 3; i++) {
+ const x = pa.nums[i] ?? 0
+ const y = pb.nums[i] ?? 0
+ if (x !== y)
+ return x < y ? -1 : 1
+ }
+ // 无预发布号 > 有预发布号
+ if (!pa.pre && !pb.pre)
+ return 0
+ if (!pa.pre)
+ return 1
+ if (!pb.pre)
+ return -1
+ // 预发布号按点分段比较:数字按数值、非数字按字典序
+ const paParts = pa.pre.split('.').map(p => (Number.isNaN(Number(p)) ? p : Number(p)))
+ const pbParts = pb.pre.split('.').map(p => (Number.isNaN(Number(p)) ? p : Number(p)))
+ const len = Math.max(paParts.length, pbParts.length)
+ for (let i = 0; i < len; i++) {
+ const x = paParts[i]
+ const y = pbParts[i]
+ if (x === undefined)
+ return -1
+ if (y === undefined)
+ return 1
+ if (x === y)
+ continue
+ if (typeof x === 'number' && typeof y === 'number')
+ return x < y ? -1 : 1
+ if (typeof x === 'number')
+ return -1
+ if (typeof y === 'number')
+ return 1
+ return x < y ? -1 : 1
+ }
+ return 0
+}
+
+/** 判断核心版本(版本串或 release tag)是否高于 rc.2 基准(引入破坏性更改) */
+export function isCoreBreakingVersion(version: string): boolean {
+ return !!version && compareVersions(version, CORE_BREAKING_BASELINE) > 0
+}