dsh-reminder-notify 0.16.1 → 0.17.1
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/README.md +9 -0
- package/client.js +55 -1
- package/cordis.patch.yml +4 -0
- package/docs/PUBLISH.md +1 -1
- package/docs/detail.en.md +1 -0
- package/docs/detail.zh.md +1 -0
- package/host/ReminderHost.ps1 +24 -5
- package/index.js +191 -9
- package/package.json +1 -1
- package/publish/index.json +2 -2
package/README.md
CHANGED
|
@@ -13,6 +13,15 @@ dsh plugin --profile desktop add link:<本目录绝对路径>
|
|
|
13
13
|
|
|
14
14
|
装完新会话就有 `notify_user`。
|
|
15
15
|
|
|
16
|
+
## 0.17 起多了什么
|
|
17
|
+
|
|
18
|
+
- **定时提醒**:`notify_user` 支持 `at: "22:00"`(今天已过就排到明天)或 `inMinutes: 25`,到点才弹,不进队列占位。
|
|
19
|
+
- **优先级**:`decide` 卡永远排在 `done`/`raw` 前面;`maxHoldSeconds` 可给任何卡设「最多挂多久」。
|
|
20
|
+
- **卡片上的链接**:传 `url` 会在卡上加「打开链接」按钮;键盘 `Enter` 知道了、`S` 稍后提醒、`Esc` 关掉。
|
|
21
|
+
- **历史导出**:面板「历史与统计」多了「导出 CSV / 导出 JSON」,文件落在桌面,统计里同时给近 30 天。
|
|
22
|
+
- **更多推送格式**:除企业微信/Server酱/JSON/纯文本,还支持 Telegram(填 chat_id)、飞书、钉钉。
|
|
23
|
+
- **服务契约第 2 版**:`ctx.get('reminder')` 现在带 `apiVersion`、`events()`(最近 20 条 shown/notified)和 `registerSource()`,别的插件也能挂自己的提醒来源。
|
|
24
|
+
|
|
16
25
|
## 用
|
|
17
26
|
|
|
18
27
|
| 场景 | 调用 |
|
package/client.js
CHANGED
|
@@ -23,6 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
// 0.11 新增:提醒历史(GET 拿统计+最近记录,POST { mode: 'clear' } 清空)。
|
|
24
24
|
const HISTORY_ROUTE = '/dsh-reminder-notify/history'
|
|
25
25
|
const DOCTOR_ROUTE = '/dsh-reminder-notify/doctor'
|
|
26
|
+
const EXPORT_ROUTE = '/dsh-reminder-notify/export'
|
|
26
27
|
const DIGEST_ROUTE = '/dsh-reminder-notify/digest'
|
|
27
28
|
// 下拉按扩展名分组:wav 一组、mp3 一组……组内按文件名排序,一眼能看出格式。
|
|
28
29
|
function groupAudioFiles(files) {
|
|
@@ -307,6 +308,18 @@ window.__ModuleLoader__.load({
|
|
|
307
308
|
quietModeHold: '留到结束后补弹',
|
|
308
309
|
quietModeSkip: '直接跳过',
|
|
309
310
|
pushFormatWecom: '企业微信机器人',
|
|
311
|
+
pushFormatTelegram: 'Telegram',
|
|
312
|
+
pushFormatFeishu: '飞书',
|
|
313
|
+
pushFormatDingtalk: '钉钉',
|
|
314
|
+
pushChat: '会话 ID(telegram)',
|
|
315
|
+
pushChatHint: 'telegram 机器人要填 chat_id;其它格式留空即可。',
|
|
316
|
+
maxHoldSeconds: '单卡最长停留(秒)',
|
|
317
|
+
maxHoldSecondsHint: '0 = 不额外限制(最多 600 秒);填 30 就是任何卡最多挂 30 秒。',
|
|
318
|
+
exportCsv: '导出 CSV',
|
|
319
|
+
exportJson: '导出 JSON',
|
|
320
|
+
exportDone: '已导出到桌面:',
|
|
321
|
+
exportFailed: '导出失败:',
|
|
322
|
+
last30: '近 30 天:',
|
|
310
323
|
pushFormatServerchan: 'Server 酱',
|
|
311
324
|
pushFormatJson: '通用 JSON',
|
|
312
325
|
pushFormatText: '纯文本',
|
|
@@ -447,6 +460,18 @@ window.__ModuleLoader__.load({
|
|
|
447
460
|
quietModeHold: 'Hold until it ends',
|
|
448
461
|
quietModeSkip: 'Skip it',
|
|
449
462
|
pushFormatWecom: 'WeCom bot',
|
|
463
|
+
pushFormatTelegram: 'Telegram',
|
|
464
|
+
pushFormatFeishu: 'Feishu',
|
|
465
|
+
pushFormatDingtalk: 'DingTalk',
|
|
466
|
+
pushChat: 'Chat ID (Telegram)',
|
|
467
|
+
pushChatHint: 'Telegram bots need a chat_id; leave empty for other formats.',
|
|
468
|
+
maxHoldSeconds: 'Max card lifetime (s)',
|
|
469
|
+
maxHoldSecondsHint: '0 = no extra cap (600 s max); 30 means no card stays longer than 30 s.',
|
|
470
|
+
exportCsv: 'Export CSV',
|
|
471
|
+
exportJson: 'Export JSON',
|
|
472
|
+
exportDone: 'Exported to Desktop: ',
|
|
473
|
+
exportFailed: 'Export failed: ',
|
|
474
|
+
last30: 'Last 30 days: ',
|
|
450
475
|
pushFormatServerchan: 'ServerChan',
|
|
451
476
|
pushFormatJson: 'Generic JSON',
|
|
452
477
|
pushFormatText: 'Plain text',
|
|
@@ -609,6 +634,7 @@ window.__ModuleLoader__.load({
|
|
|
609
634
|
{ key: 'queueEnabled', group: 'queue', kind: 'boolean' },
|
|
610
635
|
{ key: 'queueMax', group: 'queue', kind: 'number' },
|
|
611
636
|
{ key: 'mergeWindowMs', group: 'queue', kind: 'number' },
|
|
637
|
+
{ key: 'maxHoldSeconds', group: 'queue', kind: 'number' },
|
|
612
638
|
{ key: 'quietEnabled', group: 'queue', kind: 'boolean' },
|
|
613
639
|
{ key: 'quietStart', group: 'queue', kind: 'text' },
|
|
614
640
|
{ key: 'quietEnd', group: 'queue', kind: 'text' },
|
|
@@ -624,7 +650,8 @@ window.__ModuleLoader__.load({
|
|
|
624
650
|
{ key: 'digestAlertCount', group: 'digest', kind: 'number' },
|
|
625
651
|
{ key: 'pushEnabled', group: 'digest', kind: 'boolean' },
|
|
626
652
|
{ key: 'pushUrl', group: 'digest', kind: 'text' },
|
|
627
|
-
{ key: 'pushFormat', group: 'digest', kind: 'select', options: ['wecom', 'serverchan', 'json', 'text'], optionLabels: ['pushFormatWecom', 'pushFormatServerchan', 'pushFormatJson', 'pushFormatText'] },
|
|
653
|
+
{ key: 'pushFormat', group: 'digest', kind: 'select', options: ['wecom', 'serverchan', 'telegram', 'feishu', 'dingtalk', 'json', 'text'], optionLabels: ['pushFormatWecom', 'pushFormatServerchan', 'pushFormatTelegram', 'pushFormatFeishu', 'pushFormatDingtalk', 'pushFormatJson', 'pushFormatText'] },
|
|
654
|
+
{ key: 'pushChat', group: 'digest', kind: 'text' },
|
|
628
655
|
{ key: 'pushDecide', group: 'digest', kind: 'boolean' },
|
|
629
656
|
{ key: 'pushDigest', group: 'digest', kind: 'boolean' },
|
|
630
657
|
{ key: 'hostMode', group: 'host', kind: 'select', options: ['script', 'exe'], optionLabels: ['hostModeScript', 'hostModeExe'] },
|
|
@@ -637,6 +664,8 @@ window.__ModuleLoader__.load({
|
|
|
637
664
|
seconds: 'secondsHint',
|
|
638
665
|
sound: 'soundHint',
|
|
639
666
|
cooldownMs: 'cooldownHint',
|
|
667
|
+
pushChat: 'pushChatHint',
|
|
668
|
+
maxHoldSeconds: 'maxHoldSecondsHint',
|
|
640
669
|
retryHostOnce: 'retryHostOnceHint',
|
|
641
670
|
doneAudio: 'audioHint',
|
|
642
671
|
audioDir: 'audioDirHint',
|
|
@@ -1210,6 +1239,21 @@ window.__ModuleLoader__.load({
|
|
|
1210
1239
|
historyFetch({ method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' }, body: JSON.stringify({ mode: 'clear' }) })
|
|
1211
1240
|
}
|
|
1212
1241
|
|
|
1242
|
+
async function runExport(format) {
|
|
1243
|
+
const label = typeof t === 'function' ? t : (key) => key
|
|
1244
|
+
try {
|
|
1245
|
+
const response = await fetch(`${EXPORT_ROUTE}?format=${format}&days=30`)
|
|
1246
|
+
const data = await response.json()
|
|
1247
|
+
if (data && data.ok === true) {
|
|
1248
|
+
setMessage(`${label('exportDone')}${data.file}(${data.count} 条)`)
|
|
1249
|
+
} else {
|
|
1250
|
+
setMessage(`${label('exportFailed')}${(data && (data.detail || data.error)) || ''}`)
|
|
1251
|
+
}
|
|
1252
|
+
} catch (error) {
|
|
1253
|
+
setMessage(`${label('exportFailed')}${String(error && error.message ? error.message : error)}`)
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1213
1257
|
function historyText() {
|
|
1214
1258
|
const label = typeof t === 'function' ? t : (key) => key
|
|
1215
1259
|
if (history === null) return label('historyLoading')
|
|
@@ -1374,6 +1418,16 @@ window.__ModuleLoader__.load({
|
|
|
1374
1418
|
{ type: 'button', className: 'drn-btn small', disabled: historyBusy, onClick: clearHistory },
|
|
1375
1419
|
label('historyClear'),
|
|
1376
1420
|
),
|
|
1421
|
+
h(
|
|
1422
|
+
'button',
|
|
1423
|
+
{ type: 'button', className: 'drn-btn drn-digest-btn', disabled: historyBusy, onClick: () => runExport('csv') },
|
|
1424
|
+
label('exportCsv'),
|
|
1425
|
+
),
|
|
1426
|
+
h(
|
|
1427
|
+
'button',
|
|
1428
|
+
{ type: 'button', className: 'drn-btn drn-digest-btn', disabled: historyBusy, onClick: () => runExport('json') },
|
|
1429
|
+
label('exportJson'),
|
|
1430
|
+
),
|
|
1377
1431
|
),
|
|
1378
1432
|
),
|
|
1379
1433
|
)
|
package/cordis.patch.yml
CHANGED
package/docs/PUBLISH.md
CHANGED
|
@@ -12,7 +12,7 @@ DSH 的「插件市场 → 发现」页读的是**索引 URL**:一份 JSON(
|
|
|
12
12
|
| 索引地址(他人添加这个) | `https://jiangshuaiye1203.github.io/dsh-reminder-notify/publish/index.json` |
|
|
13
13
|
| 站点首页 | https://jiangshuaiye1203.github.io/dsh-reminder-notify/ |
|
|
14
14
|
| npm 包 | https://www.npmjs.com/package/dsh-reminder-notify |
|
|
15
|
-
| 当前版本 | **0.
|
|
15
|
+
| 当前版本 | **0.17.1**,装源为 **npm**(`dsh-reminder-notify@0.17.1`),不再是 git 固定提交 |
|
|
16
16
|
| Pages | Deploy from a branch,`main` / `(root)` |
|
|
17
17
|
|
|
18
18
|
发新版(npm 源):改代码 → 升 `package.json` 版本 → `scripts\publish-npm.cmd` 发布到 npm →
|
package/docs/detail.en.md
CHANGED
|
@@ -12,3 +12,4 @@ Cards are drawn by the bundled `host/ReminderHost.ps1` with the built-in PowerSh
|
|
|
12
12
|
- **Everything else**: folded into "How it works (expand to read)" inside the settings panel below, one topic at a time.
|
|
13
13
|
- **For other plugins**: this plugin exposes a `reminder` service (`notify` / `digest` / `stats` / `config`); see the README.
|
|
14
14
|
- The self-check now has a **GitHub reachability** item (it flags hosts entries pointing github.com at 127.0.0.1, i.e. the Steam++ acceleration table) plus a **Test GitHub** button; `scripts/github-push.ps1` repairs that state around a push and restores hosts afterwards.
|
|
15
|
+
- 0.17 adds scheduled reminders (`at` / `inMinutes`), `decide` priority, a max card lifetime, an "Open link" button with Enter/S/Esc shortcuts, CSV/JSON history export, Telegram/Feishu/DingTalk push formats, and service contract v2.
|
package/docs/detail.zh.md
CHANGED
|
@@ -12,3 +12,4 @@
|
|
|
12
12
|
- **其余说明**:全部收在下面设置面板的「使用说明(点开才看)」里,一次只展开一条。
|
|
13
13
|
- **给别的插件用**:本插件对外提供 `reminder` 服务(`notify` / `digest` / `stats` / `config`),写法见 README。
|
|
14
14
|
- 自检里新增「GitHub 连通性」:hosts 里有指向 127.0.0.1 的 github 行(Steam++ 加速表)时标红,另有「测 GitHub」按钮现测一次;推送用 `scripts/github-push.ps1` 可自动处理并还原。
|
|
15
|
+
- 0.17 新增:定时提醒(`at` / `inMinutes`)、`decide` 优先、单卡最长停留、卡上「打开链接」按钮与 Enter/S/Esc 快捷键、历史导出 CSV/JSON、Telegram/飞书/钉钉推送格式、服务契约第 2 版。
|
package/host/ReminderHost.ps1
CHANGED
|
@@ -35,7 +35,8 @@ param(
|
|
|
35
35
|
[string]$Speak = '',
|
|
36
36
|
[string]$ResultPath = '',
|
|
37
37
|
[int]$SnoozeMinutes = 10,
|
|
38
|
-
[switch]$NoButtons,
|
|
38
|
+
[switch]$NoButtons,
|
|
39
|
+
[string]$OpenUrl = '',
|
|
39
40
|
[switch]$Compact,
|
|
40
41
|
[switch]$AutoCompact,
|
|
41
42
|
[int]$QueueLeft = 0,
|
|
@@ -238,7 +239,12 @@ if ($showButtons) {
|
|
|
238
239
|
$snoozeRect = New-Object System.Drawing.Rectangle ($btnRight - $snoozeWidth), $btnTop, $snoozeWidth, $buttonHeight
|
|
239
240
|
$okRect = New-Object System.Drawing.Rectangle ($snoozeRect.Left - $buttonGap - $okWidth), $btnTop, $okWidth, $buttonHeight
|
|
240
241
|
$script:btnRects['snooze'] = $snoozeRect
|
|
241
|
-
$script:btnRects['ok'] = $okRect
|
|
242
|
+
$script:btnRects['ok'] = $okRect
|
|
243
|
+
if ($OpenUrl -ne '') {
|
|
244
|
+
$openWidth = 78
|
|
245
|
+
$openRect = New-Object System.Drawing.Rectangle ($okRect.Left - $buttonGap - $openWidth), $btnTop, $openWidth, $buttonHeight
|
|
246
|
+
$script:btnRects['open'] = $openRect
|
|
247
|
+
}
|
|
242
248
|
}
|
|
243
249
|
|
|
244
250
|
# ---- 定位:光标所在屏幕的工作区 ---------------------------------------------
|
|
@@ -340,7 +346,7 @@ $form.Add_Paint({
|
|
|
340
346
|
|
|
341
347
|
# 按钮
|
|
342
348
|
if ($showButtons) {
|
|
343
|
-
foreach ($key in @('ok', 'snooze')) {
|
|
349
|
+
foreach ($key in @('open', 'ok', 'snooze')) {
|
|
344
350
|
$rect = $script:btnRects[$key]
|
|
345
351
|
if ($rect -eq $null) { continue }
|
|
346
352
|
$fill = if ($script:hover -eq $key) { $btnHoverColor } else { $btnColor }
|
|
@@ -355,7 +361,7 @@ $form.Add_Paint({
|
|
|
355
361
|
$g.FillPath($btnBrush, $btnPath)
|
|
356
362
|
$btnBrush.Dispose()
|
|
357
363
|
$btnPath.Dispose()
|
|
358
|
-
$label = if ($key -eq 'ok') { $okText } else { $snoozeText }
|
|
364
|
+
$label = if ($key -eq 'ok') { $okText } elseif ($key -eq 'open') { '打开链接' } else { $snoozeText }
|
|
359
365
|
$fmt = New-Object System.Drawing.StringFormat
|
|
360
366
|
$fmt.Alignment = [System.Drawing.StringAlignment]::Center
|
|
361
367
|
$fmt.LineAlignment = [System.Drawing.StringAlignment]::Center
|
|
@@ -413,12 +419,25 @@ function Close-With([string]$action) {
|
|
|
413
419
|
Write-Log ('action ' + $action)
|
|
414
420
|
}
|
|
415
421
|
|
|
422
|
+
$form.KeyPreview = $true
|
|
423
|
+
$form.Add_KeyDown({
|
|
424
|
+
param($sender, $e)
|
|
425
|
+
if ($e.KeyCode -eq [System.Windows.Forms.Keys]::Enter) { Close-With 'ok' }
|
|
426
|
+
elseif ($e.KeyCode -eq [System.Windows.Forms.Keys]::S) { Close-With 'snooze' }
|
|
427
|
+
elseif ($e.KeyCode -eq [System.Windows.Forms.Keys]::Escape) { Close-With 'dismiss' }
|
|
428
|
+
})
|
|
429
|
+
|
|
416
430
|
$form.Add_MouseDown({
|
|
417
431
|
param($sender, $e)
|
|
418
432
|
if ($script:phase -eq 'out') { return }
|
|
419
|
-
foreach ($key in @('ok', 'snooze')) {
|
|
433
|
+
foreach ($key in @('open', 'ok', 'snooze')) {
|
|
420
434
|
$rect = $script:btnRects[$key]
|
|
421
435
|
if ($rect -ne $null -and $rect.Contains($e.X, $e.Y)) {
|
|
436
|
+
if ($key -eq 'open' -and $OpenUrl -ne '') {
|
|
437
|
+
try { Start-Process $OpenUrl | Out-Null } catch { }
|
|
438
|
+
Close-With 'ok'
|
|
439
|
+
return
|
|
440
|
+
}
|
|
422
441
|
Close-With $key
|
|
423
442
|
return
|
|
424
443
|
}
|
package/index.js
CHANGED
|
@@ -99,7 +99,9 @@ export const Config = z === null ? undefined : z.object({
|
|
|
99
99
|
digestAlertDate: z.string().default('').description('内部状态:上次弹条数预警的日期').volatile(),
|
|
100
100
|
pushEnabled: z.boolean().default(false).description('把提醒同时推到手机(企业微信机器人 / Server酱 / 自定义 webhook)').volatile(),
|
|
101
101
|
pushUrl: z.string().default('').description('推送地址,例如 https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…').volatile(),
|
|
102
|
-
pushFormat: z.union(['wecom', 'serverchan', 'json', 'text']).default('wecom').description('推送格式:wecom 企业微信机器人、serverchan Server酱、json 通用 JSON、text 纯文本').volatile(),
|
|
102
|
+
pushFormat: z.union(['wecom', 'serverchan', 'json', 'text', 'telegram', 'feishu', 'dingtalk']).default('wecom').description('推送格式:wecom 企业微信机器人、serverchan Server酱、telegram、feishu 飞书、dingtalk 钉钉、json 通用 JSON、text 纯文本').volatile(),
|
|
103
|
+
pushChat: z.string().default('').description('telegram 用的 chat_id(只 telegram 格式需要)').volatile(),
|
|
104
|
+
maxHoldSeconds: z.number().min(0).max(3600).step(5).default(0).description('单张卡最长停留秒数(0 = 不额外限制,仍以 600 为上限)').volatile(),
|
|
103
105
|
pushDecide: z.boolean().default(true).description('「需要你来决定」档位也推到手机').volatile(),
|
|
104
106
|
pushDigest: z.boolean().default(true).description('日报同时推到手机').volatile(),
|
|
105
107
|
retryHostOnce: z.boolean().default(true).description('宿主第一次没画出卡片时,自动静音重试一次').volatile(),
|
|
@@ -240,7 +242,9 @@ function settingsOf(config) {
|
|
|
240
242
|
digestAlertDate: str(c.digestAlertDate, ''),
|
|
241
243
|
pushEnabled: c.pushEnabled === true,
|
|
242
244
|
pushUrl: typeof c.pushUrl === 'string' ? c.pushUrl.trim() : '',
|
|
243
|
-
pushFormat: ['wecom', 'serverchan', 'json', 'text'].includes(c.pushFormat) ? c.pushFormat : 'wecom',
|
|
245
|
+
pushFormat: ['wecom', 'serverchan', 'json', 'text', 'telegram', 'feishu', 'dingtalk'].includes(c.pushFormat) ? c.pushFormat : 'wecom',
|
|
246
|
+
pushChat: typeof c.pushChat === 'string' ? c.pushChat.trim() : '',
|
|
247
|
+
maxHoldSeconds: Math.round(clamp(num(c.maxHoldSeconds, 0), 0, 3600)),
|
|
244
248
|
pushDecide: c.pushDecide !== false,
|
|
245
249
|
pushDigest: c.pushDigest !== false,
|
|
246
250
|
retryHostOnce: c.retryHostOnce !== false,
|
|
@@ -366,6 +370,7 @@ function argvOfScriptHost(o) {
|
|
|
366
370
|
if (o.compact) argv.push('-Compact')
|
|
367
371
|
if (o.autoCompact) argv.push('-AutoCompact')
|
|
368
372
|
if (o.queueLeft > 0) argv.push('-QueueLeft', String(o.queueLeft))
|
|
373
|
+
if (o.openUrl) argv.push('-OpenUrl', String(o.openUrl))
|
|
369
374
|
return argv
|
|
370
375
|
}
|
|
371
376
|
|
|
@@ -440,6 +445,30 @@ export function quietEndAt(settings, now = new Date()) {
|
|
|
440
445
|
return at.getTime()
|
|
441
446
|
}
|
|
442
447
|
|
|
448
|
+
function priorityOf(kind) {
|
|
449
|
+
// decide 是「要人来拍板」的,最优先;done 次之;raw 最低。
|
|
450
|
+
if (kind === 'decide') return 2
|
|
451
|
+
if (kind === 'done') return 1
|
|
452
|
+
return 0
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// at="22:00"(今天已过则明天)或 inMinutes=N → 到点时间戳;都没给返回 0(立刻弹)。
|
|
456
|
+
function dueAtOf(args) {
|
|
457
|
+
const minutes = num(args.inMinutes, NaN)
|
|
458
|
+
if (Number.isFinite(minutes) && minutes > 0) {
|
|
459
|
+
return Date.now() + Math.min(minutes, 7 * 24 * 60) * 60 * 1000
|
|
460
|
+
}
|
|
461
|
+
const clock = str(args.at, '')
|
|
462
|
+
if (clock === '') return 0
|
|
463
|
+
const target = parseClock(clock)
|
|
464
|
+
if (target === null) return 0
|
|
465
|
+
const now = new Date()
|
|
466
|
+
const at = new Date(now.getTime())
|
|
467
|
+
at.setHours(Math.floor(target / 60), target % 60, 0, 0)
|
|
468
|
+
if (at.getTime() <= now.getTime()) at.setDate(at.getDate() + 1)
|
|
469
|
+
return at.getTime()
|
|
470
|
+
}
|
|
471
|
+
|
|
443
472
|
function enqueue(item) {
|
|
444
473
|
const settings = item.settings
|
|
445
474
|
if (!settings.queueEnabled) {
|
|
@@ -452,7 +481,7 @@ function enqueue(item) {
|
|
|
452
481
|
return { queued: false, position: 0 }
|
|
453
482
|
}
|
|
454
483
|
const now = Date.now()
|
|
455
|
-
if (settings.mergeWindowMs > 0) {
|
|
484
|
+
if (settings.mergeWindowMs > 0 && !((item.dueAt ?? 0) > now)) {
|
|
456
485
|
const pending = queue.find(
|
|
457
486
|
(other) =>
|
|
458
487
|
other.kind === item.kind &&
|
|
@@ -477,17 +506,27 @@ function enqueue(item) {
|
|
|
477
506
|
function pump() {
|
|
478
507
|
if (active !== null) return
|
|
479
508
|
const now = Date.now()
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
509
|
+
// 0.17:到点的(既不在免打扰里、也过了定时时间)才放;decide 永远排在前面。
|
|
510
|
+
const ready = queue.filter(
|
|
511
|
+
(item) => (item.holdUntil ?? 0) <= now && (item.dueAt ?? 0) <= now,
|
|
512
|
+
)
|
|
513
|
+
if (ready.length === 0) {
|
|
514
|
+
// 剩下的要么在免打扰时段里,要么是定时提醒:睡到最早那个时间点再看
|
|
515
|
+
const next = queue.reduce((min, item) => {
|
|
516
|
+
const when = Math.max(item.holdUntil ?? 0, item.dueAt ?? 0)
|
|
517
|
+
return when > now ? Math.min(min, when) : min
|
|
518
|
+
}, Infinity)
|
|
484
519
|
if (Number.isFinite(next)) {
|
|
485
520
|
const timer = setTimeout(() => pump(), Math.max(1000, Math.min(next - now, 60 * 60 * 1000)))
|
|
486
521
|
if (typeof timer.unref === 'function') timer.unref()
|
|
487
522
|
}
|
|
488
523
|
return
|
|
489
524
|
}
|
|
490
|
-
|
|
525
|
+
ready.sort(
|
|
526
|
+
(a, b) => (b.priority ?? 0) - (a.priority ?? 0) || (a.createdAt ?? 0) - (b.createdAt ?? 0),
|
|
527
|
+
)
|
|
528
|
+
const item = ready[0]
|
|
529
|
+
queue.splice(queue.indexOf(item), 1)
|
|
491
530
|
active = item
|
|
492
531
|
showItem(item)
|
|
493
532
|
.catch(() => {})
|
|
@@ -520,6 +559,7 @@ async function showItem(item) {
|
|
|
520
559
|
icon: extras.icon,
|
|
521
560
|
speak: item.speak,
|
|
522
561
|
resultPath: resultFile,
|
|
562
|
+
openUrl: str(item.url, ''),
|
|
523
563
|
buttonsEnabled: settings.buttonsEnabled,
|
|
524
564
|
snoozeMinutes: settings.snoozeMinutes,
|
|
525
565
|
autoCompact: settings.compactOnFullscreen,
|
|
@@ -601,7 +641,10 @@ async function notify(kind, args, settings) {
|
|
|
601
641
|
const kindMessageTemplate = str(settings[`${kind}MessageTemplate`], '')
|
|
602
642
|
const title = renderTemplate(kindTitleTemplate !== '' ? kindTitleTemplate : settings.titleTemplate, '{title}', vars)
|
|
603
643
|
const message = renderTemplate(kindMessageTemplate !== '' ? kindMessageTemplate : settings.messageTemplate, '{message}', vars)
|
|
604
|
-
const
|
|
644
|
+
const secondsWanted = Math.round(clamp(num(args.seconds, settings.seconds), 2, 600))
|
|
645
|
+
// 0.17:单卡最长停留(maxHoldSeconds>0 时再压一道),避免 decide 卡一直挂在屏幕上。
|
|
646
|
+
const seconds =
|
|
647
|
+
settings.maxHoldSeconds > 0 ? Math.min(secondsWanted, settings.maxHoldSeconds) : secondsWanted
|
|
605
648
|
const sound = args.sound === false ? false : settings.sound
|
|
606
649
|
const audio = audioNameOf(kind, settings)
|
|
607
650
|
const speak = str(args.speak, settings.speakEnabled ? message : '')
|
|
@@ -707,11 +750,16 @@ async function notify(kind, args, settings) {
|
|
|
707
750
|
}
|
|
708
751
|
const holdUntil = quiet ? quietEndAt(settings) : 0
|
|
709
752
|
|
|
753
|
+
const dueAt = dueAtOf(args)
|
|
754
|
+
const openUrl = str(args.url, '')
|
|
710
755
|
const item = {
|
|
711
756
|
kind,
|
|
712
757
|
title,
|
|
713
758
|
message,
|
|
714
759
|
seconds,
|
|
760
|
+
url: openUrl,
|
|
761
|
+
dueAt,
|
|
762
|
+
priority: priorityOf(kind),
|
|
715
763
|
sound: sound && audioPath !== '',
|
|
716
764
|
audioPath,
|
|
717
765
|
audioMissing,
|
|
@@ -724,6 +772,12 @@ async function notify(kind, args, settings) {
|
|
|
724
772
|
holdUntil,
|
|
725
773
|
}
|
|
726
774
|
const placement = enqueue(item)
|
|
775
|
+
emitServiceEvent('notified', {
|
|
776
|
+
kind,
|
|
777
|
+
title,
|
|
778
|
+
queued: placement.queued === true || placement.merged === true,
|
|
779
|
+
scheduledAt: dueAt > 0 ? new Date(dueAt).toISOString() : '',
|
|
780
|
+
})
|
|
727
781
|
return {
|
|
728
782
|
ok: true,
|
|
729
783
|
hostMode: 'script',
|
|
@@ -744,6 +798,8 @@ async function notify(kind, args, settings) {
|
|
|
744
798
|
count: placement.count,
|
|
745
799
|
quiet: quiet || undefined,
|
|
746
800
|
holdUntil: holdUntil > 0 ? new Date(holdUntil).toISOString() : undefined,
|
|
801
|
+
url: openUrl !== '' ? openUrl : undefined,
|
|
802
|
+
scheduledAt: dueAt > 0 ? new Date(dueAt).toISOString() : undefined,
|
|
747
803
|
}
|
|
748
804
|
}
|
|
749
805
|
|
|
@@ -765,6 +821,19 @@ const parameters = {
|
|
|
765
821
|
description:
|
|
766
822
|
'用系统语音念出来的句子(不弹窗也能念)。不传时:插件里开了「语音朗读」就念正文,否则不念。',
|
|
767
823
|
},
|
|
824
|
+
url: {
|
|
825
|
+
type: 'string',
|
|
826
|
+
description: '卡片上带一个「打开链接」按钮,点了会用默认浏览器打开这个地址(https 开头)。',
|
|
827
|
+
},
|
|
828
|
+
at: {
|
|
829
|
+
type: 'string',
|
|
830
|
+
description:
|
|
831
|
+
'定时提醒:HH:MM(24 小时制)。到点才弹;今天这个时间已经过了就排到明天,最多等到 24 小时内。',
|
|
832
|
+
},
|
|
833
|
+
inMinutes: {
|
|
834
|
+
type: 'number',
|
|
835
|
+
description: '定时提醒:多少分钟之后弹(1–10080)。和 at 同时给时以 inMinutes 为准。',
|
|
836
|
+
},
|
|
768
837
|
},
|
|
769
838
|
}
|
|
770
839
|
|
|
@@ -810,6 +879,7 @@ const CONFIG_ROUTE = '/dsh-reminder-notify/config'
|
|
|
810
879
|
const PREVIEW_ROUTE = '/dsh-reminder-notify/preview'
|
|
811
880
|
const BALANCE_ROUTE = '/dsh-reminder-notify/balance'
|
|
812
881
|
const HISTORY_ROUTE = '/dsh-reminder-notify/history'
|
|
882
|
+
const EXPORT_ROUTE = '/dsh-reminder-notify/export'
|
|
813
883
|
const DIGEST_ROUTE = '/dsh-reminder-notify/digest'
|
|
814
884
|
|
|
815
885
|
// 面板要「把音频目录里的文件列成下拉」,但 Client 侧没有任何读文件能力,
|
|
@@ -1329,6 +1399,13 @@ export function historyStats(entries) {
|
|
|
1329
1399
|
d.setDate(d.getDate() - i)
|
|
1330
1400
|
buckets.set(dayKey(d.getTime()), 0)
|
|
1331
1401
|
}
|
|
1402
|
+
// 0.17:再给一份 30 天桶,面板画趋势图用(前 7 天与上面完全一致)。
|
|
1403
|
+
const monthBuckets = new Map()
|
|
1404
|
+
for (let i = 29; i >= 0; i -= 1) {
|
|
1405
|
+
const d = new Date()
|
|
1406
|
+
d.setDate(d.getDate() - i)
|
|
1407
|
+
monthBuckets.set(dayKey(d.getTime()), 0)
|
|
1408
|
+
}
|
|
1332
1409
|
const today = dayKey(Date.now())
|
|
1333
1410
|
let todayCount = 0
|
|
1334
1411
|
for (const entry of entries) {
|
|
@@ -1340,6 +1417,7 @@ export function historyStats(entries) {
|
|
|
1340
1417
|
const key = dayKey(num(entry.at, 0))
|
|
1341
1418
|
if (key === today) todayCount += 1
|
|
1342
1419
|
if (buckets.has(key)) buckets.set(key, buckets.get(key) + 1)
|
|
1420
|
+
if (monthBuckets.has(key)) monthBuckets.set(key, monthBuckets.get(key) + 1)
|
|
1343
1421
|
}
|
|
1344
1422
|
return {
|
|
1345
1423
|
total: entries.length,
|
|
@@ -1347,6 +1425,7 @@ export function historyStats(entries) {
|
|
|
1347
1425
|
byKind,
|
|
1348
1426
|
byAction,
|
|
1349
1427
|
last7: [...buckets.entries()].map(([date, count]) => ({ date, count })),
|
|
1428
|
+
last30: [...monthBuckets.entries()].map(([date, count]) => ({ date, count })),
|
|
1350
1429
|
}
|
|
1351
1430
|
}
|
|
1352
1431
|
|
|
@@ -1407,6 +1486,21 @@ export function pushPayload(settings, title, message, extra = {}) {
|
|
|
1407
1486
|
if (settings.pushFormat === 'text') {
|
|
1408
1487
|
return { headers: { 'content-type': 'text/plain; charset=utf-8' }, body: `${title}\n${body}` }
|
|
1409
1488
|
}
|
|
1489
|
+
if (settings.pushFormat === 'telegram') {
|
|
1490
|
+
return {
|
|
1491
|
+
headers: json,
|
|
1492
|
+
body: JSON.stringify({ chat_id: str(settings.pushChat, ''), text: `${title}\n${body}` }),
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
if (settings.pushFormat === 'feishu') {
|
|
1496
|
+
return { headers: json, body: JSON.stringify({ msg_type: 'text', content: { text: `${title}\n${body}` } }) }
|
|
1497
|
+
}
|
|
1498
|
+
if (settings.pushFormat === 'dingtalk') {
|
|
1499
|
+
return {
|
|
1500
|
+
headers: json,
|
|
1501
|
+
body: JSON.stringify({ msgtype: 'markdown', markdown: { title, text: `### ${title}\n\n${body}` } }),
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1410
1504
|
if (settings.pushFormat === 'wecom') {
|
|
1411
1505
|
return { headers: json, body: JSON.stringify({ msgtype: 'text', text: { content: `${title}\n${body}` } }) }
|
|
1412
1506
|
}
|
|
@@ -1780,6 +1874,67 @@ function registerDoctorRoute(ctx, getSettings) {
|
|
|
1780
1874
|
}, 'dsh-reminder-notify: doctor route')
|
|
1781
1875
|
}
|
|
1782
1876
|
|
|
1877
|
+
// 0.17:历史导出 —— 面板点一下,CSV/JSON 落到桌面,方便拿去算账或贴给别人。
|
|
1878
|
+
function exportHistoryFile(settings, entries, format, days) {
|
|
1879
|
+
const since = Date.now() - Math.max(1, days) * 24 * 60 * 60 * 1000
|
|
1880
|
+
const rows = entries.filter((entry) => num(entry?.at, 0) >= since)
|
|
1881
|
+
const stamp = new Date()
|
|
1882
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
1883
|
+
const name = `提醒历史-${stamp.getFullYear()}${pad(stamp.getMonth() + 1)}${pad(stamp.getDate())}-${pad(stamp.getHours())}${pad(stamp.getMinutes())}.${format}`
|
|
1884
|
+
const dir = path.join(os.homedir(), 'Desktop')
|
|
1885
|
+
const file = path.join(dir, name)
|
|
1886
|
+
if (format === 'json') {
|
|
1887
|
+
fs.writeFileSync(file, JSON.stringify(rows, null, 2), 'utf8')
|
|
1888
|
+
return { file, count: rows.length }
|
|
1889
|
+
}
|
|
1890
|
+
const cell = (value) => `"${String(value ?? '').replace(/"/g, '""').replace(/\r?\n/g, ' ')}"`
|
|
1891
|
+
const lines = ['时间,档位,标题,正文,处理方式,条数,稍后提醒,免打扰']
|
|
1892
|
+
for (const entry of rows) {
|
|
1893
|
+
lines.push(
|
|
1894
|
+
[
|
|
1895
|
+
new Date(num(entry.at, 0)).toISOString(),
|
|
1896
|
+
cell(entry.kind),
|
|
1897
|
+
cell(entry.title),
|
|
1898
|
+
cell(entry.message),
|
|
1899
|
+
cell(entry.action),
|
|
1900
|
+
num(entry.count, 1),
|
|
1901
|
+
entry.snoozed === true ? '是' : '否',
|
|
1902
|
+
entry.quiet === true ? '是' : '否',
|
|
1903
|
+
].join(','),
|
|
1904
|
+
)
|
|
1905
|
+
}
|
|
1906
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
1907
|
+
fs.writeFileSync(file, lines.join('\r\n'), 'utf8')
|
|
1908
|
+
return { file, count: rows.length }
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
function registerExportRoute(ctx, getSettings) {
|
|
1912
|
+
const web = ctx.get('webServer')
|
|
1913
|
+
if (web === null || web === undefined || typeof web.register !== 'function') return
|
|
1914
|
+
const reply = (res, status, payload) => {
|
|
1915
|
+
res.statusCode = status
|
|
1916
|
+
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
1917
|
+
res.end(JSON.stringify(payload))
|
|
1918
|
+
}
|
|
1919
|
+
const dispose = web.register({
|
|
1920
|
+
kind: 'exact',
|
|
1921
|
+
path: EXPORT_ROUTE,
|
|
1922
|
+
handler: (req, res) => {
|
|
1923
|
+
try {
|
|
1924
|
+
const settings = getSettings()
|
|
1925
|
+
const url = new URL(req.url ?? EXPORT_ROUTE, 'http://127.0.0.1')
|
|
1926
|
+
const format = url.searchParams.get('format') === 'json' ? 'json' : 'csv'
|
|
1927
|
+
const days = Math.round(clamp(num(url.searchParams.get('days'), 30), 1, 365))
|
|
1928
|
+
const result = exportHistoryFile(settings, readHistory(settings), format, days)
|
|
1929
|
+
reply(res, 200, { ok: true, format, days, file: result.file, count: result.count })
|
|
1930
|
+
} catch (error) {
|
|
1931
|
+
reply(res, 500, { ok: false, error: 'export-failed', detail: String(error?.message ?? error) })
|
|
1932
|
+
}
|
|
1933
|
+
},
|
|
1934
|
+
})
|
|
1935
|
+
ctx.effect(() => dispose, 'dsh-reminder-notify: history export route')
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1783
1938
|
function registerHistoryRoute(ctx, getSettings) {
|
|
1784
1939
|
const web = typeof ctx.get === 'function' ? ctx.get('webServer') : undefined
|
|
1785
1940
|
if (web === undefined || web === null || typeof web.register !== 'function') {
|
|
@@ -1842,10 +1997,36 @@ function packageVersion() {
|
|
|
1842
1997
|
* 0.15 起对外提供的服务:让别的插件也能发提醒、发日报、读统计,而不用自己起宿主。
|
|
1843
1998
|
* 全部方法是 fire-and-forget 语义(返回 Promise,失败只在返回值里体现),不会抛给调用方。
|
|
1844
1999
|
*/
|
|
2000
|
+
const serviceEvents = []
|
|
2001
|
+
const sourceHandlers = new Map()
|
|
2002
|
+
|
|
2003
|
+
// 0.17:服务契约升到 2 —— 版本号、事件流、以及「别的插件也能注册提醒来源」。
|
|
2004
|
+
export function emitServiceEvent(type, payload = {}) {
|
|
2005
|
+
const event = { type, at: Date.now(), payload }
|
|
2006
|
+
serviceEvents.push(event)
|
|
2007
|
+
if (serviceEvents.length > 60) serviceEvents.shift()
|
|
2008
|
+
for (const handler of sourceHandlers.values()) {
|
|
2009
|
+
try {
|
|
2010
|
+
handler(event)
|
|
2011
|
+
} catch {
|
|
2012
|
+
// 别人的 handler 崩了不该影响弹卡
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
return event
|
|
2016
|
+
}
|
|
2017
|
+
|
|
1845
2018
|
export function serviceOf(ctx, getSettings) {
|
|
1846
2019
|
return {
|
|
1847
2020
|
name: 'dsh-reminder-notify',
|
|
1848
2021
|
version: packageVersion(),
|
|
2022
|
+
// 0.17:契约第 2 版 —— 多了事件流与「别的插件也能注册提醒来源」。
|
|
2023
|
+
apiVersion: 2,
|
|
2024
|
+
events: () => serviceEvents.slice(-20),
|
|
2025
|
+
registerSource: (name, handler) => {
|
|
2026
|
+
const key = String(name ?? '').trim() || `source-${sourceHandlers.size + 1}`
|
|
2027
|
+
sourceHandlers.set(key, typeof handler === 'function' ? handler : () => {})
|
|
2028
|
+
return () => sourceHandlers.delete(key)
|
|
2029
|
+
},
|
|
1849
2030
|
/** 发一张提醒卡。kind: done | decide | raw;options 同 notify_user 的参数。 */
|
|
1850
2031
|
notify: (kind, options = {}) => notify(nodeKind(kind), options || {}, getSettings()),
|
|
1851
2032
|
/** 立刻发一条日报(force: true 时忽略「今天已经发过」和「日报未开启」)。 */
|
|
@@ -1874,6 +2055,7 @@ export function apply(ctx, config) {
|
|
|
1874
2055
|
registerPreviewRoute(ctx, () => settingsOf(config))
|
|
1875
2056
|
registerBalanceRoute(ctx, () => settingsOf(config), config)
|
|
1876
2057
|
registerHistoryRoute(ctx, () => settingsOf(config))
|
|
2058
|
+
registerExportRoute(ctx, () => settingsOf(config))
|
|
1877
2059
|
registerDigestRoute(ctx, () => settingsOf(config))
|
|
1878
2060
|
registerDigestLoop(ctx, () => settingsOf(config))
|
|
1879
2061
|
registerDoctorRoute(ctx, () => settingsOf(config))
|
package/package.json
CHANGED