From d7b2ec53c2676d4fdffbba03e7fb1c17685de2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B8=B4?= <155876693+wsxiaolin@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:04:11 +0000 Subject: [PATCH] fix: stop weak-network dialog from popping on every fluctuation The connection 'change' event fires on every rtt/effectiveType/saveData re-estimation, so weak links and VPN reconnects popped the warning dialog constantly. Remove the weak-network dialog entirely (image quality degradation still updates silently) and keep only the offline dialog, now edge-triggered so it shows once per actual offline event. --- src/services/utils.ts | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/services/utils.ts b/src/services/utils.ts index d424f41f..2edc9236 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -86,25 +86,29 @@ export function registerNetworkListener() { (navigator as NavigatorWithConnection).connection || (navigator as NavigatorWithConnection).mozConnection || (navigator as NavigatorWithConnection).webkitConnection - if (connection) { - connection.addEventListener('change', () => { - coverImgSuffix = getCoverImgSuffix() - avatarImgSuffix = getAvatarImgSuffix() - if(connection.saveData || ['2g', '3g'].includes(connection.effectiveType)) { - showDialog('warning', { - title: i18n.global.t('networkStatus.poor.title'), - content: i18n.global.t('networkStatus.poor.message') - }) - } + if (!connection) return + + // Refresh image-quality suffixes on network changes. The weak-network warning + // dialog was removed on purpose: `change` fires on every rtt/effectiveType + // fluctuation (weak links, VPN reconnects, Data Saver toggles), so any prompt + // here would pop up constantly. Offline remains edge-triggered below. + connection.addEventListener('change', () => { + coverImgSuffix = getCoverImgSuffix() + avatarImgSuffix = getAvatarImgSuffix() + }) + + let offlineShown = false + window.addEventListener('offline', () => { + if (offlineShown) return + offlineShown = true + showDialog('warning', { + title: i18n.global.t('networkStatus.offline.title'), + content: i18n.global.t('networkStatus.offline.message'), }) - window.addEventListener('offline', () => { - showDialog('warning', { - title: i18n.global.t('networkStatus.offline.title'), - content: i18n.global.t('networkStatus.offline.message') - }) - }) - - } + }) + window.addEventListener('online', () => { + offlineShown = false + }) } /**