diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js index ea6ae58..2718924 100644 --- a/src/lib/msgUtils.js +++ b/src/lib/msgUtils.js @@ -527,6 +527,10 @@ export const whatsappError = { * 系统弹窗通知 */ export const handleNotification = (title, _options) => { + if (!("Notification" in window)) { + alert("This browser does not support desktop notification"); + return false; + } var notification; const options = { requireInteraction: true, // 设置手动关闭 diff --git a/src/views/AuthApp.jsx b/src/views/AuthApp.jsx index 631d184..74fe21c 100644 --- a/src/views/AuthApp.jsx +++ b/src/views/AuthApp.jsx @@ -26,7 +26,12 @@ function AuthApp() { state.disconnectWebsocket, ]); useEffect(() => { - Notification.requestPermission(); + if (!("Notification" in window)) { + alert("This browser does not support desktop notification"); + return false; + } else { + Notification.requestPermission(); + } if (loginUser.userId > 0) { connectWebsocket(loginUser.userId); fetchInitialData(loginUser.userId); // userIdStr