diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index ae2437d..97bcac3 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -149,23 +149,23 @@ DC19400C1E4B39400077E0A3 /* Controllers */ = { isa = PBXGroup; children = ( - DC037CB71E4DD1A500609409 /* AddPasswordTableViewController.swift */, - DCFB77A81E502FF6008DE471 /* PasswordEditorTableViewController.swift */, - DCFB77A61E502DF9008DE471 /* EditPasswordTableViewController.swift */, DC037CB11E4CAB1700609409 /* AboutRepositoryTableViewController.swift */, - DC037CAF1E4CA51F00609409 /* GeneralSettingsTableViewController.swift */, DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */, - DC037CA71E4B898100609409 /* BasicStaticTableViewController.swift */, - DC037CAD1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift */, - DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */, - DC037CA51E4B883900609409 /* OpenSourceComponentsTableViewController.swift */, - DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */, - DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */, - DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */, + DC037CB71E4DD1A500609409 /* AddPasswordTableViewController.swift */, DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */, - DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */, - DC5734AD1E439AD400D09270 /* PasswordsViewController.swift */, + DC037CA71E4B898100609409 /* BasicStaticTableViewController.swift */, + DCFB77A61E502DF9008DE471 /* EditPasswordTableViewController.swift */, + DC037CAF1E4CA51F00609409 /* GeneralSettingsTableViewController.swift */, + DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */, + DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */, + DC037CA51E4B883900609409 /* OpenSourceComponentsTableViewController.swift */, DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */, + DCFB77A81E502FF6008DE471 /* PasswordEditorTableViewController.swift */, + DC037CAD1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift */, + DC5734AD1E439AD400D09270 /* PasswordsViewController.swift */, + DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */, + DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */, + DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */, DC8963BF1E38EEB900828B09 /* SSHKeySettingTableViewController.swift */, ); path = Controllers; diff --git a/pass/Controllers/EditPasswordTableViewController.swift b/pass/Controllers/EditPasswordTableViewController.swift index b7a41bb..d2a0e1b 100644 --- a/pass/Controllers/EditPasswordTableViewController.swift +++ b/pass/Controllers/EditPasswordTableViewController.swift @@ -48,7 +48,7 @@ class EditPasswordTableViewController: PasswordEditorTableViewController { let cellTitle = tableData[indexPath.section][indexPath.row][.title] as! String cellContents[cellTitle] = contentCell.getContent()! } - password!.updatePassword(name: cellContents["name"]!, plainText: "\(cellContents["password"]!)\n\(cellContents["additions"]!)") + password!.updatePassword(name: cellContents["name"]!, plainText: "\(cellContents["password"]!)\n\(cellContents["additions"]!)\n") } } diff --git a/pass/Controllers/PasswordDetailTableViewController.swift b/pass/Controllers/PasswordDetailTableViewController.swift index 3fefa3c..889f27e 100644 --- a/pass/Controllers/PasswordDetailTableViewController.swift +++ b/pass/Controllers/PasswordDetailTableViewController.swift @@ -9,6 +9,7 @@ import UIKit import FavIcon import SwiftyUserDefaults +import SVProgressHUD class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate { var passwordEntity: PasswordEntity? @@ -108,13 +109,22 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni } @IBAction func saveEditPassword(segue: UIStoryboardSegue) { - if password!.changed { - PasswordStore.shared.update(passwordEntity: passwordEntity!, password: password!, progressBlock: { progress in - - }) - NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) - setTableData() - tableView.reloadData() + if self.password!.changed { + SVProgressHUD.show(withStatus: "Saving") + DispatchQueue.global(qos: .userInitiated).async { + PasswordStore.shared.update(passwordEntity: self.passwordEntity!, password: self.password!, progressBlock: { progress in + SVProgressHUD.showProgress(progress, status: "Encrypting") + }) + DispatchQueue.main.async { + self.passwordEntity!.synced = false + PasswordStore.shared.saveUpdated(passwordEntity: self.passwordEntity!) + NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) + self.setTableData() + self.tableView.reloadData() + SVProgressHUD.showSuccess(withStatus: "Success") + SVProgressHUD.dismiss(withDelay: 1) + } + } } } diff --git a/pass/Models/PasswordStore.swift b/pass/Models/PasswordStore.swift index 494c25e..bc5656c 100644 --- a/pass/Models/PasswordStore.swift +++ b/pass/Models/PasswordStore.swift @@ -331,11 +331,18 @@ class PasswordStore { let encryptedData = try passwordEntity.encrypt(password: password) let saveURL = storeURL.appendingPathComponent(passwordEntity.rawPath!) try encryptedData.write(to: saveURL) - passwordEntity.synced = false + progressBlock(0.3) let _ = createAddCommitInRepository(message: "Update password by pass for iOS", fileData: encryptedData, filename: saveURL.lastPathComponent, progressBlock: progressBlock) + } catch { + print(error) + } + } + + func saveUpdated(passwordEntity: PasswordEntity) { + do { try context.save() } catch { - fatalError("Failed to fetch employees: \(error)") + fatalError("Failed to save a PasswordEntity: \(error)") } }