feat(pi-notifications): add standalone test-notify.ts and fix AppleScript sound bug
- Add packages/pi-notifications/src/test-notify.ts for isolated testing
- Run with: node --input-type=module -e "import {createJiti} from ..." ./packages/pi-notifications/src/test-notify.ts
- Decoupled from agent loop — verifies osascript in extension context
- Fix: 'default' is a reserved word in AppleScript, skip sound param when sound='default'
- Synced fix to auto-discovery extension path
This commit is contained in:
parent
45a13fd08c
commit
383cb46fe7
@ -15,7 +15,8 @@ function notify(body: string, subtitle?: string): void {
|
||||
if (!enabled) return;
|
||||
try {
|
||||
const sub = subtitle ? `subtitle "${subtitle}"` : "";
|
||||
const snd = sound ? `sound "${sound}"` : "";
|
||||
// "default" is a reserved word in AppleScript, so only add sound param if it's a custom sound
|
||||
const snd = sound && sound !== "default" ? `sound "${sound}"` : "";
|
||||
execSync(
|
||||
`osascript -e 'display notification "${body}" with title "${title}" ${sub} ${snd}'`.trim(),
|
||||
{ stdio: "ignore" }
|
||||
|
||||
25
packages/pi-notifications/src/test-notify.ts
Normal file
25
packages/pi-notifications/src/test-notify.ts
Normal file
@ -0,0 +1,25 @@
|
||||
// Standalone notification tester — run from bash to verify osascript works
|
||||
// Usage: npx jiti packages/pi-notifications/src/test-notify.ts
|
||||
//
|
||||
// This is completely decoupled from the agent loop.
|
||||
// Use it to verify that the extension's notification machinery works
|
||||
// before debugging event handler wiring.
|
||||
|
||||
import { execSync } from "node:child_process";
|
||||
|
||||
const title = process.env.PI_NOTIFICATION_TITLE || "pi";
|
||||
const sound = process.env.PI_NOTIFICATION_SOUND || "default";
|
||||
|
||||
// "default" is a reserved word in AppleScript, so only add sound param if it's a custom sound
|
||||
const soundArg = sound && sound !== "default" ? `sound "${sound}"` : "";
|
||||
|
||||
try {
|
||||
const cmd = `osascript -e 'display notification "Test notification from pi-notifications" with title "${title}" ${soundArg}'`.trim();
|
||||
console.log("[test-notify] running:", cmd);
|
||||
execSync(cmd, { stdio: ["ignore", "pipe", "pipe"] });
|
||||
console.log("[test-notify] ✅ Notification sent — check your Notification Center");
|
||||
} catch (e: any) {
|
||||
console.error("[test-notify] ❌ Failed:", e.message);
|
||||
console.error("[test-notify] Try running the command directly in bash to verify osascript works.");
|
||||
process.exit(1);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user