@xiaoqiong0v0/opencode-sound-notify 1.1.6 → 1.1.8

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.
@@ -45,8 +45,12 @@ const TX = {
45
45
  no_sound_file: { zh: "声音文件不存在: {path}", en: "Sound file not found: {path}" },
46
46
  muted_on: { zh: "声音已关闭", en: "Sound muted" },
47
47
  muted_off: { zh: "声音已开启", en: "Sound unmuted" },
48
- mute_desc: { zh: "开/关提示音", en: "Toggle notification sound" },
49
- mute_template: { zh: "用户想要切换声音状态。调用 sound_toggle 工具。", en: "User wants to toggle sound. Call sound_toggle tool." },
48
+ mute_desc: { zh: "控制提示音开关:action=on 开启,action=off 关闭,action=toggle 切换", en: "Control notification sound: action=on to enable, action=off to disable, action=toggle to switch" },
49
+ mute_template: { zh: "用户想要切换声音状态。调用 sound_toggle 工具,action 参数:on=开启,off=关闭,toggle=切换。", en: "User wants to control sound. Call sound_toggle tool: action=on to enable, action=off to disable, action=toggle to switch." },
50
+ mute_action: { zh: "on 开启 off 关闭 toggle 切换", en: "on enable off disable toggle switch" },
51
+ mute_save: { zh: "save=true 同时写入配置文件持久化", en: "save=true also persist to config file" },
52
+ save_ok: { zh: "已保存到配置文件 {path}", en: "Saved to config {path}" },
53
+ save_fail: { zh: "保存失败: {msg}", en: "Save failed: {msg}" },
50
54
  };
51
55
  const T = (key, params) => {
52
56
  const entry = TX[key] || { zh: key, en: key };
@@ -79,6 +83,13 @@ function loadCfg() {
79
83
  };
80
84
  LANG = raw.lang === "zh" ? "zh" : "en";
81
85
  }
86
+ function persistEnabled(enabled) {
87
+ if (!existsSync(CONFIG_PATH))
88
+ return;
89
+ const raw = readFileSync(CONFIG_PATH, "utf-8");
90
+ const updated = raw.replace(/"enabled"\s*:\s*(true|false)/, `"enabled": ${enabled}`);
91
+ writeFileSync(CONFIG_PATH, updated, "utf-8");
92
+ }
82
93
  try {
83
94
  loadCfg();
84
95
  }
@@ -86,6 +97,7 @@ catch (e) {
86
97
  log.error(T("init_failed"), e instanceof Error ? e : Error(String(e)));
87
98
  }
88
99
  const eventTimestamps = new Map();
100
+ const subSessions = new Set();
89
101
  let globalLastPlay = 0;
90
102
  function getPlayerArgs(sound) {
91
103
  switch (process.platform) {
@@ -174,23 +186,48 @@ export const SoundNotify = async () => {
174
186
  }
175
187
  },
176
188
  event: async ({ event }) => {
177
- if (shouldPlay(event.type)) {
178
- play(event.type);
189
+ if (event.type === "session.created") {
190
+ const info = event.properties?.info;
191
+ if (info?.parentID)
192
+ subSessions.add(info.id);
193
+ return;
179
194
  }
195
+ const sid = event.properties?.sessionID;
196
+ if (sid && subSessions.has(sid))
197
+ return;
198
+ if (shouldPlay(event.type))
199
+ play(event.type);
180
200
  },
181
201
  tool: {
182
202
  sound_toggle: tool({
183
203
  description: T("mute_desc"),
184
204
  args: {
185
- action: tool.schema.enum(["on", "off", "toggle"]).optional().describe("on=开启 off=关闭 toggle=切换"),
205
+ action: tool.schema.enum(["on", "off", "toggle"]).describe(T("mute_action")),
206
+ save: tool.schema.boolean().optional().describe(T("mute_save")),
186
207
  },
187
- execute: async ({ action }) => {
188
- if (action === "on")
208
+ execute: async ({ action, save }) => {
209
+ if (action === "on") {
189
210
  muted = false;
190
- else if (action === "off")
211
+ cfg.enabled = true;
212
+ }
213
+ else if (action === "off") {
191
214
  muted = true;
192
- else
215
+ }
216
+ else if (action === "toggle") {
193
217
  muted = !muted;
218
+ }
219
+ if (save) {
220
+ try {
221
+ persistEnabled(!muted);
222
+ cfg.enabled = !muted;
223
+ return T(muted ? "muted_on" : "muted_off") + " | " + T("save_ok", { path: CONFIG_PATH });
224
+ }
225
+ catch (e) {
226
+ const msg = e instanceof Error ? e.message : String(e);
227
+ log.error(T("save_fail", { msg }));
228
+ return T("save_fail", { msg });
229
+ }
230
+ }
194
231
  return T(muted ? "muted_on" : "muted_off");
195
232
  },
196
233
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaoqiong0v0/opencode-sound-notify",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin: play notification sounds on session events (idle, error, permission asked).",
6
6
  "files": [