dsh-plugin-restart-desktop:在 DSH Desktop 侧边栏添加有序重启按钮

前言

做 DSH Desktop 插件时,先验证安装链路、再参考最小实现,是常见路径。dsh-plugin-restart-desktop 是一个行为单一的 DSH Desktop 插件:它在侧边栏左下角添加一个「重启Desktop」按钮,点击后经二次确认调用桌面主进程有序重启。下面介绍它的功能、安装步骤和使用注意。

这是什么

dsh-plugin-restart-desktop 是一个 DSH Desktop 插件,仓库地址为 https://github.com/ExploringBB/dsh-plugin-restart-desktop,许可证为 MIT。它只负责一件事:在侧边栏底部设置行中注入「重启Desktop」按钮,并在确认后用桌面主进程完成有序重启。

它也可以作为 DSH Desktop 插件的最小示例,参考其中的五件套包结构、cordis.patch.ymlinsert 补丁,以及 host/client 双侧与 Typert Remote 写法。

核心功能

  • 按钮注入在侧边栏底部设置行内,位于齿轮右侧。
  • 点击按钮后弹出二次确认框;确认后调用 desktopActions.requestRestart()(Electron relaunch)进行有序重启。
  • 重启过程中显示「正在重启…」等待层。
  • 按钮文案接入 DSH 语言系统;在 DSH 设置 → 通用设置 → 语言 中切换中文 / English 后,文案立即切换。
  • 仅 desktop profile 生效;headless web profile 下调用会得到 { ok: false },并弹出友好错误提示。

安装与启用

该插件只适用于 desktop profile。安装时需要修改 desktop profile 的 package.json,把插件加入 dependenciesdsh.profile.bundles

先编辑 desktop profile 的 package.json,例如路径为:

~/.dsh/profiles/desktop/package.json

加入插件依赖和 bundle 配置:

"dependencies": {
  "dsh-plugin-restart-desktop": "file:<本机插件目录>"
},
"dsh": {
  "profile": {
    "bundles": [
      "@deepseek-ai/dsh-base",
      "@deepseek-ai/dsh-web-app",
      "dsh-plugin-restart-desktop"
    ]
  }
}

file: 后面的路径需要替换为插件在本机的实际目录。

然后在该 profile 目录执行安装:

pnpm install

最后重启 DSH Desktop。经过上面的步骤,左下角设置行内应能看到「重启Desktop」按钮。

典型用法

  1. 重启 DSH Desktop 后,在侧边栏底部设置行、齿轮右侧看到「重启Desktop」按钮。
  2. 点击按钮,在二次确认框中确认后,插件触发有序重启并显示「正在重启…」等待层。
  3. DSH 设置 → 通用设置 → 语言 中切换中文 / English,按钮文案立即切换。
  4. 如果当前运行的是 headless web profile,调用会得到 { ok: false } 和友好错误提示。

包声明要点

package.json 中声明了如下依赖:

{
  "dependencies": {
    "zod": "^4.4.3"
  },
  "peerDependencies": {
    "@deepseek-ai/cordis": "^4.0.1",
    "@deepseek-ai/cordis-plugin-loader": "^1.0.2",
    "@deepseek-ai/dsh-typert-protocol": "^0.1.0-rc.6",
    "react": "^18.2.0"
  }
}

其中还声明了 client 注入项:

{
  "dsh": {
    "client": {
      "inject": [
        "@deepseek-ai/dsh-client-runtime",
        "@deepseek-ai/dsh-api-remotes"
      ],
      "platform": "web"
    }
  }
}

适用场景与注意

适合:
- 验证 DSH Desktop 插件安装流程:profile 注册、pnpm install、重启生效。
- 作为自研 DSH Desktop 插件的最小参考实现。
- 查看 cordis.patch.ymlinsert 补丁、host/client 双侧与 Typert Remote 写法。

注意:
- 该插件仅适用于 desktop profile;headless web profile 下不可用,并返回 { ok: false }
- 插件会作为 desktop profile 的一部分被 DSH Desktop 加载,并以当前 dsh 进程权限运行;安装前应检查源码、MIT 许可证和依赖版本。
- 安装步骤中的 file: 路径需要替换为本机插件目录,不要照抄占位路径。

小结

dsh-plugin-restart-desktop 覆盖 DSH Desktop 插件的几个安装与运行链路:profile 注册、依赖安装、界面注入、语言系统和重启流程。它适合做安装验证或最小插件示例。

仓库地址:https://github.com/ExploringBB/dsh-plugin-restart-desktop

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜