dsh-reminder-notify 0.7.0 → 0.8.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/client.js +83 -0
- package/docs/detail.en.md +22 -0
- package/docs/detail.zh.md +22 -0
- package/index.js +129 -28
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
- package/publish/index.json +2 -2
package/client.js
CHANGED
|
@@ -14,6 +14,9 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
const h = React.createElement
|
|
15
15
|
|
|
16
16
|
const NS = 'dsh-reminder-notify'
|
|
17
|
+
// 与 index.js 里 Host 注册的路由保持一致(同源 GET,返回 { dir, files, error? })。
|
|
18
|
+
const AUDIO_ROUTE = '/dsh-reminder-notify/audio'
|
|
19
|
+
const AUDIO_KEYS = ['doneAudio', 'decideAudio', 'rawAudio']
|
|
17
20
|
|
|
18
21
|
const zh = {
|
|
19
22
|
title: '桌面提醒设置',
|
|
@@ -57,6 +60,17 @@ window.__ModuleLoader__.load({
|
|
|
57
60
|
titleTemplate: '标题模板',
|
|
58
61
|
messageTemplate: '正文模板',
|
|
59
62
|
templateHint: '可用占位符 {title} {message} {kind} {time}。',
|
|
63
|
+
doneTitleTemplate: 'done 专用标题模板',
|
|
64
|
+
doneMessageTemplate: 'done 专用正文模板',
|
|
65
|
+
decideTitleTemplate: 'decide 专用标题模板',
|
|
66
|
+
decideMessageTemplate: 'decide 专用正文模板',
|
|
67
|
+
rawTitleTemplate: 'raw 专用标题模板',
|
|
68
|
+
rawMessageTemplate: 'raw 专用正文模板',
|
|
69
|
+
perKindTemplateHint: '留空 = 用上面的通用模板;可用占位符 {title} {message} {kind} {time}。',
|
|
70
|
+
audioPick: '从目录选',
|
|
71
|
+
audioScanning: '正在读取音频目录…',
|
|
72
|
+
audioEmpty: '音频目录里没有可用的音频文件',
|
|
73
|
+
audioFailed: '读取音频目录失败:',
|
|
60
74
|
hostMode: '宿主模式',
|
|
61
75
|
hostModeScript: '包内脚本(推荐)',
|
|
62
76
|
hostModeExe: '外部 exe 客户端',
|
|
@@ -121,6 +135,17 @@ window.__ModuleLoader__.load({
|
|
|
121
135
|
titleTemplate: 'Title template',
|
|
122
136
|
messageTemplate: 'Message template',
|
|
123
137
|
templateHint: 'Placeholders: {title} {message} {kind} {time}.',
|
|
138
|
+
doneTitleTemplate: 'Done-only title template',
|
|
139
|
+
doneMessageTemplate: 'Done-only message template',
|
|
140
|
+
decideTitleTemplate: 'Decide-only title template',
|
|
141
|
+
decideMessageTemplate: 'Decide-only message template',
|
|
142
|
+
rawTitleTemplate: 'Raw-only title template',
|
|
143
|
+
rawMessageTemplate: 'Raw-only message template',
|
|
144
|
+
perKindTemplateHint: 'Empty falls back to the shared template; placeholders: {title} {message} {kind} {time}.',
|
|
145
|
+
audioPick: 'Pick from the directory',
|
|
146
|
+
audioScanning: 'Reading the sound directory…',
|
|
147
|
+
audioEmpty: 'No audio files in the sound directory',
|
|
148
|
+
audioFailed: 'Could not read the sound directory: ',
|
|
124
149
|
hostMode: 'Host mode',
|
|
125
150
|
hostModeScript: 'Bundled script (recommended)',
|
|
126
151
|
hostModeExe: 'External exe client',
|
|
@@ -194,6 +219,12 @@ window.__ModuleLoader__.load({
|
|
|
194
219
|
{ key: 'rawCardIcon', group: 'look', kind: 'text' },
|
|
195
220
|
{ key: 'titleTemplate', group: 'look', kind: 'text' },
|
|
196
221
|
{ key: 'messageTemplate', group: 'look', kind: 'text' },
|
|
222
|
+
{ key: 'doneTitleTemplate', group: 'look', kind: 'text' },
|
|
223
|
+
{ key: 'doneMessageTemplate', group: 'look', kind: 'text' },
|
|
224
|
+
{ key: 'decideTitleTemplate', group: 'look', kind: 'text' },
|
|
225
|
+
{ key: 'decideMessageTemplate', group: 'look', kind: 'text' },
|
|
226
|
+
{ key: 'rawTitleTemplate', group: 'look', kind: 'text' },
|
|
227
|
+
{ key: 'rawMessageTemplate', group: 'look', kind: 'text' },
|
|
197
228
|
{ key: 'hostMode', group: 'host', kind: 'select', options: ['script', 'exe'], optionLabels: ['hostModeScript', 'hostModeExe'] },
|
|
198
229
|
{ key: 'scriptPath', group: 'host', kind: 'text' },
|
|
199
230
|
{ key: 'powershellPath', group: 'host', kind: 'text' },
|
|
@@ -216,6 +247,12 @@ window.__ModuleLoader__.load({
|
|
|
216
247
|
rawCardIcon: 'perKindHint',
|
|
217
248
|
titleTemplate: 'templateHint',
|
|
218
249
|
messageTemplate: 'templateHint',
|
|
250
|
+
doneTitleTemplate: 'perKindTemplateHint',
|
|
251
|
+
doneMessageTemplate: 'perKindTemplateHint',
|
|
252
|
+
decideTitleTemplate: 'perKindTemplateHint',
|
|
253
|
+
decideMessageTemplate: 'perKindTemplateHint',
|
|
254
|
+
rawTitleTemplate: 'perKindTemplateHint',
|
|
255
|
+
rawMessageTemplate: 'perKindTemplateHint',
|
|
219
256
|
scriptPath: 'scriptPathHint',
|
|
220
257
|
}
|
|
221
258
|
|
|
@@ -237,6 +274,30 @@ window.__ModuleLoader__.load({
|
|
|
237
274
|
const [busy, setBusy] = React.useState(false)
|
|
238
275
|
const [picking, setPicking] = React.useState(false)
|
|
239
276
|
const [message, setMessage] = React.useState(null)
|
|
277
|
+
const [audio, setAudio] = React.useState({ dir: '', files: [], error: null })
|
|
278
|
+
|
|
279
|
+
// 音频候选:Host 端注册了只读路由 /dsh-reminder-notify/audio,页面同源 fetch 拿目录清单。
|
|
280
|
+
// 拿不到(旧宿主 / 路由被拦)就静默降级成手填文件名,不打扰用户。
|
|
281
|
+
const scanDir = (draft && typeof draft.audioDir === 'string' && draft.audioDir !== '' ? draft.audioDir : values.audioDir) || ''
|
|
282
|
+
React.useEffect(() => {
|
|
283
|
+
if (typeof fetch !== 'function') return undefined
|
|
284
|
+
let cancelled = false
|
|
285
|
+
const url = AUDIO_ROUTE + (scanDir === '' ? '' : '?dir=' + encodeURIComponent(scanDir))
|
|
286
|
+
Promise.resolve()
|
|
287
|
+
.then(() => fetch(url, { headers: { accept: 'application/json' } }))
|
|
288
|
+
.then((response) => (response && response.ok ? response.json() : Promise.reject(new Error('HTTP ' + (response ? response.status : '?')))))
|
|
289
|
+
.then((data) => {
|
|
290
|
+
if (cancelled) return
|
|
291
|
+
setAudio({ dir: (data && data.dir) || scanDir, files: data && Array.isArray(data.files) ? data.files : [], error: (data && data.error) || null })
|
|
292
|
+
})
|
|
293
|
+
.catch((error) => {
|
|
294
|
+
if (cancelled) return
|
|
295
|
+
setAudio({ dir: scanDir, files: [], error: String((error && error.message) || error) })
|
|
296
|
+
})
|
|
297
|
+
return () => {
|
|
298
|
+
cancelled = true
|
|
299
|
+
}
|
|
300
|
+
}, [scanDir])
|
|
240
301
|
|
|
241
302
|
if (props.view === 'summary') {
|
|
242
303
|
const tr = typeof t === 'function' ? t : (key) => key
|
|
@@ -349,6 +410,28 @@ window.__ModuleLoader__.load({
|
|
|
349
410
|
disabled,
|
|
350
411
|
onChange: (e) => edit(field.key, e.target.value, field.kind),
|
|
351
412
|
})
|
|
413
|
+
if (AUDIO_KEYS.includes(field.key) && audio.files.length > 0) {
|
|
414
|
+
return h(
|
|
415
|
+
'div',
|
|
416
|
+
{ className: 'drn-pick' },
|
|
417
|
+
input,
|
|
418
|
+
h(
|
|
419
|
+
'select',
|
|
420
|
+
{
|
|
421
|
+
className: 'drn-select',
|
|
422
|
+
disabled,
|
|
423
|
+
value: '',
|
|
424
|
+
onChange: (e) => {
|
|
425
|
+
const picked = e.target.value
|
|
426
|
+
if (picked !== '') edit(field.key, picked, 'text')
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
[h('option', { value: '' }, typeof t === 'function' ? t('audioPick') : 'pick')].concat(
|
|
430
|
+
audio.files.map((name) => h('option', { value: name }, name)),
|
|
431
|
+
),
|
|
432
|
+
),
|
|
433
|
+
)
|
|
434
|
+
}
|
|
352
435
|
if (field.pick === 'directory' && typeof props.pickDirectory === 'function') {
|
|
353
436
|
return h(
|
|
354
437
|
'div',
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Desktop reminder (dsh-reminder-notify)
|
|
2
|
+
|
|
3
|
+
Adds a `notify_user` tool to DeepSeek Harness: when work is done (`kind=done`) or a decision is needed (`kind=decide`), a reminder card pops in the bottom-right with the matching voice — never stealing focus, auto-dismissing after N seconds.
|
|
4
|
+
|
|
5
|
+
The card host is the bundled `host/ReminderHost.ps1`, drawn with the system PowerShell 5.1 + WinForms at run time, so the package ships no exe and is not blocked by SmartScreen or antivirus.
|
|
6
|
+
|
|
7
|
+
## Settings
|
|
8
|
+
|
|
9
|
+
Open "Desktop reminder" in the Plugins page; the panel sits right under the description and has four groups:
|
|
10
|
+
|
|
11
|
+
- **Basics**: duration, position, sound on/off
|
|
12
|
+
- **Sounds**: audio directory ("Browse…" picks a directory), the three per-kind file names (wav / mp3). Once a directory is picked the dropdown lists the audio files in it.
|
|
13
|
+
- **Look**: background image, title icon, accent colours, title/message templates (`{title}` `{message}` `{kind}` `{time}`), plus per-kind overrides for background, icon and templates
|
|
14
|
+
- **Host**: script or exe host, script path, PowerShell path
|
|
15
|
+
|
|
16
|
+
Changes apply on "Save" — no restart needed.
|
|
17
|
+
|
|
18
|
+
## Known limits
|
|
19
|
+
|
|
20
|
+
- Windows only (`os: ["win32"]`): the card host is WinForms.
|
|
21
|
+
- Each card spawns a PowerShell process; `Add-Type` compilation takes about 0.6 s before the card appears.
|
|
22
|
+
- The card lives with the DSH host process; closing DSH closes a card that is still on screen.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# 桌面提醒 dsh-reminder-notify
|
|
2
|
+
|
|
3
|
+
给 DeepSeek Harness 加一个 `notify_user` 工具:模型在任务收尾(`kind=done`)或征求同意之前(`kind=decide`)调用它,屏幕右下角弹出提醒卡片并播放对应语音,不抢焦点、按秒自动关闭。
|
|
4
|
+
|
|
5
|
+
卡片宿主是包内的 `host/ReminderHost.ps1`——用系统自带的 PowerShell 5.1 + WinForms 在运行期绘制,仓库里没有任何 exe,下载安装不会被 SmartScreen / 杀软拦。
|
|
6
|
+
|
|
7
|
+
## 设置
|
|
8
|
+
|
|
9
|
+
在「插件」页打开「桌面提醒」,描述下方就是设置面板,分四组:
|
|
10
|
+
|
|
11
|
+
- **基本**:停留秒数、弹窗位置、是否播放提示音
|
|
12
|
+
- **提示音**:提示音目录(可点「浏览…」选目录)、三档提示音文件名(wav / mp3),选了目录后下拉框会列出目录里的音频
|
|
13
|
+
- **外观**:背景图、标题图标、强调色、标题/正文模板(`{title}` `{message}` `{kind}` `{time}`),以及每档位单独覆盖的背景 / 图标 / 模板
|
|
14
|
+
- **宿主**:脚本模式或 exe 模式、脚本路径、PowerShell 路径
|
|
15
|
+
|
|
16
|
+
改完点「保存」,立刻生效,不用重启。
|
|
17
|
+
|
|
18
|
+
## 已知限制
|
|
19
|
+
|
|
20
|
+
- 仅 Windows(`os: ["win32"]`):卡片宿主是 WinForms。
|
|
21
|
+
- 每次弹卡片要起一个 PowerShell 进程,`Add-Type` 编译约 0.6 s 才出现。
|
|
22
|
+
- 卡片随 DSH 宿主进程存活;DSH 关掉时正在显示的卡片也会一起消失。
|
package/index.js
CHANGED
|
@@ -26,32 +26,45 @@ const z = await import('@deepseek-ai/schemastery')
|
|
|
26
26
|
|
|
27
27
|
// 插件页的设置表单由这份 schema 渲染(client.js 再在上面做分组面板)。
|
|
28
28
|
// 每一项的默认值与 settingsOf() 里的兜底一致:空字符串表示「用包内资源」。
|
|
29
|
+
//
|
|
30
|
+
// 为什么每个字段都要 .volatile():宿主 settings.describe() 只把「可按热更新就地改动」
|
|
31
|
+
// 的字段投影进 namespaces(volatileForm 会跳过没有 volatile 标记的字段),而插件页的
|
|
32
|
+
// 设置面板只对 namespaces 里出现过的条目渲染 form。不标 volatile 的话面板会拿到
|
|
33
|
+
// undefined 并显示「这个页面拿不到插件配置」。
|
|
34
|
+
// 标了 volatile 还有个好处:改完立刻生效,不用重启插件 —— notify() 每次调用都会用
|
|
35
|
+
// settingsOf(config) 现读,所以拿到的就是最新值。
|
|
29
36
|
export const Config = z === null ? undefined : z.object({
|
|
30
|
-
hostMode: z.union(['script', 'exe']).default('script').description('宿主模式:script = 包内 PowerShell 脚本(默认),exe = 老的客户端 exe'),
|
|
31
|
-
scriptPath: z.string().default('').description('脚本宿主路径,留空 = 包内 host/ReminderHost.ps1'),
|
|
32
|
-
powershellPath: z.string().default('powershell.exe').description('调 PowerShell 用的可执行文件'),
|
|
33
|
-
clientDir: z.string().default('').description('exe 模式下的客户端目录,留空 = 包内 assets/'),
|
|
34
|
-
audioDir: z.string().default('').description('提示音目录,留空 = 包内 assets/提示音导入/'),
|
|
35
|
-
seconds: z.number().min(2).max(600).step(1).default(60).description('弹窗停留秒数(2–600)'),
|
|
36
|
-
position: z.union(['br', 'center', 'tr']).default('br').description('弹窗位置:br 右下、center 居中、tr 右上'),
|
|
37
|
-
sound: z.boolean().default(true).description('是否播放提示音'),
|
|
38
|
-
doneAudio: z.string().default('完成提醒语音.wav').description('done 档位的提示音文件名(wav / mp3,在提示音目录下)'),
|
|
39
|
-
decideAudio: z.string().default('需要你来决定.wav').description('decide 档位的提示音文件名(wav / mp3)'),
|
|
40
|
-
rawAudio: z.string().default('').description('raw 档位的提示音文件名(wav / mp3),留空 = 静音'),
|
|
41
|
-
accentDone: z.string().default('#2ECC71').description('done 档位卡片强调色(#RRGGBB)'),
|
|
42
|
-
accentDecide: z.string().default('#F5A623').description('decide 档位卡片强调色'),
|
|
43
|
-
accentRaw: z.string().default('#4C8DFF').description('raw 档位卡片强调色'),
|
|
44
|
-
cooldownMs: z.number().min(0).step(100).default(1500).description('同档位提醒的最小间隔(毫秒)'),
|
|
45
|
-
cardBackground: z.string().default('').description('卡片背景图路径(png / jpg),留空 = 纯色背景'),
|
|
46
|
-
cardIcon: z.string().default('').description('标题左侧的小图标路径(png / ico),留空 = 不显示'),
|
|
47
|
-
doneCardBackground: z.string().default('').description('done 档位单独用的背景图,留空 = 用上面的通用背景'),
|
|
48
|
-
decideCardBackground: z.string().default('').description('decide 档位单独用的背景图,留空 = 用通用背景'),
|
|
49
|
-
rawCardBackground: z.string().default('').description('raw 档位单独用的背景图,留空 = 用通用背景'),
|
|
50
|
-
doneCardIcon: z.string().default('').description('done 档位单独用的标题图标,留空 = 用通用图标'),
|
|
51
|
-
decideCardIcon: z.string().default('').description('decide 档位单独用的标题图标,留空 = 用通用图标'),
|
|
52
|
-
rawCardIcon: z.string().default('').description('raw 档位单独用的标题图标,留空 = 用通用图标'),
|
|
53
|
-
titleTemplate: z.string().default('{title}').description('标题模板,可用占位符 {title} {message} {kind} {time}'),
|
|
54
|
-
messageTemplate: z.string().default('{message}').description('正文模板,可用占位符 {title} {message} {kind} {time}'),
|
|
37
|
+
hostMode: z.union(['script', 'exe']).default('script').description('宿主模式:script = 包内 PowerShell 脚本(默认),exe = 老的客户端 exe').volatile(),
|
|
38
|
+
scriptPath: z.string().default('').description('脚本宿主路径,留空 = 包内 host/ReminderHost.ps1').volatile(),
|
|
39
|
+
powershellPath: z.string().default('powershell.exe').description('调 PowerShell 用的可执行文件').volatile(),
|
|
40
|
+
clientDir: z.string().default('').description('exe 模式下的客户端目录,留空 = 包内 assets/').volatile(),
|
|
41
|
+
audioDir: z.string().default('').description('提示音目录,留空 = 包内 assets/提示音导入/').volatile(),
|
|
42
|
+
seconds: z.number().min(2).max(600).step(1).default(60).description('弹窗停留秒数(2–600)').volatile(),
|
|
43
|
+
position: z.union(['br', 'center', 'tr']).default('br').description('弹窗位置:br 右下、center 居中、tr 右上').volatile(),
|
|
44
|
+
sound: z.boolean().default(true).description('是否播放提示音').volatile(),
|
|
45
|
+
doneAudio: z.string().default('完成提醒语音.wav').description('done 档位的提示音文件名(wav / mp3,在提示音目录下)').volatile(),
|
|
46
|
+
decideAudio: z.string().default('需要你来决定.wav').description('decide 档位的提示音文件名(wav / mp3)').volatile(),
|
|
47
|
+
rawAudio: z.string().default('').description('raw 档位的提示音文件名(wav / mp3),留空 = 静音').volatile(),
|
|
48
|
+
accentDone: z.string().default('#2ECC71').description('done 档位卡片强调色(#RRGGBB)').volatile(),
|
|
49
|
+
accentDecide: z.string().default('#F5A623').description('decide 档位卡片强调色').volatile(),
|
|
50
|
+
accentRaw: z.string().default('#4C8DFF').description('raw 档位卡片强调色').volatile(),
|
|
51
|
+
cooldownMs: z.number().min(0).step(100).default(1500).description('同档位提醒的最小间隔(毫秒)').volatile(),
|
|
52
|
+
cardBackground: z.string().default('').description('卡片背景图路径(png / jpg),留空 = 纯色背景').volatile(),
|
|
53
|
+
cardIcon: z.string().default('').description('标题左侧的小图标路径(png / ico),留空 = 不显示').volatile(),
|
|
54
|
+
doneCardBackground: z.string().default('').description('done 档位单独用的背景图,留空 = 用上面的通用背景').volatile(),
|
|
55
|
+
decideCardBackground: z.string().default('').description('decide 档位单独用的背景图,留空 = 用通用背景').volatile(),
|
|
56
|
+
rawCardBackground: z.string().default('').description('raw 档位单独用的背景图,留空 = 用通用背景').volatile(),
|
|
57
|
+
doneCardIcon: z.string().default('').description('done 档位单独用的标题图标,留空 = 用通用图标').volatile(),
|
|
58
|
+
decideCardIcon: z.string().default('').description('decide 档位单独用的标题图标,留空 = 用通用图标').volatile(),
|
|
59
|
+
rawCardIcon: z.string().default('').description('raw 档位单独用的标题图标,留空 = 用通用图标').volatile(),
|
|
60
|
+
titleTemplate: z.string().default('{title}').description('标题模板,可用占位符 {title} {message} {kind} {time}').volatile(),
|
|
61
|
+
messageTemplate: z.string().default('{message}').description('正文模板,可用占位符 {title} {message} {kind} {time}').volatile(),
|
|
62
|
+
doneTitleTemplate: z.string().default('').description('done 档位单独的标题模板,留空 = 用上面的通用模板').volatile(),
|
|
63
|
+
doneMessageTemplate: z.string().default('').description('done 档位单独的正文模板,留空 = 用通用模板').volatile(),
|
|
64
|
+
decideTitleTemplate: z.string().default('').description('decide 档位单独的标题模板,留空 = 用通用模板').volatile(),
|
|
65
|
+
decideMessageTemplate: z.string().default('').description('decide 档位单独的正文模板,留空 = 用通用模板').volatile(),
|
|
66
|
+
rawTitleTemplate: z.string().default('').description('raw 档位单独的标题模板,留空 = 用通用模板').volatile(),
|
|
67
|
+
rawMessageTemplate: z.string().default('').description('raw 档位单独的正文模板,留空 = 用通用模板').volatile(),
|
|
55
68
|
})
|
|
56
69
|
|
|
57
70
|
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)))
|
|
@@ -97,8 +110,31 @@ function clamp(value, min, max) {
|
|
|
97
110
|
return Math.min(max, Math.max(min, value))
|
|
98
111
|
}
|
|
99
112
|
|
|
113
|
+
// 标了 .volatile() 的字段在运行期是 { get(), [write]() } 包装(schemastery 的热更新句柄),
|
|
114
|
+
// 直接读会把字符串读成 "[object Object]",所以统一在这里解包。
|
|
115
|
+
function unwrapValue(value) {
|
|
116
|
+
if (value !== null && typeof value === 'object' && typeof value.get === 'function') {
|
|
117
|
+
try {
|
|
118
|
+
return value.get()
|
|
119
|
+
} catch {
|
|
120
|
+
return undefined
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return value
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function configValues(config) {
|
|
127
|
+
const out = {}
|
|
128
|
+
if (config !== null && typeof config === 'object') {
|
|
129
|
+
for (const key of Object.keys(config)) {
|
|
130
|
+
Object.defineProperty(out, key, { value: unwrapValue(config[key]), enumerable: true })
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return out
|
|
134
|
+
}
|
|
135
|
+
|
|
100
136
|
function settingsOf(config) {
|
|
101
|
-
const c = config
|
|
137
|
+
const c = configValues(config)
|
|
102
138
|
const position = str(c.position, 'br')
|
|
103
139
|
const hostMode = str(c.hostMode, 'script').toLowerCase()
|
|
104
140
|
return {
|
|
@@ -127,6 +163,12 @@ function settingsOf(config) {
|
|
|
127
163
|
rawCardIcon: str(c.rawCardIcon, ''),
|
|
128
164
|
titleTemplate: typeof c.titleTemplate === 'string' ? c.titleTemplate : '{title}',
|
|
129
165
|
messageTemplate: typeof c.messageTemplate === 'string' ? c.messageTemplate : '{message}',
|
|
166
|
+
doneTitleTemplate: typeof c.doneTitleTemplate === 'string' ? c.doneTitleTemplate : '',
|
|
167
|
+
doneMessageTemplate: typeof c.doneMessageTemplate === 'string' ? c.doneMessageTemplate : '',
|
|
168
|
+
decideTitleTemplate: typeof c.decideTitleTemplate === 'string' ? c.decideTitleTemplate : '',
|
|
169
|
+
decideMessageTemplate: typeof c.decideMessageTemplate === 'string' ? c.decideMessageTemplate : '',
|
|
170
|
+
rawTitleTemplate: typeof c.rawTitleTemplate === 'string' ? c.rawTitleTemplate : '',
|
|
171
|
+
rawMessageTemplate: typeof c.rawMessageTemplate === 'string' ? c.rawMessageTemplate : '',
|
|
130
172
|
}
|
|
131
173
|
}
|
|
132
174
|
|
|
@@ -251,8 +293,11 @@ async function notify(kind, args, settings) {
|
|
|
251
293
|
const plainTitle = str(args.title, DEFAULT_TITLES[kind])
|
|
252
294
|
const plainMessage = str(args.message, DEFAULT_MESSAGES[kind])
|
|
253
295
|
const vars = { title: plainTitle, message: plainMessage, kind, time: clockText(new Date()) }
|
|
254
|
-
|
|
255
|
-
const
|
|
296
|
+
// 档位模板优先:留空就退回上面的通用模板,两层都空才落到 "{title}" / "{message}"。
|
|
297
|
+
const kindTitleTemplate = str(settings[`${kind}TitleTemplate`], '')
|
|
298
|
+
const kindMessageTemplate = str(settings[`${kind}MessageTemplate`], '')
|
|
299
|
+
const title = renderTemplate(kindTitleTemplate !== '' ? kindTitleTemplate : settings.titleTemplate, '{title}', vars)
|
|
300
|
+
const message = renderTemplate(kindMessageTemplate !== '' ? kindMessageTemplate : settings.messageTemplate, '{message}', vars)
|
|
256
301
|
const seconds = Math.round(clamp(num(args.seconds, settings.seconds), 2, 600))
|
|
257
302
|
const sound = args.sound === false ? false : settings.sound
|
|
258
303
|
const audio = audioNameOf(kind, settings)
|
|
@@ -387,7 +432,63 @@ function toolDefinition(getSettings) {
|
|
|
387
432
|
}
|
|
388
433
|
}
|
|
389
434
|
|
|
435
|
+
const AUDIO_EXTENSIONS = ['.wav', '.mp3', '.ogg', '.m4a', '.flac', '.aac', '.wma']
|
|
436
|
+
const AUDIO_ROUTE = '/dsh-reminder-notify/audio'
|
|
437
|
+
|
|
438
|
+
// 面板要「把音频目录里的文件列成下拉」,但 Client 侧没有任何读文件能力,
|
|
439
|
+
// 所以由 Host 注册一条只读的 GET 路由,页面用同源 fetch 取这个 JSON。
|
|
440
|
+
export function listAudioFiles(dir) {
|
|
441
|
+
const files = []
|
|
442
|
+
let entries = []
|
|
443
|
+
try {
|
|
444
|
+
entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
445
|
+
} catch (error) {
|
|
446
|
+
return { dir, files, error: String((error && error.message) || error) }
|
|
447
|
+
}
|
|
448
|
+
for (const entry of entries) {
|
|
449
|
+
if (!entry.isFile()) continue
|
|
450
|
+
const ext = path.extname(entry.name).toLowerCase()
|
|
451
|
+
if (AUDIO_EXTENSIONS.includes(ext)) files.push(entry.name)
|
|
452
|
+
}
|
|
453
|
+
files.sort((a, b) => a.localeCompare(b, 'zh-Hans-CN'))
|
|
454
|
+
return { dir, files }
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function registerAudioRoute(ctx, getSettings) {
|
|
458
|
+
const web = typeof ctx.get === 'function' ? ctx.get('webServer') : undefined
|
|
459
|
+
if (web === undefined || web === null || typeof web.register !== 'function') {
|
|
460
|
+
ctx.logger?.warn?.('dsh-reminder-notify: webServer is unavailable, the audio list dropdown stays manual-entry only')
|
|
461
|
+
return
|
|
462
|
+
}
|
|
463
|
+
const route = {
|
|
464
|
+
kind: 'exact',
|
|
465
|
+
path: AUDIO_ROUTE,
|
|
466
|
+
handler: (req, res) => {
|
|
467
|
+
const settings = getSettings()
|
|
468
|
+
const requested = (() => {
|
|
469
|
+
try {
|
|
470
|
+
const url = new URL(req.url ?? AUDIO_ROUTE, 'http://127.0.0.1')
|
|
471
|
+
return url.searchParams.get('dir') ?? ''
|
|
472
|
+
} catch {
|
|
473
|
+
return ''
|
|
474
|
+
}
|
|
475
|
+
})()
|
|
476
|
+
const dir = requested !== '' ? path.resolve(requested) : settings.audioDir
|
|
477
|
+
const body = JSON.stringify(listAudioFiles(dir))
|
|
478
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
479
|
+
res.end(body)
|
|
480
|
+
},
|
|
481
|
+
}
|
|
482
|
+
ctx.effect(() => {
|
|
483
|
+
const dispose = web.register(route)
|
|
484
|
+
return () => {
|
|
485
|
+
if (typeof dispose === 'function') dispose()
|
|
486
|
+
}
|
|
487
|
+
}, 'dsh-reminder-notify: audio list route')
|
|
488
|
+
}
|
|
489
|
+
|
|
390
490
|
export function apply(ctx, config) {
|
|
491
|
+
registerAudioRoute(ctx, () => settingsOf(config))
|
|
391
492
|
const tools = typeof ctx.get === 'function' ? ctx.get('tools') : ctx.tools
|
|
392
493
|
if (tools === undefined || tools === null || typeof tools.register !== 'function') {
|
|
393
494
|
ctx.logger?.warn?.('dsh-reminder-notify: tools service is unavailable, notify_user was not registered')
|
package/locale/en.json
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Desktop reminder",
|
|
4
4
|
"description": "Pop a floating reminder with voice when work is done or a decision is needed.",
|
|
5
|
-
"detail": "
|
|
5
|
+
"detail": "docs/detail.en.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "桌面提醒",
|
|
4
4
|
"description": "工作收尾和需要你拍板时,弹出浮动提醒并播放语音。",
|
|
5
|
-
"detail": "
|
|
5
|
+
"detail": "docs/detail.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED