do not dismiss views when application is resumed (#605)
* do not dismiss views when application is resumed * prevents the PasswordNavigationViewController and PasswordDetailTableViewController from being dismissed when the app is put to the background and then brought back to the foreground * Instead, the PasswordEntities are re-fetched from the context by their path to handle the re-creation of the entities during an update process that could have run in the background * update SwiftLint to version 0.50.* * update SwiftFormat to 0.51.* --------- Co-authored-by: Mingshen Sun <bob@mssun.me>
This commit is contained in:
parent
83c6ae33dc
commit
f2a0c4ccf1
10 changed files with 77 additions and 26 deletions
|
|
@ -15,13 +15,21 @@ import UIKit
|
|||
import YubiKit
|
||||
|
||||
class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate, AlertPresenting {
|
||||
var passwordEntity: PasswordEntity?
|
||||
var passwordEntity: PasswordEntity? {
|
||||
didSet {
|
||||
passwordPath = passwordEntity?.path
|
||||
}
|
||||
}
|
||||
|
||||
private var password: Password?
|
||||
private var passwordImage: UIImage?
|
||||
private var oneTimePasswordIndexPath: IndexPath?
|
||||
private var shouldPopCurrentView = false
|
||||
private let passwordStore = PasswordStore.shared
|
||||
|
||||
// preserve path so it can be reloaded even if the passwordEntity is deleted during the update process
|
||||
private var passwordPath: String?
|
||||
|
||||
private lazy var editUIBarButtonItem: UIBarButtonItem = {
|
||||
let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit))
|
||||
return uiBarButtonItem
|
||||
|
|
@ -74,6 +82,9 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
|
||||
// reset the data table if the disaply settings have been changed
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(decryptThenShowPasswordSelector), name: .passwordDetailDisplaySettingChanged, object: nil)
|
||||
|
||||
// A Siri shortcut can change the state of the app in the background. Hence, reload when opening the app.
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(actOnPossiblePasswordStoreUpdate), name: UIApplication.willEnterForegroundNotification, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
|
|
@ -526,6 +537,23 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
}
|
||||
|
||||
extension PasswordDetailTableViewController {
|
||||
@objc
|
||||
func actOnPossiblePasswordStoreUpdate() {
|
||||
DispatchQueue.main.async {
|
||||
if let path = self.passwordPath {
|
||||
// reload PasswordEntity because all PasswordEntities are re-created on PasswordStore update
|
||||
self.passwordEntity = PasswordStore.shared.fetchPasswordEntity(with: path)
|
||||
|
||||
// dismiss if the PasswordEntity does not exist anymore
|
||||
if self.passwordEntity == nil {
|
||||
self.navigationController?.popToRootViewController(animated: true)
|
||||
} else {
|
||||
self.decryptThenShowPassword()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func requestYubiKeyPIN(completion: @escaping (String) -> Void, cancellation: @escaping () -> Void) {
|
||||
let alert = UIAlertController(title: "YubiKey PIN", message: "Verify YubiKey OpenPGP PIN.", preferredStyle: .alert)
|
||||
alert.addAction(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue