claude-hook-notify 1.2.0 → 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.
- package/package.json +1 -1
- package/src/notify.js +19 -45
package/package.json
CHANGED
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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;
|
|
@@ -278,23 +259,16 @@ async function sendNotification(options = {}) {
|
|
|
278
259
|
|
|
279
260
|
try {
|
|
280
261
|
if (command) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const { spawn } = require("child_process");
|
|
284
|
-
const child = spawn(command, args, {
|
|
285
|
-
detached: true,
|
|
286
|
-
stdio: "ignore",
|
|
287
|
-
windowsHide: true,
|
|
288
|
-
});
|
|
289
|
-
child.unref();
|
|
290
|
-
} else {
|
|
291
|
-
const { execFileSync } = require("child_process");
|
|
292
|
-
execFileSync(command, args, { stdio: "ignore", timeout: 5000 });
|
|
293
|
-
}
|
|
262
|
+
const { execFileSync } = require("child_process");
|
|
263
|
+
execFileSync(command, args, { stdio: "ignore", timeout: 8000 });
|
|
294
264
|
}
|
|
295
265
|
} catch (err) {
|
|
296
266
|
result.sent = false;
|
|
297
267
|
result.error = err.message;
|
|
268
|
+
} finally {
|
|
269
|
+
if (tmpFile) {
|
|
270
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
271
|
+
}
|
|
298
272
|
}
|
|
299
273
|
|
|
300
274
|
return result;
|