@xiaoqiong0v0/opencode-sound-notify 1.1.0 → 1.1.3

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/assets/ask.wav CHANGED
Binary file
package/assets/error.wav CHANGED
Binary file
@@ -23,6 +23,8 @@ const SAMPLE_CFG = `{
23
23
  "events": ["session.idle", "session.error", "permission.asked"],
24
24
  // 全局默认防抖间隔(ms),未单独配置的事件使用此值
25
25
  "defaultDebounceMs": 30000,
26
+ // 全局最小间隔(ms),所有声音播放不能低于此间隔,覆盖单独配置
27
+ "minIntervalMs": 3000,
26
28
  // 按事件单独配置防抖间隔(ms),覆盖 defaultDebounceMs
27
29
  "debounceMs": {
28
30
  "permission.asked": 5000
@@ -64,6 +66,7 @@ function loadCfg() {
64
66
  sound: raw.sound || "",
65
67
  sounds: raw.sounds,
66
68
  events: raw.events,
69
+ minIntervalMs: raw.minIntervalMs ?? 3000,
67
70
  defaultDebounceMs: raw.defaultDebounceMs || 30000,
68
71
  debounceMs: raw.debounceMs,
69
72
  enabled: raw.enabled !== false,
@@ -77,10 +80,12 @@ catch (e) {
77
80
  log.error(T("init_failed"), e instanceof Error ? e : Error(String(e)));
78
81
  }
79
82
  const eventTimestamps = new Map();
83
+ let globalLastPlay = 0;
80
84
  function getPlayerArgs(sound) {
81
85
  switch (process.platform) {
82
86
  case "win32":
83
- return ["powershell", "-NoProfile", "-Command", `(New-Object System.Media.SoundPlayer '${sound}').PlaySync()`];
87
+ return ["powershell", "-NoProfile", "-Command",
88
+ `(New-Object System.Media.SoundPlayer '${sound.replace(/'/g, "''")}').PlaySync()`];
84
89
  case "darwin":
85
90
  return ["afplay", sound];
86
91
  case "linux": {
@@ -129,11 +134,17 @@ function shouldPlay(eventType) {
129
134
  if (!cfg.events?.includes(eventType))
130
135
  return false;
131
136
  const now = Date.now();
137
+ const minMs = cfg.minIntervalMs || 0;
132
138
  const debounceMs = cfg.debounceMs?.[eventType] ?? cfg.defaultDebounceMs ?? 30000;
139
+ const effective = minMs > debounceMs ? minMs : debounceMs;
140
+ // 全局间隔检查:任何声音播放后 minIntervalMs 内都不再响应
141
+ if (minMs > 0 && now - globalLastPlay < minMs)
142
+ return false;
133
143
  const last = eventTimestamps.get(eventType) || 0;
134
- if (now - last < debounceMs)
144
+ if (now - last < effective)
135
145
  return false;
136
146
  eventTimestamps.set(eventType, now);
147
+ globalLastPlay = now;
137
148
  return true;
138
149
  }
139
150
  export const SoundNotify = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaoqiong0v0/opencode-sound-notify",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin: play notification sounds on session events (idle, error, permission asked).",
6
6
  "files": [