迁移聊天室禁音入口

This commit is contained in:
2026-04-25 19:36:37 +08:00
parent 7fc40eba32
commit 36ac9d090b
3 changed files with 33 additions and 16 deletions
+3
View File
@@ -227,6 +227,7 @@ export {
shouldMigrateLocalChatPreferences,
toggleBlockMenu,
toggleFeatureMenu,
toggleSoundMute,
} from "./chat-room/preferences-status.js";
export { bindChatRightPanelControls } from "./chat-room/right-panel.js";
export {
@@ -418,6 +419,7 @@ import {
shouldMigrateLocalChatPreferences,
toggleBlockMenu,
toggleFeatureMenu,
toggleSoundMute,
} from "./chat-room/preferences-status.js";
import { bindChatRightPanelControls } from "./chat-room/right-panel.js";
import {
@@ -645,6 +647,7 @@ if (typeof window !== "undefined") {
shouldMigrateLocalChatPreferences,
toggleBlockMenu,
toggleFeatureMenu,
toggleSoundMute,
bindChatRightPanelControls,
bindRoomStatusControls,
normalizeRoomStatus,
+23 -9
View File
@@ -142,6 +142,28 @@ export function setSoundMuted(muted) {
return normalizedMuted;
}
/**
* 切换特效音效静音状态,并按需持久化到服务端偏好。
*
* @param {boolean} muted 是否禁音
* @param {(muted:boolean)=>void|Promise<void>} onChange 禁音变化回调
* @returns {boolean}
*/
export function toggleSoundMute(muted, onChange = undefined) {
const normalizedMuted = setSoundMuted(muted);
if (normalizedMuted && typeof window.EffectSounds !== "undefined") {
// 开启禁音时立即停止当前音效,避免状态切换后仍继续播放。
window.EffectSounds.stop();
}
if (typeof onChange === "function") {
void onChange(normalizedMuted);
}
return normalizedMuted;
}
/**
* 绑定禁音复选框事件,后端保存逻辑由调用方提供。
*
@@ -159,15 +181,7 @@ export function bindSoundMuteControl(onChange) {
return;
}
const muted = setSoundMuted(event.target.checked);
if (muted && typeof window.EffectSounds !== "undefined") {
window.EffectSounds.stop();
}
if (typeof onChange === "function") {
void onChange(muted);
}
toggleSoundMute(event.target.checked, onChange);
});
}
@@ -3169,15 +3169,15 @@
* @param {boolean} muted true = 禁音,false = 开启声音
*/
function toggleSoundMute(muted) {
if (window.ChatRoomTools?.setSoundMuted) {
window.ChatRoomTools.setSoundMuted(muted);
} else {
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, muted ? '1' : '0');
}
if (muted && typeof EffectSounds !== 'undefined') {
EffectSounds.stop(); // 立即停止当前音效
if (window.ChatRoomTools?.toggleSoundMute) {
window.ChatRoomTools.toggleSoundMute(muted, () => saveChatPreferences());
return;
}
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, muted ? '1' : '0');
if (muted && typeof EffectSounds !== 'undefined') {
EffectSounds.stop();
}
void saveChatPreferences();
}
window.toggleSoundMute = toggleSoundMute;