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

@ -244,6 +244,8 @@ struct MainView: App {
showInitialSheet()
case .isSaved, .needsSave:
content.saveUnconditionally()
case .isSaving:
break
case .failedToSave, .savingPausedDueToLoadErrors:
showStorageErrorSheet = true
}

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

View File

@ -184,9 +184,7 @@ final class Content: ObservableObject {
private(set) var lastModification: Date = .now
func update(saveState: SaveState) {
DispatchQueue.main.async {
self.saveState = saveState
}
self.saveState = saveState
}
func setModificationTimestamp() {

View File

@ -7,6 +7,7 @@ enum SaveState {
case isSaved
case needsSave
case failedToSave
case isSaving
var symbol: SFSymbol {
switch self {
@ -20,6 +21,8 @@ enum SaveState {
return .hourglassCircleFill
case .failedToSave:
return .exclamationmarkTriangleFill
case .isSaving:
return .hourglassCircleFill
}
}
@ -27,7 +30,7 @@ enum SaveState {
switch self {
case .storageNotInitialized:
return .red
case .isSaved:
case .isSaved, .isSaving:
return .green
case .needsSave:
return .yellow

View File

@ -13,7 +13,7 @@ struct DatePropertyView: View {
VStack(alignment: .leading) {
Text(title)
.font(.headline)
DatePicker("", selection: $value, displayedComponents: .date)
DatePicker("", selection: $value, displayedComponents: [.date, .hourAndMinute])
.datePickerStyle(.compact)
Text(footer)
.foregroundStyle(.secondary)