From b4a11fdc8e8af95aadc11e349885848921e92667 Mon Sep 17 00:00:00 2001 From: sealday Date: Fri, 11 Oct 2024 12:47:02 +0800 Subject: [PATCH] fix(notification): not support in mobile browser (#1588) Co-authored-by: sealday Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1588 --- .../src/client/web-notification/PluginWebNotification.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@tachybase/plugin-messages/src/client/web-notification/PluginWebNotification.tsx b/packages/plugins/@tachybase/plugin-messages/src/client/web-notification/PluginWebNotification.tsx index 8c8b00e72..86940fd28 100644 --- a/packages/plugins/@tachybase/plugin-messages/src/client/web-notification/PluginWebNotification.tsx +++ b/packages/plugins/@tachybase/plugin-messages/src/client/web-notification/PluginWebNotification.tsx @@ -3,10 +3,12 @@ import { Plugin } from '@tachybase/client'; import PluginMessagesClient from '..'; import { lang } from '../locale'; +const isSupported = () => 'Notification' in window && 'serviceWorker' in navigator && 'PushManager' in window; + export class PluginWebNotification extends Plugin { async afterLoad() { // ‌请求用户授予权限 - if (Notification.permission !== 'denied') { + if (isSupported() && Notification.permission !== 'denied') { await Notification.requestPermission(); } }