Skip to content

Commit

Permalink
feat: Refresh flags on app resume / tab focus
Browse files Browse the repository at this point in the history
Otherwise the user has to login/logout for her flags to be synced
  • Loading branch information
ptbrowne committed Oct 1, 2020
1 parent 71ca794 commit 3832f16
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ const setupApp = async persistedState => {
delay: 5000
})

const refreshFlags = async () => {
// TODO Remove else block after https://github.com/cozy/cozy-libs/pull/1115
// is merged
if (client.plugins.flags.refresh) {
await client.plugins.flags.refresh()
} else {
await flag.initializeFromRemote(client)
}
}

document.addEventListener('resume', () => {
refreshFlags()
})

document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
refreshFlags()
}
})

client.setStore(store)

persistState(store)
Expand Down

0 comments on commit 3832f16

Please sign in to comment.