Persist recording logs before save operation (crash-safe)

This commit is contained in:
relikd
2020-09-08 03:16:38 +02:00
parent 27ab2a621a
commit 39ca9dbdb1

View File

@@ -18,6 +18,17 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
@IBOutlet private var chooseAppTap: UITapGestureRecognizer! @IBOutlet private var chooseAppTap: UITapGestureRecognizer!
override func viewDidLoad() { override func viewDidLoad() {
if deleteOnCancel { // aka newly created
RecordingsDB.persist(record)
if Prefs.RecordingReminder.Enabled {
PushNotification.scheduleRecordingReminder(force: true)
}
// mark as destructive
buttonCancel.tintColor = .systemRed
if #available(iOS 13.0, *) {
isModalInPresentation = true
}
}
if record.isLongTerm { if record.isLongTerm {
appId = nil appId = nil
appIcon.image = nil appIcon.image = nil
@@ -44,12 +55,6 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
Duration: \(TimeFormat.from(record.duration)) Duration: \(TimeFormat.from(record.duration))
""" """
validateSaveButton() validateSaveButton()
if deleteOnCancel { // mark as destructive
buttonCancel.tintColor = .systemRed
if #available(iOS 13.0, *) {
isModalInPresentation = true
}
}
UIResponder.keyboardWillShowNotification.observe(call: #selector(keyboardWillShow), on: self) UIResponder.keyboardWillShowNotification.observe(call: #selector(keyboardWillShow), on: self)
UIResponder.keyboardWillHideNotification.observe(call: #selector(keyboardWillHide), on: self) UIResponder.keyboardWillHideNotification.observe(call: #selector(keyboardWillHide), on: self)
} }
@@ -63,11 +68,8 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
// MARK: Save & Cancel Buttons // MARK: Save & Cancel Buttons
@IBAction func didTapSave() { @IBAction func didTapSave() {
let newlyCreated = deleteOnCancel // if remains true, `viewDidDisappear` will delete the record
if newlyCreated { deleteOnCancel = false
// if remains true, `viewDidDisappear` will delete the record
deleteOnCancel = false
}
QLog.Debug("updating record #\(record.id)") QLog.Debug("updating record #\(record.id)")
if let id = appId, id != "" { if let id = appId, id != "" {
record.appId = id record.appId = id
@@ -81,12 +83,6 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
record.notes = (inputNotes.text == "") ? nil : inputNotes.text record.notes = (inputNotes.text == "") ? nil : inputNotes.text
dismiss(animated: true) { dismiss(animated: true) {
RecordingsDB.update(self.record) RecordingsDB.update(self.record)
if newlyCreated {
RecordingsDB.persist(self.record)
if Prefs.RecordingReminder.Enabled {
PushNotification.scheduleRecordingReminder(force: true)
}
}
} }
} }