Skip to content

Commit

Permalink
foreground-service: Listen to tab visibility change event (#1878)
Browse files Browse the repository at this point in the history
Fixes #1872.

This makes the foreground service also listen to the `visibilitychange`
event to stop and resume foreground activity when the tab is changed or
the browser is closed.

See
https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event.

--
Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored May 7, 2023
1 parent b9d57f0 commit a548e0d
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export default {

this.$f7.on('pageAfterIn', this.onPageAfterIn)
this.$f7.on('pageBeforeOut', this.onPageBeforeOut)

document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
this.startForegroundActivity()
} else if (document.visibilityState === 'hidden') {
this.stopForegroundActivity()
}
})
},
beforeDestroy () {
this.$f7.off('pageAfterIn', this.onPageAfterIn)
Expand Down

0 comments on commit a548e0d

Please sign in to comment.