@xiaoqiong0v0/opencode-sound-notify 1.1.1 → 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.
@@ -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,6 +80,7 @@ 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":
@@ -130,11 +134,17 @@ function shouldPlay(eventType) {
130
134
  if (!cfg.events?.includes(eventType))
131
135
  return false;
132
136
  const now = Date.now();
137
+ const minMs = cfg.minIntervalMs || 0;
133
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;
134
143
  const last = eventTimestamps.get(eventType) || 0;
135
- if (now - last < debounceMs)
144
+ if (now - last < effective)
136
145
  return false;
137
146
  eventTimestamps.set(eventType, now);
147
+ globalLastPlay = now;
138
148
  return true;
139
149
  }
140
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.1",
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": [