@@ -21,7 +21,14 @@ class PasswordNavigationViewController: UIViewController {
2121 @IBOutlet var tableView : UITableView !
2222
2323 var dataSource : PasswordNavigationDataSource ?
24- var parentPasswordEntity : PasswordEntity ?
24+ var parentPasswordEntity : PasswordEntity ? {
25+ didSet {
26+ parentPath = parentPasswordEntity? . path
27+ }
28+ }
29+
30+ // preserve parent path so it can be reloaded even if the parentPasswordEntity is deleted during the update process
31+ private var parentPath : String ?
2532
2633 var viewingUnsyncedPasswords = false
2734 var tapTabBarTime : TimeInterval = 0
@@ -181,13 +188,13 @@ class PasswordNavigationViewController: UIViewController {
181188 private func configureNotification( ) {
182189 let notificationCenter = NotificationCenter . default
183190 // Reset the data table if some password (maybe another one) has been updated.
184- notificationCenter. addObserver ( self , selector: #selector( actOnReloadTableViewRelatedNotification ) , name: . passwordStoreUpdated, object: nil )
191+ notificationCenter. addObserver ( self , selector: #selector( actOnPossiblePasswordStoreUpdate ) , name: . passwordStoreUpdated, object: nil )
185192 // Reset the data table if the disaply settings have been changed.
186193 notificationCenter. addObserver ( self , selector: #selector( actOnReloadTableViewRelatedNotification) , name: . passwordDisplaySettingChanged, object: nil )
187194 // Search entrypoint for home screen quick action.
188195 notificationCenter. addObserver ( self , selector: #selector( actOnSearchNotification) , name: . passwordSearch, object: nil )
189196 // A Siri shortcut can change the state of the app in the background. Hence, reload when opening the app.
190- notificationCenter. addObserver ( self , selector: #selector( actOnReloadTableViewRelatedNotification ) , name: UIApplication . willEnterForegroundNotification, object: nil )
197+ notificationCenter. addObserver ( self , selector: #selector( actOnPossiblePasswordStoreUpdate ) , name: UIApplication . willEnterForegroundNotification, object: nil )
191198 }
192199
193200 @objc
@@ -352,6 +359,23 @@ extension PasswordNavigationViewController {
352359 }
353360 }
354361
362+ @objc
363+ func actOnPossiblePasswordStoreUpdate( ) {
364+ DispatchQueue . main. async {
365+ if let path = self . parentPath {
366+ // reload parent because all PasswordEntities are re-created on PasswordStore update
367+ self . parentPasswordEntity = PasswordStore . shared. fetchPasswordEntity ( with: path)
368+
369+ // pop to the root controller if the parent does not exist anymore
370+ if self . parentPasswordEntity == nil {
371+ self . navigationController? . popToRootViewController ( animated: true )
372+ }
373+ }
374+
375+ self . resetViews ( )
376+ }
377+ }
378+
355379 func resetViews( ) {
356380 configureTableView ( in: parentPasswordEntity)
357381 tableView. reloadData ( )
@@ -447,14 +471,14 @@ extension PasswordNavigationViewController: PasswordAlertPresenter {
447471 }
448472 DispatchQueue . global ( qos: . userInitiated) . async { [ unowned self] in
449473 do {
450- let pullOptions = gitCredential. getCredentialOptions ( passwordProvider: self . present)
474+ let pullOptions = gitCredential. getCredentialOptions ( passwordProvider: present)
451475 try PasswordStore . shared. pullRepository ( options: pullOptions) { git_transfer_progress, _ in
452476 DispatchQueue . main. async {
453477 SVProgressHUD . showProgress ( Float ( git_transfer_progress. pointee. received_objects) / Float( git_transfer_progress. pointee. total_objects) , status: " PullingFromRemoteRepository " . localize ( ) )
454478 }
455479 }
456480 if PasswordStore . shared. numberOfLocalCommits > 0 {
457- let pushOptions = gitCredential. getCredentialOptions ( passwordProvider: self . present)
481+ let pushOptions = gitCredential. getCredentialOptions ( passwordProvider: present)
458482 try PasswordStore . shared. pushRepository ( options: pushOptions) { current, total, _, _ in
459483 DispatchQueue . main. async {
460484 SVProgressHUD . showProgress ( Float ( current) / Float( total) , status: " PushingToRemoteRepository " . localize ( ) )
0 commit comments