Compare commits
1
Commits
81542d96fe
..
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f38b7ea3c |
+11
@@ -0,0 +1,11 @@
|
||||
# <emoji> <type>[(scope)][!]: <中文描述,一句话,不加句号>
|
||||
# 一条提交信息只有这一行,不写正文,也不写脚注。
|
||||
# 破坏性变更只用 ! 标记,例如:♻️ refactor!: 改掉了某某行为
|
||||
# 需要交代背景时,把说明写进 README.md、CHANGELOG.md、CONTRIBUTING.md 或代码注释。
|
||||
#
|
||||
# 类型与 emoji:feat ✨ / fix 🐛 / docs 📝 / refactor ♻️ / perf ⚡️ /
|
||||
# test ✅ / build 📦️ / ci 💚 / chore 🔧 / revert ⏪️
|
||||
# 作用域(可选):client 浏览器半 / host 宿主半
|
||||
# 例:✨ feat(client): 后台走系统通知,前台走应用内轻弹窗
|
||||
# 例:🐛 fix(client): 前台判定改为现读可见性
|
||||
# 例:📝 docs: 安装说明补充 Git 标签与本地路径两种方式
|
||||
@@ -0,0 +1,35 @@
|
||||
# 变更记录
|
||||
|
||||
版本说明按倒序排列。提交信息遵循 [CONTRIBUTING.md](CONTRIBUTING.md) 的单行规范,因此每次改动"为什么这样改、影响面是什么"记在这里,而不是提交信息里。
|
||||
|
||||
## v1.0.5
|
||||
|
||||
- 修复:**应用在后台时不发系统通知**。前台/后台以前只靠 `window` 的 `focus`/`blur` 事件记住,桌面外壳里 `blur` 可能不到,插件就一直以为窗口在前台,于是走了轻弹窗分支(而用户没在看,表现就是完全没有通知)。现在每次投递都现读 `document.visibilityState` 与 `document.hasFocus()`,任一表示不可见即走系统通知;观察器订阅的事件只是让重算更及时,不再决定通道。
|
||||
- 系统通知构造失败时降级:改用轻弹窗,并把被拒原因写进插件页,不再静默失败。
|
||||
- 插件页新增诊断:窗口当前状态(前台/后台,即会走哪条通道)、观察器健康、最近一次投递的通道与时间;「测试系统通知」按钮直接走系统通道(前台也照发),用来单独验证系统通知是否可用。
|
||||
- 修掉日志前缀重复(`session-notify: session-notify:`)。
|
||||
|
||||
## v1.0.4
|
||||
|
||||
- 配置块去掉重复:插件页顶部已经有 DSH 渲染的插件标题与描述,原配置块又写了一遍标题和几乎一样的说明。现在这一段直接用一句「提醒是怎么送出去的」开头,随后进入设置项。
|
||||
- 移除未使用的字典键 `config.title` / `config.note`,保证字典里没有死键。
|
||||
|
||||
## v1.0.3
|
||||
|
||||
- 设置从「设置 → 通用」移到插件自己的介绍页:注册 `plugins.bundle.config`(key 取包名),与官方 `dsh-experimental-voice-input-bundle` 用的是同一个口子;通用设置里不再有本插件的行。
|
||||
- 应用内轻弹窗改成标题 + 描述两行:标题是提醒类型(会话已完成 / 需要授权 / 需要回答),描述是会话题目与细节;关闭按钮从 18px 放大到 28px 的方形热区,「查看」改成有 hover 背景的文字按钮,整条浮窗 hover 时暂停自动消失。
|
||||
- 三个开关改为存浏览器本地(`localStorage`),重开页面、重装插件都保留;仍然不写 DSH 的配置文件。
|
||||
- 插件页配置分四段:说明、提醒内容(三个开关)、系统通知权限、运行状态。
|
||||
|
||||
## v1.0.2
|
||||
|
||||
- 补上 `ctx.locale.register('session-notify', { zh, en })`:没有注册时 `locale.bind(ns)` 会把 key 原样返回,界面上就显示成 `settings.title` 这样的原始键。
|
||||
- 字典兜底与 locale 兜底同时保留:缺框架的 `t`、或 locale 服务没保存注册,都不会显示原始键。
|
||||
- 快照语言字段改为真实字段 `snapshot.active`。
|
||||
|
||||
## v1.0.1
|
||||
|
||||
- 首个发布版本:会话完成 / 需要授权 / 需要回答三类提醒。
|
||||
- 窗口不在前台走系统通知(Windows / macOS / Linux 同一条渲染进程通道,无平台分支);窗口在前台走应用内轻弹窗;正在看的那个会话完成时不打扰。
|
||||
- 只对「运行中 → 空闲」的转变提醒,同一会话同一轮只报一次,同一待处理请求只报一次;子智能体会话与空白会话跳过;多个会话同时完成有 1.5 秒节流,完成提醒前有 400ms 确认窗口。
|
||||
- 修复:无渲染观察器原先挂在 `sidebar.panellist`,而该 slot 的宿主会把每个条目的 id 当作一个左侧面板按钮,导致左侧多出一行空面板并挤坏侧边栏;现改挂通用浮层 `shell.overlay`。
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
# 提交信息规范
|
||||
|
||||
本仓库的提交信息遵循 [Conventional Commits](https://www.conventionalcommits.org/) 的**首行**结构,并在行首加一个 emoji 做视觉标记。**描述用中文**,类型关键字、作用域保持英文。
|
||||
|
||||
## 格式
|
||||
|
||||
**一条提交信息只有一行**,没有正文,也没有脚注:
|
||||
|
||||
```text
|
||||
<emoji> <type>[(scope)][!]: <中文描述>
|
||||
```
|
||||
|
||||
- `<emoji>`:下面表格里该类型对应的 emoji,后面跟**一个空格**。emoji 是必需的,且必须与本行类型一致——`📝 docs:` 对,`✨ docs:` 不对。
|
||||
- `<type>`:小写英文关键字,见下表。
|
||||
- `(scope)`:可选,改动范围。用 `()` 包住一个简短英文标识,例如 `fix(client)`、`fix(host)`、`docs(ci)`。
|
||||
- `!`:可选,紧跟在 type 或 scope 之后、冒号之前,表示破坏性变更。
|
||||
- `<描述>`:中文,一句话,讲清这次改动做了什么;不换行、不用列表、不加句号。宽度不超过 72(中文字符按 2 个宽度算)。
|
||||
|
||||
**不要写正文,也不要写脚注。** 连 `Refs:` / `Closes:` / `BREAKING CHANGE:` 这类尾注也不写——需要交代的"为什么""影响面""迁移注意事项",写进 [README.md](README.md)、[CHANGELOG.md](CHANGELOG.md) 或本文件,或写进代码注释,让说明跟着代码走,而不是埋在 `git log` 里。
|
||||
|
||||
**破坏性变更只靠 `!` 标记**(例如 `♻️ refactor!: …`)。这一条是对 Conventional Commits 的有意偏离:它要求破坏性变更必须有 `BREAKING CHANGE:` 脚注,本仓库不写脚注,所以判断破坏性变更以 `!` 为准。
|
||||
|
||||
如果确实需要多行说明,说明这次改动不该只用一个提交标题交代——先补文档(这个插件的版本级说明进 [CHANGELOG.md](CHANGELOG.md)),再提交。
|
||||
|
||||
## 类型与 emoji
|
||||
|
||||
| 类型 | emoji | 码位 | 用途 |
|
||||
| --- | --- | --- | --- |
|
||||
| `feat` | ✨ | `U+2728` | 新增功能 |
|
||||
| `fix` | 🐛 | `U+1F41B` | 修复缺陷 |
|
||||
| `docs` | 📝 | `U+1F4DD` | 只改文档 |
|
||||
| `refactor` | ♻️ | `U+267B U+FE0F` | 重构,行为不变 |
|
||||
| `perf` | ⚡️ | `U+26A1 U+FE0F` | 性能优化 |
|
||||
| `test` | ✅ | `U+2705` | 变更测试 |
|
||||
| `build` | 📦️ | `U+1F4E6 U+FE0F` | 构建系统或依赖 |
|
||||
| `ci` | 💚 | `U+1F49A` | CI 配置 |
|
||||
| `chore` | 🔧 | `U+1F527` | 杂项,以上都不属于时用 |
|
||||
| `revert` | ⏪️ | `U+23EA U+FE0F` | 回滚某次提交,正文写 `Refs: <被回滚的提交>` |
|
||||
|
||||
**复制上表里的 emoji,不要手敲。** 带 `U+FE0F` 的那五个是「基础字符 + 变体选择符」两个码位,手敲时很容易只打出前一个字符;对工具来说 `♻`(`U+267B`)和 `♻️`(`U+267B U+FE0F`)是两个不同的字符串,比对会失败。写规范或写脚本时,比较 emoji 前先做一次 NFC 归一化,或把两边都按 `\uFE0F?` 处理。
|
||||
|
||||
## 作用域约定
|
||||
|
||||
这个插件只有一个包,作用域用来区分改动落在哪一半,不是必需的:
|
||||
|
||||
- `client`:浏览器半(`client.js`)—— 通知引擎、轻弹窗、插件页配置、观察器;
|
||||
- `host`:宿主半(`index.js`、`cordis.patch.yml`)—— 目前是空壳,只有它变化时才需要重启 DSH;
|
||||
- 其它临时作用域(如 `deps`、`naming`)按需起,不必登记。
|
||||
|
||||
## 示例
|
||||
|
||||
每条都是一整条提交信息,就这一行:
|
||||
|
||||
```text
|
||||
✨ feat(client): 后台走系统通知,前台走应用内轻弹窗
|
||||
```
|
||||
|
||||
```text
|
||||
🐛 fix(client): 前台判定改为现读可见性,不再只信 blur 事件
|
||||
```
|
||||
|
||||
带作用域与破坏性标记(破坏性变更**没有**脚注,只看 `!`):
|
||||
|
||||
```text
|
||||
♻️ refactor(client)!: 配置从通用设置挪到插件页
|
||||
```
|
||||
|
||||
```text
|
||||
📝 docs: 安装说明补充 Git 标签与本地路径两种方式
|
||||
```
|
||||
|
||||
## 工具链提示
|
||||
|
||||
emoji 在行首是本仓库的有意选择,视觉上整齐。代价是:以类型前缀开头的解析工具(`commitlint`、`semantic-release`、`release-please` 等)会读不到类型。如果以后要接这类工具,有两条路:
|
||||
|
||||
1. 把 emoji 挪到冒号之后(`feat: ✨ 描述`),类型回到行首,规范其余部分不变;
|
||||
2. 保留行首 emoji,给工具写一个剥掉开头 emoji 与空格的预处理。可用的正则(`\p{Extended_Pictographic}` 已覆盖带与不带变体选择符两种写法):
|
||||
|
||||
```text
|
||||
^(?:\p{Extended_Pictographic}\uFE0F?\s+)?(?<type>[a-z]+)(?:\((?<scope>[^)]*)\))?(?<breaking>!)?:\s(?<desc>.+)$
|
||||
```
|
||||
|
||||
## 自查
|
||||
|
||||
`scripts/check-commit-log.mjs` 会按本规范检查现有提交,只报告、不拦提交。除了首行格式,它还会报出**任何带正文或脚注的提交**:
|
||||
|
||||
```bash
|
||||
node scripts/check-commit-log.mjs # 最近 10 条
|
||||
node scripts/check-commit-log.mjs all # 全部
|
||||
DN_SPEC=path/to/CONTRIBUTING.md node scripts/check-commit-log.mjs # 换一份规范文件(可选)
|
||||
```
|
||||
|
||||
它从本文件的类型表里读 emoji 对照表,所以改了表不用改脚本。
|
||||
|
||||
## 启用提交模板(可选)
|
||||
|
||||
`.gitmessage` 是提交信息模板。启用后每次 `git commit` 会带上前缀提示:
|
||||
|
||||
```bash
|
||||
git config commit.template .gitmessage
|
||||
```
|
||||
|
||||
模板整份都是 `#` 开头的注释,git 会自动丢弃,所以直接 `git commit -m` 也不受影响。只对当前仓库生效;换机器要重新执行一次。
|
||||
@@ -19,54 +19,40 @@ Windows / macOS / Linux 三个平台走的是同一条通知通道(渲染进
|
||||
| 状态 | 行为 |
|
||||
| --- | --- |
|
||||
| DSH 窗口**不在前台** | **系统通知**(这是插件唯一能拿到的系统通知通道,三个平台一致)。点通知:窗口回到前台并跳到该会话 |
|
||||
| DSH 窗口在前台,且**不是**你正在看的那个会话 | **应用内轻弹窗**:右上角悬浮,标题是提醒类型、下面一行是会话题目与细节;点「查看」跳过去,6 秒自动消失,鼠标悬停时不消失,Esc 或者 ✕ 关掉 |
|
||||
| DSH 窗口在前台,且**不是**你正在看的那个会话 | **应用内轻弹窗**:右上角悬浮,点「查看」跳过去,6 秒自动消失,鼠标悬停时不消失,Esc 关掉最上面一条 |
|
||||
| DSH 窗口在前台,且就是你**正在看的**那个会话 | 不打扰(你在看,不需要弹) |
|
||||
|
||||
## 设置
|
||||
|
||||
**插件 → 会话通知**(插件自己的介绍页里):
|
||||
**设置 → 通用 → 会话通知**:
|
||||
|
||||
- 三个开关分别控制**完成 / 授权 / 提问**三类提醒(默认全开),状态存在浏览器本地,重装插件不丢;
|
||||
- 系统通知权限状态;未授权时点「允许通知」请求权限(浏览器要求必须由你手动点击才能弹权限框),授权后自动发一条测试通知;权限被系统层关闭时按平台给出开启路径;
|
||||
- 「测试系统通知」直接走系统通知通道(窗口在前台也照发),专门用来验证系统通知本身是否可用;
|
||||
- 「运行状态」一段显示:窗口现在是前台还是后台(决定会走哪条通道)、观察器是否真的收到了会话状态、以及**最近一次投递走的通道与时间**。
|
||||
|
||||
设置放在插件自己的页面里,而不是「设置 → 通用」:它是这个插件的配置,不是 DSH 的通用偏好。页面顶部是 DSH 自己渲染的插件标题与描述,所以这块配置不再重复标题,直接用一句「提醒是怎么送出去的」开头。
|
||||
- 显示系统通知权限状态;
|
||||
- 未授权时点「允许通知」请求权限(浏览器要求必须由你手动点击才能弹权限框),授权后自动发一条测试通知;
|
||||
- 已授权时点「测试通知」随时验证;
|
||||
- 权限被系统层关闭时,按平台给出开启路径(Windows / macOS 的通知设置、Linux 桌面环境的通知设置);
|
||||
- 三个开关分别控制**完成 / 授权 / 提问**三类提醒(默认全开;开关状态存在当前页面内存里,刷新回到默认——本插件不写配置文件)。
|
||||
|
||||
## 安装
|
||||
|
||||
### 1. 从 Git 仓库安装(推荐)
|
||||
|
||||
在 DSH 的 **插件 → 添加插件** 的上方输入框里填:
|
||||
|
||||
```text
|
||||
https://gitea.iwake.top/dsh-plugin/session-notify.git#v1.0.3
|
||||
```
|
||||
|
||||
`#` 后面跟标签或提交,用来锁定版本;不写则取默认分支。跟随 1.x 最新版可以写 `#semver:^1.0.3`。仓库是公开的,不需要凭据,也不用改「安装源」。
|
||||
|
||||
### 2. 本地路径安装
|
||||
|
||||
把仓库克隆或下载到本机,在同一个输入框里填包目录的绝对路径,例如:
|
||||
在 DSH 的 **插件 → 添加插件** 里填本目录的绝对路径即可(`plugin_manager` 也会做同样的安装):
|
||||
|
||||
```text
|
||||
D:\DeepSeek Harness Plugins\dsh-session-notify
|
||||
```
|
||||
|
||||
### 装完之后
|
||||
安装后:
|
||||
|
||||
- **浏览器半**随页面加载,**刷新页面**即生效;
|
||||
- **宿主半**是空壳(不改任何 DSH 状态、不注册服务与路由),只有它变化时才需要完全退出 DSH 再打开;
|
||||
- 本插件没有第三方依赖,不需要 pnpm 下载,也没有构建步骤。
|
||||
- **浏览器半**随页面加载,刷新页面即生效;
|
||||
- **宿主半**为空壳(不改任何 DSH 状态),如需重启才生效,完全退出 DSH 再打开即可;
|
||||
- 本插件没有第三方依赖,不需要 pnpm 下载,也不需要构建步骤。
|
||||
|
||||
卸载:插件页里移除 `@dsh-plugin/session-notify`(它同时是 profile 的一个 bundle)。
|
||||
|
||||
## 平台说明与验证范围
|
||||
|
||||
- **通道是跨平台统一的**:插件的提醒都通过页面(Electron 渲染进程)的 `Notification` 构造器发出,Windows 通知中心 / macOS 通知中心 / Linux 通知守护(libnotify、GNOME、KDE)都由系统把它转成原生通知;应用内轻弹窗是纯 DOM,与平台无关。
|
||||
- **前台/后台的判定不依赖单一信号**:每次都现读页面的可见性与文档焦点(任一为"不可见"就算后台),不靠"记住上次的 blur 事件"——桌面外壳里漏掉一次 blur 曾让插件误判为前台而吃掉提醒(v1.0.5 修)。
|
||||
- **宿主半拿不到系统通知**:DSH Desktop 的宿主进程是纯 Node 进程(不是 Electron 主进程),没有 Electron 的 `Notification` 可用,所以插件的所有提醒都在浏览器半产生——这也正是"三个平台一套代码"的原因。
|
||||
- **已验证**:Windows 上的安装、三个 slot 条目注册、以及 28 项离线断言(接线 / 国际化 / 两种后台信号 / 系统通道被拒时的降级 / 配置页诊断 / 全部投递规则)。
|
||||
- **已验证**:Windows 上的安装、三个 slot 条目注册、以及 22 条投递规则(见下)的离线验证;设置行与轻弹窗的文案/交互按 DSH 自带的 toast 与 switch 组件对齐。
|
||||
- **未验证**:macOS 与 Linux 上的实际弹窗效果本机无法测试。结构上它们与 Windows 共用同一条通道、同一份代码,只有"权限被系统关闭时显示的开启路径"是分平台的。
|
||||
- 提醒只在 DSH 进程运行、页面打开时产生:**DSH 完全退出期间结束的会话不会再补发通知**。
|
||||
|
||||
@@ -86,14 +72,10 @@ D:\DeepSeek Harness Plugins\dsh-session-notify
|
||||
依赖的都是稳定契约:
|
||||
|
||||
- 浏览器半只依赖 **slot 的标准 props**(`useSessions`、`useSessionStatus`)读取会话状态,这是 DSH 官方给插件读会话数据的方式;不轮询、不自己订阅会话事件、不读别的插件的 DOM;
|
||||
- 只往两个官方 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>`,会在该行上多出一个「配置」入口;
|
||||
- 只往两个官方 slot 注册:`settings.general.item`(设置行)与 `shell.overlay`(两个条目:轻弹窗层 + 无渲染的观察器,内容永远是 `null`);
|
||||
- **不要**把"无渲染"条目放进 `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 修订号上打点,已经渲染出来的部件会自动换上文案,不需要刷新;
|
||||
- **前台/后台要现读、不能只靠事件**:桌面外壳里 `blur` 可能不到,只记事件会让插件一直以为在前台而吃掉系统通知(本插件第三版踩过这个坑)。现在每次投递都读 `document.visibilityState` 与 `document.hasFocus()`;
|
||||
- 另外自带一份本地字典兜底:即使拿不到框架的 `t`、或 locale 服务没有保存注册,也会渲染中文/英文文案而不是原始键;
|
||||
- 样式只用主题 token,不 import 任何 `@deepseek-ai/dsh-client-*` 包(规范要求,也是渲染不被上游改动打断的前提);
|
||||
- 宿主半不声明 `inject`、不注册服务、不注册路由;三个开关存浏览器本地,不改 DSH 的配置文件。
|
||||
- 宿主半不声明 `inject`、不注册服务、不注册路由。
|
||||
|
||||
上游若改动 slot 名或 hook 名:注册会静默跳过而不是把页面弄坏,插件会退化成"不提醒";这类情况请按上面的契约名核对。
|
||||
|
||||
@@ -101,14 +83,8 @@ D:\DeepSeek Harness Plugins\dsh-session-notify
|
||||
|
||||
`client.js` 是纯 JavaScript、浏览器端运行,可以在 Node 里用桩模块加载器评估并驱动:
|
||||
|
||||
- 模块接线:插件返回值、注册集合(含"配置挂在插件页""观察器绝不在 `sidebar.*` 里"这两条);
|
||||
- 国际化:字典中英键集合一致且没有死键、插件页与弹窗渲染出的每个字符串都不是原始键、拿不到框架 `t` 时本地字典兜底;
|
||||
- 前台/后台判定:**只给"页面不可见"信号**、或**只给"文档失焦"信号**(都不发 blur 事件)时,都必须走系统通知;
|
||||
- 系统通道被拒时降级:构造器抛错时改用轻弹窗,并在配置页写明被拒;
|
||||
- 配置页诊断:窗口状态、观察器健康、最近一次投递的通道与时间都能渲染;
|
||||
- 投递规则:完成提醒一次、当前会话不打扰、授权/提问各提醒一次、运行中延后、子会话跳过、空白会话跳过、历史不补发等。
|
||||
|
||||
合计 28 项断言。
|
||||
- 模块接线:加载后返回的插件、`inject` 声明、注册集合(含"观察器绝不在 sidebar.* 里"这一条)、以及各组件在空状态 / 权限被拒 / 无 Notification API 下的渲染都不报错;
|
||||
- 投递规则:40 项断言覆盖上面"行为细节"里的每一条(完成提醒一次、当前会话不打扰、后台走系统通知、授权/提问各提醒一次、运行中延后、子会话跳过、历史不补发、开关生效、弹窗自动消失等)。
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ 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. */
|
||||
@@ -73,8 +71,7 @@ window.__ModuleLoader__.load({
|
||||
'settings.permission.hint.mac': '系统设置 → 通知 → DeepSeek Harness',
|
||||
'settings.permission.hint.linux': '在桌面环境的通知设置(GNOME / KDE)中允许 DeepSeek Harness',
|
||||
'settings.action.allow': '允许通知',
|
||||
'settings.action.testSystem': '测试系统通知',
|
||||
'settings.action.testAny': '测试提醒',
|
||||
'settings.action.test': '测试通知',
|
||||
'settings.action.unsupported': '不可用',
|
||||
'settings.permission.promptFailed': '无法请求通知权限:{message}',
|
||||
'settings.health.watching': '正在监听会话状态',
|
||||
@@ -85,22 +82,6 @@ window.__ModuleLoader__.load({
|
||||
'settings.kind.completion': '完成',
|
||||
'settings.kind.approval': '授权',
|
||||
'settings.kind.question': '提问',
|
||||
'config.section.kinds': '提醒内容',
|
||||
'config.section.permission': '系统通知权限',
|
||||
'config.section.status': '运行状态',
|
||||
'config.intro': '提醒都从当前页面发出:窗口不在前台时是系统通知,窗口在前台时是这里的轻弹窗。',
|
||||
'config.saveNote': '开关保存在浏览器本地,重装插件不会丢失。',
|
||||
'config.testHint': '这里的按钮直接走系统通知通道,用来验证系统通知本身是否可用(窗口在前台也照发)。',
|
||||
'config.testAny': '测试提醒',
|
||||
'config.testSystem': '测试系统通知',
|
||||
'config.diag.window': '窗口状态',
|
||||
'config.diag.inFront': '在前台(会走轻弹窗)',
|
||||
'config.diag.away': '不在前台(会走系统通知)',
|
||||
'config.diag.last': '最近一次投递',
|
||||
'config.diag.none': '还没有投递过',
|
||||
'config.diag.system': '系统通知',
|
||||
'config.diag.popup': '应用内轻弹窗',
|
||||
'config.diag.refused': '系统通知被拒绝,改用了轻弹窗',
|
||||
}
|
||||
const en = {
|
||||
'notification.completion': 'Conversation finished',
|
||||
@@ -125,8 +106,7 @@ window.__ModuleLoader__.load({
|
||||
'settings.permission.hint.mac': 'System Settings → Notifications → DeepSeek Harness',
|
||||
'settings.permission.hint.linux': 'Allow DeepSeek Harness in your desktop notification settings (GNOME / KDE)',
|
||||
'settings.action.allow': 'Allow notifications',
|
||||
'settings.action.testSystem': 'Test system notification',
|
||||
'settings.action.testAny': 'Test alert',
|
||||
'settings.action.test': 'Test notification',
|
||||
'settings.action.unsupported': 'Unavailable',
|
||||
'settings.permission.promptFailed': 'Could not request notification permission: {message}',
|
||||
'settings.health.watching': 'Watching session status',
|
||||
@@ -137,64 +117,42 @@ window.__ModuleLoader__.load({
|
||||
'settings.kind.completion': 'Finished',
|
||||
'settings.kind.approval': 'Approval',
|
||||
'settings.kind.question': 'Questions',
|
||||
'config.section.kinds': 'What to notify about',
|
||||
'config.section.permission': 'System notification permission',
|
||||
'config.section.status': 'Status',
|
||||
'config.intro': 'Every alert comes from this page: a system notification while the window is in the background, the light popup here while it is in the foreground.',
|
||||
'config.saveNote': 'The switches are stored in this browser and survive reinstalling the plugin.',
|
||||
'config.testHint': 'The buttons here go straight to the system channel, so you can verify it on its own (they fire even while the window is in front).',
|
||||
'config.testAny': 'Test alert',
|
||||
'config.testSystem': 'Test system notification',
|
||||
'config.diag.window': 'Window',
|
||||
'config.diag.inFront': 'in front (popup is used)',
|
||||
'config.diag.away': 'not in front (system notification is used)',
|
||||
'config.diag.last': 'Last delivery',
|
||||
'config.diag.none': 'nothing delivered yet',
|
||||
'config.diag.system': 'system notification',
|
||||
'config.diag.popup': 'in-app popup',
|
||||
'config.diag.refused': 'system channel refused, popup was used instead',
|
||||
}
|
||||
|
||||
/**
|
||||
* 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`) 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).
|
||||
* `--dsw-shadow-lv3`), the switch copies `Switch.module.css` behavior and
|
||||
* proportion, and the settings row copies the General-section row pattern.
|
||||
* 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: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}
|
||||
.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}
|
||||
@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;height:22px;color:var(--dsw-alias-state-warn-label)}
|
||||
.dsn-toast-icon{display:grid;place-items:center;flex:none;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{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-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-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: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{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:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
||||
.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-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-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}
|
||||
@@ -333,33 +291,13 @@ window.__ModuleLoader__.load({
|
||||
return 'default'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the Harness window is somewhere the user cannot see the app.
|
||||
*
|
||||
* Two independent browser facts are consulted, and ANY of them counts as "not
|
||||
* in the foreground": the page's visibility and the document's focus. They are
|
||||
* read at delivery time rather than remembered from an event, because a missed
|
||||
* blur in the desktop shell made this plugin believe the window was in front
|
||||
* and swallow the alert.
|
||||
* @returns whether the alert must go to the system notification channel.
|
||||
*/
|
||||
function windowIsAway() {
|
||||
try {
|
||||
if (document.visibilityState === 'hidden') return true
|
||||
} catch {
|
||||
/* an unreadable visibility state leaves the focus fact */
|
||||
}
|
||||
try {
|
||||
if (typeof document.hasFocus === 'function') return !document.hasFocus()
|
||||
} catch {
|
||||
/* an unreadable focus state leaves the default below */
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** Read the window's live focus state rather than a cached value. */
|
||||
function currentFocus() {
|
||||
return !windowIsAway()
|
||||
try {
|
||||
return typeof document.hasFocus === 'function' ? document.hasFocus() : true
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/** Focus the window without letting a refusal stop the navigation. */
|
||||
@@ -437,35 +375,10 @@ window.__ModuleLoader__.load({
|
||||
return preview(interaction.displayReason?.text ?? interaction.reason?.text ?? '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's dictionaries with the locale service.
|
||||
*
|
||||
* Without this the service has no entry for the namespace and every
|
||||
* `locale.bind(NS)` lookup answers with the key itself, so the settings row
|
||||
* shows `settings.title` instead of its copy. The typed form takes every
|
||||
* shipped locale in one call, and the older single-locale form stays
|
||||
* supported as a fallback. Registration bumps the locale revision, so
|
||||
* already-rendered entries pick the copy up without a reload.
|
||||
* @param locale - the locale service, or undefined when this profile has none.
|
||||
* @returns a disposer for whichever registrations were installed.
|
||||
*/
|
||||
function registerDictionaries(locale) {
|
||||
if (locale === undefined || typeof locale.register !== 'function') return () => {}
|
||||
const dictionaries = { zh, en }
|
||||
try {
|
||||
return locale.register(NS, dictionaries)
|
||||
} catch {
|
||||
const disposers = Object.entries(dictionaries).map(([id, dict]) => locale.register(NS, id, dict))
|
||||
return () => {
|
||||
for (const dispose of disposers) dispose?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a translate function for one locale service: the service's own bound
|
||||
* namespace first, then this package's dictionaries, then the key itself, so
|
||||
* a missing seat degrades copy instead of rendering.
|
||||
* namespace first, then the current language's dictionary, then the key
|
||||
* itself, so a missing seat degrades copy instead of rendering.
|
||||
* @param locale - the locale service, or undefined when this profile has none.
|
||||
* @returns a translate function with `{ name }` interpolation.
|
||||
*/
|
||||
@@ -474,10 +387,7 @@ window.__ModuleLoader__.load({
|
||||
if (locale !== undefined && typeof locale.bind === 'function') {
|
||||
try {
|
||||
const bound = locale.bind(NS)
|
||||
if (typeof bound === 'function') {
|
||||
const translated = bound(key, params)
|
||||
if (typeof translated === 'string' && translated !== key) return translated
|
||||
}
|
||||
if (typeof bound === 'function') return bound(key, params)
|
||||
} catch {
|
||||
/* a locale service without this namespace still renders the fallback */
|
||||
}
|
||||
@@ -485,7 +395,7 @@ window.__ModuleLoader__.load({
|
||||
let language = ''
|
||||
try {
|
||||
const snapshot = locale?.getSnapshot?.()
|
||||
language = String(snapshot?.active ?? '')
|
||||
language = String(snapshot?.language ?? snapshot?.locale ?? snapshot?.id ?? '')
|
||||
} catch {
|
||||
language = ''
|
||||
}
|
||||
@@ -498,42 +408,6 @@ 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`.
|
||||
@@ -544,14 +418,13 @@ window.__ModuleLoader__.load({
|
||||
|
||||
const store = createStore({
|
||||
permission: notificationPermission(),
|
||||
kinds: readStoredKinds(),
|
||||
kinds: { completion: true, approval: true, question: true },
|
||||
toasts: [],
|
||||
promptError: '',
|
||||
health: { state: 'starting', message: '' },
|
||||
lastDelivery: null,
|
||||
})
|
||||
const notify = (message) => {
|
||||
report(message)
|
||||
report(`session-notify: ${message}`)
|
||||
}
|
||||
/** Every component translates through this: the slot's own seat when the owner supplies one, else the locale service. */
|
||||
const seatFor = (props) => (typeof props.t === 'function' ? props.t : t)
|
||||
@@ -566,6 +439,7 @@ window.__ModuleLoader__.load({
|
||||
live: {
|
||||
list: undefined,
|
||||
status: undefined,
|
||||
focus: true,
|
||||
},
|
||||
}
|
||||
const timers = new Map()
|
||||
@@ -637,18 +511,13 @@ window.__ModuleLoader__.load({
|
||||
timers.delete(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/** Show one light in-app popup. */
|
||||
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,
|
||||
}
|
||||
@@ -676,15 +545,12 @@ window.__ModuleLoader__.load({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise one system notification, tolerating every refusal a browser may give.
|
||||
* @returns the outcome the config page reports, so a refusal is never silent.
|
||||
*/
|
||||
/** Raise one system notification, tolerating every refusal a browser may give. */
|
||||
const systemNotify = (candidate, force) => {
|
||||
const Ctor = globalThis.Notification
|
||||
const permission = notificationPermission()
|
||||
if (permission === 'unsupported') return 'unsupported'
|
||||
if (!force && permission !== 'granted') return 'permission'
|
||||
if (permission === 'unsupported') return false
|
||||
if (!force && permission !== 'granted') return false
|
||||
try {
|
||||
const notice = copyFor(candidate)
|
||||
const options = {
|
||||
@@ -703,10 +569,10 @@ window.__ModuleLoader__.load({
|
||||
/* close is best effort on every platform */
|
||||
}
|
||||
}
|
||||
return 'raised'
|
||||
return true
|
||||
} catch (error) {
|
||||
notify(`system notification failed: ${text(error)}`)
|
||||
return 'threw'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,25 +588,6 @@ window.__ModuleLoader__.load({
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Record what actually happened to the newest alert.
|
||||
*
|
||||
* Everything on the delivery path used to fail invisibly: the alert simply
|
||||
* never appeared, with no way to tell a wrong channel decision from a
|
||||
* refused constructor. The config page shows this record, so the next
|
||||
* question ("did it even try?") has an answer.
|
||||
*/
|
||||
const recordDelivery = (outcome, candidate) => {
|
||||
store.set({
|
||||
...store.getSnapshot(),
|
||||
lastDelivery: {
|
||||
outcome,
|
||||
at: new Date().toISOString().slice(11, 19),
|
||||
title: copyFor(candidate).title,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a queued candidate is still worth delivering. Read from the LIVE
|
||||
* snapshot rather than the one captured when the transition was seen: a
|
||||
@@ -760,12 +607,9 @@ window.__ModuleLoader__.load({
|
||||
|
||||
/**
|
||||
* Deliver one candidate through exactly one channel: the system
|
||||
* notification while the window is away, the light popup while it is in
|
||||
* front, and nothing at all for the conversation on screen.
|
||||
*
|
||||
* The channel decision reads the window state right here, at delivery time,
|
||||
* instead of trusting the state the observer last remembered — that is what
|
||||
* an unreported blur used to defeat.
|
||||
* notification while the window is in the background, the light popup while
|
||||
* it is in the foreground, and nothing at all for the conversation on
|
||||
* screen.
|
||||
*/
|
||||
const deliver = (candidate, ignoreThrottle) => {
|
||||
if (ignoreThrottle !== true) {
|
||||
@@ -773,21 +617,12 @@ window.__ModuleLoader__.load({
|
||||
if (now - state.lastDelivery < THROTTLE_MS) return
|
||||
state.lastDelivery = now
|
||||
}
|
||||
if (!windowIsAway()) {
|
||||
if (isOnScreen(candidate.sessionId, state.live.list)) return
|
||||
showToast(candidate)
|
||||
recordDelivery('popup', candidate)
|
||||
if (state.live.focus) {
|
||||
if (!isOnScreen(candidate.sessionId, state.live.list)) showToast(candidate)
|
||||
return
|
||||
}
|
||||
const outcome = systemNotify(candidate, candidate.test === true)
|
||||
if (outcome === 'raised') {
|
||||
recordDelivery('system', candidate)
|
||||
return
|
||||
}
|
||||
// A test alert still has to reach the user, and so does a real one when
|
||||
// the system channel refuses: the popup is the channel that remains.
|
||||
showToast(candidate)
|
||||
recordDelivery(`system-refused-${outcome}`, candidate)
|
||||
if (systemNotify(candidate, candidate.test === true)) return
|
||||
if (candidate.test === true) showToast(candidate)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -814,13 +649,11 @@ window.__ModuleLoader__.load({
|
||||
* One derivation pass over the client's own session state: remember the
|
||||
* freshest snapshot for the settle tick, compare it against what this page
|
||||
* already observed, emit at most one candidate per transition, and let the
|
||||
* settle tick decide delivery. The window state is deliberately NOT captured
|
||||
* here — the delivery reads it fresh, because it can change inside the
|
||||
* settle window.
|
||||
* settle tick decide delivery.
|
||||
*/
|
||||
const observe = (list, status) => {
|
||||
const observe = (focus, list, status) => {
|
||||
if (list === undefined || status === undefined) return
|
||||
state.live = { list, status }
|
||||
state.live = { list, status, focus }
|
||||
const kinds = store.getSnapshot().kinds
|
||||
for (const sessionId of Object.keys(list.byId ?? {})) {
|
||||
const summary = list.byId[sessionId]
|
||||
@@ -880,36 +713,18 @@ window.__ModuleLoader__.load({
|
||||
|
||||
// --------------------------------------------------------------- actions
|
||||
|
||||
/** Build one test alert that skips the throttle and the "on screen" rule. */
|
||||
const testCandidate = (title) => ({
|
||||
/** Raise one test notification through the channel the current state selects. */
|
||||
const sendTest = () => {
|
||||
const candidate = {
|
||||
kind: 'completion',
|
||||
sessionId: 'test',
|
||||
title,
|
||||
title: t('settings.title'),
|
||||
detail: '',
|
||||
pendingKind: '',
|
||||
test: true,
|
||||
})
|
||||
|
||||
/**
|
||||
* Raise one test alert through whichever channel the window state selects.
|
||||
* Verified from the config page, where the user is looking at the app, so it
|
||||
* normally lands in the popup — the way to prove the system channel is to
|
||||
* press the button in a channel-specific test instead.
|
||||
*/
|
||||
const sendTest = () => {
|
||||
deliver(testCandidate(t('config.testAny')), true)
|
||||
}
|
||||
|
||||
/** Raise the test alert on the system channel specifically, whatever the focus is. */
|
||||
const sendTestSystem = () => {
|
||||
const candidate = testCandidate(t('config.testSystem'))
|
||||
const outcome = systemNotify(candidate, true)
|
||||
if (outcome === 'raised') {
|
||||
recordDelivery('system', candidate)
|
||||
return
|
||||
}
|
||||
if (!currentFocus() && notificationPermission() === 'granted' && systemNotify(candidate, true)) return
|
||||
showToast(candidate)
|
||||
recordDelivery(`system-refused-${outcome}`, candidate)
|
||||
}
|
||||
|
||||
/** Request notification permission inside a user gesture, then report the outcome. */
|
||||
@@ -937,12 +752,10 @@ window.__ModuleLoader__.load({
|
||||
if (notificationPermission() === 'granted') sendTest()
|
||||
}
|
||||
|
||||
/** Toggle one trigger and remember the choice. */
|
||||
/** Toggle one trigger. */
|
||||
const setKindEnabled = (kind, enabled) => {
|
||||
const snapshot = store.getSnapshot()
|
||||
const kinds = { ...snapshot.kinds, [kind]: enabled }
|
||||
writeStoredKinds(kinds)
|
||||
store.set({ ...snapshot, kinds })
|
||||
store.set({ ...snapshot, kinds: { ...snapshot.kinds, [kind]: enabled } })
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------- components
|
||||
@@ -952,27 +765,21 @@ window.__ModuleLoader__.load({
|
||||
return React.useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot)
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to every browser signal that says whether the app is visible:
|
||||
* the window's focus events and the document's visibility change. The value
|
||||
* itself is a boolean, so the observer re-renders once per transition.
|
||||
*/
|
||||
function useWindowState() {
|
||||
/** The window's focus state as a React value, kept current by the DOM's own events. */
|
||||
function useFocus() {
|
||||
const subscribe = React.useCallback((listener) => {
|
||||
try {
|
||||
window.addEventListener('focus', listener)
|
||||
window.addEventListener('blur', listener)
|
||||
document.addEventListener('visibilitychange', listener)
|
||||
} catch {
|
||||
return () => {}
|
||||
}
|
||||
return () => {
|
||||
window.removeEventListener('focus', listener)
|
||||
window.removeEventListener('blur', listener)
|
||||
document.removeEventListener('visibilitychange', listener)
|
||||
}
|
||||
}, [])
|
||||
return React.useSyncExternalStore(subscribe, () => !windowIsAway(), () => true)
|
||||
return React.useSyncExternalStore(subscribe, currentFocus, () => true)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -980,13 +787,9 @@ window.__ModuleLoader__.load({
|
||||
* how a plugin reaches the session hooks without occupying visible UI. It
|
||||
* renders `null`, and any failure in its own derivation is contained here so
|
||||
* a slot entry can never crash.
|
||||
*
|
||||
* It subscribes to the window state only so a foreground/background change
|
||||
* re-derives promptly; the delivery itself re-reads that state, so a missed
|
||||
* event can no longer pick the wrong channel.
|
||||
*/
|
||||
function NotifyObserver(props) {
|
||||
useWindowState()
|
||||
const focus = useFocus()
|
||||
const useSessions = props.useSessions
|
||||
const useSessionStatus = props.useSessionStatus
|
||||
const select = React.useCallback((snapshot) => snapshot, [])
|
||||
@@ -1002,7 +805,7 @@ window.__ModuleLoader__.load({
|
||||
applyHealth(store, { state: 'starting', message: '' })
|
||||
return
|
||||
}
|
||||
observe(list, status)
|
||||
observe(focus, list, status)
|
||||
applyHealth(store, { state: 'watching', message: '' })
|
||||
} catch (error) {
|
||||
applyHealth(store, { state: 'error', message: text(error) })
|
||||
@@ -1042,10 +845,7 @@ 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('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('span', { className: 'dsn-toast-text' }, toast.body),
|
||||
h('button', {
|
||||
type: 'button',
|
||||
className: 'dsn-toast-action',
|
||||
@@ -1059,43 +859,16 @@ window.__ModuleLoader__.load({
|
||||
className: 'dsn-toast-close',
|
||||
'aria-label': tr('toast.dismiss'),
|
||||
onClick: () => props.dismiss(toast.id),
|
||||
}, h(CloseIcon, { size: 14 })))))))
|
||||
}, h(CloseIcon, { size: 12 }))))))
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
/** The General-settings row: permission state, one action, per-trigger switches. */
|
||||
function SettingsRow(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'
|
||||
@@ -1103,7 +876,7 @@ window.__ModuleLoader__.load({
|
||||
: supported
|
||||
? 'settings.permission.default'
|
||||
: 'settings.permission.unsupported'
|
||||
const permissionText = snapshot.promptError === ''
|
||||
const statusText = snapshot.promptError === ''
|
||||
? `${tr(statusKey)}${permission === 'denied' || !supported ? ` · ${tr(`settings.permission.hint.${props.platform}`)}` : ''}`
|
||||
: snapshot.promptError
|
||||
const health = snapshot.health
|
||||
@@ -1114,69 +887,39 @@ 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-sections' },
|
||||
// The page header already shows this bundle's title and description, so
|
||||
// this section opens with what the header cannot say: how alerts are
|
||||
// carried, and what this form changes.
|
||||
h('section', { className: 'dsn-section' },
|
||||
h('p', { className: 'dsn-section-desc' }, tr('config.intro'))),
|
||||
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', {
|
||||
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',
|
||||
}, permissionText)),
|
||||
}, 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.testSystem : props.ask,
|
||||
}, tr(!supported
|
||||
? 'settings.action.unsupported'
|
||||
: permission === 'granted' ? 'settings.action.testSystem' : 'settings.action.allow'))),
|
||||
h('p', { className: 'dsn-section-desc' }, tr('config.testHint'))),
|
||||
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' }, `${tr('config.diag.window')}: ${tr(windowIsAway() ? 'config.diag.away' : 'config.diag.inFront')}`),
|
||||
h('p', {
|
||||
className: `dsn-status${healthFailed ? ' dsn-status-error' : ''}`,
|
||||
role: healthFailed ? 'alert' : 'status',
|
||||
}, healthText),
|
||||
h('p', { className: 'dsn-status' }, deliveryText(tr))),
|
||||
h('button', {
|
||||
type: 'button',
|
||||
className: 'dsn-button',
|
||||
onClick: props.testAny,
|
||||
}, tr('settings.action.testAny'))))))
|
||||
}
|
||||
|
||||
/** Describe the newest alert's fate in one line. */
|
||||
function deliveryText(tr) {
|
||||
const last = store.getSnapshot().lastDelivery
|
||||
if (last === null || last === undefined) return tr('config.diag.none')
|
||||
const outcome = last.outcome.startsWith('system-refused')
|
||||
? tr('config.diag.refused')
|
||||
: last.outcome === 'system'
|
||||
? tr('config.diag.system')
|
||||
: tr('config.diag.popup')
|
||||
return `${tr('config.diag.last')}: ${last.at} · ${outcome} · ${last.title}`
|
||||
onClick: permission === 'granted' ? props.test : props.ask,
|
||||
}, tr(!supported ? 'settings.action.unsupported' : permission === 'granted' ? 'settings.action.test' : 'settings.action.allow'))))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------- registration
|
||||
@@ -1208,7 +951,6 @@ window.__ModuleLoader__.load({
|
||||
}
|
||||
}
|
||||
|
||||
ctx.effect(() => registerDictionaries(locale), 'session-notify: dictionaries')
|
||||
ctx.effect(() => installBridges(), 'session-notify: window focus')
|
||||
ctx.effect(() => () => {
|
||||
disposed = true
|
||||
@@ -1231,24 +973,19 @@ window.__ModuleLoader__.load({
|
||||
}),
|
||||
}, ToastLayer))
|
||||
|
||||
// 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,
|
||||
ctx.slots.inject('settings.general.item', () => ctx.slots.register({
|
||||
name: 'settings.general.item',
|
||||
id: NS,
|
||||
order: 97,
|
||||
locale: NS,
|
||||
inject: () => ({
|
||||
store,
|
||||
platform: platformKey(),
|
||||
ask: requestPermission,
|
||||
testAny: sendTest,
|
||||
testSystem: sendTestSystem,
|
||||
test: sendTest,
|
||||
setKind: setKindEnabled,
|
||||
}),
|
||||
}, ConfigSection))
|
||||
}, SettingsRow))
|
||||
|
||||
// The observer lives in the frame-wide overlay, NOT in `sidebar.panellist`.
|
||||
//
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@dsh-plugin/session-notify",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "会话完成、需要授权、需要回答时提醒你:窗口不在前台用系统通知,窗口在前台用应用内轻弹窗。",
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// Checks existing commits against the CONTRIBUTING.md spec. The spec allows one
|
||||
// line only, so a subject must both parse (emoji + type + Chinese description)
|
||||
// and be the whole message: any body or footer is reported too.
|
||||
//
|
||||
// This is a reporting tool, not a hook: it never blocks a commit.
|
||||
//
|
||||
// Usage:
|
||||
// node scripts/check-commit-log.mjs # newest 10 commits
|
||||
// node scripts/check-commit-log.mjs 50 # newest 50 commits
|
||||
// node scripts/check-commit-log.mjs all # every commit
|
||||
// DSD_SPEC=path/to/CONTRIBUTING.md node scripts/check-commit-log.mjs
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const specPath = process.env.DN_SPEC ?? resolve(repoRoot, 'CONTRIBUTING.md')
|
||||
const doc = readFileSync(specPath, 'utf8')
|
||||
const count = process.argv[2] ?? '10'
|
||||
|
||||
/** The regex the spec documents for a subject line. */
|
||||
const SUBJECT = new RegExp(
|
||||
'^(?:\\p{Extended_Pictographic}\\uFE0F?\\s+)?' +
|
||||
'(?<type>[a-z]+)' +
|
||||
'(?:\\((?<scope>[^)]*)\\))?' +
|
||||
'(?<breaking>!)?' +
|
||||
':\\s(?<desc>.+)$',
|
||||
'u',
|
||||
)
|
||||
|
||||
// The spec's table is the single source of truth for the type → emoji mapping,
|
||||
// so a table edit cannot drift from what this script checks.
|
||||
const emojiOfType = new Map()
|
||||
for (const row of doc.split('\n').filter((line) => /^\| `[a-z]+` \| /.test(line))) {
|
||||
const cells = row.split('|').map((cell) => cell.trim())
|
||||
emojiOfType.set(cells[1].replaceAll('`', ''), cells[2])
|
||||
}
|
||||
if (emojiOfType.size === 0) throw new Error(`${specPath} has no type table to read`)
|
||||
|
||||
/** Strip the variation selector, so '♻' and '♻️' compare equal. */
|
||||
const base = (text) => text.replace(/\uFE0F/g, '')
|
||||
/** Display width, counting anything above U+2000 as double. */
|
||||
const widthOf = (text) => [...text].reduce((n, c) => n + (c.codePointAt(0) > 0x2000 ? 2 : 1), 0)
|
||||
|
||||
// %B is the raw message body, so a record can hold several lines: a record ends
|
||||
// at the next hash that starts a line, which is what this splits on.
|
||||
const range = count === 'all' ? [] : [`-${Number(count)}`]
|
||||
const raw = execFileSync('git', ['log', ...range, '--format=%h%x09%B%x00'], {
|
||||
encoding: 'utf8',
|
||||
cwd: repoRoot,
|
||||
})
|
||||
|
||||
const commits = raw.split('\0').map((chunk) => chunk.replace(/^\n+/, '')).filter((chunk) => chunk.trim() !== '')
|
||||
|
||||
let problems = 0
|
||||
for (const chunk of commits) {
|
||||
const tab = chunk.indexOf('\t')
|
||||
const hash = chunk.slice(0, tab)
|
||||
const message = chunk.slice(tab + 1).replace(/\n+$/, '')
|
||||
const lines = message.split('\n')
|
||||
const subject = lines[0]
|
||||
const extra = lines.slice(1).filter((line) => line.trim() !== '')
|
||||
const notes = []
|
||||
|
||||
const match = SUBJECT.exec(subject)
|
||||
if (match === null) {
|
||||
notes.push('首行缺少类型前缀,或整体格式不是 <emoji> <type>[(scope)][!]: <描述>')
|
||||
} else {
|
||||
const expected = emojiOfType.get(match.groups.type)
|
||||
const lead = [...subject][0]
|
||||
if (expected === undefined) notes.push(`类型不在规范表里:${match.groups.type}`)
|
||||
else if (base(lead) !== base(expected)) notes.push(`类型 ${match.groups.type} 的 emoji 应为 ${expected},实际是 ${lead}`)
|
||||
const width = widthOf(subject)
|
||||
if (width > 72) notes.push(`首行宽度 ${width},超过 72`)
|
||||
if (/[。.]$/.test(subject)) notes.push('首行结尾不应有句号')
|
||||
}
|
||||
if (extra.length > 0) notes.push(`带了 ${extra.length} 行正文或脚注,规范要求只有一行`)
|
||||
|
||||
if (notes.length > 0) problems += 1
|
||||
const mark = notes.length === 0 ? 'ok ' : 'FAIL'
|
||||
console.log(` ${mark} ${hash} ${notes.length === 0 ? '' : notes.join(';') + ' — '}${subject}`)
|
||||
}
|
||||
|
||||
console.log(problems === 0
|
||||
? `\n检查了 ${commits.length} 条提交,全部符合规范`
|
||||
: `\n检查了 ${commits.length} 条提交,其中 ${problems} 条不符合规范(规范文件:${specPath})`)
|
||||
process.exit(problems === 0 ? 0 : 1)
|
||||
Reference in New Issue
Block a user