From 2edab85b3f44c7f95840bfe91c700f96eb630a5b Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Tue, 24 Sep 2024 10:06:36 +0800 Subject: [PATCH] fix: try to fix the white screen issue in iOS WebView. --- .../src/lib/components/messages/ProfileDetail.svelte | 4 +++- src/ic_panda_frontend/src/lib/services/notification.sw.ts | 4 +++- src/ic_panda_frontend/src/lib/utils/window.ts | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ic_panda_frontend/src/lib/components/messages/ProfileDetail.svelte b/src/ic_panda_frontend/src/lib/components/messages/ProfileDetail.svelte index ca9adda..5a70d45 100644 --- a/src/ic_panda_frontend/src/lib/components/messages/ProfileDetail.svelte +++ b/src/ic_panda_frontend/src/lib/components/messages/ProfileDetail.svelte @@ -15,6 +15,7 @@ import { ErrorLogs, toastRun } from '$lib/stores/toast' import { sleep } from '$lib/utils/helper' import { md } from '$lib/utils/markdown' + import { isNotificationSupported } from '$lib/utils/window' import { myMessageStateAsync, toDisplayUserInfo, @@ -51,7 +52,8 @@ let userInfo: Readable let myInfo: Readable<(UserInfo & ProfileInfo) | null> - let grantedNotification = Notification.permission === 'granted' + let grantedNotification = + isNotificationSupported && Notification.permission === 'granted' let displayDebug = false async function loadMyFollowing() { diff --git a/src/ic_panda_frontend/src/lib/services/notification.sw.ts b/src/ic_panda_frontend/src/lib/services/notification.sw.ts index 8543751..d1b4ba1 100644 --- a/src/ic_panda_frontend/src/lib/services/notification.sw.ts +++ b/src/ic_panda_frontend/src/lib/services/notification.sw.ts @@ -20,7 +20,9 @@ export async function notifyd() { console.log('Notification service started') while (true) { const identity = - Notification.permission === 'granted' && (await loadIdentity()) + 'Notification' in globalThis && + Notification.permission === 'granted' && + (await loadIdentity()) if (identity) { const now = Date.now() await tryRun(async () => { diff --git a/src/ic_panda_frontend/src/lib/utils/window.ts b/src/ic_panda_frontend/src/lib/utils/window.ts index fef1339..55429a9 100644 --- a/src/ic_panda_frontend/src/lib/utils/window.ts +++ b/src/ic_panda_frontend/src/lib/utils/window.ts @@ -6,6 +6,8 @@ const STR_UNDEFINED = 'undefined' // NOTE: Use the function to guarantee it's re-evaluated between jsdom and node runtime for tests. export const isWindowDefined = typeof window != STR_UNDEFINED export const isDocumentDefined = typeof document != STR_UNDEFINED +export const isNotificationSupported = + isWindowDefined && 'Notification' in window export const hasRequestAnimationFrame = () => isWindowDefined && typeof window['requestAnimationFrame'] != STR_UNDEFINED export const noop = () => {}