dsh-reminder-notify 0.3.1 → 0.5.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/client.js CHANGED
@@ -37,12 +37,19 @@ window.__ModuleLoader__.load({
37
37
  doneAudio: '完成(done)提示音文件',
38
38
  decideAudio: '需要决定(decide)提示音文件',
39
39
  rawAudio: '通用(raw)提示音文件',
40
- audioHint: '填文件名,在下面的提示音目录里找;留空表示静音。',
40
+ audioHint: '填文件名(wav / mp3,ogg 取决于系统解码器),在下面的提示音目录里找;留空表示静音。',
41
41
  audioDir: '提示音目录',
42
42
  audioDirHint: '留空 = 用插件自带的 assets/提示音导入/。',
43
43
  accentDone: '完成强调色',
44
44
  accentDecide: '需要决定强调色',
45
45
  accentRaw: '通用强调色',
46
+ cardBackground: '卡片背景图',
47
+ cardBackgroundHint: 'png / jpg 路径(绝对路径或相对插件目录),留空 = 纯色背景。',
48
+ cardIcon: '标题图标',
49
+ cardIconHint: '标题左侧的小图标(png),留空 = 不显示。',
50
+ titleTemplate: '标题模板',
51
+ messageTemplate: '正文模板',
52
+ templateHint: '可用占位符 {title} {message} {kind} {time}。',
46
53
  hostMode: '宿主模式',
47
54
  hostModeScript: '包内脚本(推荐)',
48
55
  hostModeExe: '外部 exe 客户端',
@@ -84,12 +91,19 @@ window.__ModuleLoader__.load({
84
91
  doneAudio: 'Done sound file',
85
92
  decideAudio: 'Decide sound file',
86
93
  rawAudio: 'Raw sound file',
87
- audioHint: 'A file name resolved inside the sound directory; empty means silent.',
94
+ audioHint: 'A file name resolved inside the sound directory (wav / mp3; ogg depends on system codecs); empty means silent.',
88
95
  audioDir: 'Sound directory',
89
96
  audioDirHint: 'Empty uses the bundled assets/提示音导入/.',
90
97
  accentDone: 'Done accent',
91
98
  accentDecide: 'Decide accent',
92
99
  accentRaw: 'Raw accent',
100
+ cardBackground: 'Card background',
101
+ cardBackgroundHint: 'A png / jpg path (absolute or relative to the plugin); empty keeps the solid colour.',
102
+ cardIcon: 'Title icon',
103
+ cardIconHint: 'A small png shown left of the title; empty hides it.',
104
+ titleTemplate: 'Title template',
105
+ messageTemplate: 'Message template',
106
+ templateHint: 'Placeholders: {title} {message} {kind} {time}.',
93
107
  hostMode: 'Host mode',
94
108
  hostModeScript: 'Bundled script (recommended)',
95
109
  hostModeExe: 'External exe client',
@@ -147,6 +161,10 @@ window.__ModuleLoader__.load({
147
161
  { key: 'accentDone', group: 'look', kind: 'color' },
148
162
  { key: 'accentDecide', group: 'look', kind: 'color' },
149
163
  { key: 'accentRaw', group: 'look', kind: 'color' },
164
+ { key: 'cardBackground', group: 'look', kind: 'text' },
165
+ { key: 'cardIcon', group: 'look', kind: 'text' },
166
+ { key: 'titleTemplate', group: 'look', kind: 'text' },
167
+ { key: 'messageTemplate', group: 'look', kind: 'text' },
150
168
  { key: 'hostMode', group: 'host', kind: 'select', options: ['script', 'exe'], optionLabels: ['hostModeScript', 'hostModeExe'] },
151
169
  { key: 'scriptPath', group: 'host', kind: 'text' },
152
170
  { key: 'powershellPath', group: 'host', kind: 'text' },
@@ -159,6 +177,10 @@ window.__ModuleLoader__.load({
159
177
  cooldownMs: 'cooldownHint',
160
178
  doneAudio: 'audioHint',
161
179
  audioDir: 'audioDirHint',
180
+ cardBackground: 'cardBackgroundHint',
181
+ cardIcon: 'cardIconHint',
182
+ titleTemplate: 'templateHint',
183
+ messageTemplate: 'templateHint',
162
184
  scriptPath: 'scriptPathHint',
163
185
  }
164
186
 
@@ -22,6 +22,8 @@ param(
22
22
  [string]$Pos = 'br',
23
23
  [string]$Audio = '',
24
24
  [string]$Accent = '#2ECC71',
25
+ [string]$Background = '',
26
+ [string]$Icon = '',
25
27
  [switch]$NoSound,
26
28
  [string]$Log = ''
27
29
  )
@@ -114,6 +116,33 @@ $measureGfx = [System.Drawing.Graphics]::FromImage($measureBmp)
114
116
  $measureGfx.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
115
117
 
116
118
  $textWidth = $width - (2 * $padX) - $accentWidth - 6
119
+
120
+ # ---- 自定义外观:背景图与标题左侧图标(都可缺省) ---------------------------
121
+ $iconSize = 22
122
+ $iconGap = 8
123
+ $bgBitmap = $null
124
+ $iconBitmap = $null
125
+ if (-not [string]::IsNullOrEmpty($Background) -and (Test-Path -LiteralPath $Background)) {
126
+ try {
127
+ # 先读进内存,避免 GDI+ 锁住用户文件
128
+ $bgBitmap = New-Object System.Drawing.Bitmap((New-Object System.IO.MemoryStream(,[System.IO.File]::ReadAllBytes($Background))))
129
+ Write-Log ('background ' + $Background)
130
+ } catch {
131
+ $bgBitmap = $null
132
+ Write-Log ('background-failed ' + $_.Exception.Message)
133
+ }
134
+ }
135
+ if (-not [string]::IsNullOrEmpty($Icon) -and (Test-Path -LiteralPath $Icon)) {
136
+ try {
137
+ $iconBitmap = New-Object System.Drawing.Bitmap((New-Object System.IO.MemoryStream(,[System.IO.File]::ReadAllBytes($Icon))))
138
+ Write-Log ('icon ' + $Icon)
139
+ } catch {
140
+ $iconBitmap = $null
141
+ Write-Log ('icon-failed ' + $_.Exception.Message)
142
+ }
143
+ }
144
+ $hasIcon = $iconBitmap -ne $null
145
+ if ($hasIcon) { $textWidth = $textWidth - $iconSize - $iconGap }
117
146
  $titleSize = $measureGfx.MeasureString($Title, $titleFont, $textWidth)
118
147
  $bodyText = if ([string]::IsNullOrWhiteSpace($Msg)) { '' } else { $Msg }
119
148
  $bodySize = if ($bodyText -eq '') { New-Object System.Drawing.SizeF 0, 0 } else { $measureGfx.MeasureString($bodyText, $bodyFont, $textWidth) }
@@ -176,6 +205,19 @@ $form.Add_Paint({
176
205
  $barRect = New-Object System.Drawing.Rectangle 0, 0, ($accentWidth + 8), $height
177
206
  $oldClip = $g.Clip
178
207
  $g.SetClip($path)
208
+ # 背景图:等比裁切鋪满,再压一层暗色保证白字可读
209
+ if ($bgBitmap -ne $null) {
210
+ $g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
211
+ $scale = [Math]::Max($width / $bgBitmap.Width, $height / $bgBitmap.Height)
212
+ $drawW = [int][Math]::Ceiling($bgBitmap.Width * $scale)
213
+ $drawH = [int][Math]::Ceiling($bgBitmap.Height * $scale)
214
+ $dx = [int](($width - $drawW) / 2)
215
+ $dy = [int](($height - $drawH) / 2)
216
+ $g.DrawImage($bgBitmap, (New-Object System.Drawing.Rectangle $dx, $dy, $drawW, $drawH))
217
+ $shade = New-Object System.Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(150, 12, 15, 20))
218
+ $g.FillRectangle($shade, 0, 0, $width, $height)
219
+ $shade.Dispose()
220
+ }
179
221
  $barBrush = New-Object System.Drawing.SolidBrush $accentColor
180
222
  $g.FillRectangle($barBrush, $barRect)
181
223
  $barBrush.Dispose()
@@ -187,6 +229,12 @@ $form.Add_Paint({
187
229
  $pen.Dispose()
188
230
 
189
231
  $textLeft = $accentWidth + $padX
232
+ if ($hasIcon) {
233
+ $g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
234
+ $iconRect = New-Object System.Drawing.Rectangle $textLeft, ($padX - 1), $iconSize, $iconSize
235
+ $g.DrawImage($iconBitmap, $iconRect)
236
+ $textLeft = $textLeft + $iconSize + $iconGap
237
+ }
190
238
  $titleBrush = New-Object System.Drawing.SolidBrush $titleColor
191
239
  $g.DrawString($Title, $titleFont, $titleBrush, $textLeft, $padX - 2)
192
240
  $titleBrush.Dispose()
@@ -245,14 +293,26 @@ $form.Add_Click({
245
293
  })
246
294
 
247
295
  # ---- 声音(异步,窗口先出) -------------------------------------------------
296
+ # wav 用 SoundPlayer(零依赖、异步);其余格式(mp3/wma…)走 Windows Media Player COM。
297
+ # ogg 是否可播取决于系统是否装了对应解码器,播不了只记日志、不影响弹卡。
248
298
  $script:player = $null
299
+ $script:wmp = $null
249
300
  if (-not $NoSound -and -not [string]::IsNullOrEmpty($Audio) -and (Test-Path -LiteralPath $Audio)) {
301
+ $ext = [System.IO.Path]::GetExtension($Audio).ToLowerInvariant()
250
302
  try {
251
- $script:player = New-Object System.Media.SoundPlayer $Audio
252
- $script:player.Play()
253
- Write-Log ('audio ' + $Audio)
303
+ if ($ext -eq '.wav') {
304
+ $script:player = New-Object System.Media.SoundPlayer $Audio
305
+ $script:player.Play()
306
+ Write-Log ('audio wav ' + $Audio)
307
+ } else {
308
+ $script:wmp = New-Object -ComObject WMPlayer.OCX
309
+ $script:wmp.settings.volume = 100
310
+ $script:wmp.URL = $Audio
311
+ $script:wmp.controls.play()
312
+ Write-Log ('audio media ' + $ext + ' ' + $Audio)
313
+ }
254
314
  } catch {
255
- Write-Log ('audio-failed ' + $_.Exception.Message)
315
+ Write-Log ('audio-failed ' + $ext + ' ' + $_.Exception.Message)
256
316
  }
257
317
  }
258
318
 
@@ -264,8 +324,14 @@ $timer.Start()
264
324
  [System.Windows.Forms.Application]::Run()
265
325
 
266
326
  if ($script:player -ne $null) { $script:player.Dispose() }
327
+ if ($script:wmp -ne $null) {
328
+ try { $script:wmp.controls.stop(); $script:wmp.close() } catch { }
329
+ try { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($script:wmp) } catch { }
330
+ }
267
331
  $titleFont.Dispose()
268
332
  $bodyFont.Dispose()
269
333
  $hintFont.Dispose()
334
+ if ($bgBitmap -ne $null) { $bgBitmap.Dispose() }
335
+ if ($iconBitmap -ne $null) { $iconBitmap.Dispose() }
270
336
  $path.Dispose()
271
337
  Write-Log 'exit'
package/index.js CHANGED
@@ -35,13 +35,17 @@ export const Config = z === null ? undefined : z.object({
35
35
  seconds: z.number().min(2).max(600).step(1).default(60).description('弹窗停留秒数(2–600)'),
36
36
  position: z.union(['br', 'center', 'tr']).default('br').description('弹窗位置:br 右下、center 居中、tr 右上'),
37
37
  sound: z.boolean().default(true).description('是否播放提示音'),
38
- doneAudio: z.string().default('完成提醒语音.wav').description('done 档位的提示音文件名(在提示音目录下)'),
39
- decideAudio: z.string().default('需要你来决定.wav').description('decide 档位的提示音文件名'),
40
- rawAudio: z.string().default('').description('raw 档位的提示音文件名,留空 = 静音'),
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
41
  accentDone: z.string().default('#2ECC71').description('done 档位卡片强调色(#RRGGBB)'),
42
42
  accentDecide: z.string().default('#F5A623').description('decide 档位卡片强调色'),
43
43
  accentRaw: z.string().default('#4C8DFF').description('raw 档位卡片强调色'),
44
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
+ titleTemplate: z.string().default('{title}').description('标题模板,可用占位符 {title} {message} {kind} {time}'),
48
+ messageTemplate: z.string().default('{message}').description('正文模板,可用占位符 {title} {message} {kind} {time}'),
45
49
  })
46
50
 
47
51
  const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)))
@@ -107,6 +111,10 @@ function settingsOf(config) {
107
111
  accentDecide: str(c.accentDecide, DEFAULT_ACCENTS.decide),
108
112
  accentRaw: str(c.accentRaw, DEFAULT_ACCENTS.raw),
109
113
  cooldownMs: Math.max(0, Math.round(num(c.cooldownMs, 1500))),
114
+ cardBackground: str(c.cardBackground, ''),
115
+ cardIcon: str(c.cardIcon, ''),
116
+ titleTemplate: typeof c.titleTemplate === 'string' ? c.titleTemplate : '{title}',
117
+ messageTemplate: typeof c.messageTemplate === 'string' ? c.messageTemplate : '{message}',
110
118
  }
111
119
  }
112
120
 
@@ -127,6 +135,25 @@ function accentOf(kind, settings) {
127
135
  return String(raw).replace(/^#/, '')
128
136
  }
129
137
 
138
+ // 文案模板:{title} {message} {kind} {time},模板为空或整行留空时按原文输出。
139
+ function clockText(date) {
140
+ const pad = (n) => String(n).padStart(2, '0')
141
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}`
142
+ }
143
+
144
+ function renderTemplate(template, fallback, vars) {
145
+ const tpl = typeof template === 'string' && template.trim() !== '' ? template : fallback
146
+ return tpl.replace(/\{(title|message|kind|time)\}/g, (_match, key) => String(vars[key] ?? ''))
147
+ }
148
+
149
+ // 背景图 / 图标:支持绝对路径,也支持相对包目录的路径;文件不在就当作没配。
150
+ function assetPath(value) {
151
+ const raw = typeof value === 'string' ? value.trim() : ''
152
+ if (raw === '') return ''
153
+ const full = path.isAbsolute(raw) ? raw : path.resolve(PACKAGE_ROOT, raw)
154
+ return fs.existsSync(full) ? full : ''
155
+ }
156
+
130
157
  // 参数数组交给 spawn,Windows 下由 CreateProcess 的引号规则处理空格与中文;
131
158
  // PowerShell 自己还会再解析一遍 -File 之后的参数,所以这里把英文双引号替换掉,
132
159
  // 避免一条带引号的正文把后面所有参数吃掉。
@@ -165,7 +192,7 @@ function launch(file, argv, cwd) {
165
192
  })
166
193
  }
167
194
 
168
- function argvOfScriptHost(title, message, seconds, position, accent, audioPath, sound) {
195
+ function argvOfScriptHost(title, message, seconds, position, accent, audioPath, sound, extras) {
169
196
  const argv = [
170
197
  '-NoProfile',
171
198
  '-NonInteractive',
@@ -188,6 +215,8 @@ function argvOfScriptHost(title, message, seconds, position, accent, audioPath,
188
215
  ]
189
216
  if (sound && audioPath !== '') argv.push('-Audio', audioPath)
190
217
  else argv.push('-NoSound')
218
+ if (extras && extras.background) argv.push('-Background', extras.background)
219
+ if (extras && extras.icon) argv.push('-Icon', extras.icon)
191
220
  return argv
192
221
  }
193
222
 
@@ -196,8 +225,11 @@ async function notify(kind, args, settings) {
196
225
  return { ok: false, error: 'only-windows', detail: '桌面提醒只能在本机 Windows 上弹出' }
197
226
  }
198
227
 
199
- const title = str(args.title, DEFAULT_TITLES[kind])
200
- const message = str(args.message, DEFAULT_MESSAGES[kind])
228
+ const plainTitle = str(args.title, DEFAULT_TITLES[kind])
229
+ const plainMessage = str(args.message, DEFAULT_MESSAGES[kind])
230
+ const vars = { title: plainTitle, message: plainMessage, kind, time: clockText(new Date()) }
231
+ const title = renderTemplate(settings.titleTemplate, '{title}', vars)
232
+ const message = renderTemplate(settings.messageTemplate, '{message}', vars)
201
233
  const seconds = Math.round(clamp(num(args.seconds, settings.seconds), 2, 600))
202
234
  const sound = args.sound === false ? false : settings.sound
203
235
  const audio = audioNameOf(kind, settings)
@@ -256,7 +288,8 @@ async function notify(kind, args, settings) {
256
288
  }
257
289
 
258
290
  async function fireScript(settings, title, message, seconds, kind, audioPath, sound, scriptPath, missingAudio) {
259
- const argv = argvOfScriptHost(title, message, seconds, settings.position, accentOf(kind, settings), audioPath, sound)
291
+ const extras = { background: assetPath(settings.cardBackground), icon: assetPath(settings.cardIcon) }
292
+ const argv = argvOfScriptHost(title, message, seconds, settings.position, accentOf(kind, settings), audioPath, sound, extras)
260
293
  argv[argv.indexOf(null)] = scriptPath
261
294
  try {
262
295
  const { pid, exited } = await launch(settings.powershellPath, argv, PACKAGE_ROOT)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-reminder-notify",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "DSH 桌面提醒插件:把「完成/需要决定」提醒变成 notify_user 工具(浮动卡片 + 提示音,不抢焦点,纯 PowerShell 源码宿主,仓库零 exe)",
5
5
  "author": "Jiangshuaiye1203",
6
6
  "type": "module",
@@ -48,8 +48,8 @@
48
48
  },
49
49
  "versions": [
50
50
  {
51
- "version": "0.3.0",
52
- "publishTimestamp": 1795058390,
51
+ "version": "0.4.0",
52
+ "publishTimestamp": 1795061969,
53
53
  "source": {
54
54
  "type": "npm"
55
55
  },