dsh-reminder-notify 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +53 -2
- package/assets//346/217/220/347/244/272/351/237/263/345/257/274/345/205/245//345/256/214/346/210/220/346/217/220/351/206/222/350/257/255/351/237/263.wav +0 -0
- package/assets//346/217/220/347/244/272/351/237/263/345/257/274/345/205/245//351/234/200/350/246/201/344/275/240/346/235/245/345/206/263/345/256/232.wav +0 -0
- package/cordis.patch.yml +47 -0
- package/docs/DETAIL.md +86 -0
- package/docs/INSTALL-ZIP.md +30 -0
- package/docs/PUBLISH.md +114 -0
- package/docs/PUSH-CHECKLIST.md +172 -0
- package/host/ReminderHost.ps1 +271 -0
- package/icon.svg +13 -0
- package/index.js +314 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +54 -4
- package/scripts/build-index.mjs +153 -0
- package/scripts/npm-login-and-publish.ps1 +82 -0
- package/scripts/npm-login-tee.ps1 +35 -0
- package/scripts/npm-publish-interactive.ps1 +20 -0
- package/scripts/publish-npm-window.cmd +3 -0
- package/scripts/publish-npm.cmd +5 -0
- package/scripts/publish-npm.ps1 +76 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
<#
|
|
2
|
+
ReminderHost.ps1 —— 零二进制的桌面提醒宿主(Windows 自带 PowerShell 5.1 + WinForms)
|
|
3
|
+
|
|
4
|
+
为什么存在:原来的 assets/Harness完成提醒.exe 是未签名的编译产物,公开分发会被
|
|
5
|
+
SmartScreen / 杀软拦。本脚本用系统自带组件画同一个提醒窗口,仓库里不出现任何二进制,
|
|
6
|
+
也不需要买代码签名证书、不需要编译环境。
|
|
7
|
+
|
|
8
|
+
行为(对齐原 exe):
|
|
9
|
+
· 右下角(可换角)悬浮卡片,圆角、无边框、置顶
|
|
10
|
+
· 不抢焦点(ShowWithoutActivation + WS_EX_NOACTIVATE),不进 Alt+Tab
|
|
11
|
+
· 按秒自动淡出关闭;点一下立即关
|
|
12
|
+
· 可选播放 wav(System.Media.SoundPlayer,异步,不阻塞)
|
|
13
|
+
|
|
14
|
+
参数:-Title -Msg -Seconds -Pos(br|tr|tl|bc|center) -Audio -Accent -NoSound -Log
|
|
15
|
+
#>
|
|
16
|
+
[CmdletBinding()]
|
|
17
|
+
param(
|
|
18
|
+
[string]$Title = 'Harness 提醒',
|
|
19
|
+
[string]$Msg = '',
|
|
20
|
+
[int]$Seconds = 60,
|
|
21
|
+
[ValidateSet('br', 'tr', 'tl', 'bc', 'center')]
|
|
22
|
+
[string]$Pos = 'br',
|
|
23
|
+
[string]$Audio = '',
|
|
24
|
+
[string]$Accent = '#2ECC71',
|
|
25
|
+
[switch]$NoSound,
|
|
26
|
+
[string]$Log = ''
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
$ErrorActionPreference = 'Stop'
|
|
30
|
+
|
|
31
|
+
# ---- 日志(可选,仅用于自测排障) -------------------------------------------
|
|
32
|
+
function Write-Log([string]$text) {
|
|
33
|
+
if ([string]::IsNullOrEmpty($Log)) { return }
|
|
34
|
+
try {
|
|
35
|
+
('{0} {1}' -f (Get-Date -Format 'HH:mm:ss.fff'), $text) | Add-Content -LiteralPath $Log -Encoding UTF8
|
|
36
|
+
} catch { }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# ---- 组装窗口类(C# 源码内联,运行时由系统自带的 csc 编译,不落地任何 exe) --
|
|
40
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
41
|
+
Add-Type -AssemblyName System.Drawing
|
|
42
|
+
|
|
43
|
+
$source = @'
|
|
44
|
+
using System;
|
|
45
|
+
using System.Drawing;
|
|
46
|
+
using System.Runtime.InteropServices;
|
|
47
|
+
using System.Windows.Forms;
|
|
48
|
+
|
|
49
|
+
public sealed class ReminderWindow : Form
|
|
50
|
+
{
|
|
51
|
+
[DllImport("user32.dll")]
|
|
52
|
+
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
|
53
|
+
|
|
54
|
+
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
|
55
|
+
private const uint SWP_NOSIZE = 0x0001;
|
|
56
|
+
private const uint SWP_NOMOVE = 0x0002;
|
|
57
|
+
private const uint SWP_NOACTIVATE = 0x0010;
|
|
58
|
+
private const uint SWP_SHOWWINDOW = 0x0040;
|
|
59
|
+
|
|
60
|
+
public ReminderWindow()
|
|
61
|
+
{
|
|
62
|
+
SetStyle(ControlStyles.OptimizedDoubleBuffer
|
|
63
|
+
| ControlStyles.AllPaintingInWmPaint
|
|
64
|
+
| ControlStyles.UserPaint, true);
|
|
65
|
+
UpdateStyles();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 关键:显示时不激活,抢占焦点会让正在打字的人跳光标
|
|
69
|
+
protected override bool ShowWithoutActivation { get { return true; } }
|
|
70
|
+
|
|
71
|
+
protected override CreateParams CreateParams
|
|
72
|
+
{
|
|
73
|
+
get
|
|
74
|
+
{
|
|
75
|
+
CreateParams cp = base.CreateParams;
|
|
76
|
+
cp.ExStyle |= 0x08000000; // WS_EX_NOACTIVATE
|
|
77
|
+
cp.ExStyle |= 0x00000080; // WS_EX_TOOLWINDOW:不进 Alt+Tab、不出任务栏按钮
|
|
78
|
+
return cp;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public void RaiseWithoutActivating()
|
|
83
|
+
{
|
|
84
|
+
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0,
|
|
85
|
+
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
'@
|
|
89
|
+
|
|
90
|
+
Add-Type -TypeDefinition $source -ReferencedAssemblies System.Windows.Forms, System.Drawing
|
|
91
|
+
|
|
92
|
+
# ---- 外观常量 ---------------------------------------------------------------
|
|
93
|
+
$width = 380
|
|
94
|
+
$radius = 12
|
|
95
|
+
$padX = 16
|
|
96
|
+
$accentWidth = 4
|
|
97
|
+
$bgColor = [System.Drawing.Color]::FromArgb(27, 31, 39) # #1B1F27
|
|
98
|
+
$lineColor = [System.Drawing.Color]::FromArgb(48, 54, 66) # 细边框
|
|
99
|
+
$titleColor = [System.Drawing.Color]::FromArgb(255, 255, 255)
|
|
100
|
+
$bodyColor = [System.Drawing.Color]::FromArgb(201, 209, 217)
|
|
101
|
+
$mutedColor = [System.Drawing.Color]::FromArgb(139, 148, 158)
|
|
102
|
+
# 允许调用方传 "2ECC71"(不带 #):从 node 里 spawn 时,# 开头的 token 会被
|
|
103
|
+
# PowerShell 当成注释,导致 -Accent 后面没有值。这里统一补上 #。
|
|
104
|
+
if ($Accent -and -not $Accent.StartsWith('#')) { $Accent = '#' + $Accent }
|
|
105
|
+
$accentColor = [System.Drawing.ColorTranslator]::FromHtml($Accent)
|
|
106
|
+
|
|
107
|
+
$titleFont = New-Object System.Drawing.Font('Microsoft YaHei UI', 11.5, [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Point)
|
|
108
|
+
$bodyFont = New-Object System.Drawing.Font('Microsoft YaHei UI', 9.5, [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Point)
|
|
109
|
+
$hintFont = New-Object System.Drawing.Font('Microsoft YaHei UI', 8, [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Point)
|
|
110
|
+
|
|
111
|
+
# ---- 先量文字,再定窗口高度(正文自动折行) --------------------------------
|
|
112
|
+
$measureBmp = New-Object System.Drawing.Bitmap 8, 8
|
|
113
|
+
$measureGfx = [System.Drawing.Graphics]::FromImage($measureBmp)
|
|
114
|
+
$measureGfx.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
|
|
115
|
+
|
|
116
|
+
$textWidth = $width - (2 * $padX) - $accentWidth - 6
|
|
117
|
+
$titleSize = $measureGfx.MeasureString($Title, $titleFont, $textWidth)
|
|
118
|
+
$bodyText = if ([string]::IsNullOrWhiteSpace($Msg)) { '' } else { $Msg }
|
|
119
|
+
$bodySize = if ($bodyText -eq '') { New-Object System.Drawing.SizeF 0, 0 } else { $measureGfx.MeasureString($bodyText, $bodyFont, $textWidth) }
|
|
120
|
+
$measureGfx.Dispose()
|
|
121
|
+
$measureBmp.Dispose()
|
|
122
|
+
|
|
123
|
+
$headerHeight = [int][Math]::Ceiling($titleSize.Height)
|
|
124
|
+
$bodyHeight = [int][Math]::Ceiling($bodySize.Height)
|
|
125
|
+
$hintHeight = 16
|
|
126
|
+
$height = $padX + $headerHeight + $(if ($bodyHeight -gt 0) { 4 + $bodyHeight } else { 0 }) + 6 + $hintHeight + $padX
|
|
127
|
+
if ($height -lt 96) { $height = 96 }
|
|
128
|
+
if ($height -gt 260) { $height = 260 }
|
|
129
|
+
|
|
130
|
+
# ---- 定位:光标所在屏幕的工作区 ---------------------------------------------
|
|
131
|
+
$screen = [System.Windows.Forms.Screen]::FromPoint([System.Windows.Forms.Cursor]::Position)
|
|
132
|
+
$area = $screen.WorkingArea
|
|
133
|
+
$margin = 24
|
|
134
|
+
$x = switch ($Pos) {
|
|
135
|
+
'br' { $area.Right - $width - $margin }
|
|
136
|
+
'tr' { $area.Right - $width - $margin }
|
|
137
|
+
'tl' { $area.Left + $margin }
|
|
138
|
+
'bc' { $area.Left + [int](($area.Width - $width) / 2) }
|
|
139
|
+
'center' { $area.Left + [int](($area.Width - $width) / 2) }
|
|
140
|
+
default { $area.Right - $width - $margin }
|
|
141
|
+
}
|
|
142
|
+
$y = switch ($Pos) {
|
|
143
|
+
'tr' { $area.Top + $margin }
|
|
144
|
+
'tl' { $area.Top + $margin }
|
|
145
|
+
'bc' { $area.Bottom - $height - $margin }
|
|
146
|
+
'center' { $area.Top + [int](($area.Height - $height) / 2) }
|
|
147
|
+
default { $area.Bottom - $height - $margin }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
# ---- 窗口 -------------------------------------------------------------------
|
|
151
|
+
$form = New-Object ReminderWindow
|
|
152
|
+
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
|
|
153
|
+
$form.ShowInTaskbar = $false
|
|
154
|
+
$form.TopMost = $true
|
|
155
|
+
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual
|
|
156
|
+
$form.Bounds = New-Object System.Drawing.Rectangle $x, $y, $width, $height
|
|
157
|
+
$form.BackColor = $bgColor
|
|
158
|
+
$form.Opacity = 0
|
|
159
|
+
|
|
160
|
+
# 圆角
|
|
161
|
+
$path = New-Object System.Drawing.Drawing2D.GraphicsPath
|
|
162
|
+
$path.AddArc(0, 0, $radius * 2, $radius * 2, 180, 90)
|
|
163
|
+
$path.AddArc($width - $radius * 2 - 1, 0, $radius * 2, $radius * 2, 270, 90)
|
|
164
|
+
$path.AddArc($width - $radius * 2 - 1, $height - $radius * 2 - 1, $radius * 2, $radius * 2, 0, 90)
|
|
165
|
+
$path.AddArc(0, $height - $radius * 2 - 1, $radius * 2, $radius * 2, 90, 90)
|
|
166
|
+
$path.CloseFigure()
|
|
167
|
+
$form.Region = New-Object System.Drawing.Region $path
|
|
168
|
+
|
|
169
|
+
$form.Add_Paint({
|
|
170
|
+
param($sender, $e)
|
|
171
|
+
$g = $e.Graphics
|
|
172
|
+
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
|
173
|
+
$g.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
|
|
174
|
+
|
|
175
|
+
# 左侧强调色条(用圆角裁剪,跟着卡片形状走)
|
|
176
|
+
$barRect = New-Object System.Drawing.Rectangle 0, 0, ($accentWidth + 8), $height
|
|
177
|
+
$oldClip = $g.Clip
|
|
178
|
+
$g.SetClip($path)
|
|
179
|
+
$barBrush = New-Object System.Drawing.SolidBrush $accentColor
|
|
180
|
+
$g.FillRectangle($barBrush, $barRect)
|
|
181
|
+
$barBrush.Dispose()
|
|
182
|
+
$g.Clip = $oldClip
|
|
183
|
+
|
|
184
|
+
# 边框
|
|
185
|
+
$pen = New-Object System.Drawing.Pen $lineColor, 1
|
|
186
|
+
$g.DrawPath($pen, $path)
|
|
187
|
+
$pen.Dispose()
|
|
188
|
+
|
|
189
|
+
$textLeft = $accentWidth + $padX
|
|
190
|
+
$titleBrush = New-Object System.Drawing.SolidBrush $titleColor
|
|
191
|
+
$g.DrawString($Title, $titleFont, $titleBrush, $textLeft, $padX - 2)
|
|
192
|
+
$titleBrush.Dispose()
|
|
193
|
+
|
|
194
|
+
if ($bodyText -ne '') {
|
|
195
|
+
$bodyBrush = New-Object System.Drawing.SolidBrush $bodyColor
|
|
196
|
+
$bodyRect = New-Object System.Drawing.RectangleF $textLeft, ($padX + $headerHeight + 4), $textWidth, ($bodyHeight + 4)
|
|
197
|
+
$g.DrawString($bodyText, $bodyFont, $bodyBrush, $bodyRect)
|
|
198
|
+
$bodyBrush.Dispose()
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
$hint = ('{0} 秒后自动关闭 · 点一下关掉' -f $Seconds)
|
|
202
|
+
$hintBrush = New-Object System.Drawing.SolidBrush $mutedColor
|
|
203
|
+
$g.DrawString($hint, $hintFont, $hintBrush, $textLeft, ($height - $padX - 12))
|
|
204
|
+
$hintBrush.Dispose()
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
# ---- 淡入 / 停留 / 淡出 ------------------------------------------------------
|
|
208
|
+
$script:phase = 'in'
|
|
209
|
+
$script:ticks = 0
|
|
210
|
+
$fadeTicks = 12 # ~180ms
|
|
211
|
+
$script:deadline = (Get-Date).AddSeconds([Math]::Max(1, $Seconds))
|
|
212
|
+
|
|
213
|
+
$timer = New-Object System.Windows.Forms.Timer
|
|
214
|
+
$timer.Interval = 10
|
|
215
|
+
|
|
216
|
+
$timer.Add_Tick({
|
|
217
|
+
$script:ticks++
|
|
218
|
+
switch ($script:phase) {
|
|
219
|
+
'in' {
|
|
220
|
+
$form.Opacity = [Math]::Min(1.0, $script:ticks / $fadeTicks)
|
|
221
|
+
if ($script:ticks -ge $fadeTicks) { $script:phase = 'hold'; $script:ticks = 0 }
|
|
222
|
+
}
|
|
223
|
+
'hold' {
|
|
224
|
+
# 用真实时钟而不是 tick 数:WinForms 计时器最细约 15ms,数 tick 会明显偏长
|
|
225
|
+
if ((Get-Date) -ge $script:deadline) { $script:phase = 'out'; $script:ticks = 0 }
|
|
226
|
+
}
|
|
227
|
+
'out' {
|
|
228
|
+
$form.Opacity = [Math]::Max(0.0, 1.0 - ($script:ticks / $fadeTicks))
|
|
229
|
+
if ($script:ticks -ge $fadeTicks) {
|
|
230
|
+
$timer.Stop()
|
|
231
|
+
Write-Log 'closed'
|
|
232
|
+
$form.Close()
|
|
233
|
+
[System.Windows.Forms.Application]::Exit()
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
$form.Add_Click({
|
|
240
|
+
if ($script:phase -ne 'out') {
|
|
241
|
+
$script:phase = 'out'
|
|
242
|
+
$script:ticks = 0
|
|
243
|
+
Write-Log 'clicked'
|
|
244
|
+
}
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
# ---- 声音(异步,窗口先出) -------------------------------------------------
|
|
248
|
+
$script:player = $null
|
|
249
|
+
if (-not $NoSound -and -not [string]::IsNullOrEmpty($Audio) -and (Test-Path -LiteralPath $Audio)) {
|
|
250
|
+
try {
|
|
251
|
+
$script:player = New-Object System.Media.SoundPlayer $Audio
|
|
252
|
+
$script:player.Play()
|
|
253
|
+
Write-Log ('audio ' + $Audio)
|
|
254
|
+
} catch {
|
|
255
|
+
Write-Log ('audio-failed ' + $_.Exception.Message)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
# ---- 显示并进入消息循环 -----------------------------------------------------
|
|
260
|
+
$form.Show()
|
|
261
|
+
$form.RaiseWithoutActivating()
|
|
262
|
+
Write-Log ('shown hwnd=' + $form.Handle + ' bounds=' + $form.Bounds)
|
|
263
|
+
$timer.Start()
|
|
264
|
+
[System.Windows.Forms.Application]::Run()
|
|
265
|
+
|
|
266
|
+
if ($script:player -ne $null) { $script:player.Dispose() }
|
|
267
|
+
$titleFont.Dispose()
|
|
268
|
+
$bodyFont.Dispose()
|
|
269
|
+
$hintFont.Dispose()
|
|
270
|
+
$path.Dispose()
|
|
271
|
+
Write-Log 'exit'
|
package/icon.svg
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="Desktop reminder">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#2f6fed"/>
|
|
5
|
+
<stop offset="1" stop-color="#1b3f9e"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="url(#g)"/>
|
|
9
|
+
<path d="M32 14c-6.1 0-10.5 4.6-10.5 10.7v6.1c0 2.4-.9 4.3-2.4 6.1-1.2 1.5-.3 3.6 1.7 3.6h22.4c2 0 2.9-2.1 1.7-3.6-1.5-1.8-2.4-3.7-2.4-6.1v-6.1C42.5 18.6 38.1 14 32 14z" fill="#fff"/>
|
|
10
|
+
<path d="M27 45.5a5 5 0 0 0 10 0z" fill="#ffd45e"/>
|
|
11
|
+
<circle cx="46" cy="18" r="7" fill="#ffd45e"/>
|
|
12
|
+
<path d="M42.6 18.1l2.4 2.4 4.2-4.4" fill="none" stroke="#1b3f9e" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
13
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// dsh-reminder-notify —— 把「桌面提醒」变成 DSH 插件
|
|
2
|
+
//
|
|
3
|
+
// 设计要点(见 docs/DETAIL.md):
|
|
4
|
+
// * 默认宿主是包内的 host/ReminderHost.ps1:系统自带 PowerShell 5.1 + WinForms,
|
|
5
|
+
// C# 代码在运行期用 Add-Type 编译,仓库里没有任何二进制,也就不需要签名证书、
|
|
6
|
+
// 不会被 SmartScreen / 杀软当成未知 exe 拦下来。
|
|
7
|
+
// * 老宿主 Harness完成提醒.exe 仍然支持(hostMode: 'exe'),给已经装了客户端的机器用。
|
|
8
|
+
// * 一律用参数数组而不是 shell 字符串 —— 中文、空格、括号("D:\\a豆包制作工作")都不需要转义。
|
|
9
|
+
// * detached + stdio:'ignore' + unref():弹窗是独立进程,不会拖住 DSH 或本轮对话。
|
|
10
|
+
// * 工具只做一件小事(弹提醒并立刻返回),失败也不抛异常,避免把收尾动作变成阻塞。
|
|
11
|
+
|
|
12
|
+
import { spawn } from 'node:child_process'
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
|
|
17
|
+
export const name = 'dsh-reminder-notify'
|
|
18
|
+
export const inject = ['tools']
|
|
19
|
+
|
|
20
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)))
|
|
21
|
+
const BUNDLED_HOST_SCRIPT = path.join(PACKAGE_ROOT, 'host', 'ReminderHost.ps1')
|
|
22
|
+
const BUNDLED_CLIENT_DIR = path.join(PACKAGE_ROOT, 'assets')
|
|
23
|
+
const BUNDLED_AUDIO_DIR = path.join(PACKAGE_ROOT, 'assets', '提示音导入')
|
|
24
|
+
const EXE_NAME = 'Harness完成提醒.exe'
|
|
25
|
+
const AUDIO_SUBDIR = '提示音导入'
|
|
26
|
+
|
|
27
|
+
const KINDS = ['done', 'decide', 'raw']
|
|
28
|
+
const POSITIONS = new Set(['br', 'center', 'tr'])
|
|
29
|
+
// 脚本宿主额外支持左上、底部居中;exe 宿主只有 br/center/tr,两个模式的交集就是上面这三个。
|
|
30
|
+
|
|
31
|
+
const DEFAULT_TITLES = {
|
|
32
|
+
done: 'Harness 已完成工作',
|
|
33
|
+
decide: '需要你来决定',
|
|
34
|
+
raw: 'Harness 提醒',
|
|
35
|
+
}
|
|
36
|
+
const DEFAULT_MESSAGES = {
|
|
37
|
+
done: '你交代的任务已经做完,可以来收货了。',
|
|
38
|
+
decide: '有件事需要你来决定,请回来看一眼。',
|
|
39
|
+
raw: '',
|
|
40
|
+
}
|
|
41
|
+
const DEFAULT_ACCENTS = {
|
|
42
|
+
done: '#2ECC71',
|
|
43
|
+
decide: '#F5A623',
|
|
44
|
+
raw: '#4C8DFF',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 同一种提醒在冷却窗口内只弹一次:模型偶尔会在同一轮里重复调用收尾提醒。
|
|
48
|
+
const lastFiredAt = new Map()
|
|
49
|
+
|
|
50
|
+
function str(value, fallback) {
|
|
51
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : fallback
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function num(value, fallback) {
|
|
55
|
+
const n = typeof value === 'number' ? value : Number(value)
|
|
56
|
+
return Number.isFinite(n) ? n : fallback
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function clamp(value, min, max) {
|
|
60
|
+
return Math.min(max, Math.max(min, value))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function settingsOf(config) {
|
|
64
|
+
const c = config && typeof config === 'object' ? config : {}
|
|
65
|
+
const position = str(c.position, 'br')
|
|
66
|
+
const hostMode = str(c.hostMode, 'script').toLowerCase()
|
|
67
|
+
return {
|
|
68
|
+
hostMode: hostMode === 'exe' ? 'exe' : 'script',
|
|
69
|
+
clientDir: str(c.clientDir, ''),
|
|
70
|
+
scriptPath: str(c.scriptPath, BUNDLED_HOST_SCRIPT),
|
|
71
|
+
powershellPath: str(c.powershellPath, 'powershell.exe'),
|
|
72
|
+
audioDir: str(c.audioDir, BUNDLED_AUDIO_DIR),
|
|
73
|
+
seconds: Math.round(clamp(num(c.seconds, 60), 2, 600)),
|
|
74
|
+
position: POSITIONS.has(position) ? position : 'br',
|
|
75
|
+
sound: c.sound !== false,
|
|
76
|
+
doneAudio: str(c.doneAudio, '完成提醒语音.wav'),
|
|
77
|
+
decideAudio: str(c.decideAudio, '需要你来决定.wav'),
|
|
78
|
+
rawAudio: str(c.rawAudio, ''),
|
|
79
|
+
accentDone: str(c.accentDone, DEFAULT_ACCENTS.done),
|
|
80
|
+
accentDecide: str(c.accentDecide, DEFAULT_ACCENTS.decide),
|
|
81
|
+
accentRaw: str(c.accentRaw, DEFAULT_ACCENTS.raw),
|
|
82
|
+
cooldownMs: Math.max(0, Math.round(num(c.cooldownMs, 1500))),
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function clientDirOf(settings) {
|
|
87
|
+
const dir = settings.clientDir !== '' ? settings.clientDir : BUNDLED_CLIENT_DIR
|
|
88
|
+
return path.resolve(dir)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function audioNameOf(kind, settings) {
|
|
92
|
+
if (kind === 'done') return settings.doneAudio
|
|
93
|
+
if (kind === 'decide') return settings.decideAudio
|
|
94
|
+
return settings.rawAudio
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function accentOf(kind, settings) {
|
|
98
|
+
const raw = kind === 'done' ? settings.accentDone : kind === 'decide' ? settings.accentDecide : settings.accentRaw
|
|
99
|
+
// 不带 #:PowerShell 会把 # 开头的参数当成注释,后面就等于没传值。
|
|
100
|
+
return String(raw).replace(/^#/, '')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 参数数组交给 spawn,Windows 下由 CreateProcess 的引号规则处理空格与中文;
|
|
104
|
+
// PowerShell 自己还会再解析一遍 -File 之后的参数,所以这里把英文双引号替换掉,
|
|
105
|
+
// 避免一条带引号的正文把后面所有参数吃掉。
|
|
106
|
+
function psSafe(value) {
|
|
107
|
+
return String(value).replace(/"/g, "'").replace(/[\r\n]+/g, ' ')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function launch(file, argv, cwd) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
let child
|
|
113
|
+
try {
|
|
114
|
+
// 注意:这里**不能** detached:true —— 在 Windows 上 detached 会让 powershell.exe
|
|
115
|
+
// 立刻以 0 退出、什么都不画(实测 404ms 就没了,连日志都不写)。
|
|
116
|
+
// windowsHide:true + stdio:'ignore' 已经看不见控制台窗口,unref() 让父进程不必等它。
|
|
117
|
+
child = spawn(file, argv, {
|
|
118
|
+
cwd,
|
|
119
|
+
detached: false,
|
|
120
|
+
stdio: 'ignore',
|
|
121
|
+
windowsHide: true,
|
|
122
|
+
})
|
|
123
|
+
} catch (error) {
|
|
124
|
+
reject(error)
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
const onError = (error) => reject(error)
|
|
128
|
+
child.once('error', onError)
|
|
129
|
+
child.once('spawn', () => {
|
|
130
|
+
child.off('error', onError)
|
|
131
|
+
child.unref()
|
|
132
|
+
resolve({
|
|
133
|
+
pid: child.pid ?? null,
|
|
134
|
+
// 退出码只用于自检,不阻塞工具返回;失败时也不会让本轮报错。
|
|
135
|
+
exited: new Promise((done) => child.once('exit', (code) => done(code))),
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function argvOfScriptHost(title, message, seconds, position, accent, audioPath, sound) {
|
|
142
|
+
const argv = [
|
|
143
|
+
'-NoProfile',
|
|
144
|
+
'-NonInteractive',
|
|
145
|
+
'-ExecutionPolicy',
|
|
146
|
+
'Bypass',
|
|
147
|
+
'-WindowStyle',
|
|
148
|
+
'Hidden',
|
|
149
|
+
'-File',
|
|
150
|
+
null, // 由调用方填入脚本路径
|
|
151
|
+
'-Title',
|
|
152
|
+
psSafe(title),
|
|
153
|
+
'-Msg',
|
|
154
|
+
psSafe(message),
|
|
155
|
+
'-Seconds',
|
|
156
|
+
String(seconds),
|
|
157
|
+
'-Pos',
|
|
158
|
+
position,
|
|
159
|
+
'-Accent',
|
|
160
|
+
accent,
|
|
161
|
+
]
|
|
162
|
+
if (sound && audioPath !== '') argv.push('-Audio', audioPath)
|
|
163
|
+
else argv.push('-NoSound')
|
|
164
|
+
return argv
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function notify(kind, args, settings) {
|
|
168
|
+
if (process.platform !== 'win32') {
|
|
169
|
+
return { ok: false, error: 'only-windows', detail: '桌面提醒只能在本机 Windows 上弹出' }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const title = str(args.title, DEFAULT_TITLES[kind])
|
|
173
|
+
const message = str(args.message, DEFAULT_MESSAGES[kind])
|
|
174
|
+
const seconds = Math.round(clamp(num(args.seconds, settings.seconds), 2, 600))
|
|
175
|
+
const sound = args.sound === false ? false : settings.sound
|
|
176
|
+
const audio = audioNameOf(kind, settings)
|
|
177
|
+
|
|
178
|
+
if (settings.hostMode === 'exe') {
|
|
179
|
+
const dir = clientDirOf(settings)
|
|
180
|
+
const exePath = path.join(dir, EXE_NAME)
|
|
181
|
+
if (!fs.existsSync(exePath)) {
|
|
182
|
+
return {
|
|
183
|
+
ok: false,
|
|
184
|
+
error: 'client-not-found',
|
|
185
|
+
detail: `找不到提醒宿主:${exePath}(hostMode=exe 时检查 clientDir,或改回 hostMode=script 用包内脚本宿主)`,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const argv = ['--title', title, '--msg', message, '--seconds', String(seconds), '--pos', settings.position]
|
|
189
|
+
if (sound && audio !== '') argv.push('--audio', audio)
|
|
190
|
+
else if (!sound) argv.push('--no-sound')
|
|
191
|
+
try {
|
|
192
|
+
const { pid, exited } = await launch(exePath, argv, dir)
|
|
193
|
+
const early = await Promise.race([exited, new Promise((r) => setTimeout(() => r('running'), 300))])
|
|
194
|
+
return {
|
|
195
|
+
ok: true,
|
|
196
|
+
hostMode: 'exe',
|
|
197
|
+
kind,
|
|
198
|
+
title,
|
|
199
|
+
message,
|
|
200
|
+
seconds,
|
|
201
|
+
position: settings.position,
|
|
202
|
+
sound: sound && audio !== '',
|
|
203
|
+
audio: sound ? audio : null,
|
|
204
|
+
pid,
|
|
205
|
+
host: exePath,
|
|
206
|
+
earlyExit: early === 'running' ? null : early,
|
|
207
|
+
}
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return { ok: false, error: 'spawn-failed', detail: String(error && error.message ? error.message : error) }
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 默认:脚本宿主。音频传绝对路径(脚本宿主直接读文件,不像 exe 那样按自身目录解析)。
|
|
214
|
+
const scriptPath = path.resolve(settings.scriptPath)
|
|
215
|
+
if (!fs.existsSync(scriptPath)) {
|
|
216
|
+
return {
|
|
217
|
+
ok: false,
|
|
218
|
+
error: 'host-script-not-found',
|
|
219
|
+
detail: `找不到提醒脚本宿主:${scriptPath}(重新安装插件可恢复包内 host/ReminderHost.ps1)`,
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const audioDir = path.resolve(settings.audioDir)
|
|
223
|
+
const audioPath = sound && audio !== '' ? path.join(audioDir, audio) : ''
|
|
224
|
+
if (audioPath !== '' && !fs.existsSync(audioPath)) {
|
|
225
|
+
// 音频缺失不该让提醒消失:退回静音,正文照常弹。
|
|
226
|
+
return await fireScript(settings, title, message, seconds, kind, '', false, scriptPath, audioPath)
|
|
227
|
+
}
|
|
228
|
+
return await fireScript(settings, title, message, seconds, kind, audioPath, sound, scriptPath, '')
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function fireScript(settings, title, message, seconds, kind, audioPath, sound, scriptPath, missingAudio) {
|
|
232
|
+
const argv = argvOfScriptHost(title, message, seconds, settings.position, accentOf(kind, settings), audioPath, sound)
|
|
233
|
+
argv[argv.indexOf(null)] = scriptPath
|
|
234
|
+
try {
|
|
235
|
+
const { pid, exited } = await launch(settings.powershellPath, argv, PACKAGE_ROOT)
|
|
236
|
+
// Add-Type 编译 C# 需要几百毫秒,所以等 900ms 才能发现「参数错、起不来」的情况。
|
|
237
|
+
const early = await Promise.race([exited, new Promise((r) => setTimeout(() => r('running'), 900))])
|
|
238
|
+
return {
|
|
239
|
+
ok: true,
|
|
240
|
+
hostMode: 'script',
|
|
241
|
+
kind,
|
|
242
|
+
title,
|
|
243
|
+
message,
|
|
244
|
+
seconds,
|
|
245
|
+
position: settings.position,
|
|
246
|
+
sound: sound && audioPath !== '',
|
|
247
|
+
audio: sound && audioPath !== '' ? audioPath : null,
|
|
248
|
+
audioMissing: missingAudio !== '' ? missingAudio : undefined,
|
|
249
|
+
pid,
|
|
250
|
+
host: scriptPath,
|
|
251
|
+
earlyExit: early === 'running' ? null : early,
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return { ok: false, error: 'spawn-failed', detail: String(error && error.message ? error.message : error) }
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const parameters = {
|
|
259
|
+
type: 'object',
|
|
260
|
+
properties: {
|
|
261
|
+
kind: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
enum: KINDS,
|
|
264
|
+
description:
|
|
265
|
+
"提醒档位:done = 一轮工作做完的收尾提醒(默认);decide = 需要用户拍板/同意之前的提醒;raw = 自定标题与正文的通用提醒。",
|
|
266
|
+
},
|
|
267
|
+
message: { type: 'string', description: '弹窗正文。不传时按档位使用默认正文(done / decide 有默认文案)。' },
|
|
268
|
+
title: { type: 'string', description: '弹窗标题。不传时按档位使用默认标题。' },
|
|
269
|
+
seconds: { type: 'number', description: '弹窗停留秒数,2–600。不传用插件 Config 的 seconds(默认 60)。' },
|
|
270
|
+
sound: { type: 'boolean', description: '本次是否播放提示音。不传用插件 Config 的 sound(默认开)。' },
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function toolDefinition(getSettings) {
|
|
275
|
+
return {
|
|
276
|
+
name: 'notify_user',
|
|
277
|
+
description:
|
|
278
|
+
"Pop a native desktop reminder (voice + toast, bottom-right, auto-dismiss, never steals focus) on the user's Windows screen, then return immediately. " +
|
|
279
|
+
'It renders the card with the system PowerShell + WinForms host shipped in this plugin, so nothing is downloaded and no unsigned exe is involved. ' +
|
|
280
|
+
'Use kind="done" when a piece of work is finished and handed off, and kind="decide" before asking the user to approve or choose something. ' +
|
|
281
|
+
'This replaces running 发送提醒.ps1 -Voice 完成/决定 by hand: do not spawn a reminder host yourself, and do not call this in a loop.',
|
|
282
|
+
parameters,
|
|
283
|
+
output: {
|
|
284
|
+
schema: { type: 'string' },
|
|
285
|
+
render: (_args, value) => [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value) }],
|
|
286
|
+
},
|
|
287
|
+
async execute(args) {
|
|
288
|
+
const settings = getSettings()
|
|
289
|
+
const kind = KINDS.includes(args && args.kind) ? args.kind : 'done'
|
|
290
|
+
const cooldownMs = settings.cooldownMs
|
|
291
|
+
const now = Date.now()
|
|
292
|
+
if (cooldownMs > 0) {
|
|
293
|
+
const last = lastFiredAt.get(kind) ?? 0
|
|
294
|
+
if (now - last < cooldownMs) {
|
|
295
|
+
return JSON.stringify({ ok: true, kind, skipped: 'cooldown', cooldownMs })
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const result = await notify(kind, args && typeof args === 'object' ? args : {}, settings)
|
|
299
|
+
if (result.ok) lastFiredAt.set(kind, now)
|
|
300
|
+
return JSON.stringify(result)
|
|
301
|
+
},
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function apply(ctx, config) {
|
|
306
|
+
const tools = typeof ctx.get === 'function' ? ctx.get('tools') : ctx.tools
|
|
307
|
+
if (tools === undefined || tools === null || typeof tools.register !== 'function') {
|
|
308
|
+
ctx.logger?.warn?.('dsh-reminder-notify: tools service is unavailable, notify_user was not registered')
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
const definition = toolDefinition(() => settingsOf(config))
|
|
312
|
+
const dispose = tools.register(definition)
|
|
313
|
+
ctx.effect(() => dispose, 'dsh-reminder-notify: notify_user tool')
|
|
314
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Desktop reminder",
|
|
4
|
+
"description": "Pop a floating reminder with voice when work is done or a decision is needed.",
|
|
5
|
+
"detail": "Registers the notify_user tool, which pops a bottom-right reminder card with the matching voice — never stealing focus, auto-dismissing after N seconds. The card is drawn by host/ReminderHost.ps1 with the system PowerShell + WinForms at run time, so the package ships no exe and is not blocked by SmartScreen or antivirus. Duration, position, sounds, accent colours and the cooldown live in the plugin Config; hostMode=exe still points at the original client folder on older machines."
|
|
6
|
+
}
|
|
7
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "桌面提醒",
|
|
4
|
+
"description": "工作收尾和需要你拍板时,弹出浮动提醒并播放语音。",
|
|
5
|
+
"detail": "把「桌面提醒」包成插件:注册 notify_user 工具,模型在任务收尾(kind=done)或征求同意之前(kind=decide)调用它,右下角弹出提醒卡片并播放对应语音,不抢焦点、按秒自动关闭。卡片宿主是包内的 host/ReminderHost.ps1——用系统自带的 PowerShell + WinForms 在运行期绘制,仓库里没有任何 exe,下载安装不会被 SmartScreen / 杀软拦。停留秒数、位置、提示音、强调色、冷却间隔都在插件 Config 里改;老机器仍可用 hostMode=exe 指向原来的客户端目录。"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-reminder-notify",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "DSH 桌面提醒插件:把「完成/需要决定」提醒变成 notify_user 工具(浮动卡片 + 提示音,不抢焦点,纯 PowerShell 源码宿主,仓库零 exe)",
|
|
5
|
+
"author": "Jiangshuaiye1203",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./icon": "./icon.svg",
|
|
11
|
+
"./locale/*.json": "./locale/*.json",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"host",
|
|
18
|
+
"assets",
|
|
19
|
+
"locale",
|
|
20
|
+
"docs",
|
|
21
|
+
"scripts",
|
|
22
|
+
"icon.svg",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"icon": "./icon.svg",
|
|
27
|
+
"os": [
|
|
28
|
+
"win32"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"dsh",
|
|
35
|
+
"dsh-plugin",
|
|
36
|
+
"deepseek-harness",
|
|
37
|
+
"notify",
|
|
38
|
+
"reminder",
|
|
39
|
+
"toast"
|
|
40
|
+
],
|
|
41
|
+
"dsh": {
|
|
42
|
+
"bundle": {
|
|
43
|
+
"patch": "./cordis.patch.yml"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/Jiangshuaiye1203/dsh-reminder-notify.git"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://jiangshuaiye1203.github.io/dsh-reminder-notify/",
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"registry": "https://registry.npmjs.org/"
|
|
54
|
+
},
|
|
55
|
+
"license": "MIT"
|
|
56
|
+
}
|