@timmy6942025/cli-timer 1.1.2 → 1.1.4

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/index.js +46 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmy6942025/cli-timer",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Simple customizable terminal timer and stopwatch",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -14,6 +14,8 @@ const TIMER_SAMPLE_TEXT = "00:00:00";
14
14
 
15
15
  const MIN_TICK_RATE_MS = 50;
16
16
  const MAX_TICK_RATE_MS = 1000;
17
+ const MAC_NOTIFICATION_VERIFY_ATTEMPTS = 8;
18
+ const MAC_NOTIFICATION_VERIFY_DELAY_MS = 75;
17
19
 
18
20
  const DEFAULT_KEYBINDINGS = Object.freeze({
19
21
  pauseKey: "p",
@@ -480,6 +482,43 @@ function spawnOk(command, args, options) {
480
482
  }
481
483
  }
482
484
 
485
+ function sleepSync(ms) {
486
+ const durationMs = Math.max(0, Number(ms) || 0);
487
+ if (durationMs <= 0) {
488
+ return;
489
+ }
490
+ try {
491
+ const waitArray = new Int32Array(new SharedArrayBuffer(4));
492
+ Atomics.wait(waitArray, 0, 0, durationMs);
493
+ } catch (_error) {
494
+ const started = Date.now();
495
+ while (Date.now() - started < durationMs) {
496
+ }
497
+ }
498
+ }
499
+
500
+ function terminalNotifierDelivered(groupId) {
501
+ try {
502
+ for (let attempt = 0; attempt < MAC_NOTIFICATION_VERIFY_ATTEMPTS; attempt += 1) {
503
+ const listed = spawnSync("terminal-notifier", ["-list", groupId], { encoding: "utf8", stdio: "pipe" });
504
+ if (!listed.error && listed.status === 0) {
505
+ const output = String(listed.stdout || "");
506
+ if (output.includes(groupId)) {
507
+ return true;
508
+ }
509
+ }
510
+ if (attempt + 1 < MAC_NOTIFICATION_VERIFY_ATTEMPTS) {
511
+ sleepSync(MAC_NOTIFICATION_VERIFY_DELAY_MS);
512
+ }
513
+ }
514
+ return false;
515
+ } catch (_error) {
516
+ return false;
517
+ } finally {
518
+ spawnOk("terminal-notifier", ["-remove", groupId]);
519
+ }
520
+ }
521
+
483
522
  function sendSystemNotification({ title, message }) {
484
523
  const safeTitle = String(title || "").trim() || "Timer";
485
524
  const safeMessage = String(message || "").trim();
@@ -490,8 +529,13 @@ function sendSystemNotification({ title, message }) {
490
529
 
491
530
  try {
492
531
  if (process.platform === "darwin") {
493
- if (spawnOk("terminal-notifier", ["-title", safeTitle, "-message", safeMessage])) {
494
- return true;
532
+ const groupId = `cli-timer-${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
533
+ if (
534
+ spawnOk("terminal-notifier", ["-title", safeTitle, "-message", safeMessage, "-group", groupId, "-ignoreDnD"])
535
+ ) {
536
+ if (terminalNotifierDelivered(groupId)) {
537
+ return true;
538
+ }
495
539
  }
496
540
  const script = `display notification "${escapeAppleScriptString(safeMessage)}" with title "${escapeAppleScriptString(safeTitle)}"`;
497
541
  if (spawnOk("osascript", ["-e", script])) {