@timmy6942025/cli-timer 1.1.3 → 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 +32 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmy6942025/cli-timer",
3
- "version": "1.1.3",
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,14 +482,36 @@ 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
+
483
500
  function terminalNotifierDelivered(groupId) {
484
501
  try {
485
- const listed = spawnSync("terminal-notifier", ["-list", groupId], { encoding: "utf8", stdio: "pipe" });
486
- if (listed.error || listed.status !== 0) {
487
- return false;
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
+ }
488
513
  }
489
- const output = String(listed.stdout || "");
490
- return output.includes(groupId);
514
+ return false;
491
515
  } catch (_error) {
492
516
  return false;
493
517
  } finally {
@@ -506,7 +530,9 @@ function sendSystemNotification({ title, message }) {
506
530
  try {
507
531
  if (process.platform === "darwin") {
508
532
  const groupId = `cli-timer-${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
509
- if (spawnOk("terminal-notifier", ["-title", safeTitle, "-message", safeMessage, "-group", groupId])) {
533
+ if (
534
+ spawnOk("terminal-notifier", ["-title", safeTitle, "-message", safeMessage, "-group", groupId, "-ignoreDnD"])
535
+ ) {
510
536
  if (terminalNotifierDelivered(groupId)) {
511
537
  return true;
512
538
  }