claude-hook-notify 1.2.1 → 1.2.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/notify.js +17 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-hook-notify",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "🔔 Claude Code 任务完成桌面通知 — 一键安装,跨平台支持",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/notify.js CHANGED
@@ -189,6 +189,7 @@ async function sendNotification(options = {}) {
189
189
  let method = "unknown";
190
190
  let command = "";
191
191
  let args = [];
192
+ let tmpFile = null;
192
193
 
193
194
  if (platform === "darwin") {
194
195
  // macOS
@@ -234,43 +235,23 @@ async function sendNotification(options = {}) {
234
235
  return result;
235
236
  }
236
237
  } else if (platform === "win32") {
237
- method = "powershell-toast";
238
- command = "powershell.exe";
239
- const t = title.replace(/'/g, "''");
240
- const m = message.replace(/'/g, "''");
241
- const appId =
242
- "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe";
243
- const psScript = [
244
- "$t='" + t + "'",
245
- "$m='" + m + "'",
246
- "try{",
247
- " [void][Windows.UI.Notifications.ToastNotificationManager,Windows.UI.Notifications,ContentType=WindowsRuntime]",
248
- " [void][Windows.Data.Xml.Dom.XmlDocument,Windows.Data.Xml.Dom,ContentType=WindowsRuntime]",
249
- " $x=New-Object Windows.Data.Xml.Dom.XmlDocument",
250
- " $te=[System.Security.SecurityElement]::Escape($t)",
251
- " $me=[System.Security.SecurityElement]::Escape($m)",
252
- ' $x.LoadXml("<toast><visual><binding template=\'ToastGeneric\'><text>$te</text><text>$me</text></binding></visual></toast>")',
253
- " $toast=[Windows.UI.Notifications.ToastNotification]::new($x)",
254
- " [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('" + appId + "').Show($toast)",
255
- "}catch{",
256
- " [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')",
257
- " $n=New-Object System.Windows.Forms.NotifyIcon",
258
- " $n.Icon=[System.Drawing.SystemIcons]::Information",
259
- " $n.BalloonTipTitle=$t",
260
- " $n.BalloonTipText=$m",
261
- " $n.Visible=$true",
262
- " $n.ShowBalloonTip(5000)",
263
- " Start-Sleep -Seconds 6",
264
- " $n.Dispose()",
265
- "}",
266
- ].join("\n");
267
- const encoded = Buffer.from(psScript, "utf16le").toString("base64");
268
- args = ["-NoProfile", "-EncodedCommand", encoded];
238
+ // VBScript Popup: 零依赖,启动极快(<0.5 秒)
239
+ method = "vbscript-popup";
240
+ command = "wscript";
241
+ const escapedTitle = title.replace(/"/g, '""');
242
+ const escapedMessage = message.replace(/"/g, '""');
243
+ const vbsScript = `CreateObject("WScript.Shell").Popup "${escapedMessage}", 5, "${escapedTitle}", 64`;
244
+ tmpFile = path.join(os.tmpdir(), `claude-notify-${process.pid}.vbs`);
245
+ fs.writeFileSync(tmpFile, vbsScript, "utf-8");
246
+ args = ["//nologo", tmpFile];
269
247
  }
270
248
 
271
249
  const result = { sent: !dryRun, method, command, args };
272
250
 
273
251
  if (dryRun) {
252
+ if (tmpFile) {
253
+ try { fs.unlinkSync(tmpFile); } catch {}
254
+ }
274
255
  result.sent = false;
275
256
  console.log(JSON.stringify(result, null, 2));
276
257
  return result;
@@ -284,6 +265,10 @@ async function sendNotification(options = {}) {
284
265
  } catch (err) {
285
266
  result.sent = false;
286
267
  result.error = err.message;
268
+ } finally {
269
+ if (tmpFile) {
270
+ try { fs.unlinkSync(tmpFile); } catch {}
271
+ }
287
272
  }
288
273
 
289
274
  return result;