Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Delay clients synchronize() call 10s after startup
Browse files Browse the repository at this point in the history
Call to `synchronize()` may slow down the startup process but is not
necessary for the app to work

It is here only to update the cozy-settings's OAuth clients list to
display the last connexion to the app

So we chose to delay this call a short delay after the startup (for now
10s)

By doing so, we may fail calling the `synchronize()` method if the user
closes the app less than 10s after opening it, but as this is used only
for display purpose, we chose to consider this as not-critical
Ldoppea committed Dec 20, 2024
1 parent 0089fd8 commit f4e1815
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/app/domain/authentication/services/SynchronizeService.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import { saveClient } from '/libs/clientHelpers/persistClient'

export const syncLog = Minilog('📱 SynchronizeService')

const SYNCHRONIZE_DELAY_IN_MS = 10 * 1000

export const synchronizeDevice = async (client: CozyClient): Promise<void> => {
try {
await client.getStackClient().fetchJSON('POST', '/settings/synchronized')
@@ -50,6 +52,12 @@ export const checkClientName = async (client: CozyClient): Promise<void> => {
}

export const synchronizeOnInit = async (client: CozyClient): Promise<void> => {
await checkClientName(client)
await synchronizeDevice(client)
return new Promise(resolve => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async (): Promise<void> => {
await checkClientName(client)
await synchronizeDevice(client)
resolve()
}, SYNCHRONIZE_DELAY_IN_MS)
})
}

0 comments on commit f4e1815

Please sign in to comment.