kaizen-agent 1.53.0 → 1.54.0

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.
@@ -24,8 +24,58 @@ export function askNotify() {
24
24
  if (typeof Notification !== "undefined" && Notification.permission === "default") Notification.requestPermission();
25
25
  } catch (e) {}
26
26
  }
27
+ // Per browser: whether notices go out at all, and the sound each one plays. The OS
28
+ // notification's own sound is often silent (Windows toasts, focus assist), so the page
29
+ // plays its own sound.
30
+ const pref = (k, d) => {
31
+ try {
32
+ return localStorage.getItem(k) || d;
33
+ } catch (e) {
34
+ return d;
35
+ }
36
+ };
37
+ export const notifyOn = () => pref("kz-notify", "on") === "on";
38
+ export const soundPick = () => pref("kz-sound", "Bellatrix");
39
+ const SAMPLES = ["Adara", "Alya", "Bellatrix", "Beryllium", "Cobalt", "Fluorine", "Krypton", "Palladium", "Rubidium", "Xenon"];
40
+ export const SOUNDS = ["off", ...SAMPLES, "chime", "bell", "pop"];
41
+ // [frequency Hz, start s, length s] per note.
42
+ const NOTES = { chime: [[880, 0, 0.25], [1320, 0.12, 0.35]], bell: [[660, 0, 0.9]], pop: [[520, 0, 0.08]] };
43
+ let actx;
44
+ export function playSound(name = soundPick()) {
45
+ try {
46
+ if (SAMPLES.includes(name)) {
47
+ new Audio(`/sounds/${name}.mp3`).play().catch(() => {});
48
+ return;
49
+ }
50
+ if (!NOTES[name]) return;
51
+ actx = actx || new AudioContext();
52
+ actx.resume();
53
+ const t0 = actx.currentTime + 0.02;
54
+ for (const [hz, at, len] of NOTES[name]) {
55
+ const o = actx.createOscillator(),
56
+ g = actx.createGain();
57
+ o.type = name === "pop" ? "triangle" : "sine";
58
+ o.frequency.value = hz;
59
+ g.gain.setValueAtTime(0.0001, t0 + at);
60
+ g.gain.exponentialRampToValueAtTime(0.25, t0 + at + 0.01);
61
+ g.gain.exponentialRampToValueAtTime(0.0001, t0 + at + len);
62
+ o.connect(g).connect(actx.destination);
63
+ o.start(t0 + at);
64
+ o.stop(t0 + at + len + 0.05);
65
+ }
66
+ } catch (e) {}
67
+ }
68
+ // A browser only lets a page make sound after a press on it; the first one unlocks it.
69
+ addEventListener("pointerdown", () => {
70
+ try {
71
+ actx = actx || new AudioContext();
72
+ actx.resume();
73
+ } catch (e) {}
74
+ }, { once: true });
27
75
  // tag: one notification per thing, so several open board tabs replace each other's.
28
76
  export function notifyUser(body, tag?: string) {
77
+ if (!notifyOn()) return;
78
+ playSound();
29
79
  try {
30
80
  if (typeof Notification !== "undefined" && Notification.permission === "granted")
31
81
  new Notification("kaizen", { body, icon: "/logo.png", tag });