Skip to content

Commit

Permalink
Don't do online check when tab not visible - seems to lead to spuriou…
Browse files Browse the repository at this point in the history
…s offline indicators.
  • Loading branch information
edwh committed Dec 28, 2023
1 parent 81a0c09 commit 1848245
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions stores/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,37 @@ export const useMiscStore = defineStore({
}
},
async checkOnline() {
try {
const response = await this.fetchWithTimeout(
this.config.public.APIv2 + '/online',
null,
5000
)
if (this.visible) {
try {
const response = await this.fetchWithTimeout(
this.config.public.APIv2 + '/online',
null,
5000
)

if (response?.status === 200) {
const rsp = await response.json()
if (response?.status === 200) {
const rsp = await response.json()

if (!this.online) {
console.log('Back online')
this.online = rsp.online
if (!this.online) {
console.log('Back online')
this.online = rsp.online
}
} else {
// Null response happens when we time out
console.log('Offline', response)
this.online = false
}
} catch (e) {
if (this.online) {
console.log('Gone offline', e)
this.online = false
}
} else {
// Null response happens when we time out
console.log('Offline', response)
this.online = false
}
} catch (e) {
if (this.online) {
console.log('Gone offline', e)
this.online = false
}
}

this.onlineTimer = setTimeout(
this.checkOnline,
this.visible ? 1000 : 30000
1000
)
},
waitForOnline() {
Expand Down

0 comments on commit 1848245

Please sign in to comment.