Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

/**
Expand Down
Loading