feat: save memo before dismissing canvas view

This commit is contained in:
dscyrescotti
2024-06-09 14:40:33 +07:00
parent c3a14bd608
commit 87b53e069a
2 changed files with 12 additions and 12 deletions
+4 -4
View File
@@ -203,15 +203,15 @@ extension GraphicContext {
withPersistence(\.backgroundContext) { [penStroke] context in withPersistence(\.backgroundContext) { [penStroke] context in
penStroke.object?.bounds = penStroke.bounds penStroke.object?.bounds = penStroke.bounds
try context.saveIfNeeded() try context.saveIfNeeded()
if let object = penStroke.object { context.refreshAllObjects()
context.refresh(object, mergeChanges: false)
}
} }
} else if let eraserStroke = currentStroke.stroke(as: EraserStroke.self) { } else if let eraserStroke = currentStroke.stroke(as: EraserStroke.self) {
eraserStroke.saveQuads() eraserStroke.saveQuads()
eraserStrokes.insert(eraserStroke) eraserStrokes.insert(eraserStroke)
withPersistence(\.backgroundContext) { context in withPersistence(\.backgroundContext) { [eraserStroke] context in
eraserStroke.object?.bounds = eraserStroke.bounds
try context.saveIfNeeded() try context.saveIfNeeded()
context.refreshAllObjects()
} }
} }
previousStroke = currentStroke previousStroke = currentStroke
+8 -8
View File
@@ -128,15 +128,15 @@ struct Toolbar: View {
} }
func closeMemo() { func closeMemo() {
DispatchQueue.global(qos: .userInitiated).async { withAnimation {
canvas.state = .closing
}
withPersistence(\.backgroundContext) { context in
try? context.saveIfNeeded()
DispatchQueue.main.async { DispatchQueue.main.async {
canvas.state = .closing withAnimation {
} canvas.state = .closed
withPersistenceSync(\.viewContext) { context in }
try context.saveIfNeeded()
}
DispatchQueue.main.async {
canvas.state = .closed
dismiss() dismiss()
} }
} }