@timmy6942025/cli-timer 1.1.4 → 1.1.5
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/index.js +71 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -497,6 +497,56 @@ function sleepSync(ms) {
|
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
+
function readProcessCommand(pid) {
|
|
501
|
+
try {
|
|
502
|
+
const result = spawnSync("ps", ["-p", String(pid), "-o", "comm="], { encoding: "utf8", stdio: "pipe" });
|
|
503
|
+
if (result.error || result.status !== 0) {
|
|
504
|
+
return "";
|
|
505
|
+
}
|
|
506
|
+
return String(result.stdout || "").trim();
|
|
507
|
+
} catch (_error) {
|
|
508
|
+
return "";
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function resolveMacNotificationSenderCandidates() {
|
|
513
|
+
const candidates = [];
|
|
514
|
+
const explicit = String(process.env.CLI_TIMER_NOTIFICATION_SENDER || "").trim();
|
|
515
|
+
if (explicit) {
|
|
516
|
+
candidates.push(explicit);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const termProgram = String(process.env.TERM_PROGRAM || "").toLowerCase();
|
|
520
|
+
if (termProgram === "apple_terminal") {
|
|
521
|
+
candidates.push("com.apple.Terminal");
|
|
522
|
+
} else if (termProgram === "iterm.app") {
|
|
523
|
+
candidates.push("com.googlecode.iterm2");
|
|
524
|
+
} else if (termProgram === "vscode") {
|
|
525
|
+
candidates.push("com.microsoft.VSCode");
|
|
526
|
+
} else if (termProgram === "warpterminal" || termProgram === "warp") {
|
|
527
|
+
candidates.push("dev.warp.Warp-Stable");
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const parentCommand = readProcessCommand(process.ppid).toLowerCase();
|
|
531
|
+
if (parentCommand.includes("terminal.app")) {
|
|
532
|
+
candidates.push("com.apple.Terminal");
|
|
533
|
+
}
|
|
534
|
+
if (parentCommand.includes("iterm")) {
|
|
535
|
+
candidates.push("com.googlecode.iterm2");
|
|
536
|
+
}
|
|
537
|
+
if (parentCommand.includes("warp")) {
|
|
538
|
+
candidates.push("dev.warp.Warp-Stable");
|
|
539
|
+
}
|
|
540
|
+
if (parentCommand.includes("visual studio code") || parentCommand.includes("vscode")) {
|
|
541
|
+
candidates.push("com.microsoft.VSCode");
|
|
542
|
+
}
|
|
543
|
+
if (parentCommand.includes("codex.app")) {
|
|
544
|
+
candidates.push("com.openai.codex");
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return [...new Set(candidates)].filter(Boolean);
|
|
548
|
+
}
|
|
549
|
+
|
|
500
550
|
function terminalNotifierDelivered(groupId) {
|
|
501
551
|
try {
|
|
502
552
|
for (let attempt = 0; attempt < MAC_NOTIFICATION_VERIFY_ATTEMPTS; attempt += 1) {
|
|
@@ -514,8 +564,6 @@ function terminalNotifierDelivered(groupId) {
|
|
|
514
564
|
return false;
|
|
515
565
|
} catch (_error) {
|
|
516
566
|
return false;
|
|
517
|
-
} finally {
|
|
518
|
-
spawnOk("terminal-notifier", ["-remove", groupId]);
|
|
519
567
|
}
|
|
520
568
|
}
|
|
521
569
|
|
|
@@ -529,12 +577,27 @@ function sendSystemNotification({ title, message }) {
|
|
|
529
577
|
|
|
530
578
|
try {
|
|
531
579
|
if (process.platform === "darwin") {
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
580
|
+
const senderCandidates = resolveMacNotificationSenderCandidates();
|
|
581
|
+
const senderArgsSets = senderCandidates.map((bundleId) => ["-sender", bundleId]);
|
|
582
|
+
senderArgsSets.push([]);
|
|
583
|
+
|
|
584
|
+
for (const senderArgs of senderArgsSets) {
|
|
585
|
+
const groupId = `cli-timer-${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
|
|
586
|
+
if (
|
|
587
|
+
spawnOk("terminal-notifier", [
|
|
588
|
+
"-title",
|
|
589
|
+
safeTitle,
|
|
590
|
+
"-message",
|
|
591
|
+
safeMessage,
|
|
592
|
+
"-group",
|
|
593
|
+
groupId,
|
|
594
|
+
"-ignoreDnD",
|
|
595
|
+
...senderArgs
|
|
596
|
+
])
|
|
597
|
+
) {
|
|
598
|
+
if (terminalNotifierDelivered(groupId)) {
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
538
601
|
}
|
|
539
602
|
}
|
|
540
603
|
const script = `display notification "${escapeAppleScriptString(safeMessage)}" with title "${escapeAppleScriptString(safeTitle)}"`;
|