dsh-reminder-notify 0.4.0 → 0.6.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 +48 -0
- package/host/ReminderHost.ps1 +50 -0
- package/index.js +63 -5
- package/package.json +1 -1
- package/publish/index.json +2 -2
package/client.js
CHANGED
|
@@ -43,6 +43,20 @@ window.__ModuleLoader__.load({
|
|
|
43
43
|
accentDone: '完成强调色',
|
|
44
44
|
accentDecide: '需要决定强调色',
|
|
45
45
|
accentRaw: '通用强调色',
|
|
46
|
+
cardBackground: '卡片背景图',
|
|
47
|
+
cardBackgroundHint: 'png / jpg 路径(绝对路径或相对插件目录),留空 = 纯色背景。',
|
|
48
|
+
cardIcon: '标题图标',
|
|
49
|
+
cardIconHint: '标题左侧的小图标(png),留空 = 不显示。',
|
|
50
|
+
doneCardBackground: 'done 专用背景图',
|
|
51
|
+
decideCardBackground: 'decide 专用背景图',
|
|
52
|
+
rawCardBackground: 'raw 专用背景图',
|
|
53
|
+
doneCardIcon: 'done 专用图标',
|
|
54
|
+
decideCardIcon: 'decide 专用图标',
|
|
55
|
+
rawCardIcon: 'raw 专用图标',
|
|
56
|
+
perKindHint: '按档位覆盖通用设置,留空就用上面的通用背景 / 图标。',
|
|
57
|
+
titleTemplate: '标题模板',
|
|
58
|
+
messageTemplate: '正文模板',
|
|
59
|
+
templateHint: '可用占位符 {title} {message} {kind} {time}。',
|
|
46
60
|
hostMode: '宿主模式',
|
|
47
61
|
hostModeScript: '包内脚本(推荐)',
|
|
48
62
|
hostModeExe: '外部 exe 客户端',
|
|
@@ -90,6 +104,20 @@ window.__ModuleLoader__.load({
|
|
|
90
104
|
accentDone: 'Done accent',
|
|
91
105
|
accentDecide: 'Decide accent',
|
|
92
106
|
accentRaw: 'Raw accent',
|
|
107
|
+
cardBackground: 'Card background',
|
|
108
|
+
cardBackgroundHint: 'A png / jpg path (absolute or relative to the plugin); empty keeps the solid colour.',
|
|
109
|
+
cardIcon: 'Title icon',
|
|
110
|
+
cardIconHint: 'A small png shown left of the title; empty hides it.',
|
|
111
|
+
doneCardBackground: 'Done-only background',
|
|
112
|
+
decideCardBackground: 'Decide-only background',
|
|
113
|
+
rawCardBackground: 'Raw-only background',
|
|
114
|
+
doneCardIcon: 'Done-only icon',
|
|
115
|
+
decideCardIcon: 'Decide-only icon',
|
|
116
|
+
rawCardIcon: 'Raw-only icon',
|
|
117
|
+
perKindHint: 'Overrides the shared background / icon per kind; empty falls back to the shared value.',
|
|
118
|
+
titleTemplate: 'Title template',
|
|
119
|
+
messageTemplate: 'Message template',
|
|
120
|
+
templateHint: 'Placeholders: {title} {message} {kind} {time}.',
|
|
93
121
|
hostMode: 'Host mode',
|
|
94
122
|
hostModeScript: 'Bundled script (recommended)',
|
|
95
123
|
hostModeExe: 'External exe client',
|
|
@@ -147,6 +175,16 @@ window.__ModuleLoader__.load({
|
|
|
147
175
|
{ key: 'accentDone', group: 'look', kind: 'color' },
|
|
148
176
|
{ key: 'accentDecide', group: 'look', kind: 'color' },
|
|
149
177
|
{ key: 'accentRaw', group: 'look', kind: 'color' },
|
|
178
|
+
{ key: 'cardBackground', group: 'look', kind: 'text' },
|
|
179
|
+
{ key: 'cardIcon', group: 'look', kind: 'text' },
|
|
180
|
+
{ key: 'doneCardBackground', group: 'look', kind: 'text' },
|
|
181
|
+
{ key: 'decideCardBackground', group: 'look', kind: 'text' },
|
|
182
|
+
{ key: 'rawCardBackground', group: 'look', kind: 'text' },
|
|
183
|
+
{ key: 'doneCardIcon', group: 'look', kind: 'text' },
|
|
184
|
+
{ key: 'decideCardIcon', group: 'look', kind: 'text' },
|
|
185
|
+
{ key: 'rawCardIcon', group: 'look', kind: 'text' },
|
|
186
|
+
{ key: 'titleTemplate', group: 'look', kind: 'text' },
|
|
187
|
+
{ key: 'messageTemplate', group: 'look', kind: 'text' },
|
|
150
188
|
{ key: 'hostMode', group: 'host', kind: 'select', options: ['script', 'exe'], optionLabels: ['hostModeScript', 'hostModeExe'] },
|
|
151
189
|
{ key: 'scriptPath', group: 'host', kind: 'text' },
|
|
152
190
|
{ key: 'powershellPath', group: 'host', kind: 'text' },
|
|
@@ -159,6 +197,16 @@ window.__ModuleLoader__.load({
|
|
|
159
197
|
cooldownMs: 'cooldownHint',
|
|
160
198
|
doneAudio: 'audioHint',
|
|
161
199
|
audioDir: 'audioDirHint',
|
|
200
|
+
cardBackground: 'cardBackgroundHint',
|
|
201
|
+
cardIcon: 'cardIconHint',
|
|
202
|
+
doneCardBackground: 'perKindHint',
|
|
203
|
+
decideCardBackground: 'perKindHint',
|
|
204
|
+
rawCardBackground: 'perKindHint',
|
|
205
|
+
doneCardIcon: 'perKindHint',
|
|
206
|
+
decideCardIcon: 'perKindHint',
|
|
207
|
+
rawCardIcon: 'perKindHint',
|
|
208
|
+
titleTemplate: 'templateHint',
|
|
209
|
+
messageTemplate: 'templateHint',
|
|
162
210
|
scriptPath: 'scriptPathHint',
|
|
163
211
|
}
|
|
164
212
|
|
package/host/ReminderHost.ps1
CHANGED
|
@@ -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()
|
|
@@ -283,5 +331,7 @@ if ($script:wmp -ne $null) {
|
|
|
283
331
|
$titleFont.Dispose()
|
|
284
332
|
$bodyFont.Dispose()
|
|
285
333
|
$hintFont.Dispose()
|
|
334
|
+
if ($bgBitmap -ne $null) { $bgBitmap.Dispose() }
|
|
335
|
+
if ($iconBitmap -ne $null) { $iconBitmap.Dispose() }
|
|
286
336
|
$path.Dispose()
|
|
287
337
|
Write-Log 'exit'
|
package/index.js
CHANGED
|
@@ -42,6 +42,16 @@ export const Config = z === null ? undefined : z.object({
|
|
|
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
|
+
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}'),
|
|
45
55
|
})
|
|
46
56
|
|
|
47
57
|
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)))
|
|
@@ -107,6 +117,16 @@ function settingsOf(config) {
|
|
|
107
117
|
accentDecide: str(c.accentDecide, DEFAULT_ACCENTS.decide),
|
|
108
118
|
accentRaw: str(c.accentRaw, DEFAULT_ACCENTS.raw),
|
|
109
119
|
cooldownMs: Math.max(0, Math.round(num(c.cooldownMs, 1500))),
|
|
120
|
+
cardBackground: str(c.cardBackground, ''),
|
|
121
|
+
cardIcon: str(c.cardIcon, ''),
|
|
122
|
+
doneCardBackground: str(c.doneCardBackground, ''),
|
|
123
|
+
decideCardBackground: str(c.decideCardBackground, ''),
|
|
124
|
+
rawCardBackground: str(c.rawCardBackground, ''),
|
|
125
|
+
doneCardIcon: str(c.doneCardIcon, ''),
|
|
126
|
+
decideCardIcon: str(c.decideCardIcon, ''),
|
|
127
|
+
rawCardIcon: str(c.rawCardIcon, ''),
|
|
128
|
+
titleTemplate: typeof c.titleTemplate === 'string' ? c.titleTemplate : '{title}',
|
|
129
|
+
messageTemplate: typeof c.messageTemplate === 'string' ? c.messageTemplate : '{message}',
|
|
110
130
|
}
|
|
111
131
|
}
|
|
112
132
|
|
|
@@ -127,7 +147,37 @@ function accentOf(kind, settings) {
|
|
|
127
147
|
return String(raw).replace(/^#/, '')
|
|
128
148
|
}
|
|
129
149
|
|
|
130
|
-
//
|
|
150
|
+
// 文案模板:{title} {message} {kind} {time},模板为空或整行留空时按原文输出。
|
|
151
|
+
function clockText(date) {
|
|
152
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
153
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function renderTemplate(template, fallback, vars) {
|
|
157
|
+
const tpl = typeof template === 'string' && template.trim() !== '' ? template : fallback
|
|
158
|
+
return tpl.replace(/\{(title|message|kind|time)\}/g, (_match, key) => String(vars[key] ?? ''))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 背景图 / 图标:支持绝对路径,也支持相对包目录的路径;文件不在就当作没配。
|
|
162
|
+
function assetPath(value) {
|
|
163
|
+
const raw = typeof value === 'string' ? value.trim() : ''
|
|
164
|
+
if (raw === '') return ''
|
|
165
|
+
const full = path.isAbsolute(raw) ? raw : path.resolve(PACKAGE_ROOT, raw)
|
|
166
|
+
return fs.existsSync(full) ? full : ''
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 档位外观:doneCardBackground / decideCardIcon 这类按档位覆盖,留空就退回通用值。
|
|
170
|
+
function appearanceOf(kind, settings) {
|
|
171
|
+
const background = str(settings[`${kind}CardBackground`], '') !== ''
|
|
172
|
+
? settings[`${kind}CardBackground`]
|
|
173
|
+
: settings.cardBackground
|
|
174
|
+
const icon = str(settings[`${kind}CardIcon`], '') !== ''
|
|
175
|
+
? settings[`${kind}CardIcon`]
|
|
176
|
+
: settings.cardIcon
|
|
177
|
+
return { background: assetPath(background), icon: assetPath(icon) }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
131
181
|
// PowerShell 自己还会再解析一遍 -File 之后的参数,所以这里把英文双引号替换掉,
|
|
132
182
|
// 避免一条带引号的正文把后面所有参数吃掉。
|
|
133
183
|
function psSafe(value) {
|
|
@@ -165,7 +215,7 @@ function launch(file, argv, cwd) {
|
|
|
165
215
|
})
|
|
166
216
|
}
|
|
167
217
|
|
|
168
|
-
function argvOfScriptHost(title, message, seconds, position, accent, audioPath, sound) {
|
|
218
|
+
function argvOfScriptHost(title, message, seconds, position, accent, audioPath, sound, extras) {
|
|
169
219
|
const argv = [
|
|
170
220
|
'-NoProfile',
|
|
171
221
|
'-NonInteractive',
|
|
@@ -188,6 +238,8 @@ function argvOfScriptHost(title, message, seconds, position, accent, audioPath,
|
|
|
188
238
|
]
|
|
189
239
|
if (sound && audioPath !== '') argv.push('-Audio', audioPath)
|
|
190
240
|
else argv.push('-NoSound')
|
|
241
|
+
if (extras && extras.background) argv.push('-Background', extras.background)
|
|
242
|
+
if (extras && extras.icon) argv.push('-Icon', extras.icon)
|
|
191
243
|
return argv
|
|
192
244
|
}
|
|
193
245
|
|
|
@@ -196,8 +248,11 @@ async function notify(kind, args, settings) {
|
|
|
196
248
|
return { ok: false, error: 'only-windows', detail: '桌面提醒只能在本机 Windows 上弹出' }
|
|
197
249
|
}
|
|
198
250
|
|
|
199
|
-
const
|
|
200
|
-
const
|
|
251
|
+
const plainTitle = str(args.title, DEFAULT_TITLES[kind])
|
|
252
|
+
const plainMessage = str(args.message, DEFAULT_MESSAGES[kind])
|
|
253
|
+
const vars = { title: plainTitle, message: plainMessage, kind, time: clockText(new Date()) }
|
|
254
|
+
const title = renderTemplate(settings.titleTemplate, '{title}', vars)
|
|
255
|
+
const message = renderTemplate(settings.messageTemplate, '{message}', vars)
|
|
201
256
|
const seconds = Math.round(clamp(num(args.seconds, settings.seconds), 2, 600))
|
|
202
257
|
const sound = args.sound === false ? false : settings.sound
|
|
203
258
|
const audio = audioNameOf(kind, settings)
|
|
@@ -256,7 +311,8 @@ async function notify(kind, args, settings) {
|
|
|
256
311
|
}
|
|
257
312
|
|
|
258
313
|
async function fireScript(settings, title, message, seconds, kind, audioPath, sound, scriptPath, missingAudio) {
|
|
259
|
-
const
|
|
314
|
+
const extras = appearanceOf(kind, settings)
|
|
315
|
+
const argv = argvOfScriptHost(title, message, seconds, settings.position, accentOf(kind, settings), audioPath, sound, extras)
|
|
260
316
|
argv[argv.indexOf(null)] = scriptPath
|
|
261
317
|
try {
|
|
262
318
|
const { pid, exited } = await launch(settings.powershellPath, argv, PACKAGE_ROOT)
|
|
@@ -273,6 +329,8 @@ async function fireScript(settings, title, message, seconds, kind, audioPath, so
|
|
|
273
329
|
sound: sound && audioPath !== '',
|
|
274
330
|
audio: sound && audioPath !== '' ? audioPath : null,
|
|
275
331
|
audioMissing: missingAudio !== '' ? missingAudio : undefined,
|
|
332
|
+
background: extras.background !== '' ? extras.background : null,
|
|
333
|
+
icon: extras.icon !== '' ? extras.icon : null,
|
|
276
334
|
pid,
|
|
277
335
|
host: scriptPath,
|
|
278
336
|
earlyExit: early === 'running' ? null : early,
|
package/package.json
CHANGED