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 + }) } /**