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

View File

@@ -203,15 +203,15 @@ extension GraphicContext {
withPersistence(\.backgroundContext) { [penStroke] context in
penStroke.object?.bounds = penStroke.bounds
try context.saveIfNeeded()
if let object = penStroke.object {
context.refresh(object, mergeChanges: false)
}
context.refreshAllObjects()
}
} else if let eraserStroke = currentStroke.stroke(as: EraserStroke.self) {
eraserStroke.saveQuads()
eraserStrokes.insert(eraserStroke)
withPersistence(\.backgroundContext) { context in
withPersistence(\.backgroundContext) { [eraserStroke] context in
eraserStroke.object?.bounds = eraserStroke.bounds
try context.saveIfNeeded()
context.refreshAllObjects()
}
}
previousStroke = currentStroke

View File

@@ -128,15 +128,15 @@ struct Toolbar: View {
}
func closeMemo() {
DispatchQueue.global(qos: .userInitiated).async {
withAnimation {
canvas.state = .closing
}
withPersistence(\.backgroundContext) { context in
try? context.saveIfNeeded()
DispatchQueue.main.async {
canvas.state = .closing
}
withPersistenceSync(\.viewContext) { context in
try context.saveIfNeeded()
}
DispatchQueue.main.async {
canvas.state = .closed
withAnimation {
canvas.state = .closed
}
dismiss()
}
}