Skip to content
dsh.fish
Bundle

dsh-oneclick-restart

DSH 侧边栏一键重启 Harness 按钮(调用 DSH Desktop 的 harness:restart IPC)

Source
liuhao11223
License
MIT
Updated
Updated 5 days ago

Readme

# dsh-oneclick-restart

DSH Web 侧边栏底部的**一键重启 Harness** 按钮(DSH Desktop)。

![位置] 侧边栏最底部、Settings 行上方的 `sidebar.footer.action` 座位:展开时是
「⟳ 重启 Harness」整行按钮,侧栏收起时自动变成 36px 圆形图标按钮(与 Cordis 插件入口同款)。

## 它做什么

一次点击调用 `window.dshDesktop.restartHarness()` —— DSH Desktop preload 桥接的
`harness:restart` IPC,等同于原生菜单里的「重启 Harness」:

- 停掉当前 Harness 进程并重新拉起(重新扫描插件树、生成新的 auth URL);
- 复用同一个窗口,服务回来后窗口自动加载新地址;
- **当前正在进行的对话会被中断**(按钮 tooltip 已说明)。

按钮在请求进行中显示旋转图标、文案变「正在重启…」并禁用,防止重复点击。

## 状态

| 相位 | 文案 | 说明 |
| --- | --- | --- |
| `idle` | 重启 Harness | 可点击 |
| `restarting` | 正在重启… | 图标旋转,按钮禁用 |
| `unsupported` | 仅桌面端可一键重启 | 纯浏览器标签页里没有 `window.dshDesktop`,4 秒后复原 |
| `failed` | 重启失败,请重试 | IPC 抛错或 `{ ok: false }`,4 秒后复原可重试 |

## 安装

### 方式一:CLI(需要 dsh CLI)

```bash
dsh plugin --profile web add dsh-oneclick-restart
dsh plugin --profile web add link:<本目录绝对路径>   # 本地开发
```

### 方式二:手工安装(不经 CLI)

1. 把整个包目录复制到 profile 的 node_modules:

   ```
   $DSH_HOME/profiles/web/node_modules/dsh-oneclick-restart/
   ```

2. 在 `$DSH_HOME/profiles/web/cordis.patch.yml`(你自己的 patch 层)里加一条 insert:

   ```yaml
   - insert:
       - id: dsh-oneclick-restart
         name: dsh-oneclick-restart
   ```

3. 让 Harness 重新加载:profile 的 `patchReload: live` 通常会即时生效,随后**刷新页面**
   即可看到按钮;若没生效,用原生菜单「重启 Harness」重启一次。

Windows 上 `$DSH_HOME` 默认为 `%APPDATA%\dsh-desktop\harness`(本仓库附带的 `install.ps1`
就是按这个默认值做上面两步的,可重复执行)。

> 注意:profile 的 `node_modules` 由 pnpm 管理,一次 `pnpm install` 可能清掉手工放进去的
> 目录;被清掉后重新复制即可(或用方式一安装)。

## 包结构

```
package.json        dsh.client = { platform: 'web' },导出 ./client 浏览器 bundle
cordis.patch.yml    bundle 挂载声明(insert 条目)
lib/index.js        宿主半侧:无行为,仅作为“已启用的 Loader 条目”
lib/client.js       浏览器半侧:模块加载器 bundle(注册槽位 + 组件 + 样式 + 词典)
test/client.test.mjs 组件级功能验证(jsdom + react-dom)
```

## 实现要点

- 客户端 bundle 走 DSH 的客户端模块系统:`window.__ModuleLoader__.load({ id, factory })`,
  `id` 即包名;只 require 平台种子表内的模块(`react`、
  `@deepseek-ai/dsh-client-ui-primitives`),因此无需 `dsh.client.external` / `inject`。
- 槽位注册:`ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({...}, Component))`。
  该座位由 `@deepseek-ai/dsh-client-ui-sidebar` 声明为 `list` / `scope: root`,组件收到
  `{ wide }`(侧栏是否展开)与 `t`(本插件词典)。
- 样式:`<style data-plugin data-plugin-css>` 注入,类名前缀 `ocr1_`,颜色全部使用
  主题 CSS 变量(`--dsw-alias-*`),暗色/亮色与字体缩放自动跟随。
- 词典:`ctx.locale.register('oneclick-restart', { zh, en })`,两份词典键集一致。

## 验证

```bash
node test/client.test.mjs
```

用真实 react/react-dom/jsdom 跑:模块加载、槽位注册形状、宽/窄两态渲染、中英文案、
单击只调用一次桥接、重启中禁点、无桥接降级提示、失败提示、样式注入。

测试从 DSH Desktop profile 的 `node_modules` 借用 react / react-dom / jsdom(不额外装依赖);
profile 不在默认位置时用 `DSH_PROFILE_MODULES` 指向一个含这三个包的 `node_modules`。

## 许可

MIT

Install

dsh plugin --profile web add github:liuhao11223/dsh-oneclick-restart#e2ce1b7433dd6f2137a950f3956e30ac72f9f451

Profile: web

Source