Improve saving, show start time

This commit is contained in:
Christoph Hagen
2025-02-16 18:03:53 +01:00
parent ece39cb95e
commit 0cc0f76254
5 changed files with 12 additions and 10 deletions

View File

@ -6,7 +6,7 @@ extension Content {
setModificationTimestamp()
if saveState == .isSaved {
update(saveState: saveState)
update(saveState: .needsSave)
}
// Wait a few seconds for a save, to allow additional changes
// Reduces the number of saves
@ -17,18 +17,16 @@ extension Content {
func saveIfNeeded() {
switch saveState {
case .isSaved, .savingPausedDueToLoadErrors, .storageNotInitialized:
case .isSaved, .savingPausedDueToLoadErrors, .storageNotInitialized, .isSaving:
return
default:
case .needsSave, .failedToSave:
break
}
if Date.now.timeIntervalSince(lastModification) < 5 {
// Additional modification made
// Wait for next scheduled invocation of saveIfNeeded()
// if the overall unsaved time is not too long
if Date.now.timeIntervalSince(lastSave) < 30 {
//print("Waiting while modifying")
return
}
print("Saving after 30 seconds of modifications")
@ -37,6 +35,7 @@ extension Content {
}
func saveUnconditionally() {
update(saveState: .isSaving)
guard saveToDisk() else {
update(saveState: .failedToSave)
// TODO: Try to save again