()
| 288 | let initialSyncDone = false |
| 289 | |
| 290 | export function waitForInitialSyncDone() { |
| 291 | return new Promise<void>((resolve) => { |
| 292 | if (initialSyncDone) { |
| 293 | resolve() |
| 294 | return |
| 295 | } |
| 296 | const handleStorageChange = (e: StorageEvent) => { |
| 297 | if (e.key === `syncStatus` && e.newValue) { |
| 298 | const [newStatus] = JSON.parse(e.newValue) |
| 299 | if (newStatus === `done`) { |
| 300 | window.removeEventListener(`storage`, handleStorageChange) |
| 301 | initialSyncDone = true |
| 302 | resolve() |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // Check current status first |
| 308 | const currentSyncStatusJson = localStorage.getItem(`syncStatus`) |
| 309 | const [currentStatus] = currentSyncStatusJson |
| 310 | ? JSON.parse(currentSyncStatusJson) |
| 311 | : [`initial-sync`] |
| 312 | |
| 313 | if (currentStatus === `done`) { |
| 314 | initialSyncDone = true |
| 315 | resolve() |
| 316 | } else { |
| 317 | window.addEventListener(`storage`, handleStorageChange) |
| 318 | } |
| 319 | }) |
| 320 | } |
no test coverage detected