From e8a638e7b2be3dde9e66e37dd746f7728a6d1d9c Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 19 Mar 2024 15:15:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20window.Notification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/msgUtils.js | 4 ++++ src/views/AuthApp.jsx | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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