Skip to content

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

fix(plugin): 插件页如实展示 cordis.patch.yml 配置覆盖禁用状态(issue #399)

hairyf0b9479c77c96
diff --git a/src-tauri/src/bridge/plugin.rs b/src-tauri/src/bridge/plugin.rs
index 31cd508a..4d5862fe 100644
--- a/src-tauri/src/bridge/plugin.rs
+++ b/src-tauri/src/bridge/plugin.rs
@@ -221,9 +221,18 @@ pub fn disable_dsh_plugin(app_handle: AppHandle, id: String) -> Result<(), Strin
}
/// 启用单个已禁用的插件:加回 `dsh.profile.bundles` 并从独立禁用清单移除。
+///
+/// 若插件同时被 profile 的 `cordis.patch.yml` 配置覆盖禁用(`disabled: true`,
+/// 优先级高于桌面禁用清单),必须显式传 `clear_config_override=true`(前端
+/// 弹窗确认后)才会移除该覆盖;否则返回 `ENABLE_CONFIG_OVERRIDE`,避免
+/// 「声称启用成功、运行期却仍被配置禁用」的虚假成功(issue #399)。
#[tauri::command]
-pub fn enable_dsh_plugin(app_handle: AppHandle, id: String) -> Result<(), String> {
- plugin::enable(&app_handle, &id)?;
+pub fn enable_dsh_plugin(
+ app_handle: AppHandle,
+ id: String,
+ clear_config_override: Option<bool>,
+) -> Result<(), String> {
+ plugin::enable(&app_handle, &id, clear_config_override.unwrap_or(false))?;
plugin::watch::force_emit(&app_handle);
Ok(())
}
diff --git a/src-tauri/src/service/plugin/disable.rs b/src-tauri/src/service/plugin/disable.rs
index 6773e274..13c4cde3 100644
--- a/src-tauri/src/service/plugin/disable.rs
+++ b/src-tauri/src/service/plugin/disable.rs
@@ -4,7 +4,7 @@
//!
//! 机制遵循 ADR-0001:禁用 = 从加载列表移除 + 记入独立禁用清单;启用 = 精确逆操作。
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
@@ -51,6 +51,146 @@ fn save_disabled(profile: &Path, map: &HashMap<String, DisabledEntry>) -> Result
.map_err(|e| format!("DISABLED_WRITE_FAILED: {e}"))
}
+/// 读取 profile 的 `cordis.patch.yml`,返回「配置层显式禁用」条目的目标集合。
+///
+/// 配置覆盖禁用 = 顶层数组条目带真值 `disabled` 字段(`disabled: true` 等)。
+/// 与桌面禁用清单(`disabled-plugins.json`)独立:patch 覆盖优先级更高,
+/// 运行期同样不加载该插件。匹配口径与 `recovery::uninstall::patch_entry_targets`
+/// 一致——把条目的 `id` 与任意字符串键/值都收进集合,由调用方按「包名或
+/// package.json name 命中」判断,兼容 loader 入口 id 与 npm 包名不一致的别名场景。
+///
+/// 文件缺失/无法解析为顶层数组时按空集处理(与 `load_disabled` 一致,
+/// 不阻断插件列表解析)。
+pub(crate) fn load_patch_disabled(profile: &Path) -> HashSet<String> {
+ let Ok(content) = fs::read_to_string(profile.join("cordis.patch.yml")) else {
+ return HashSet::new();
+ };
+ let Ok(doc) = serde_yaml::from_str::<serde_yaml::Value>(&content) else {
+ return HashSet::new();
+ };
+ let Some(entries) = doc.as_sequence() else {
+ return HashSet::new();
+ };
+ let mut targets = HashSet::new();
+ for entry in entries {
+ let Some(map) = entry.as_mapping() else {
+ continue;
+ };
+ if !patch_entry_disabled(map) {
+ continue;
+ }
+ for (key, value) in map {
+ if let Some(s) = key.as_str() {
+ targets.insert(s.to_string());
+ }
+ if let Some(s) = value.as_str() {
+ targets.insert(s.to_string());
+ }
+ }
+ }
+ targets
+}
+
+/// patch 顶层条目是否带「禁用」语义(`disabled` 字段为真值)。
+///
+/// 兼容 YAML 常见真值写法:布尔 `true`、非零数字、字符串 true/1/yes/on。
+fn patch_entry_disabled(map: &serde_yaml::Mapping) -> bool {
+ let Some(value) = map.get(&serde_yaml::Value::String("disabled".to_string())) else {
+ return false;
+ };
+ match value {
+ serde_yaml::Value::Bool(b) => *b,
+ serde_yaml::Value::Number(n) => n.as_i64() != Some(0),
+ serde_yaml::Value::String(s) => {
+ s.eq_ignore_ascii_case("true")
+ || s == "1"
+ || s.eq_ignore_ascii_case("yes")
+ || s.eq_ignore_ascii_case("on")
+ }
+ _ => false,
+ }
+}
+
+/// 目标插件的匹配候选名:npm 包名(依赖键)+ 包内 package.json 的 `name` 字段。
+///
+/// 覆盖「依赖键即展示名」与「loader 入口 id 用包内 name」两种形态。
+fn plugin_target_names(profile: &Path, id: &str) -> Vec<String> {
+ let mut names = vec![id.to_string()];
+ if let Ok(content) =
+ fs::read_to_string(profile.join("node_modules").join(id).join("package.json"))
+ {
+ if let Ok(json) = serde_json::from_str::<serde_json::Value>(&content) {
+ if let Some(name) = json.get("name").and_then(|n| n.as_str()) {
+ names.push(name.to_string());
+ }
+ }
+ }
+ names
+}
+
+/// 插件是否被 profile 的 `cordis.patch.yml` 配置覆盖禁用。
+pub(crate) fn has_patch_disable(profile: &Path, id: &str) -> bool {
+ let names = plugin_target_names(profile, id);
+ load_patch_disabled(profile)
+ .iter()
+ .any(|target| names.iter().any(|n| n == target))
+}
+
+/// 从 `cordis.patch.yml` 移除目标插件的显式禁用覆盖,其余配置原样保留。
+///
+/// 精确语义(对应 issue #399「不删除无关配置」):
+/// - 纯禁用条目(仅 `id` + `disabled`)→ 整条移除;
+/// - 带其它配置的条目 → 仅摘除 `disabled` 键,其余键原样保留;
+/// - 其它插件的条目一律不动。
+///
+/// 幂等:无 patch 文件 / 无法解析 / 无目标禁用条目时返回 `Ok(false)` 且不写盘;
+/// 实际修改时返回 `Ok(true)`。
+pub(crate) fn strip_patch_disable(profile: &Path, id: &str) -> Result<bool, String> {
+ let path = profile.join("cordis.patch.yml");
+ let Ok(content) = fs::read_to_string(&path) else {
+ return Ok(false);
+ };
+ let mut doc: serde_yaml::Value =
+ serde_yaml::from_str(&content).map_err(|e| format!("ENABLE_PATCH_PARSE_FAILED: {e}"))?;
+ let Some(entries) = doc.as_sequence_mut() else {
+ return Ok(false);
+ };
+ let names = plugin_target_names(profile, id);
+ let mut changed = false;
+ let mut kept: Vec<serde_yaml::Value> = Vec::with_capacity(entries.len());
+ for entry in entries.drain(..) {
+ let Some(mut map) = entry.as_mapping().cloned() else {
+ kept.push(entry);
+ continue;
+ };
+ let targeted = map.iter().any(|(k, v)| {
+ names
+ .iter()
+ .any(|n| k.as_str() == Some(n.as_str()) || v.as_str() == Some(n.as_str()))
+ });
+ if !targeted || !patch_entry_disabled(&map) {
+ kept.push(entry);
+ continue;
+ }
+ changed = true;
+ map.remove(&serde_yaml::Value::String("disabled".to_string()));
+ // 摘除 disabled 后仅剩 id(或为空)→ 纯禁用条目,整条丢弃;
+ // 还有其它键 → 保留该条目的其余配置。
+ let keeps_other_config = map.iter().any(|(k, _)| k.as_str() != Some("id"));
+ if keeps_other_config {
+ kept.push(serde_yaml::Value::Mapping(map));
+ }
+ }
+ if !changed {
+ return Ok(false);
+ }
+ let rendered = serde_yaml::to_string(&serde_yaml::Value::Sequence(kept))
+ .map_err(|e| format!("ENABLE_PATCH_RENDER_FAILED: {e}"))?;
+ fs::write(&path, rendered).map_err(|e| format!("ENABLE_PATCH_WRITE_FAILED: {e}"))?;
+ log::info!("Stripped cordis.patch.yml disable override for plugin {id}");
+ Ok(true)
+}
+
/// 仅从 `dsh.profile.bundles` 移除指定插件(不动 `dependencies`)。
/// 返回是否实际移除了条目。
fn remove_from_bundles(manifest: &mut serde_json::Value, id: &str) -> bool {
@@ -189,14 +329,21 @@ fn rollback_enable(profile: &Path, id: &str) {
/// 1. `fs_guard::validate_id(id)`
/// 2. 读取 manifest
/// 3. 校验插件仍安装
-/// 4. 校验插件在禁用清单中
-/// 5. 先从禁用清单移除条目
-/// 6. 加回 bundles 并写回 manifest
+/// 4. 校验插件处于禁用态:桌面禁用清单或 `cordis.patch.yml` 配置覆盖(二选一)
+/// 5. 配置覆盖禁用时,**必须**显式传 `clear_config_override=true`(前端已确认)
+/// 才会移除该覆盖;否则返回 `ENABLE_CONFIG_OVERRIDE`——避免「声称启用成功、
+/// 运行期却仍被更高优先级配置覆盖禁用」的虚假成功(issue #399)
+/// 6. 从桌面禁用清单移除条目
+/// 7. 加回 bundles 并写回 manifest
///
-/// 写入顺序保证:若步骤 6 失败,通过回滚步骤 5 使两文件恢复一致,
+/// 写入顺序保证:若最后一步失败,通过回滚使持久化文件恢复一致,
/// 避免插件加回 bundles 后禁用清单缺条目(否则再次启用会返回
/// `ENABLE_NOT_DISABLED`,用户无法通过正常流程恢复)。
-pub(crate) fn enable_plugin_at(profile: &Path, id: &str) -> Result<(), String> {
+pub(crate) fn enable_plugin_at(
+ profile: &Path,
+ id: &str,
+ clear_config_override: bool,
+) -> Result<(), String> {
fs_guard::validate_id(id)?;
let manifest_path = profile.join("package.json");
let content = fs::read_to_string(&manifest_path)
@@ -209,14 +356,29 @@ pub(crate) fn enable_plugin_at(profile: &Path, id: &str) -> Result<(), String> {
));
}
let mut map = load_disabled(profile);
- if !map.contains_key(id) {
+ let desktop_disabled = map.contains_key(id);
+ let config_disabled = has_patch_disable(profile, id);
+ if !desktop_disabled && !config_disabled {
return Err(format!(
"ENABLE_NOT_DISABLED: plugin {id} is not in the disabled list"
));
}
- // 先从禁用清单移除,确保 manifest 写入失败时可回滚该条目。
- map.remove(id);
- save_disabled(profile, &map)?;
+ // 存在配置覆盖但未显式确认:拒绝并给出来源指引,让前端提示用户查看
+ // `cordis.patch.yml`;绝不静默绕过高优先级覆盖。
+ if config_disabled && !clear_config_override {
+ return Err(format!(
+ "ENABLE_CONFIG_OVERRIDE: plugin {id} is disabled by the cordis.patch.yml config override; confirm removing the override to enable"
+ ));
+ }
+ // 确认后先移除配置覆盖(幂等,只摘该插件的禁用条目,其余配置保留),
+ // 再清理桌面禁用清单,最后写回 manifest——任一步失败都保持可恢复状态。
+ if config_disabled {
+ strip_patch_disable(profile, id)?;
+ }
+ if desktop_disabled {
+ map.remove(id);
+ save_disabled(profile, &map)?;
+ }
add_to_bundles(&mut manifest, id);
let rendered = serde_json::to_string_pretty(&manifest)
.map_err(|e| format!("ENABLE_RENDER_MANIFEST: {e}"))?;
@@ -238,10 +400,13 @@ pub fn disable(app_handle: &AppHandle, id: &str) -> Result<(), String> {
}
/// 启用插件(AppHandle 入口):获取 profile 目录 → 持有操作锁 → 执行纯逻辑 → 推送变更。
-pub fn enable(app_handle: &AppHandle, id: &str) -> Result<(), String> {
+///
+/// `clear_config_override`:插件被 `cordis.patch.yml` 配置覆盖禁用时,是否
+/// 移除该覆盖(需用户在前端明确确认后才为 true)。
+pub fn enable(app_handle: &AppHandle, id: &str, clear_config_override: bool) -> Result<(), String> {
let profile = profile_dir(app_handle);
let _guard = tauri::async_runtime::block_on(process::acquire_operation_lock());
- let result = enable_plugin_at(&profile, id);
+ let result = enable_plugin_at(&profile, id, clear_config_override);
drop(_guard);
watch::force_emit(app_handle);
result
@@ -320,7 +485,7 @@ mod tests {
fn enable_restores_to_bundles() {
let profile = build_profile("enable-restore", "c");
disable_plugin_at(&profile, "dsh-better-sidebar").unwrap();
- enable_plugin_at(&profile, "dsh-better-sidebar").unwrap();
+ enable_plugin_at(&profile, "dsh-better-sidebar", false).unwrap();
let manifest = read_manifest(&profile);
let bundles = manifest["dsh"]["profile"]["bundles"].as_array().unwrap();
@@ -333,7 +498,7 @@ mod tests {
fn enable_removes_from_disabled_json() {
let profile = build_profile("enable-rm-json", "d");
disable_plugin_at(&profile, "dsh-better-sidebar").unwrap();
- enable_plugin_at(&profile, "dsh-better-sidebar").unwrap();
+ enable_plugin_at(&profile, "dsh-better-sidebar", false).unwrap();
let map = load_disabled(&profile);
assert!(!map.contains_key("dsh-better-sidebar"));
@@ -368,7 +533,7 @@ mod tests {
fn enable_not_disabled_is_rejected() {
let profile = build_profile("not-disabled", "g");
// 未禁用就启用 → 拒绝
- let err = enable_plugin_at(&profile, "dsh-better-sidebar").unwrap_err();
+ let err = enable_plugin_at(&profile, "dsh-better-sidebar", false).unwrap_err();
assert!(err.contains("ENABLE_NOT_DISABLED"));
let _ = fs::remove_dir_all(&profile);
@@ -378,7 +543,7 @@ mod tests {
fn round_trip_preserves_other_bundles() {
let profile = build_profile("round-trip", "h");
disable_plugin_at(&profile, "dsh-better-sidebar").unwrap();
- enable_plugin_at(&profile, "dsh-better-sidebar").unwrap();
+ enable_plugin_at(&profile, "dsh-better-sidebar", false).unwrap();
let manifest = read_manifest(&profile);
let bundles = manifest["dsh"]["profile"]["bundles"]
@@ -419,4 +584,119 @@ mod tests {
let _ = fs::remove_dir_all(&profile);
}
+
+ /// 写入配置覆盖禁用条目的测试用 patch 文件。
+ fn write_patch(profile: &Path, content: &str) {
+ fs::write(profile.join("cordis.patch.yml"), content).unwrap();
+ }
+
+ /// `load_patch_disabled` 只收集带真值 `disabled` 字段的条目目标;
+ /// `disabled: false`、无 disabled 字段、非映射条目都不算禁用。
+ #[test]
+ fn load_patch_disabled_collects_only_true_disables() {
+ let profile = build_profile("patch-collect", "j");
+ write_patch(
+ &profile,
+ "- id: dshmarket\n disabled: true\n- id: dsh-better-sidebar\n disabled: false\n- id: dsh-tauri-pet\n config: 1\n- plain-string\n",
+ );
+ let targets = load_patch_disabled(&profile);
+ assert!(targets.contains("dshmarket"));
+ assert!(!targets.contains("dsh-better-sidebar"));
+ assert!(!targets.contains("dsh-tauri-pet"));
+
+ // 缺文件/非法 YAML/非数组 → 空集
+ assert!(load_patch_disabled(&std::env::temp_dir()).is_empty());
+ let broken = build_profile("patch-broken", "k");
+ write_patch(&broken, "not: [valid");
+ assert!(load_patch_disabled(&broken).is_empty());
+ fs::remove_dir_all(&broken).ok();
+
+ fs::remove_dir_all(&profile).ok();
+ }
+
+ /// 配置覆盖禁用但未显式确认 → ENABLE_CONFIG_OVERRIDE(绝不静默绕过)。
+ #[test]
+ fn enable_without_override_confirmation_is_rejected() {
+ let profile = build_profile("patch-reject", "l");
+ write_patch(&profile, "- id: dsh-better-sidebar\n disabled: true\n");
+ let err = enable_plugin_at(&profile, "dsh-better-sidebar", false).unwrap_err();
+ assert!(err.contains("ENABLE_CONFIG_OVERRIDE"));
+
+ // 覆盖条目原样保留
+ let content = fs::read_to_string(profile.join("cordis.patch.yml")).unwrap();
+ assert!(content.contains("disabled: true"));
+
+ fs::remove_dir_all(&profile).ok();
+ }
+
+ /// 确认后启用:仅移除目标插件的禁用覆盖、清桌面记录、加回 bundles,
+ /// 其它插件的 patch 条目原样保留。
+ #[test]
+ fn enable_with_override_confirmation_strips_only_target() {
+ let profile = build_profile("patch-strip", "m");
+ write_patch(
+ &profile,
+ "- id: dsh-better-sidebar\n disabled: true\n- id: dshmarket\n disabled: true\n- id: dsh-tauri-pet\n foo: bar\n",
+ );
+ enable_plugin_at(&profile, "dsh-better-sidebar", true).unwrap();
+
+ let content = fs::read_to_string(profile.join("cordis.patch.yml")).unwrap();
+ assert!(!content.contains("dsh-better-sidebar"));
+ assert!(content.contains("dshmarket"));
+ assert!(content.contains("dsh-tauri-pet"));
+ assert!(content.contains("foo: bar"));
+ // 其余禁用条目仍是禁用态
+ let targets = load_patch_disabled(&profile);
+ assert!(targets.contains("dshmarket"));
+ assert!(!targets.contains("dsh-better-sidebar"));
+
+ // bundles 已加回
+ let manifest = read_manifest(&profile);
+ let bundles = manifest["dsh"]["profile"]["bundles"].as_array().unwrap();
+ assert!(bundles.iter().any(|b| b.as_str() == Some("dsh-better-sidebar")));
+
+ fs::remove_dir_all(&profile).ok();
+ }
+
+ /// 带其它配置的禁用条目:只摘 `disabled` 键,其余配置保留(不删除无关配置)。
+ #[test]
+ fn strip_patch_disable_keeps_other_config_keys() {
+ let profile = build_profile("patch-keep", "n");
+ write_patch(
+ &profile,
+ "- id: dsh-better-sidebar\n disabled: true\n logLevel: debug\n",
+ );
+ enable_plugin_at(&profile, "dsh-better-sidebar", true).unwrap();
+
+ let content = fs::read_to_string(profile.join("cordis.patch.yml")).unwrap();
+ assert!(!content.contains("disabled"));
+ assert!(content.contains("logLevel: debug"));
+ assert!(content.contains("dsh-better-sidebar"));
+
+ fs::remove_dir_all(&profile).ok();
+ }
+
+ /// 别名匹配:patch 条目的 id 用包内 `name`(非依赖键)时同样命中。
+ #[test]
+ fn patch_disable_matches_package_json_name_alias() {
+ let profile = build_profile("patch-alias", "o");
+ // 依赖键 dsh-better-sidebar,但包内 name 为 better-sidebar(loader 别名形态)
+ let pkg_dir = profile.join("node_modules").join("dsh-better-sidebar");
+ fs::create_dir_all(&pkg_dir).unwrap();
+ fs::write(
+ pkg_dir.join("package.json"),
+ r#"{"name":"better-sidebar","version":"1.0.0"}"#,
+ )
+ .unwrap();
+ write_patch(&profile, "- id: better-sidebar\n disabled: true\n");
+
+ assert!(has_patch_disable(&profile, "dsh-better-sidebar"));
+
+ // 确认后启用:别名条目被移除
+ enable_plugin_at(&profile, "dsh-better-sidebar", true).unwrap();
+ let content = fs::read_to_string(profile.join("cordis.patch.yml")).unwrap();
+ assert!(!content.contains("better-sidebar"));
+
+ fs::remove_dir_all(&profile).ok();
+ }
}
diff --git a/src-tauri/src/service/plugin/watch.rs b/src-tauri/src/service/plugin/watch.rs
index 57a4be71..58cd16f3 100644
--- a/src-tauri/src/service/plugin/watch.rs
+++ b/src-tauri/src/service/plugin/watch.rs
@@ -50,6 +50,13 @@ pub struct DshPlugin {
/// 禁用清单时才视为「已禁用」;否则为「未加载」(用户未主动禁用,
/// 启用操作会返回 `ENABLE_NOT_DISABLED`,前端不应展示启用入口)。
pub disabled: bool,
+ /// 是否在 profile 的 `cordis.patch.yml` 中被配置层禁用(`disabled: true`)。
+ ///
+ /// 与 `disabled`(桌面禁用清单)独立:patch 覆盖是用户/第三方直接写在
+ /// 配置文件里的更高优先级禁用,运行期同样不加载。桌面「启用」操作不会
+ /// 静默清除它——需用户确认后才会移除对应覆盖(见
+ /// `disable::strip_patch_disable`),避免「声称成功却仍被配置禁用」。
+ pub patch_disabled: bool,
/// 预设清单中的「推荐」标记(绿色 chip)
pub recommended: bool,
/// 预设清单中的「修复」标记(黄色 chip)
@@ -157,6 +164,9 @@ fn parse_plugins(profile: &Path, presets: &[PreinstallPluginInfo]) -> Vec<DshPlu
// 禁用清单:用于区分「已禁用」(用户主动禁用)与「未加载」(不在 bundles
// 但也不在禁用清单,启用会返回 ENABLE_NOT_DISABLED)。
let disabled_map = crate::service::plugin::disable::load_disabled(profile);
+ // 配置覆盖禁用集合(cordis.patch.yml 顶层 `disabled: true` 条目):命中的
+ // 插件按「配置覆盖禁用」展示,与桌面禁用清单区分(优先级更高)。
+ let patch_disabled_set = crate::service::plugin::disable::load_patch_disabled(profile);
let mut dep_ids: Vec<&String> = manifest.dependencies.keys().collect();
// 稳定排序:启动加载(bundles)的插件在前,其余按 id 字典序
@@ -177,13 +187,15 @@ fn parse_plugins(profile: &Path, presets: &[PreinstallPluginInfo]) -> Vec<DshPlu
.or_else(|| preset.map(|p| p.repo_url.clone()))
.map(|url| normalize_repo_url(&url))
.unwrap_or_default();
+ let name = meta
+ .as_ref()
+ .and_then(|m| m.name.clone())
+ .or_else(|| preset.map(|p| p.name.clone()))
+ .unwrap_or_else(|| id.clone());
+ let patch_disabled_by_name = patch_disabled_set.contains(name.as_str());
Some(DshPlugin {
id: id.clone(),
- name: meta
- .as_ref()
- .and_then(|m| m.name.clone())
- .or_else(|| preset.map(|p| p.name.clone()))
- .unwrap_or_else(|| id.clone()),
+ name,
version: meta
.as_ref()
.and_then(|m| m.version.clone())
@@ -196,6 +208,8 @@ fn parse_plugins(profile: &Path, presets: &[PreinstallPluginInfo]) -> Vec<DshPlu
repo_url,
bundled: bundled.contains(id.as_str()),
disabled: disabled_map.contains_key(id),
+ patch_disabled: patch_disabled_set.contains(id.as_str())
+ || patch_disabled_by_name,
recommended: preset.map(|p| p.recommended).unwrap_or(false),
fix: preset.map(|p| p.fix).unwrap_or(false),
internal: internal_names.contains(id.as_str()),
@@ -259,10 +273,13 @@ pub fn force_emit(app_handle: &AppHandle) {
emit(app_handle);
}
-/// 变化指纹:profile package.json 与各直接依赖插件 package.json 的内容拼接。
+/// 变化指纹:profile package.json、各直接依赖插件 package.json,以及
+/// `cordis.patch.yml` / `disabled-plugins.json` 的内容拼接。
///
/// pnpm add/remove/install 会重写 profile 清单(依赖与 bundles)并落盘插件包,
-/// 任一变化都会改变指纹;profile 未初始化(首次运行)时返回 None。
+/// 任一变化都会改变指纹;配置覆盖(patch)与桌面禁用清单被外部修改时也应
+/// 触发插件列表刷新(issue #399:监听 patch/禁用清单变化)。profile 未初始化
+/// (首次运行)时返回 None。
fn fingerprint(app_handle: &AppHandle) -> Option<String> {
let dir = profile_dir(app_handle);
let manifest = std::fs::read_to_string(dir.join("package.json")).ok()?;
@@ -276,6 +293,13 @@ fn fingerprint(app_handle: &AppHandle) -> Option<String> {
parts.push(content);
}
}
+ // 配置覆盖与桌面禁用清单不在依赖文件里,但直接影响插件列表的展示态:
+ // 一并纳入指纹,外部直接编辑这些文件时也能实时刷新。
+ for extra in ["cordis.patch.yml", "disabled-plugins.json"] {
+ if let Ok(content) = std::fs::read_to_string(dir.join(extra)) {
+ parts.push(content);
+ }
+ }
Some(parts.join("\n---\n"))
}
@@ -490,6 +514,7 @@ mod tests {
repo_url: String::new(),
bundled: true,
disabled: false,
+ patch_disabled: false,
recommended: false,
fix: false,
internal: false,
@@ -522,6 +547,7 @@ mod tests {
repo_url: String::new(),
bundled: true,
disabled: false,
+ patch_disabled: false,
recommended: false,
fix: false,
internal: false,
@@ -622,4 +648,63 @@ mod tests {
std::fs::remove_dir_all(&dir).ok();
}
+
+ /// `cordis.patch.yml` 配置覆盖禁用(`disabled: true`)独立于桌面禁用清单:
+ /// 命中条目目标(依赖键或包内 name 别名)的插件标记 `patch_disabled`,
+ /// `disabled: false` 与未禁用的条目不标记。
+ #[test]
+ fn parse_plugins_marks_config_override_disabled() {
+ let dir = build_profile(
+ "patch",
+ &[
+ (
+ "dshmarket",
+ r#"{"name":"dshmarket","version":"1.13.1","dsh":{"bundle":{}}}"#,
+ ),
+ ("dsh-tauri-pet", r#"{"name":"dsh-tauri-pet","version":"0.1.0"}"#),
+ ("dsh-other", r#"{"name":"dsh-other","version":"0.1.0"}"#),
+ ],
+ );
+ // dshmarket 由配置覆盖禁用;dsh-tauri-pet 显式 disabled: false(非禁用)
+ std::fs::write(
+ dir.join("cordis.patch.yml"),
+ "- id: dshmarket\n disabled: true\n- id: dsh-tauri-pet\n disabled: false\n",
+ )
+ .unwrap();
+ let plugins = parse_plugins(&dir, &presets_for_test());
+ let market = plugins.iter().find(|p| p.id == "dshmarket").unwrap();
+ assert!(market.patch_disabled);
+ let pet = plugins.iter().find(|p| p.id == "dsh-tauri-pet").unwrap();
+ assert!(!pet.patch_disabled);
+ let other = plugins.iter().find(|p| p.id == "dsh-other").unwrap();
+ assert!(!other.patch_disabled);
+
+ std::fs::remove_dir_all(&dir).ok();
+ }
+
+ /// 包内 `name` 与依赖键不一致(loader 别名形态)时,patch 条目按
+ /// package.json name 命中同样标记为配置覆盖禁用。
+ #[test]
+ fn parse_plugins_marks_patch_disabled_by_package_name_alias() {
+ let dir = build_profile(
+ "patch-alias",
+ &[(
+ "dsh-better-sidebar",
+ r#"{"name":"better-sidebar","version":"1.0.0"}"#,
+ )],
+ );
+ std::fs::write(
+ dir.join("cordis.patch.yml"),
+ "- id: better-sidebar\n disabled: true\n",
+ )
+ .unwrap();
+ let plugins = parse_plugins(&dir, &[]);
+ let sidebar = plugins
+ .iter()
+ .find(|p| p.id == "dsh-better-sidebar")
+ .unwrap();
+ assert!(sidebar.patch_disabled);
+
+ std::fs::remove_dir_all(&dir).ok();
+ }
}
diff --git a/src/components/config-plugin.tsx b/src/components/config-plugin.tsx
index 8df4e3bf..4016de2d 100644
--- a/src/components/config-plugin.tsx
+++ b/src/components/config-plugin.tsx
@@ -101,14 +101,15 @@ export function ConfigPlugin() {
},
})
const enable = useMutation({
- mutationFn: (id: string) => enablePlugin(id),
- onSuccess: (_data, id) => {
- const name = plugins.find(p => p.id === id)?.name ?? id
+ mutationFn: (args: { id: string, clearConfigOverride: boolean }) =>
+ enablePlugin(args.id, args.clearConfigOverride),
+ onSuccess: (_data, args) => {
+ const name = plugins.find(p => p.id === args.id)?.name ?? args.id
void queryClient.invalidateQueries({ queryKey: ['plugins'] })
toast(t('plugins.enable_toast', { name }), {})
},
- onError: (err, id) => {
- const name = plugins.find(p => p.id === id)?.name ?? id
+ onError: (err, args) => {
+ const name = plugins.find(p => p.id === args.id)?.name ?? args.id
console.error('[ConfigPlugin] enable failed:', err)
toast(t('plugins.enable_failed', { name }), {})
},
@@ -221,12 +222,33 @@ export function ConfigPlugin() {
}
}
- async function onEnable(id: string) {
+ async function onEnable(id: string, clearConfigOverride = false) {
if (busy)
return
+ // 配置覆盖禁用:启用会修改用户的 cordis.patch.yml(仅移除该插件的禁用覆盖,
+ // 其余配置条目保留),属于改写用户配置文件的操作,必须先明确确认。
+ if (clearConfigOverride) {
+ const name = plugins.find(p => p.id === id)?.name ?? id
+ try {
+ await openDialog({
+ status: 'warning',
+ title: t('plugins.enable_override_confirm_title'),
+ description: (
+ <p>
+ {t('plugins.enable_override_confirm_desc', { name })}
+ </p>
+ ),
+ confirmText: t('plugins.enable_override_confirm'),
+ })
+ }
+ catch (e) {
+ silence(e, 'plugin enable: config override dialog cancelled')
+ return
+ }
+ }
setBusy({ id, action: 'enable' })
try {
- await enable.mutateAsync(id)
+ await enable.mutateAsync({ id, clearConfigOverride })
}
catch (e) {
silence(e, 'plugin enable: error already shown by mutation onError')
@@ -431,6 +453,13 @@ export function ConfigPlugin() {
{t('plugins.disabled_badge')}
</Chip>
</If>
+ {/* 配置覆盖禁用:展示在 cordis.patch.yml 中被显式禁用的真实状态
+ (内置插件同样标注,issue #399:Scheduler/Pet 行此前只有「内置」) */}
+ <If cond={plugin.patchDisabled}>
+ <Chip size="sm" variant="soft" color="warning">
+ {t('plugins.patch_disabled_badge')}
+ </Chip>
+ </If>
</div>
<If cond={plugin.description !== ''}>
<TextEllipsis lineClamp={2} className="text-xs text-muted">
@@ -462,33 +491,35 @@ export function ConfigPlugin() {
</span>
</Chip>
</If>
+ {/* 启用入口:配置覆盖禁用(含内置插件)或桌面禁用清单 → 可启用。
+ 配置覆盖禁用时点击会先弹确认框,确认后后端才移除该覆盖 */}
+ <If cond={plugin.patchDisabled || (!plugin.internal && plugin.disabled)}>
+ <Chip
+ className={actionChip({ busy: !!busy })}
+ variant="primary"
+ color="accent"
+ size="sm"
+ onClick={() => onEnable(plugin.id, plugin.patchDisabled)}
+ >
+ <span className="flex items-center gap-1">
+ <If cond={busy?.id === plugin.id && busy.action === 'enable'} then={<Spinner size="sm" color="current" />} />
+ {t('plugins.enable')}
+ </span>
+ </Chip>
+ </If>
+ <If cond={!plugin.internal && !plugin.patchDisabled && !plugin.disabled}>
+ <Chip
+ className={actionChip({ busy: !!busy })}
+ size="sm"
+ onClick={() => onDisable(plugin.id)}
+ >
+ <span className="flex items-center gap-1">
+ <If cond={busy?.id === plugin.id && busy.action === 'disable'} then={<Spinner size="sm" color="current" />} />
+ {t('plugins.disable')}
+ </span>
+ </Chip>
+ </If>
<If cond={!plugin.internal}>
- <If cond={plugin.disabled}>
- <Chip
- className={actionChip({ busy: !!busy })}
- variant="primary"
- color="accent"
- size="sm"
- onClick={() => onEnable(plugin.id)}
- >
- <span className="flex items-center gap-1">
- <If cond={busy?.id === plugin.id && busy.action === 'enable'} then={<Spinner size="sm" color="current" />} />
- {t('plugins.enable')}
- </span>
- </Chip>
- </If>
- <If cond={!plugin.disabled}>
- <Chip
- className={actionChip({ busy: !!busy })}
- size="sm"
- onClick={() => onDisable(plugin.id)}
- >
- <span className="flex items-center gap-1">
- <If cond={busy?.id === plugin.id && busy.action === 'disable'} then={<Spinner size="sm" color="current" />} />
- {t('plugins.disable')}
- </span>
- </Chip>
- </If>
{/* 单插件快照:快照始终可用(已存在时覆盖确认);还原/删除快照仅在
存在快照时显示。还原会停服务,还原后 toast 提示重启(issue #303) */}
<Chip
diff --git a/src/hooks/use-dsh-plugins.ts b/src/hooks/use-dsh-plugins.ts
index c143a81b..ecc21374 100644
--- a/src/hooks/use-dsh-plugins.ts
+++ b/src/hooks/use-dsh-plugins.ts
@@ -30,6 +30,8 @@ export interface DshPlugin {
bundled: boolean
/** 是否在禁用清单(disabled-plugins.json)中,独立于 bundled */
disabled: boolean
+ /** 是否在 cordis.patch.yml 中被配置覆盖禁用(disabled: true),优先级高于禁用清单 */
+ patchDisabled: boolean
/** 预设清单中的「推荐」标记 */
recommended: boolean
/** 预设清单中的「修复」标记 */
@@ -54,8 +56,8 @@ export interface UseDshPluginsResult {
refresh: () => Promise<void>
/** 禁用指定插件(从 dsh.profile.bundles 移除,保留包体) */
disablePlugin: (id: string) => Promise<void>
- /** 启用指定插件(加回 dsh.profile.bundles) */
- enablePlugin: (id: string) => Promise<void>
+ /** 启用指定插件(加回 dsh.profile.bundles);clearConfigOverride 为 true 时同时移除 cordis.patch.yml 中的禁用覆盖 */
+ enablePlugin: (id: string, clearConfigOverride?: boolean) => Promise<void>
}
/**
@@ -122,8 +124,8 @@ export function useDshPlugins(): UseDshPluginsResult {
function disablePlugin(id: string) {
return invoke<void>('disable_dsh_plugin', { id })
}
- function enablePlugin(id: string) {
- return invoke<void>('enable_dsh_plugin', { id })
+ function enablePlugin(id: string, clearConfigOverride = false) {
+ return invoke<void>('enable_dsh_plugin', { id, clearConfigOverride })
}
async function refresh() {
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index b7694bd7..426778ed 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -223,10 +223,14 @@
"plugins.disable": "Disable",
"plugins.enable": "Enable",
"plugins.disabled_badge": "Disabled",
+ "plugins.patch_disabled_badge": "Disabled · Config Override",
"plugins.disable_toast": "Plugin {{name}} disabled",
"plugins.disable_failed": "Failed to disable {{name}}",
"plugins.enable_toast": "Plugin {{name}} enabled",
"plugins.enable_failed": "Failed to enable {{name}}",
+ "plugins.enable_override_confirm_title": "Enable via config override",
+ "plugins.enable_override_confirm_desc": "{{name}} is disabled in cordis.patch.yml. Enabling will remove only that disable override (other config entries are kept) and restart the service. Continue?",
+ "plugins.enable_override_confirm": "Remove override & enable",
"plugins.snapshot": "Snapshot",
"plugins.snapshot_toast": "Plugin {{name}} snapshotted",
"plugins.snapshot_failed": "Failed to snapshot {{name}}",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index d25279fd..05c94fc6 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -223,10 +223,14 @@
"plugins.disable": "禁用",
"plugins.enable": "启用",
"plugins.disabled_badge": "已禁用",
+ "plugins.patch_disabled_badge": "已禁用 · 配置覆盖",
"plugins.disable_toast": "插件 {{name}} 已禁用",
"plugins.disable_failed": "禁用插件 {{name}} 失败",
"plugins.enable_toast": "插件 {{name}} 已启用",
"plugins.enable_failed": "启用插件 {{name}} 失败",
+ "plugins.enable_override_confirm_title": "启用被配置覆盖禁用的插件",
+ "plugins.enable_override_confirm_desc": "插件 {{name}} 在 cordis.patch.yml 中被配置覆盖禁用。启用将仅移除该禁用覆盖(保留其它配置条目)并重启服务,确定吗?",
+ "plugins.enable_override_confirm": "移除覆盖并启用",
"plugins.snapshot": "快照",
"plugins.snapshot_toast": "插件 {{name}} 已创建快照",
"plugins.snapshot_failed": "创建插件 {{name}} 快照失败",