@xiaoqiong0v0/opencode-sound-notify 1.1.7 → 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.
- package/dist/sound-notify.js +32 -5
- package/package.json +1 -1
package/dist/sound-notify.js
CHANGED
|
@@ -47,7 +47,10 @@ const TX = {
|
|
|
47
47
|
muted_off: { zh: "声音已开启", en: "Sound unmuted" },
|
|
48
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
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
|
|
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}" },
|
|
51
54
|
};
|
|
52
55
|
const T = (key, params) => {
|
|
53
56
|
const entry = TX[key] || { zh: key, en: key };
|
|
@@ -80,6 +83,13 @@ function loadCfg() {
|
|
|
80
83
|
};
|
|
81
84
|
LANG = raw.lang === "zh" ? "zh" : "en";
|
|
82
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
|
+
}
|
|
83
93
|
try {
|
|
84
94
|
loadCfg();
|
|
85
95
|
}
|
|
@@ -193,14 +203,31 @@ export const SoundNotify = async () => {
|
|
|
193
203
|
description: T("mute_desc"),
|
|
194
204
|
args: {
|
|
195
205
|
action: tool.schema.enum(["on", "off", "toggle"]).describe(T("mute_action")),
|
|
206
|
+
save: tool.schema.boolean().optional().describe(T("mute_save")),
|
|
196
207
|
},
|
|
197
|
-
execute: async ({ action }) => {
|
|
198
|
-
if (action === "on")
|
|
208
|
+
execute: async ({ action, save }) => {
|
|
209
|
+
if (action === "on") {
|
|
199
210
|
muted = false;
|
|
200
|
-
|
|
211
|
+
cfg.enabled = true;
|
|
212
|
+
}
|
|
213
|
+
else if (action === "off") {
|
|
201
214
|
muted = true;
|
|
202
|
-
|
|
215
|
+
}
|
|
216
|
+
else if (action === "toggle") {
|
|
203
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
|
+
}
|
|
204
231
|
return T(muted ? "muted_on" : "muted_off");
|
|
205
232
|
},
|
|
206
233
|
}),
|
package/package.json
CHANGED