Skip to content

Commit

Permalink
fix(Project): set autoSaveToCloudState to Saved when retrying aut…
Browse files Browse the repository at this point in the history
…o-save without unsynced changes

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
  • Loading branch information
aofei committed Aug 23, 2024
1 parent f1714cd commit 20957dc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions spx-gui/src/models/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,25 +430,27 @@ export class Project extends Disposable {
try {
if (this.hasUnsyncedChanges) await this.saveToCloud()
this.autoSaveToCloudState = AutoSaveToCloudState.Saved
if (this.hasUnsyncedChanges) autoSaveToCloud()
else await localHelper.clear(localCacheKey)
} catch (e) {
await this.saveToLocalCache(localCacheKey) // prevent data loss
this.autoSaveToCloudState = AutoSaveToCloudState.Failed
startRetry()
await this.saveToLocalCache(localCacheKey) // prevent data loss
throw e
}

if (this.hasUnsyncedChanges) autoSaveToCloud()
else await localHelper.clear(localCacheKey)
}, 1500)

let retryTimeoutId: ReturnType<typeof setTimeout>
const startRetry = () => {
stopRetry()
retryTimeoutId = setTimeout(() => {
if (
this.autoSaveToCloudState === AutoSaveToCloudState.Failed &&
this.hasUnsyncedChanges
) {
retryTimeoutId = setTimeout(async () => {
if (this.autoSaveToCloudState !== AutoSaveToCloudState.Failed) return
if (this.hasUnsyncedChanges) {
autoSaveToCloud()
} else {
this.autoSaveToCloudState = AutoSaveToCloudState.Saved
await localHelper.clear(localCacheKey)
}
}, 5000)
}
Expand Down

0 comments on commit 20957dc

Please sign in to comment.