Skip to content

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

【WIP】fix(12): 推荐插件页面支持卸载与 diff 增量操作 (#270)

CoderStorya976c3f72d12
diff --git a/src-tauri/src/bridge/plugin.rs b/src-tauri/src/bridge/plugin.rs
index b3d76e5e..32522aba 100644
--- a/src-tauri/src/bridge/plugin.rs
+++ b/src-tauri/src/bridge/plugin.rs
@@ -19,12 +19,45 @@ pub async fn get_preinstall_plugins(
/// 安装选中的预装插件(`dsh plugin --profile web add <ids...>`),
/// 进程输出实时通过 `preinstall-log` 事件推送;成功后标记引导完成并记录预设指纹。
+///
+/// 同时支持卸载用户取消勾选的已安装插件(`uninstall_ids`):走
+/// `dsh plugin remove`(与安装对称的命令行卸载),失败时自动回退离线精准卸载
+/// (`plugin::uninstall_recovery`,直接改 profile 清单),不依赖网络兜底。
#[tauri::command]
pub async fn install_preinstall_plugins(
app_handle: AppHandle,
- ids: Vec<String>,
+ install_ids: Vec<String>,
+ uninstall_ids: Vec<String>,
) -> Result<(), String> {
- plugin::install(&app_handle, &ids).await?;
+ // 安装与卸载均为空:无需操作,直接标记完成
+ if install_ids.is_empty() && uninstall_ids.is_empty() {
+ let mut setting = config::get_store_dat_setting(&app_handle);
+ setting.preinstall_done = true;
+ if let Some(hash) = plugin::current_preset_hash(&app_handle) {
+ setting.preset_hash = Some(hash);
+ }
+ config::set_store_dat_setting(&app_handle, setting);
+ return Ok(());
+ }
+
+ // 先卸载取消勾选的已安装插件(走 dsh plugin remove,与安装对称)
+ // 卸载在前:避免新装插件与待卸载插件冲突;remove 内部会先停服务再执行
+ log::info!("[preinstall] uninstall_ids={uninstall_ids:?}, install_ids={install_ids:?}");
+ for id in &uninstall_ids {
+ log::info!("[preinstall] removing plugin {id} via dsh plugin remove");
+ if let Err(e) = plugin::remove(&app_handle, id).await {
+ log::error!("[preinstall] failed to remove plugin {id}: {e}");
+ return Err(e);
+ }
+ log::info!("[preinstall] successfully removed plugin {id}");
+ }
+
+ // 再安装新勾选的插件(会走 dsh plugin add)
+ if !install_ids.is_empty() {
+ log::info!("[preinstall] installing plugins {install_ids:?}");
+ plugin::install(&app_handle, &install_ids).await?;
+ }
+
let mut setting = config::get_store_dat_setting(&app_handle);
setting.preinstall_done = true;
if let Some(hash) = plugin::current_preset_hash(&app_handle) {
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index 9ff0823c..45dda333 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -29,6 +29,7 @@
"preinstall.recommend": "Recommended",
"preinstall.fix": "Fix",
"preinstall.installed": "Installed",
+ "preinstall.to_uninstall": "To be uninstalled",
"preinstall.confirm": "Install",
"preinstall.skip": "Skip",
"preinstall.installing": "Installing plugins...",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index 4890ebac..1d06c552 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -29,6 +29,7 @@
"preinstall.recommend": "推荐",
"preinstall.fix": "修复",
"preinstall.installed": "已安装",
+ "preinstall.to_uninstall": "待卸载",
"preinstall.confirm": "确定",
"preinstall.skip": "跳过",
"preinstall.installing": "正在安装插件...",
diff --git a/src/layout/components/preinstall-setup.tsx b/src/layout/components/preinstall-setup.tsx
index 5cb0ff9a..5e6ced7a 100644
--- a/src/layout/components/preinstall-setup.tsx
+++ b/src/layout/components/preinstall-setup.tsx
@@ -19,50 +19,78 @@ import { toast } from '@/utils/toast'
* 或跳过;两者都会标记完成并继续启动服务。
*/
-/** 派生默认勾选集合:未安装的推荐/修复/默认勾选项(用户手动调整前的基础态) */
-function defaultSelectedSet(plugins: readonly PreinstallPlugin[]): Set<string> {
- return new Set(plugins.filter(p => !p.installed && (p.recommended || p.fix || p.defaultChecked)).map(p => p.id))
+/**
+ * 初始勾选态 = 已安装 + 推荐/修复/默认勾选(进入页面时的完整勾选集合)。
+ * 用于和用户最终选择做 diff,得出 toInstall / toUninstall。
+ *
+ * 策略由 isFirstTime 决定:
+ * - 首次安装引导(isFirstTime=true):已安装 + 推荐/修复/默认勾选均默认勾上
+ * - 手动打开(isFirstTime=false):只有已安装的插件才默认勾上(已卸载的推荐项不勾)
+ */
+function initialCheckedSet(plugins: readonly PreinstallPlugin[], isFirstTime: boolean): Set<string> {
+ return new Set(plugins.filter((p) => {
+ if (p.installed)
+ return true
+ // 非首次场景:不推荐未安装的插件,避免已卸载的推荐项仍默认勾着
+ if (!isFirstTime)
+ return false
+ return p.recommended || p.fix || p.defaultChecked
+ }).map(p => p.id))
}
-/** 插件列表的一行:名称 + 推荐/已安装标签在左,勾选框 + 仓库跳转按钮在右 */
-function PluginRow({ plugin, checked, disabled, onToggle, onOpenRepo }: {
+/** 插件列表的一行:名称 + 推荐/已安装/待卸载标签在左,勾选框 + 仓库跳转按钮在右 */
+function PluginRow({ plugin, checked, toUninstall, disabled, onToggle, onOpenRepo }: {
plugin: PreinstallPlugin
checked: boolean
+ /** 已安装但被取消勾选 → 待卸载(删除线 + 警告 chip) */
+ toUninstall: boolean
disabled: boolean
onToggle: (id: string, checked: boolean) => void
onOpenRepo: (id: string) => void
}) {
const { t } = useTranslation()
+ // 已安装且未被取消勾选 → 保持「已安装」样式;已安装但取消勾选 → 待卸载样式
+ const labelClass = toUninstall
+ ? 'text-muted line-through'
+ : plugin.installed
+ ? 'text-success'
+ : 'text-ink'
+
return (
<Item
left={(
<>
- <Label className={`min-w-0 truncate text-sm font-medium ${plugin.installed ? 'text-muted line-through' : 'text-ink'}`}>
+ <Label className={`min-w-0 truncate text-sm font-medium ${labelClass}`}>
{plugin.name}
</Label>
- <If cond={plugin.recommended && !plugin.installed}>
+ <If cond={plugin.recommended && !plugin.installed && !toUninstall}>
<Chip size="sm" variant="soft" color="success" className="shrink-0 font-medium">
{t('preinstall.recommend')}
</Chip>
</If>
- <If cond={plugin.fix && !plugin.installed}>
+ <If cond={plugin.fix && !plugin.installed && !toUninstall}>
<Chip size="sm" variant="soft" color="warning" className="shrink-0 font-medium">
{t('preinstall.fix')}
</Chip>
</If>
- <If cond={plugin.installed}>
+ <If cond={plugin.installed && !toUninstall}>
<Chip size="sm" variant="soft" color="success" className="shrink-0 font-medium">
{t('preinstall.installed')}
</Chip>
</If>
+ <If cond={toUninstall}>
+ <Chip size="sm" variant="soft" color="warning" className="shrink-0 font-medium">
+ {t('preinstall.to_uninstall')}
+ </Chip>
+ </If>
</>
)}
right={(
<>
<Checkbox
- isSelected={checked || plugin.installed}
- isDisabled={disabled || plugin.installed}
+ isSelected={checked}
+ isDisabled={disabled}
onChange={isSelected => onToggle(plugin.id, isSelected)}
className="shrink-0"
aria-label={plugin.name}
@@ -138,18 +166,18 @@ export function PreinstallSetup() {
void store.harness.loadPreinstallPlugins()
}, [])
- // 默认勾选:未安装的推荐插件 +「修复」类项 + 无 chip 但标记默认勾选的项(如 dsh-notification)。
+ // 默认勾选:已安装 + 未安装的推荐插件 +「修复」类项 + 无 chip 但标记默认勾选的项(如 dsh-notification)。
// 派生计算而非在加载回调里 setState,避免与 store 的加载去重守卫竞争,
// 保证插件到位后默认勾选必定生效(用户手动调整后以用户选择为准)。
const effectiveSelected = !touched
- ? defaultSelectedSet(preinstall.plugins)
+ ? initialCheckedSet(preinstall.plugins, preinstall.isFirstTime)
: selected
function toggle(id: string, checked: boolean) {
// 首次交互以「当前默认勾选」为起点:selected 初始为空,若直接在其上增删,
- // 取消一个会误把其余默认项一并取消。这里先以 defaultSelectedSet 播种,
+ // 取消一个会误把其余默认项一并取消。这里先以 initialCheckedSet 播种,
// 再应用本次勾选,保证「取消一个 = 只取消这一个」。
- const seed = !touched ? defaultSelectedSet(preinstall.plugins) : null
+ const seed = !touched ? initialCheckedSet(preinstall.plugins, preinstall.isFirstTime) : null
setTouched(true)
setSelected((prev) => {
const next = new Set(seed ?? prev)
@@ -170,16 +198,24 @@ export function PreinstallSetup() {
}
function handleConfirm() {
- void store.harness.confirmPreinstall([...effectiveSelected])
+ // 基于 plugin.installed 推导操作:选中且未安装 → 安装;已安装且未选中 → 卸载
+ const toInstall = preinstall.plugins
+ .filter(p => effectiveSelected.has(p.id) && !p.installed)
+ .map(p => p.id)
+ const toUninstall = preinstall.plugins
+ .filter(p => p.installed && !effectiveSelected.has(p.id))
+ .map(p => p.id)
+ void store.harness.confirmPreinstall({ installIds: toInstall, uninstallIds: toUninstall })
}
function handleSkip() {
void store.harness.skipPreinstall()
}
- // 可选中的插件(未安装项)勾选数,用于禁用"确定"
- const selectableCount = preinstall.plugins.filter(p => !p.installed).length
- const selectedCount = [...effectiveSelected].filter(id => preinstall.plugins.some(p => p.id === id && !p.installed)).length
+ // 是否有变更:存在需安装或需卸载的插件时启用"确定"
+ const toInstallCount = preinstall.plugins.filter(p => effectiveSelected.has(p.id) && !p.installed).length
+ const toUninstallCount = preinstall.plugins.filter(p => p.installed && !effectiveSelected.has(p.id)).length
+ const hasChanges = toInstallCount > 0 || toUninstallCount > 0
const installing = preinstall.installing
return (
@@ -227,16 +263,22 @@ export function PreinstallSetup() {
<Empty>{t('preinstall.empty')}</Empty>
)}
>
- {preinstall.plugins.map(plugin => (
- <PluginRow
- key={plugin.id}
- plugin={plugin}
- checked={effectiveSelected.has(plugin.id)}
- disabled={installing}
- onToggle={toggle}
- onOpenRepo={openRepo}
- />
- ))}
+ {preinstall.plugins.map((plugin) => {
+ const checked = effectiveSelected.has(plugin.id)
+ // 已安装但用户取消勾选 → 待卸载
+ const toUninstall = plugin.installed && !checked
+ return (
+ <PluginRow
+ key={plugin.id}
+ plugin={plugin}
+ checked={checked}
+ toUninstall={toUninstall}
+ disabled={installing}
+ onToggle={toggle}
+ onOpenRepo={openRepo}
+ />
+ )
+ })}
</If>
</If>
</div>
@@ -246,19 +288,19 @@ export function PreinstallSetup() {
<p className="text-center text-xs text-muted">{t('preinstall.can_uncheck_hint')}</p>
</If>
- {/* 操作区:跳过 / 确定(空选时主按钮蜕变为「跳过」) */}
+ {/* 操作区:跳过 / 确定(无变更时主按钮蜕变为「跳过」) */}
<div className="flex items-center justify-end gap-2">
<Button className="h-8 rounded-md" size="sm" variant="tertiary" onPress={handleSkip} isDisabled={installing}>
{t('preinstall.skip')}
</Button>
- <If cond={selectedCount === 0}>
+ <If cond={!hasChanges}>
<Then>
<Button
className="h-8 rounded-md"
size="sm"
variant="primary"
onPress={handleSkip}
- isDisabled={installing || selectableCount === 0}
+ isDisabled={installing}
>
{t('preinstall.skip')}
</Button>
@@ -269,7 +311,7 @@ export function PreinstallSetup() {
size="sm"
variant="primary"
onPress={handleConfirm}
- isDisabled={installing || selectableCount === 0}
+ isDisabled={installing}
>
{t('preinstall.confirm')}
</Button>
@@ -297,7 +339,7 @@ export function PreinstallSetup() {
size="sm"
variant="primary"
onPress={handleConfirm}
- isDisabled={installing || selectedCount === 0 || selectableCount === 0}
+ isDisabled={installing || !hasChanges}
>
{t('app.retry')}
</Button>
diff --git a/src/store/modules/harness/store.ts b/src/store/modules/harness/store.ts
index 5523c702..36451042 100644
--- a/src/store/modules/harness/store.ts
+++ b/src/store/modules/harness/store.ts
@@ -251,6 +251,8 @@ export const harness = defineStore({
error: '',
/** 拉取预装插件列表失败(区别于空列表;UI 据此展示错误态 + 重试) */
loadError: '',
+ /** 是否为首次安装引导(决定默认勾选策略):boot 流程进入时为 true,侧边栏手动打开为 false */
+ isFirstTime: true,
},
serviceUrl: 'http://127.0.0.1:3080',
/** 带时间戳的 iframe 地址(boot 时生成一次,避免缓存) */
@@ -704,6 +706,7 @@ export const harness = defineStore({
// 由 Rust 侧记录内容指纹到 app-data(.store.dat),启动时比对是否有变更。
if (await invoke<boolean>('get_preinstall_pending')) {
this.status = 'preinstall'
+ this.preinstall.isFirstTime = true
await this.loadPreinstallPlugins()
return
}
@@ -937,9 +940,17 @@ export const harness = defineStore({
})
},
- /** 确认安装选中的预装插件:流式日志,完成后继续启动服务 */
- async confirmPreinstall(ids: string[]) {
- if (this.preinstall.installing || ids.length === 0)
+ /**
+ * 确认安装/卸载预装插件:流式日志,完成后继续启动服务。
+ *
+ * 前端传入 diff 结果(installIds = 新增勾选需安装;uninstallIds = 取消勾选需卸载),
+ * 无变化时两者均为空,后端直接标记完成。
+ */
+ async confirmPreinstall(input: { installIds?: string[], uninstallIds?: string[] } | string[]) {
+ // 兼容旧调用方(直接传数组)与新调用方(传 {installIds, uninstallIds})
+ const installIds = Array.isArray(input) ? input : (input.installIds ?? [])
+ const uninstallIds = Array.isArray(input) ? [] : (input.uninstallIds ?? [])
+ if (this.preinstall.installing || (installIds.length === 0 && uninstallIds.length === 0))
return
this.preinstall.installing = true
this.preinstall.error = ''
@@ -947,7 +958,7 @@ export const harness = defineStore({
let unlisten: UnlistenFn | null = null
try {
unlisten = await this.listenPreinstallLog()
- await invoke('install_preinstall_plugins', { ids })
+ await invoke('install_preinstall_plugins', { installIds, uninstallIds })
// 后端装完已把服务停掉,这里在日志面板讲清接下来的重启(issue #48),
// 避免用户把"插件安装后的自动重启"误认为崩溃/故障。
this.preinstall.logs = [...this.preinstall.logs, i18next.t('preinstall.restarting_hint')].slice(-200)
@@ -1026,6 +1037,8 @@ export const harness = defineStore({
emitter.emit('config:dialog:hidden')
this.preinstall.error = ''
this.preinstall.logs = []
+ // 侧边栏手动打开:非首次安装,默认勾选策略为「仅已安装」
+ this.preinstall.isFirstTime = false
this.status = 'preinstall'
await this.loadPreinstallPlugins()
},
diff --git a/test/preinstall-uncheck.test.ts b/test/preinstall-uncheck.test.ts
index b0bdcd09..efcdedd9 100644
--- a/test/preinstall-uncheck.test.ts
+++ b/test/preinstall-uncheck.test.ts
@@ -29,9 +29,9 @@ describe('preinstallSetup hint text', () => {
// ── Suite C — component has dynamic button label (source assertion) ──────────
describe('preinstallSetup primary button morph', () => {
- it('guards the label switch on selectedCount === 0', () => {
+ it('guards the label switch on hasChanges', () => {
const source = readFileSync(new URL('../src/layout/components/preinstall-setup.tsx', import.meta.url), 'utf8')
- expect(source).toContain('selectedCount === 0')
+ expect(source).toContain('hasChanges')
})
it('can render the Skip label', () => {