迁移聊天室禁音入口
This commit is contained in:
@@ -227,6 +227,7 @@ export {
|
|||||||
shouldMigrateLocalChatPreferences,
|
shouldMigrateLocalChatPreferences,
|
||||||
toggleBlockMenu,
|
toggleBlockMenu,
|
||||||
toggleFeatureMenu,
|
toggleFeatureMenu,
|
||||||
|
toggleSoundMute,
|
||||||
} from "./chat-room/preferences-status.js";
|
} from "./chat-room/preferences-status.js";
|
||||||
export { bindChatRightPanelControls } from "./chat-room/right-panel.js";
|
export { bindChatRightPanelControls } from "./chat-room/right-panel.js";
|
||||||
export {
|
export {
|
||||||
@@ -418,6 +419,7 @@ import {
|
|||||||
shouldMigrateLocalChatPreferences,
|
shouldMigrateLocalChatPreferences,
|
||||||
toggleBlockMenu,
|
toggleBlockMenu,
|
||||||
toggleFeatureMenu,
|
toggleFeatureMenu,
|
||||||
|
toggleSoundMute,
|
||||||
} from "./chat-room/preferences-status.js";
|
} from "./chat-room/preferences-status.js";
|
||||||
import { bindChatRightPanelControls } from "./chat-room/right-panel.js";
|
import { bindChatRightPanelControls } from "./chat-room/right-panel.js";
|
||||||
import {
|
import {
|
||||||
@@ -645,6 +647,7 @@ if (typeof window !== "undefined") {
|
|||||||
shouldMigrateLocalChatPreferences,
|
shouldMigrateLocalChatPreferences,
|
||||||
toggleBlockMenu,
|
toggleBlockMenu,
|
||||||
toggleFeatureMenu,
|
toggleFeatureMenu,
|
||||||
|
toggleSoundMute,
|
||||||
bindChatRightPanelControls,
|
bindChatRightPanelControls,
|
||||||
bindRoomStatusControls,
|
bindRoomStatusControls,
|
||||||
normalizeRoomStatus,
|
normalizeRoomStatus,
|
||||||
|
|||||||
@@ -142,6 +142,28 @@ export function setSoundMuted(muted) {
|
|||||||
return normalizedMuted;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const muted = setSoundMuted(event.target.checked);
|
toggleSoundMute(event.target.checked, onChange);
|
||||||
|
|
||||||
if (muted && typeof window.EffectSounds !== "undefined") {
|
|
||||||
window.EffectSounds.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof onChange === "function") {
|
|
||||||
void onChange(muted);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3169,15 +3169,15 @@
|
|||||||
* @param {boolean} muted true = 禁音,false = 开启声音
|
* @param {boolean} muted true = 禁音,false = 开启声音
|
||||||
*/
|
*/
|
||||||
function toggleSoundMute(muted) {
|
function toggleSoundMute(muted) {
|
||||||
if (window.ChatRoomTools?.setSoundMuted) {
|
if (window.ChatRoomTools?.toggleSoundMute) {
|
||||||
window.ChatRoomTools.setSoundMuted(muted);
|
window.ChatRoomTools.toggleSoundMute(muted, () => saveChatPreferences());
|
||||||
} else {
|
return;
|
||||||
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, muted ? '1' : '0');
|
|
||||||
}
|
|
||||||
if (muted && typeof EffectSounds !== 'undefined') {
|
|
||||||
EffectSounds.stop(); // 立即停止当前音效
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, muted ? '1' : '0');
|
||||||
|
if (muted && typeof EffectSounds !== 'undefined') {
|
||||||
|
EffectSounds.stop();
|
||||||
|
}
|
||||||
void saveChatPreferences();
|
void saveChatPreferences();
|
||||||
}
|
}
|
||||||
window.toggleSoundMute = toggleSoundMute;
|
window.toggleSoundMute = toggleSoundMute;
|
||||||
|
|||||||
Reference in New Issue
Block a user