优化通知逻辑以防止重复通知

This commit is contained in:
shuaiplus committed 2025-05-24 21:39:46 +08:00
1 parent 08d339f9c2
commit 554fedaefe
2 files changed
+13 -7

No files matched your search

+1 -3
View File
@@ -65,7 +65,7 @@ import {
// Set global configuration parameters
window.config = {
wsAddress: 'wss://crypt.works/ws', // WebSocket 服务器地址 / WebSocket server address
debug: false // 是否开启调试模式 / Enable debug mode
debug: true // 是否开启调试模式 / Enable debug mode
};
// 把一些函数挂载到 window 对象上供其他模块使用
@@ -78,8 +78,6 @@ window.setupEmojiPicker = setupEmojiPicker;
// 当 DOM 内容加载完成后执行初始化逻辑
// Run initialization logic when the DOM content is fully loaded
window.addEventListener('DOMContentLoaded', () => {
const loginContainer = $id('login-container'); // 登录容器 / Login container
const chatContainer = $id('chat-container'); // 聊天容器 / Chat container
const loginForm = $id('login-form'); // 登录表单 / Login form
if (loginForm) {
+12 -4
View File
@@ -92,9 +92,13 @@ function setupSettingsPanel() {
if (soundCheckbox) soundCheckbox.checked = false;
saveSettings(settings);
applySettings(settings);
new Notification('Notifications enabled', {
body: 'You will receive alerts here.'
})
// 防止重复通知,添加一个标志位
if (!panel._notificationShown) {
new Notification('Notifications enabled', {
body: 'You will receive alerts here.'
});
panel._notificationShown = true; // 设置标志位
}
} else {
settings.notify = false;
e.target.checked = false;
@@ -106,7 +110,11 @@ function setupSettingsPanel() {
} else {
settings.notify = false;
saveSettings(settings);
applySettings(settings)
applySettings(settings);
// 重置标志位
if (panel._notificationShown) {
panel._notificationShown = false;
}
}
});
on(soundCheckbox, 'change', e => {