dsh-meow-notifier 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/client.js +464 -0
- package/cordis.patch.yml +5 -0
- package/host.js +822 -0
- package/icon.svg +13 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oliver-314
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-meow-notifier
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/Oliver-314/dsh-MeoW-notifier/actions/workflows/test.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/dsh-meow-notifier)
|
|
5
|
+
[](https://github.com/Oliver-314/dsh-MeoW-notifier/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
把 DeepSeek Harness 的关键状态通过 [MeoW](https://www.chuckfang.com/MeoW/api_doc.html) 推送到手机,离开电脑时也能收到项目的最新消息。
|
|
8
|
+
|
|
9
|
+
- **任务完成 / 出错 / 中止**:一轮工作结束、Agent 回到空闲时发送。
|
|
10
|
+
- **等待你确认**:工具调用需要批准且等待超过 2 秒时发送(自动批准或秒答不会打扰)。
|
|
11
|
+
- **AI 向你提问**:`ask_user_question` 等待回答时发送。
|
|
12
|
+
- 插件挂在 profile 层,**所有工作区、所有会话**(含新开会话)都生效。
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
要求:DeepSeek Harness 0.2.x,Node 22+。
|
|
17
|
+
|
|
18
|
+
从 npm 安装:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
dsh plugin add dsh-meow-notifier
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
从源码安装(本地目录会被链接,修改后需重启 Harness 加载 Host 代码):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/Oliver-314/dsh-MeoW-notifier.git
|
|
28
|
+
dsh plugin add ./dsh-MeoW-notifier
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
也可以在 Web 界面的 **插件(Plugins) → Add plugin** 里填包名或本地目录,安装后启用 `MeoW Notifications`。
|
|
32
|
+
|
|
33
|
+
## 配置
|
|
34
|
+
|
|
35
|
+
1. 打开侧边栏 **插件(Plugins) → Installed plugins → MeoW Notifications**。
|
|
36
|
+
2. 填写 MeoW App 里注册的**昵称**,按需修改分类(最多 10 个字)、三类通知开关和**消息格式**。
|
|
37
|
+
3. 点 **保存**,再点 **发送测试通知** 确认手机能收到。
|
|
38
|
+
4. 页面底部会显示“最近一次通知”的结果,便于排查。
|
|
39
|
+
|
|
40
|
+
### 消息格式
|
|
41
|
+
|
|
42
|
+
手机通知大约能显示 180 个字符,页面提供三档:
|
|
43
|
+
|
|
44
|
+
| 格式 | 内容 | 长度 |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| 完整版 | 会话、项目 + 完整回复摘要 | 最长 260 字,可能被客户端截断 |
|
|
47
|
+
| 精简版(默认) | `已完成 · 会话` + 项目 + 一句话摘要 | 正文 ≤ 160 字 |
|
|
48
|
+
| 仅状态 | `已完成 · 会话` | 约 10–20 字 |
|
|
49
|
+
|
|
50
|
+
状态词包括:`已完成 / 出错 / 已中止 / 超出长度上限 / 被阻断 / 等待确认 / 需要回答`。精简版的摘要是本地取回复的第一句话,不调用模型,不产生额外费用。
|
|
51
|
+
|
|
52
|
+
设置保存在 `$DSH_HOME/meow-notify/state.json`(默认 `~/.dsh/meow-notify/state.json`),不会上传除昵称外的任何内容。
|
|
53
|
+
|
|
54
|
+
## 工作原理
|
|
55
|
+
|
|
56
|
+
插件是一个 DSH bundle,包含两部分:
|
|
57
|
+
|
|
58
|
+
| 部分 | 文件 | 职责 |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| Host 半 | `host.js` | 监听 `agent/status`、`approval/request`、`user-questions/request`,组装消息并调用 MeoW API;在 `/meow-notify/api/` 下提供设置读写和测试发送的路由 |
|
|
61
|
+
| 浏览器半 | `client.js` | 在插件页注册 `plugins.bundle.config`,渲染设置表单(React 来自浏览器模块表,样式使用 `--dsw-alias-*` 主题变量) |
|
|
62
|
+
|
|
63
|
+
Host 半是纯 ESM,浏览器半是 `window.__ModuleLoader__` 工厂格式,**没有构建步骤,也没有运行时依赖**。
|
|
64
|
+
|
|
65
|
+
发送队列串行执行:最小间隔 4.5 秒、每小时最多 60 条、每天最多 1000 条;只在 JSON 业务状态 `status=200` 且 `data=true` 时判定成功,超时、断连或 `500` 不做自动重试(推送不是幂等操作)。仅当 Harness 对外公布的地址不是 `127.0.0.1` / `localhost` 时,通知才附带打开链接。
|
|
66
|
+
|
|
67
|
+
## 已知限制
|
|
68
|
+
|
|
69
|
+
- MeoW 每天允许输错昵称 3 次,超过会封禁 IP 一天;昵称务必与 App 中完全一致。
|
|
70
|
+
- 尽量避免通过多人共享的公共出口 IP 发送:同一 IP 向多个昵称推送可能被判定为攻击流量。
|
|
71
|
+
- 当前会话审批策略为 `never` 时工具调用会被自动拒绝,不会产生“等待确认”提醒;需要把权限策略调到会询问的模式。
|
|
72
|
+
- MeoW 只支持纯文本和 HTML,不支持 Markdown;本插件只发送纯文本。
|
|
73
|
+
|
|
74
|
+
## 开发
|
|
75
|
+
|
|
76
|
+
没有依赖需要安装。克隆后直接跑测试:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm test
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
或者分别运行:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
node test/host.test.mjs # 事件、消息组装、限流、发送队列
|
|
86
|
+
node test/style.test.mjs # 三种消息格式的长度与内容
|
|
87
|
+
node test/client.test.mjs # 设置页渲染冒烟
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
修改 Host 代码后需要重启 Harness 才会加载新模块(Node ESM 缓存);浏览器半由客户端按文件变更刷新。
|
|
91
|
+
|
|
92
|
+
发布说明见 [RELEASING.md](https://github.com/Oliver-314/dsh-MeoW-notifier/blob/main/RELEASING.md),贡献指南见 [CONTRIBUTING.md](https://github.com/Oliver-314/dsh-MeoW-notifier/blob/main/CONTRIBUTING.md),安全问题见 [SECURITY.md](https://github.com/Oliver-314/dsh-MeoW-notifier/blob/main/SECURITY.md)。
|
|
93
|
+
|
|
94
|
+
## English
|
|
95
|
+
|
|
96
|
+
Push DeepSeek Harness task completion, approval, and question alerts to your phone through MeoW.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
dsh plugin add dsh-meow-notifier
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Open **Plugins → MeoW Notifications**, enter the nickname registered in the MeoW app, save, and send a test notification. Completion messages carry the session title, project folder, and the last reply; approvals and questions wait 2 and 1.5 seconds so instant answers stay quiet.
|
|
103
|
+
|
|
104
|
+
Phone clients show roughly 180 characters, so the page offers three formats: **Full**, **Compact** (default, one sentence, ≤ 160 characters), and **Status only** (for example `已完成 · 重构登录页`). The summary is local text processing and never calls a model. Notifications are queued at 4.5-second intervals and capped at 60 per hour.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
[MIT](https://github.com/Oliver-314/dsh-MeoW-notifier/blob/main/LICENSE)
|
package/client.js
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MeoW notification settings page (browser half).
|
|
3
|
+
*
|
|
4
|
+
* The copy for this file is intentionally dependency free: React comes from the
|
|
5
|
+
* browser module table, theme styling comes from `--dsw-alias-*` tokens, and the
|
|
6
|
+
* page talks to its own Host half through two exact routes under
|
|
7
|
+
* `/meow-notify/api/`. It renders on the bundle's page under Plugins.
|
|
8
|
+
*/
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-meow-notifier',
|
|
11
|
+
factory: (require) => {
|
|
12
|
+
const React = require('react')
|
|
13
|
+
const h = React.createElement
|
|
14
|
+
|
|
15
|
+
/** Slot key: a bundle's own configuration is dispatched by package name. */
|
|
16
|
+
const PKG = 'dsh-meow-notifier'
|
|
17
|
+
/** Locale namespace owned by this plugin. */
|
|
18
|
+
const NS = 'meowNotify'
|
|
19
|
+
|
|
20
|
+
const zh = {
|
|
21
|
+
lead: 'AI 完成任务、等待你确认或需要你回答时,通过 MeoW 推送到手机。',
|
|
22
|
+
nickname: 'MeoW 昵称',
|
|
23
|
+
nicknameHint: '填写 MeoW App 中注册的昵称;留空则不会发送任何通知。昵称需完全一致,多次输错可能导致 IP 被封禁。',
|
|
24
|
+
category: '通知分类',
|
|
25
|
+
categoryHint: '可选,最多 10 个字,例如 DSH。',
|
|
26
|
+
events: '通知时机',
|
|
27
|
+
done: '任务完成时',
|
|
28
|
+
doneHint: '一轮工作结束后发送,并附上最后一段回复。',
|
|
29
|
+
approval: '需要你确认时',
|
|
30
|
+
approvalHint: '工具调用等待你批准超过 2 秒后发送。',
|
|
31
|
+
question: 'AI 向你提问时',
|
|
32
|
+
questionHint: 'AI 请你选择或补充信息时发送。',
|
|
33
|
+
style: '消息格式',
|
|
34
|
+
styleHint: '手机端通知约 180 字,精简版控制在 180 字以内;完整版可能被截断。',
|
|
35
|
+
styleFull: '完整版',
|
|
36
|
+
styleCompact: '精简版',
|
|
37
|
+
styleStatus: '仅状态',
|
|
38
|
+
styleFullHint: '标题、项目与完整摘要',
|
|
39
|
+
styleCompactHint: '状态、会话与一句话摘要',
|
|
40
|
+
styleStatusHint: '只发“已完成 / 等待确认”等状态',
|
|
41
|
+
save: '保存',
|
|
42
|
+
saving: '保存中…',
|
|
43
|
+
test: '发送测试通知',
|
|
44
|
+
testing: '发送中…',
|
|
45
|
+
saved: '设置已保存。',
|
|
46
|
+
needNickname: '请先填写 MeoW 昵称。',
|
|
47
|
+
testSent: '测试通知已发送,请查看手机。',
|
|
48
|
+
testFailed: '发送失败:{error}',
|
|
49
|
+
saveFailed: '保存失败:{error}',
|
|
50
|
+
loadFailed: '读取设置失败:{error}',
|
|
51
|
+
retry: '重试',
|
|
52
|
+
loading: '正在读取设置…',
|
|
53
|
+
lastSend: '最近一次通知:{text}',
|
|
54
|
+
lastOk: '发送成功',
|
|
55
|
+
lastFail: '失败({error})',
|
|
56
|
+
privacy: '昵称只保存在本机;通知通过 MeoW 官方接口发送。',
|
|
57
|
+
dirty: '有未保存的修改',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const en = {
|
|
61
|
+
lead: 'When the AI finishes a task, waits for your approval, or needs an answer, MeoW pushes it to your phone.',
|
|
62
|
+
nickname: 'MeoW nickname',
|
|
63
|
+
nicknameHint: 'The nickname registered in the MeoW app. Leave it blank to disable every notification. It must match exactly; repeated wrong nicknames can get this IP banned.',
|
|
64
|
+
category: 'Notification category',
|
|
65
|
+
categoryHint: 'Optional, up to 10 characters, for example DSH.',
|
|
66
|
+
events: 'When to notify',
|
|
67
|
+
done: 'Task finished',
|
|
68
|
+
doneHint: 'Sent when a run settles, with the last reply attached.',
|
|
69
|
+
approval: 'Waiting for approval',
|
|
70
|
+
approvalHint: 'Sent when a tool call has waited for your decision for over 2 seconds.',
|
|
71
|
+
question: 'AI asks a question',
|
|
72
|
+
questionHint: 'Sent when the AI wants you to choose or add information.',
|
|
73
|
+
style: 'Message format',
|
|
74
|
+
styleHint: 'Phone notifications show about 180 characters. Compact stays within that budget; full may be cut.',
|
|
75
|
+
styleFull: 'Full',
|
|
76
|
+
styleCompact: 'Compact',
|
|
77
|
+
styleStatus: 'Status only',
|
|
78
|
+
styleFullHint: 'Title, project, and the whole summary',
|
|
79
|
+
styleCompactHint: 'Status, session, and one sentence',
|
|
80
|
+
styleStatusHint: 'Only “done / waiting” and the session',
|
|
81
|
+
save: 'Save',
|
|
82
|
+
saving: 'Saving…',
|
|
83
|
+
test: 'Send test notification',
|
|
84
|
+
testing: 'Sending…',
|
|
85
|
+
saved: 'Settings saved.',
|
|
86
|
+
needNickname: 'Enter your MeoW nickname first.',
|
|
87
|
+
testSent: 'Test notification sent. Check your phone.',
|
|
88
|
+
testFailed: 'Send failed: {error}',
|
|
89
|
+
saveFailed: 'Save failed: {error}',
|
|
90
|
+
loadFailed: 'Could not read settings: {error}',
|
|
91
|
+
retry: 'Retry',
|
|
92
|
+
loading: 'Reading settings…',
|
|
93
|
+
lastSend: 'Last notification: {text}',
|
|
94
|
+
lastOk: 'delivered',
|
|
95
|
+
lastFail: 'failed ({error})',
|
|
96
|
+
privacy: 'The nickname stays on this machine; notifications go through the official MeoW API.',
|
|
97
|
+
dirty: 'Unsaved changes',
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const CSS = `
|
|
101
|
+
.meow-page{display:flex;flex-direction:column;gap:14px;width:100%;max-width:760px;color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5}
|
|
102
|
+
.meow-lead{margin:0;color:var(--dsw-alias-label-secondary)}
|
|
103
|
+
.meow-field{display:flex;flex-direction:column;gap:6px}
|
|
104
|
+
.meow-label{font-size:13px;color:var(--dsw-alias-label-primary)}
|
|
105
|
+
.meow-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
106
|
+
.meow-input{height:34px;width:100%;max-width:360px;padding:0 10px;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;outline:none}
|
|
107
|
+
.meow-input:focus-visible{border-color:var(--dsw-alias-brand-primary);box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-brand-primary) 18%,transparent)}
|
|
108
|
+
.meow-row{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}
|
|
109
|
+
.meow-row-text{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
110
|
+
.meow-section{margin:4px 0 0;font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary)}
|
|
111
|
+
.meow-switch{position:relative;flex:none;width:36px;height:20px;border:none;border-radius:10px;background:var(--dsw-alias-border-l2);cursor:pointer;padding:0;transition:background .15s ease}
|
|
112
|
+
.meow-switch[aria-checked="true"]{background:var(--dsw-alias-brand-primary)}
|
|
113
|
+
.meow-switch:disabled{opacity:.5;cursor:default}
|
|
114
|
+
.meow-switch-knob{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:transform .15s ease;box-shadow:0 1px 2px rgba(0,0,0,.2)}
|
|
115
|
+
.meow-switch[aria-checked="true"] .meow-switch-knob{transform:translateX(16px)}
|
|
116
|
+
.meow-seg{display:inline-flex;flex:none;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;overflow:hidden}
|
|
117
|
+
.meow-seg-btn{height:28px;padding:0 12px;border:none;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;cursor:pointer}
|
|
118
|
+
.meow-seg-btn+.meow-seg-btn{border-left:.5px solid var(--dsw-alias-border-l2)}
|
|
119
|
+
.meow-seg-btn[aria-pressed="true"]{background:var(--dsw-alias-brand-primary);color:#fff}
|
|
120
|
+
.meow-seg-btn:disabled{opacity:.5;cursor:default}
|
|
121
|
+
.meow-seg-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
122
|
+
.meow-actions{display:flex;align-items:center;gap:10px;margin-top:4px;flex-wrap:wrap}
|
|
123
|
+
.meow-primary{height:32px;padding:0 14px;border:none;border-radius:8px;background:var(--dsw-alias-brand-primary);color:#fff;font:inherit;font-size:13px;cursor:pointer}
|
|
124
|
+
.meow-secondary{height:32px;padding:0 14px;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;cursor:pointer}
|
|
125
|
+
.meow-primary:disabled,.meow-secondary:disabled{opacity:.5;cursor:default}
|
|
126
|
+
.meow-notice{margin:0;font-size:12px}
|
|
127
|
+
.meow-notice.ok{color:var(--dsw-alias-state-success-primary)}
|
|
128
|
+
.meow-notice.error{color:var(--dsw-alias-state-error-primary)}
|
|
129
|
+
.meow-notice.info{color:var(--dsw-alias-label-tertiary)}
|
|
130
|
+
`
|
|
131
|
+
|
|
132
|
+
/** Resolve a route against the document mount point (reverse-proxy safe). */
|
|
133
|
+
function apiPath(path) {
|
|
134
|
+
try {
|
|
135
|
+
const base = typeof document === 'undefined' ? undefined : document.baseURI
|
|
136
|
+
if (!base) return path
|
|
137
|
+
return new URL(path.replace(/^\/+/u, ''), base).pathname
|
|
138
|
+
} catch {
|
|
139
|
+
return path
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Replace `{name}` placeholders. */
|
|
144
|
+
function interpolate(text, params) {
|
|
145
|
+
if (!params) return text
|
|
146
|
+
return String(text).replace(/\{(\w+)\}/gu, (match, key) => {
|
|
147
|
+
const value = params[key]
|
|
148
|
+
return value === undefined || value === null ? match : String(value)
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** One JSON call to the Host half; a business failure becomes an Error. */
|
|
153
|
+
async function apiRequest(path, init) {
|
|
154
|
+
const request = init ?? {}
|
|
155
|
+
const response = await fetch(apiPath(`/meow-notify/api/${path}`), {
|
|
156
|
+
cache: 'no-store',
|
|
157
|
+
credentials: 'same-origin',
|
|
158
|
+
...request,
|
|
159
|
+
headers: { 'content-type': 'application/json', ...(request.headers ?? {}) },
|
|
160
|
+
})
|
|
161
|
+
let body
|
|
162
|
+
try {
|
|
163
|
+
body = await response.json()
|
|
164
|
+
} catch {
|
|
165
|
+
body = undefined
|
|
166
|
+
}
|
|
167
|
+
if (body && body.ok === false) throw new Error(body.error || `HTTP ${response.status}`)
|
|
168
|
+
if (!response.ok) throw new Error(body?.error || `HTTP ${response.status}`)
|
|
169
|
+
return body
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Keep the Host's own `t` where available and degrade to local copy. */
|
|
173
|
+
function createTranslator(ctx) {
|
|
174
|
+
let bound
|
|
175
|
+
try {
|
|
176
|
+
bound = ctx.locale.bind(NS)
|
|
177
|
+
} catch {
|
|
178
|
+
bound = undefined
|
|
179
|
+
}
|
|
180
|
+
return (key, params) => {
|
|
181
|
+
let text
|
|
182
|
+
if (typeof bound === 'function') {
|
|
183
|
+
try {
|
|
184
|
+
text = bound(key, params)
|
|
185
|
+
} catch {
|
|
186
|
+
text = undefined
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (typeof text !== 'string' || text.length === 0 || text === key) {
|
|
190
|
+
let language = 'zh'
|
|
191
|
+
try {
|
|
192
|
+
language = String(ctx.locale.getLocale()?.id ?? 'zh').toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
193
|
+
} catch {
|
|
194
|
+
language = 'zh'
|
|
195
|
+
}
|
|
196
|
+
text = (language === 'zh' ? zh : en)[key] ?? key
|
|
197
|
+
}
|
|
198
|
+
return interpolate(text, params)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Accessible switch matching the host's switch behavior. */
|
|
203
|
+
function Switch(props) {
|
|
204
|
+
return h('button', {
|
|
205
|
+
type: 'button',
|
|
206
|
+
role: 'switch',
|
|
207
|
+
'aria-checked': props.checked === true,
|
|
208
|
+
'aria-label': props.label,
|
|
209
|
+
className: 'meow-switch',
|
|
210
|
+
disabled: props.disabled === true,
|
|
211
|
+
onClick: () => props.onChange(props.checked !== true),
|
|
212
|
+
}, h('span', { className: 'meow-switch-knob' }))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** One label + hint + control row. */
|
|
216
|
+
function Row(props) {
|
|
217
|
+
return h('div', { className: 'meow-row' },
|
|
218
|
+
h('div', { className: 'meow-row-text' },
|
|
219
|
+
h('div', { className: 'meow-label' }, props.label),
|
|
220
|
+
props.hint ? h('p', { className: 'meow-hint' }, props.hint) : null,
|
|
221
|
+
),
|
|
222
|
+
props.children,
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
name: 'meow-notify:settings',
|
|
228
|
+
inject: ['slots', 'locale'],
|
|
229
|
+
apply(ctx) {
|
|
230
|
+
const t = createTranslator(ctx)
|
|
231
|
+
|
|
232
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'meow-notify: dictionaries')
|
|
233
|
+
|
|
234
|
+
if (typeof document !== 'undefined') {
|
|
235
|
+
const tag = document.createElement('style')
|
|
236
|
+
tag.dataset.plugin = PKG
|
|
237
|
+
tag.textContent = CSS
|
|
238
|
+
document.head.appendChild(tag)
|
|
239
|
+
ctx.effect(() => () => {
|
|
240
|
+
tag.remove()
|
|
241
|
+
}, 'meow-notify: styles')
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The bundle's own configuration page. */
|
|
245
|
+
function Page(props) {
|
|
246
|
+
const [phase, setPhase] = React.useState('loading')
|
|
247
|
+
const [saved, setSaved] = React.useState(null)
|
|
248
|
+
const [draft, setDraft] = React.useState(null)
|
|
249
|
+
const [meta, setMeta] = React.useState(null)
|
|
250
|
+
const [busy, setBusy] = React.useState('')
|
|
251
|
+
const [notice, setNotice] = React.useState(null)
|
|
252
|
+
|
|
253
|
+
const dirty = saved !== null && draft !== null && JSON.stringify(saved) !== JSON.stringify(draft)
|
|
254
|
+
|
|
255
|
+
const load = React.useCallback(async () => {
|
|
256
|
+
setPhase('loading')
|
|
257
|
+
setNotice(null)
|
|
258
|
+
try {
|
|
259
|
+
const body = await apiRequest('state')
|
|
260
|
+
setSaved(body.state)
|
|
261
|
+
setDraft(body.state)
|
|
262
|
+
setMeta({ diagnostics: body.diagnostics, url: body.url })
|
|
263
|
+
setPhase('ready')
|
|
264
|
+
} catch (error) {
|
|
265
|
+
setPhase('error')
|
|
266
|
+
setNotice({ tone: 'error', text: t('loadFailed', { error: error.message }) })
|
|
267
|
+
}
|
|
268
|
+
}, [])
|
|
269
|
+
|
|
270
|
+
const refreshMeta = React.useCallback(async () => {
|
|
271
|
+
try {
|
|
272
|
+
const body = await apiRequest('state')
|
|
273
|
+
setMeta({ diagnostics: body.diagnostics, url: body.url })
|
|
274
|
+
} catch {
|
|
275
|
+
/* diagnostics are optional */
|
|
276
|
+
}
|
|
277
|
+
}, [])
|
|
278
|
+
|
|
279
|
+
React.useEffect(() => {
|
|
280
|
+
void load()
|
|
281
|
+
}, [load])
|
|
282
|
+
|
|
283
|
+
// The bundle configuration slot asks for `page`; a summary render is
|
|
284
|
+
// not part of this surface and must not repeat the form.
|
|
285
|
+
if (props?.view === 'summary') return null
|
|
286
|
+
|
|
287
|
+
const setField = (key, value) => {
|
|
288
|
+
setDraft((current) => (current === null ? current : { ...current, [key]: value }))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const persist = async () => {
|
|
292
|
+
const body = await apiRequest('state', {
|
|
293
|
+
method: 'POST',
|
|
294
|
+
body: JSON.stringify(draft),
|
|
295
|
+
})
|
|
296
|
+
setSaved(body.state)
|
|
297
|
+
setDraft(body.state)
|
|
298
|
+
return body.state
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const save = async () => {
|
|
302
|
+
if (draft === null || busy !== '') return
|
|
303
|
+
setBusy('save')
|
|
304
|
+
setNotice(null)
|
|
305
|
+
try {
|
|
306
|
+
await persist()
|
|
307
|
+
setNotice({ tone: 'ok', text: t('saved') })
|
|
308
|
+
await refreshMeta()
|
|
309
|
+
} catch (error) {
|
|
310
|
+
setNotice({ tone: 'error', text: t('saveFailed', { error: error.message }) })
|
|
311
|
+
} finally {
|
|
312
|
+
setBusy('')
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const test = async () => {
|
|
317
|
+
if (draft === null || busy !== '') return
|
|
318
|
+
setBusy('test')
|
|
319
|
+
setNotice(null)
|
|
320
|
+
try {
|
|
321
|
+
if (!String(draft.nickname ?? '').trim()) throw new Error(t('needNickname'))
|
|
322
|
+
await persist()
|
|
323
|
+
const body = await apiRequest('test', { method: 'POST' })
|
|
324
|
+
const detail = body?.detail && body.detail !== '发送成功' ? `(${body.detail})` : ''
|
|
325
|
+
setNotice({ tone: 'ok', text: t('testSent') + detail })
|
|
326
|
+
await refreshMeta()
|
|
327
|
+
} catch (error) {
|
|
328
|
+
setNotice({ tone: 'error', text: t('testFailed', { error: error.message }) })
|
|
329
|
+
} finally {
|
|
330
|
+
setBusy('')
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (phase === 'loading') {
|
|
335
|
+
return h('div', { className: 'meow-page' }, h('p', { className: 'meow-hint' }, t('loading')))
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (phase === 'error' || draft === null) {
|
|
339
|
+
return h('div', { className: 'meow-page' },
|
|
340
|
+
h('p', { className: 'meow-notice error', role: 'status' }, notice?.text ?? t('loadFailed', { error: '' })),
|
|
341
|
+
h('div', { className: 'meow-actions' },
|
|
342
|
+
h('button', { type: 'button', className: 'meow-secondary', onClick: () => { void load() } }, t('retry')),
|
|
343
|
+
),
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const disabled = busy !== ''
|
|
348
|
+
// The style control is only meaningful once the Host half reports the
|
|
349
|
+
// field; an older Host bundle without it would silently drop the save.
|
|
350
|
+
const styleSupported = typeof saved?.messageStyle === 'string'
|
|
351
|
+
const last = meta?.diagnostics?.lastSend
|
|
352
|
+
const lastText = last
|
|
353
|
+
? (last.ok === true
|
|
354
|
+
? t('lastOk')
|
|
355
|
+
: t('lastFail', { error: String(last.detail || '').slice(0, 80) }))
|
|
356
|
+
: ''
|
|
357
|
+
|
|
358
|
+
return h('div', { className: 'meow-page' },
|
|
359
|
+
h('p', { className: 'meow-lead' }, t('lead')),
|
|
360
|
+
|
|
361
|
+
h('label', { className: 'meow-field' },
|
|
362
|
+
h('span', { className: 'meow-label' }, t('nickname')),
|
|
363
|
+
h('input', {
|
|
364
|
+
className: 'meow-input',
|
|
365
|
+
type: 'text',
|
|
366
|
+
value: draft.nickname ?? '',
|
|
367
|
+
autoComplete: 'off',
|
|
368
|
+
spellCheck: false,
|
|
369
|
+
placeholder: 'your-meow-nickname',
|
|
370
|
+
disabled,
|
|
371
|
+
onChange: (event) => setField('nickname', event.currentTarget.value),
|
|
372
|
+
}),
|
|
373
|
+
h('span', { className: 'meow-hint' }, t('nicknameHint')),
|
|
374
|
+
),
|
|
375
|
+
|
|
376
|
+
h('label', { className: 'meow-field' },
|
|
377
|
+
h('span', { className: 'meow-label' }, t('category')),
|
|
378
|
+
h('input', {
|
|
379
|
+
className: 'meow-input',
|
|
380
|
+
type: 'text',
|
|
381
|
+
value: draft.category ?? '',
|
|
382
|
+
maxLength: 10,
|
|
383
|
+
autoComplete: 'off',
|
|
384
|
+
spellCheck: false,
|
|
385
|
+
placeholder: 'DSH',
|
|
386
|
+
disabled,
|
|
387
|
+
onChange: (event) => setField('category', event.currentTarget.value),
|
|
388
|
+
}),
|
|
389
|
+
h('span', { className: 'meow-hint' }, t('categoryHint')),
|
|
390
|
+
),
|
|
391
|
+
|
|
392
|
+
h('div', { className: 'meow-section' }, t('events')),
|
|
393
|
+
|
|
394
|
+
h(Row, { label: t('done'), hint: t('doneHint') },
|
|
395
|
+
h(Switch, {
|
|
396
|
+
checked: draft.notifyDone !== false,
|
|
397
|
+
onChange: (value) => setField('notifyDone', value),
|
|
398
|
+
disabled,
|
|
399
|
+
label: t('done'),
|
|
400
|
+
}),
|
|
401
|
+
),
|
|
402
|
+
h(Row, { label: t('approval'), hint: t('approvalHint') },
|
|
403
|
+
h(Switch, {
|
|
404
|
+
checked: draft.notifyApproval !== false,
|
|
405
|
+
onChange: (value) => setField('notifyApproval', value),
|
|
406
|
+
disabled,
|
|
407
|
+
label: t('approval'),
|
|
408
|
+
}),
|
|
409
|
+
),
|
|
410
|
+
h(Row, { label: t('question'), hint: t('questionHint') },
|
|
411
|
+
h(Switch, {
|
|
412
|
+
checked: draft.notifyQuestion !== false,
|
|
413
|
+
onChange: (value) => setField('notifyQuestion', value),
|
|
414
|
+
disabled,
|
|
415
|
+
label: t('question'),
|
|
416
|
+
}),
|
|
417
|
+
),
|
|
418
|
+
|
|
419
|
+
styleSupported
|
|
420
|
+
? h(Row, { label: t('style'), hint: t('styleHint') },
|
|
421
|
+
h('div', { className: 'meow-seg', role: 'group', 'aria-label': t('style') },
|
|
422
|
+
...[['full', 'styleFull'], ['compact', 'styleCompact'], ['status', 'styleStatus']].map(([value, key]) =>
|
|
423
|
+
h('button', {
|
|
424
|
+
key: value,
|
|
425
|
+
type: 'button',
|
|
426
|
+
className: 'meow-seg-btn',
|
|
427
|
+
'aria-pressed': (draft.messageStyle ?? 'compact') === value,
|
|
428
|
+
disabled,
|
|
429
|
+
onClick: () => setField('messageStyle', value),
|
|
430
|
+
}, t(key))),
|
|
431
|
+
),
|
|
432
|
+
)
|
|
433
|
+
: null,
|
|
434
|
+
|
|
435
|
+
h('div', { className: 'meow-actions' },
|
|
436
|
+
h('button', {
|
|
437
|
+
type: 'button',
|
|
438
|
+
className: 'meow-primary',
|
|
439
|
+
disabled: disabled || !dirty,
|
|
440
|
+
onClick: () => { void save() },
|
|
441
|
+
}, busy === 'save' ? t('saving') : t('save')),
|
|
442
|
+
h('button', {
|
|
443
|
+
type: 'button',
|
|
444
|
+
className: 'meow-secondary',
|
|
445
|
+
disabled: disabled || !String(draft.nickname ?? '').trim(),
|
|
446
|
+
onClick: () => { void test() },
|
|
447
|
+
}, busy === 'test' ? t('testing') : t('test')),
|
|
448
|
+
dirty ? h('span', { className: 'meow-hint' }, t('dirty')) : null,
|
|
449
|
+
),
|
|
450
|
+
|
|
451
|
+
notice ? h('p', { className: `meow-notice ${notice.tone}`, role: 'status' }, notice.text) : null,
|
|
452
|
+
lastText ? h('p', { className: 'meow-hint' }, t('lastSend', { text: lastText })) : null,
|
|
453
|
+
h('p', { className: 'meow-hint' }, t('privacy')),
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
458
|
+
name: 'plugins.bundle.config',
|
|
459
|
+
key: PKG,
|
|
460
|
+
}, Page))
|
|
461
|
+
},
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
})
|