From f0c11176f2ec6743ff0582cf297a77d8004fe77c Mon Sep 17 00:00:00 2001 From: pyh Date: Wed, 30 Sep 2026 16:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(client):=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=8C=AA=E5=88=B0=E6=8F=92=E4=BB=B6=E9=A1=B5=EF=BC=8C=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=94=B9=E6=A0=87=E9=A2=98=E5=8A=A0=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E5=B9=B6=E6=8C=81=E4=B9=85=E5=8C=96=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 48 +++++++--- client.js | 257 ++++++++++++++++++++++++++++++++++++--------------- package.json | 2 +- 3 files changed, 215 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index 209388f..d8d9fb8 100644 --- a/README.md +++ b/README.md @@ -19,32 +19,47 @@ Windows / macOS / Linux 三个平台走的是同一条通知通道(渲染进 | 状态 | 行为 | | --- | --- | | DSH 窗口**不在前台** | **系统通知**(这是插件唯一能拿到的系统通知通道,三个平台一致)。点通知:窗口回到前台并跳到该会话 | -| DSH 窗口在前台,且**不是**你正在看的那个会话 | **应用内轻弹窗**:右上角悬浮,点「查看」跳过去,6 秒自动消失,鼠标悬停时不消失,Esc 关掉最上面一条 | +| DSH 窗口在前台,且**不是**你正在看的那个会话 | **应用内轻弹窗**:右上角悬浮,标题是提醒类型、下面一行是会话题目与细节;点「查看」跳过去,6 秒自动消失,鼠标悬停时不消失,Esc 或者 ✕ 关掉 | | DSH 窗口在前台,且就是你**正在看的**那个会话 | 不打扰(你在看,不需要弹) | ## 设置 -**设置 → 通用 → 会话通知**: +**插件 → 会话通知**(插件自己的介绍页里): - 显示系统通知权限状态; - 未授权时点「允许通知」请求权限(浏览器要求必须由你手动点击才能弹权限框),授权后自动发一条测试通知; - 已授权时点「测试通知」随时验证; - 权限被系统层关闭时,按平台给出开启路径(Windows / macOS 的通知设置、Linux 桌面环境的通知设置); -- 三个开关分别控制**完成 / 授权 / 提问**三类提醒(默认全开;开关状态存在当前页面内存里,刷新回到默认——本插件不写配置文件)。 +- 三个开关分别控制**完成 / 授权 / 提问**三类提醒(默认全开),状态存在浏览器本地,重装插件不丢; +- 最后一段显示观察器自身的健康状态(收不到会话状态时直接标红)。 + +设置放在插件自己的页面里,而不是「设置 → 通用」:它是这个插件的配置,不是 DSH 的通用偏好。 ## 安装 -在 DSH 的 **插件 → 添加插件** 里填本目录的绝对路径即可(`plugin_manager` 也会做同样的安装): +### 1. 从 Git 仓库安装(推荐) + +在 DSH 的 **插件 → 添加插件** 的上方输入框里填: + +```text +https://gitea.iwake.top/dsh-plugin/session-notify.git#v1.0.3 +``` + +`#` 后面跟标签或提交,用来锁定版本;不写则取默认分支。跟随 1.x 最新版可以写 `#semver:^1.0.3`。仓库是公开的,不需要凭据,也不用改「安装源」。 + +### 2. 本地路径安装 + +把仓库克隆或下载到本机,在同一个输入框里填包目录的绝对路径,例如: ```text D:\DeepSeek Harness Plugins\dsh-session-notify ``` -安装后: +### 装完之后 -- **浏览器半**随页面加载,刷新页面即生效; -- **宿主半**为空壳(不改任何 DSH 状态),如需重启才生效,完全退出 DSH 再打开即可; -- 本插件没有第三方依赖,不需要 pnpm 下载,也不需要构建步骤。 +- **浏览器半**随页面加载,**刷新页面**即生效; +- **宿主半**是空壳(不改任何 DSH 状态、不注册服务与路由),只有它变化时才需要完全退出 DSH 再打开; +- 本插件没有第三方依赖,不需要 pnpm 下载,也没有构建步骤。 卸载:插件页里移除 `@dsh-plugin/session-notify`(它同时是 profile 的一个 bundle)。 @@ -52,7 +67,7 @@ D:\DeepSeek Harness Plugins\dsh-session-notify - **通道是跨平台统一的**:插件的提醒都通过页面(Electron 渲染进程)的 `Notification` 构造器发出,Windows 通知中心 / macOS 通知中心 / Linux 通知守护(libnotify、GNOME、KDE)都由系统把它转成原生通知;应用内轻弹窗是纯 DOM,与平台无关。 - **宿主半拿不到系统通知**:DSH Desktop 的宿主进程是纯 Node 进程(不是 Electron 主进程),没有 Electron 的 `Notification` 可用,所以插件的所有提醒都在浏览器半产生——这也正是"三个平台一套代码"的原因。 -- **已验证**:Windows 上的安装、三个 slot 条目注册、以及 22 条投递规则(见下)的离线验证;设置行与轻弹窗的文案/交互按 DSH 自带的 toast 与 switch 组件对齐。 +- **已验证**:Windows 上的安装、三个 slot 条目注册、以及 52 项离线断言(接线 / 国际化 / 轻弹窗结构 / 开关持久化 / 全部投递规则)。 - **未验证**:macOS 与 Linux 上的实际弹窗效果本机无法测试。结构上它们与 Windows 共用同一条通道、同一份代码,只有"权限被系统关闭时显示的开启路径"是分平台的。 - 提醒只在 DSH 进程运行、页面打开时产生:**DSH 完全退出期间结束的会话不会再补发通知**。 @@ -72,12 +87,13 @@ D:\DeepSeek Harness Plugins\dsh-session-notify 依赖的都是稳定契约: - 浏览器半只依赖 **slot 的标准 props**(`useSessions`、`useSessionStatus`)读取会话状态,这是 DSH 官方给插件读会话数据的方式;不轮询、不自己订阅会话事件、不读别的插件的 DOM; -- 只往两个官方 slot 注册:`settings.general.item`(设置行)与 `shell.overlay`(两个条目:轻弹窗层 + 无渲染的观察器,内容永远是 `null`); +- 只往两个官方 slot 注册:`plugins.bundle.config`(本插件在插件页里的配置,key 就是包名)与 `shell.overlay`(两个条目:轻弹窗层 + 无渲染的观察器,内容永远是 `null`); +- **配置放在插件页**:`plugins.bundle.config` 的 key 取包名(`@dsh-plugin/session-notify`),插件页就会渲染这块配置;官方 `dsh-experimental-voice-input-bundle` 用的就是这个口子。行级口子是 `plugins.row.config`,key 形如 `<包名>#<行 id>`,会在该行上多出一个「配置」入口; - **不要**把"无渲染"条目放进 `sidebar.panellist`:该 slot 的宿主会把**每个条目的 id 当成一个左侧面板按钮**(`entriesOfSlot('sidebar.panellist')` → 面板列表,按钮文字取 `options.label ?? options.id`,条目本身作为图标内联渲染),放进去会在左侧多出一行空面板并挤坏侧边栏。本插件第一版踩过这个坑,现已改挂到通用浮层; -- **文案必须注册字典**:`ctx.locale.register('session-notify', { zh, en })`,否则 `locale.bind(ns)` 在查不到该命名空间时会把 key 原样返回——界面上就会显示成 `settings.title` 这样的原始键(本插件第二版踩过这个坑)。注册会在 locale 修订号上打点,已经渲染出来的条目会自动换上文案,不需要刷新; +- **文案必须注册字典**:`ctx.locale.register('session-notify', { zh, en })`,否则 `locale.bind(ns)` 在查不到该命名空间时会把 key 原样返回——界面上就会显示成 `settings.title` 这样的原始键(本插件第二版踩过这个坑)。注册会在 locale 修订号上打点,已经渲染出来的部件会自动换上文案,不需要刷新; - 另外自带一份本地字典兜底:即使拿不到框架的 `t`、或 locale 服务没有保存注册,也会渲染中文/英文文案而不是原始键; - 样式只用主题 token,不 import 任何 `@deepseek-ai/dsh-client-*` 包(规范要求,也是渲染不被上游改动打断的前提); -- 宿主半不声明 `inject`、不注册服务、不注册路由。 +- 宿主半不声明 `inject`、不注册服务、不注册路由;三个开关存浏览器本地,不改 DSH 的配置文件。 上游若改动 slot 名或 hook 名:注册会静默跳过而不是把页面弄坏,插件会退化成"不提醒";这类情况请按上面的契约名核对。 @@ -85,12 +101,14 @@ D:\DeepSeek Harness Plugins\dsh-session-notify `client.js` 是纯 JavaScript、浏览器端运行,可以在 Node 里用桩模块加载器评估并驱动: -- 模块接线:加载后返回的插件、`inject` 声明、注册集合(含"观察器绝不在 `sidebar.*` 里"这一条); -- 国际化:字典已注册且中英键集合一致、设置行与弹窗渲染出的每个字符串都不是原始键、拿不到框架 `t` 时本地字典兜底、locale 服务不保存注册时仍然有文案; +- 模块接线:插件返回值、`inject` 声明、注册集合(含"配置挂在插件页""观察器绝不在 `sidebar.*` 里"这两条); +- 国际化:字典已注册且中英键集合一致、插件页与弹窗渲染出的每个字符串都不是原始键、拿不到框架 `t` 时本地字典兜底、locale 服务不保存注册时仍然有文案; +- 轻弹窗结构:标题是触发类型、描述含会话名与细节; +- 开关:切换即写入浏览器本地,重开页面能读回; - 渲染健壮性:各组件在空状态 / 权限被拒 / 无 Notification API 下渲染都不报错; - 投递规则:完成提醒一次、当前会话不打扰、后台走系统通知、授权/提问各提醒一次、运行中延后、子会话跳过、空白会话跳过、历史不补发、开关生效、弹窗自动消失等。 -合计 44 项断言。 +合计 52 项断言。 ## License diff --git a/client.js b/client.js index b9ecc36..826311f 100644 --- a/client.js +++ b/client.js @@ -36,6 +36,8 @@ window.__ModuleLoader__.load({ /** Locale namespace owned by this package. */ const NS = 'session-notify' + /** This package's name: the plugin manager keys a bundle's configuration by it. */ + const PACKAGE_NAME = '@dsh-plugin/session-notify' /** Trigger ids shared by the store, the copy table, and the settings row. */ const KINDS = ['completion', 'approval', 'question'] /** Pending-interaction kinds the Harness itself renders, and this plugin serves. */ @@ -82,6 +84,12 @@ window.__ModuleLoader__.load({ 'settings.kind.completion': '完成', 'settings.kind.approval': '授权', 'settings.kind.question': '提问', + 'config.title': '会话通知', + 'config.note': '只在会话需要你注意时提醒,而且只在 DSH 运行时。', + 'config.section.kinds': '提醒内容', + 'config.section.permission': '系统通知权限', + 'config.section.status': '运行状态', + 'config.saveNote': '开关保存在浏览器本地,重装插件不会丢失。', } const en = { 'notification.completion': 'Conversation finished', @@ -117,42 +125,54 @@ window.__ModuleLoader__.load({ 'settings.kind.completion': 'Finished', 'settings.kind.approval': 'Approval', 'settings.kind.question': 'Questions', + 'config.title': 'Session notifications', + 'config.note': 'Alerts you when a conversation needs attention, while DSH is running.', + 'config.section.kinds': 'What to notify about', + 'config.section.permission': 'System notification permission', + 'config.section.status': 'Status', + 'config.saveNote': 'The switches are stored in this browser and survive reinstalling the plugin.', } /** * Every declaration below belongs to this package. The popup copies the * shipped toast surface (a fixed entry in the frame-wide overlay, the * `--dsw-alias-toast-bg` / `--dsw-alias-toast-label` pair, `--dsw-radius-lg`, - * `--dsw-shadow-lv3`), the switch copies `Switch.module.css` behavior and - * proportion, and the settings row copies the General-section row pattern. + * `--dsw-shadow-lv3`) and adds a title line above the text; the switch copies + * `Switch.module.css` behavior and proportion; the configuration sections + * follow the Plugin Manager page's own section rhythm (a column, 32px apart). * Class names are renamed under `dsn-`; only the popup glyphs carry their own * artwork colors. */ const CSS = ` .dsn-stack{position:fixed;top:40px;right:24px;z-index:1100;display:flex;flex-direction:column;align-items:flex-end;gap:8px;pointer-events:none} @media (max-width:520px){.dsn-stack{right:12px}} -.dsn-toast{box-sizing:border-box;pointer-events:auto;display:flex;align-items:center;gap:10px;width:max-content;max-width:min(420px,calc(100vw - 48px));padding:12px 16px;border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-toast-bg);color:var(--dsw-alias-toast-label);font-size:14px;line-height:22px;box-shadow:var(--dsw-shadow-lv3);animation:dsn-toast-in 160ms ease-out} +.dsn-toast{box-sizing:border-box;pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:min(420px,calc(100vw - 48px));padding:12px 12px 12px 16px;border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-toast-bg);color:var(--dsw-alias-toast-label);font-size:14px;line-height:22px;box-shadow:var(--dsw-shadow-lv3);animation:dsn-toast-in 160ms ease-out} @keyframes dsn-toast-in{from{opacity:0;transform:translateX(8px)}to{opacity:1;transform:translateX(0)}} @media (prefers-reduced-motion: reduce){.dsn-toast{animation:none}} -.dsn-toast-icon{display:grid;place-items:center;flex:none;color:var(--dsw-alias-state-warn-label)} +.dsn-toast-icon{display:grid;place-items:center;flex:none;height:22px;color:var(--dsw-alias-state-warn-label)} .dsn-toast-icon.is-completion{color:var(--dsw-alias-state-success-primary)} .dsn-toast-icon.is-question{color:var(--dsw-alias-brand-primary)} -.dsn-toast-text{min-width:0} -.dsn-toast-action{padding:0;border:0;background:none;color:var(--dsw-static-deepseek-400);font:inherit;cursor:pointer;margin-inline:3px} -.dsn-toast-action:hover{opacity:.8} +.dsn-toast-text{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px} +.dsn-toast-title{font-weight:500;font-size:14px;line-height:22px} +.dsn-toast-desc{color:var(--dsw-alias-toast-label);opacity:.8;font-size:13px;line-height:20px;overflow-wrap:break-word} +.dsn-toast-actions{display:flex;align-items:center;gap:2px;flex:none} +.dsn-toast-action{display:inline-flex;align-items:center;height:28px;padding:0 8px;border:0;border-radius:var(--dsw-radius-sm);background:none;color:var(--dsw-static-deepseek-400);font:inherit;font-size:13px;line-height:20px;cursor:pointer} +.dsn-toast-action:hover{background:var(--dsw-alias-interactive-bg-hover)} .dsn-toast-action:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px} -.dsn-toast-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border:0;border-radius:var(--dsw-radius-xs);background:transparent;color:var(--dsw-alias-toast-label);opacity:.7;cursor:pointer} -.dsn-toast-close:hover{opacity:1} +.dsn-toast-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-toast-label);opacity:.8;cursor:pointer} +.dsn-toast-close:hover{background:var(--dsw-alias-interactive-bg-hover);opacity:1} .dsn-toast-close:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px} -.dsn-row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex} -.dsn-row-text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex} -.dsn-row-title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px} -.dsn-row-desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px} -.dsn-status{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px} -.dsn-status + .dsn-status,.dsn-row-desc + .dsn-status,.dsn-kinds + .dsn-status{margin-top:8px} +.dsn-sections{display:flex;flex-direction:column;gap:24px} +.dsn-section{display:flex;flex-direction:column;gap:10px} +.dsn-section-title{margin:0;color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px} +.dsn-section-desc{margin:0;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px} +.dsn-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:10px 0;border-bottom:.5px solid var(--dsw-alias-border-l2)} +.dsn-row:last-child{border-bottom:0} +.dsn-row-text{display:flex;flex-direction:column;gap:2px;min-width:0} +.dsn-row-title{color:var(--dsw-alias-label-primary);font-size:14px;line-height:22px} +.dsn-row-desc{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px} +.dsn-status{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px} .dsn-status-error{color:var(--dsw-alias-state-error-primary)} -.dsn-kinds{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:10px;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px} -.dsn-kind{display:inline-flex;align-items:center;gap:6px;color:var(--dsw-alias-label-secondary)} .dsn-switch{box-sizing:border-box;position:relative;flex:0 0 auto;width:36px;height:20px;padding:2px;border:0;border-radius:999px;background:var(--dsw-alias-border-l3);cursor:pointer} .dsn-switch[aria-checked='true']{background:var(--dsw-alias-brand-primary)} .dsn-switch:disabled{cursor:default;opacity:.5} @@ -436,6 +456,42 @@ window.__ModuleLoader__.load({ } } + /** Storage key for this package's own preferences. */ + const STORAGE_KEY = 'dsh-plugin/session-notify' + + /** + * Read this package's stored trigger switches. + * + * These are browser preferences rather than cordis configuration, so they live + * in this origin's own storage instead of the profile's patch file: the plugin + * writes nothing into DSH's configuration, and every read is defensive because + * storage can be unavailable or hold something an older version wrote. + * @returns the stored switches, defaulting to everything on. + */ + function readStoredKinds() { + const kinds = { completion: true, approval: true, question: true } + try { + const raw = globalThis.localStorage?.getItem(STORAGE_KEY) + if (typeof raw !== 'string' || raw === '') return kinds + const stored = JSON.parse(raw) + for (const kind of KINDS) { + if (typeof stored?.[kind] === 'boolean') kinds[kind] = stored[kind] + } + } catch { + /* unreadable or foreign storage keeps the defaults */ + } + return kinds + } + + /** Store one trigger switch, ignoring storage that refuses to write. */ + function writeStoredKinds(kinds) { + try { + globalThis.localStorage?.setItem(STORAGE_KEY, JSON.stringify(kinds)) + } catch { + /* a refused write leaves the switches live for this page only */ + } + } + /** * Install the plugin. * @param ctx - Client root context providing `slots` and `locale`. @@ -446,7 +502,7 @@ window.__ModuleLoader__.load({ const store = createStore({ permission: notificationPermission(), - kinds: { completion: true, approval: true, question: true }, + kinds: readStoredKinds(), toasts: [], promptError: '', health: { state: 'starting', message: '' }, @@ -539,13 +595,18 @@ window.__ModuleLoader__.load({ timers.delete(id) } - /** Show one light in-app popup. */ + /** + * Show one light in-app popup: the trigger as the title, the conversation + * and its detail as the description, so the heading says what happened and + * the line under it says where. + */ const showToast = (candidate) => { const notice = copyFor(candidate) state.toastSeq += 1 const toast = { id: `dsn-${String(state.toastSeq)}`, kind: notice.kind, + title: notice.title, body: notice.body, sessionId: candidate.sessionId, } @@ -780,10 +841,12 @@ window.__ModuleLoader__.load({ if (notificationPermission() === 'granted') sendTest() } - /** Toggle one trigger. */ + /** Toggle one trigger and remember the choice. */ const setKindEnabled = (kind, enabled) => { const snapshot = store.getSnapshot() - store.set({ ...snapshot, kinds: { ...snapshot.kinds, [kind]: enabled } }) + const kinds = { ...snapshot.kinds, [kind]: enabled } + writeStoredKinds(kinds) + store.set({ ...snapshot, kinds }) } // ----------------------------------------------------------- components @@ -873,30 +936,60 @@ window.__ModuleLoader__.load({ onMouseLeave: () => props.arm(toast.id), }, h('span', { className: `dsn-toast-icon is-${toast.kind}` }, h(KindIcon, { kind: toast.kind, size: 16 })), - h('span', { className: 'dsn-toast-text' }, toast.body), - h('button', { - type: 'button', - className: 'dsn-toast-action', - onClick: () => { - props.dismiss(toast.id) - props.open(toast.sessionId) - }, - }, tr('toast.view')), - h('button', { - type: 'button', - className: 'dsn-toast-close', - 'aria-label': tr('toast.dismiss'), - onClick: () => props.dismiss(toast.id), - }, h(CloseIcon, { size: 12 })))))) + h('div', { className: 'dsn-toast-text' }, + h('div', { className: 'dsn-toast-title' }, toast.title), + h('div', { className: 'dsn-toast-desc' }, toast.body)), + h('div', { className: 'dsn-toast-actions' }, + h('button', { + type: 'button', + className: 'dsn-toast-action', + onClick: () => { + props.dismiss(toast.id) + props.open(toast.sessionId) + }, + }, tr('toast.view')), + h('button', { + type: 'button', + className: 'dsn-toast-close', + 'aria-label': tr('toast.dismiss'), + onClick: () => props.dismiss(toast.id), + }, h(CloseIcon, { size: 14 }))))))) } - /** The General-settings row: permission state, one action, per-trigger switches. */ - function SettingsRow(props) { + /** + * One trigger switch row: the label says which notification it governs and + * the switch is the control, so the row never needs a second description. + */ + function KindRow(props) { + return h('div', { className: 'dsn-row' }, + h('div', { className: 'dsn-row-text' }, + h('div', { className: 'dsn-row-title' }, props.label)), + h('button', { + type: 'button', + role: 'switch', + className: 'dsn-switch', + 'aria-checked': props.checked, + 'aria-label': props.label, + disabled: props.disabled, + onClick: props.onToggle, + }, h('span', { className: 'dsn-thumb' }))) + } + + /** + * This plugin's configuration, rendered on its own page in the plugin + * manager (`plugins.bundle.config`, keyed by this package's name). + * + * The owner asks for two views: `summary` (a one-liner that stands in for + * the row's description) and `page` (the whole form). Everything visible here + * belongs to this package, including the platform-specific permission hint. + */ + function ConfigSection(props) { const snapshot = useOwnStore(props.store) + const tr = seatFor(props) + if (props.view === 'summary') return h(React.Fragment, null, tr('settings.description')) const permission = snapshot.permission const supported = permission !== 'unsupported' const failed = permission === 'denied' || snapshot.promptError !== '' - const tr = seatFor(props) const statusKey = permission === 'granted' ? 'settings.permission.granted' : permission === 'denied' @@ -904,7 +997,7 @@ window.__ModuleLoader__.load({ : supported ? 'settings.permission.default' : 'settings.permission.unsupported' - const statusText = snapshot.promptError === '' + const permissionText = snapshot.promptError === '' ? `${tr(statusKey)}${permission === 'denied' || !supported ? ` · ${tr(`settings.permission.hint.${props.platform}`)}` : ''}` : snapshot.promptError const health = snapshot.health @@ -915,39 +1008,47 @@ window.__ModuleLoader__.load({ : health.state === 'error' ? tr('settings.health.error', { message: health.message }) : tr('settings.health.starting') + const healthFailed = health.state !== 'watching' && health.state !== 'starting' return h(React.Fragment, null, h('style', null, CSS), - h('div', { className: 'dsn-row' }, - h('div', { className: 'dsn-row-text' }, - h('div', { className: 'dsn-row-title' }, tr('settings.title')), - h('div', { className: 'dsn-row-desc' }, tr('settings.description')), - h('div', { - className: `dsn-status${failed ? ' dsn-status-error' : ''}`, - role: failed ? 'alert' : 'status', - }, statusText), - h('div', { - className: `dsn-status${health.state === 'watching' || health.state === 'starting' ? '' : ' dsn-status-error'}`, - role: health.state === 'watching' || health.state === 'starting' ? 'status' : 'alert', - }, healthText), - h('div', { className: 'dsn-kinds' }, - h('span', null, tr('settings.kinds.label')), - KINDS.map((kind) => h('span', { className: 'dsn-kind', key: kind }, - h('span', null, tr(`settings.kind.${kind}`)), - h('button', { - type: 'button', - role: 'switch', - className: 'dsn-switch', - 'aria-checked': snapshot.kinds[kind] === true, - 'aria-label': tr(`settings.kind.${kind}`), - disabled: !supported, - onClick: () => props.setKind(kind, snapshot.kinds[kind] !== true), - }, h('span', { className: 'dsn-thumb' })))))), - h('button', { - type: 'button', - className: 'dsn-button', - disabled: !supported, - onClick: permission === 'granted' ? props.test : props.ask, - }, tr(!supported ? 'settings.action.unsupported' : permission === 'granted' ? 'settings.action.test' : 'settings.action.allow')))) + h('div', { className: 'dsn-sections' }, + h('section', { className: 'dsn-section' }, + h('h3', { className: 'dsn-section-title' }, tr('config.title')), + h('p', { className: 'dsn-section-desc' }, tr('config.note'))), + h('section', { className: 'dsn-section' }, + h('h3', { className: 'dsn-section-title' }, tr('config.section.kinds')), + KINDS.map((kind) => h(KindRow, { + key: kind, + label: tr(`settings.kind.${kind}`), + checked: snapshot.kinds[kind] === true, + disabled: false, + onToggle: () => props.setKind(kind, snapshot.kinds[kind] !== true), + })), + h('p', { className: 'dsn-section-desc' }, tr('config.saveNote'))), + h('section', { className: 'dsn-section' }, + h('h3', { className: 'dsn-section-title' }, tr('config.section.permission')), + h('div', { className: 'dsn-row' }, + h('div', { className: 'dsn-row-text' }, + h('p', { + className: `dsn-status${failed ? ' dsn-status-error' : ''}`, + role: failed ? 'alert' : 'status', + }, permissionText)), + h('button', { + type: 'button', + className: 'dsn-button', + disabled: !supported, + onClick: permission === 'granted' ? props.test : props.ask, + }, tr(!supported + ? 'settings.action.unsupported' + : permission === 'granted' ? 'settings.action.test' : 'settings.action.allow')))), + h('section', { className: 'dsn-section' }, + h('h3', { className: 'dsn-section-title' }, tr('config.section.status')), + h('div', { className: 'dsn-row' }, + h('div', { className: 'dsn-row-text' }, + h('p', { + className: `dsn-status${healthFailed ? ' dsn-status-error' : ''}`, + role: healthFailed ? 'alert' : 'status', + }, healthText)))))) } // ---------------------------------------------------------- registration @@ -1002,10 +1103,14 @@ window.__ModuleLoader__.load({ }), }, ToastLayer)) - ctx.slots.inject('settings.general.item', () => ctx.slots.register({ - name: 'settings.general.item', - id: NS, - order: 97, + // This plugin's configuration lives on its own page in the plugin manager, + // keyed by this package's name — the seat the shipped experimental bundle + // uses for its own settings, and the one the plugin page renders between the + // bundle's description and its rows. It is deliberately NOT a General + // settings row: a plugin's options belong to the plugin. + ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({ + name: 'plugins.bundle.config', + key: PACKAGE_NAME, locale: NS, inject: () => ({ store, @@ -1014,7 +1119,7 @@ window.__ModuleLoader__.load({ test: sendTest, setKind: setKindEnabled, }), - }, SettingsRow)) + }, ConfigSection)) // The observer lives in the frame-wide overlay, NOT in `sidebar.panellist`. // diff --git a/package.json b/package.json index e1d119e..45246e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dsh-plugin/session-notify", - "version": "1.0.2", + "version": "1.0.3", "private": true, "type": "module", "description": "会话完成、需要授权、需要回答时提醒你:窗口不在前台用系统通知,窗口在前台用应用内轻弹窗。",