Improve saving, show start time
This commit is contained in:
parent
ece39cb95e
commit
0cc0f76254
@ -244,6 +244,8 @@ struct MainView: App {
|
|||||||
showInitialSheet()
|
showInitialSheet()
|
||||||
case .isSaved, .needsSave:
|
case .isSaved, .needsSave:
|
||||||
content.saveUnconditionally()
|
content.saveUnconditionally()
|
||||||
|
case .isSaving:
|
||||||
|
break
|
||||||
case .failedToSave, .savingPausedDueToLoadErrors:
|
case .failedToSave, .savingPausedDueToLoadErrors:
|
||||||
showStorageErrorSheet = true
|
showStorageErrorSheet = true
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ extension Content {
|
|||||||
setModificationTimestamp()
|
setModificationTimestamp()
|
||||||
|
|
||||||
if saveState == .isSaved {
|
if saveState == .isSaved {
|
||||||
update(saveState: saveState)
|
update(saveState: .needsSave)
|
||||||
}
|
}
|
||||||
// Wait a few seconds for a save, to allow additional changes
|
// Wait a few seconds for a save, to allow additional changes
|
||||||
// Reduces the number of saves
|
// Reduces the number of saves
|
||||||
@ -17,18 +17,16 @@ extension Content {
|
|||||||
|
|
||||||
func saveIfNeeded() {
|
func saveIfNeeded() {
|
||||||
switch saveState {
|
switch saveState {
|
||||||
case .isSaved, .savingPausedDueToLoadErrors, .storageNotInitialized:
|
case .isSaved, .savingPausedDueToLoadErrors, .storageNotInitialized, .isSaving:
|
||||||
return
|
return
|
||||||
default:
|
case .needsSave, .failedToSave:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if Date.now.timeIntervalSince(lastModification) < 5 {
|
if Date.now.timeIntervalSince(lastModification) < 5 {
|
||||||
// Additional modification made
|
// Additional modification made
|
||||||
// Wait for next scheduled invocation of saveIfNeeded()
|
// Wait for next scheduled invocation of saveIfNeeded()
|
||||||
// if the overall unsaved time is not too long
|
// if the overall unsaved time is not too long
|
||||||
if Date.now.timeIntervalSince(lastSave) < 30 {
|
if Date.now.timeIntervalSince(lastSave) < 30 {
|
||||||
//print("Waiting while modifying")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
print("Saving after 30 seconds of modifications")
|
print("Saving after 30 seconds of modifications")
|
||||||
@ -37,6 +35,7 @@ extension Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveUnconditionally() {
|
func saveUnconditionally() {
|
||||||
|
update(saveState: .isSaving)
|
||||||
guard saveToDisk() else {
|
guard saveToDisk() else {
|
||||||
update(saveState: .failedToSave)
|
update(saveState: .failedToSave)
|
||||||
// TODO: Try to save again
|
// TODO: Try to save again
|
||||||
|
@ -184,9 +184,7 @@ final class Content: ObservableObject {
|
|||||||
private(set) var lastModification: Date = .now
|
private(set) var lastModification: Date = .now
|
||||||
|
|
||||||
func update(saveState: SaveState) {
|
func update(saveState: SaveState) {
|
||||||
DispatchQueue.main.async {
|
self.saveState = saveState
|
||||||
self.saveState = saveState
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setModificationTimestamp() {
|
func setModificationTimestamp() {
|
||||||
|
@ -7,6 +7,7 @@ enum SaveState {
|
|||||||
case isSaved
|
case isSaved
|
||||||
case needsSave
|
case needsSave
|
||||||
case failedToSave
|
case failedToSave
|
||||||
|
case isSaving
|
||||||
|
|
||||||
var symbol: SFSymbol {
|
var symbol: SFSymbol {
|
||||||
switch self {
|
switch self {
|
||||||
@ -20,6 +21,8 @@ enum SaveState {
|
|||||||
return .hourglassCircleFill
|
return .hourglassCircleFill
|
||||||
case .failedToSave:
|
case .failedToSave:
|
||||||
return .exclamationmarkTriangleFill
|
return .exclamationmarkTriangleFill
|
||||||
|
case .isSaving:
|
||||||
|
return .hourglassCircleFill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +30,7 @@ enum SaveState {
|
|||||||
switch self {
|
switch self {
|
||||||
case .storageNotInitialized:
|
case .storageNotInitialized:
|
||||||
return .red
|
return .red
|
||||||
case .isSaved:
|
case .isSaved, .isSaving:
|
||||||
return .green
|
return .green
|
||||||
case .needsSave:
|
case .needsSave:
|
||||||
return .yellow
|
return .yellow
|
||||||
|
@ -13,7 +13,7 @@ struct DatePropertyView: View {
|
|||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Text(title)
|
Text(title)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
DatePicker("", selection: $value, displayedComponents: .date)
|
DatePicker("", selection: $value, displayedComponents: [.date, .hourAndMinute])
|
||||||
.datePickerStyle(.compact)
|
.datePickerStyle(.compact)
|
||||||
Text(footer)
|
Text(footer)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user