set all password as synced after push to repository
This commit is contained in:
parent
010ec3b322
commit
3ce3155711
3 changed files with 57 additions and 5 deletions
|
|
@ -68,6 +68,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
self.reloadTableView(data: self.passwordEntities!)
|
self.reloadTableView(data: self.passwordEntities!)
|
||||||
|
PasswordStore.shared.setAllSynced()
|
||||||
|
self.setNavigationItemTitle()
|
||||||
Defaults[.lastUpdatedTime] = Date()
|
Defaults[.lastUpdatedTime] = Date()
|
||||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||||
SVProgressHUD.dismiss(withDelay: 1)
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
|
|
@ -83,6 +85,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
setNavigationItemTitle()
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
|
||||||
|
|
@ -134,7 +137,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
} else {
|
} else {
|
||||||
password = passwordEntities![index]
|
password = passwordEntities![index]
|
||||||
}
|
}
|
||||||
cell.textLabel?.text = password.name
|
if password.synced {
|
||||||
|
cell.textLabel?.text = password.name!
|
||||||
|
} else {
|
||||||
|
cell.textLabel?.text = "↻ \(password.name!)"
|
||||||
|
}
|
||||||
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
|
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
|
||||||
longPressGestureRecognizer.minimumPressDuration = 0.6
|
longPressGestureRecognizer.minimumPressDuration = 0.6
|
||||||
cell.addGestureRecognizer(longPressGestureRecognizer)
|
cell.addGestureRecognizer(longPressGestureRecognizer)
|
||||||
|
|
@ -220,6 +227,15 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
func actOnPasswordUpdatedNotification() {
|
func actOnPasswordUpdatedNotification() {
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
reloadTableView(data: passwordEntities!)
|
reloadTableView(data: passwordEntities!)
|
||||||
|
setNavigationItemTitle()
|
||||||
|
}
|
||||||
|
private func setNavigationItemTitle() {
|
||||||
|
let numberOfUnsynced = PasswordStore.shared.getNumberOfUnsyncedPasswords()
|
||||||
|
if numberOfUnsynced == 0 {
|
||||||
|
navigationItem.title = "Password Store"
|
||||||
|
} else {
|
||||||
|
navigationItem.title = "Password Store (\(numberOfUnsynced))"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func actOnPasswordStoreErasedNotification() {
|
func actOnPasswordStoreErasedNotification() {
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ class PasswordStore {
|
||||||
let fetchedPasswordEntities = try context.fetch(passwordEntityFetch) as! [PasswordEntity]
|
let fetchedPasswordEntities = try context.fetch(passwordEntityFetch) as! [PasswordEntity]
|
||||||
return fetchedPasswordEntities.sorted { $0.name!.caseInsensitiveCompare($1.name!) == .orderedAscending }
|
return fetchedPasswordEntities.sorted { $0.name!.caseInsensitiveCompare($1.name!) == .orderedAscending }
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("Failed to fetch employees: \(error)")
|
fatalError("Failed to fetch passwords: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,6 +173,39 @@ class PasswordStore {
|
||||||
do {
|
do {
|
||||||
let passwordCategoryEntities = try context.fetch(passwordCategoryEntityFetchRequest) as! [PasswordCategoryEntity]
|
let passwordCategoryEntities = try context.fetch(passwordCategoryEntityFetchRequest) as! [PasswordCategoryEntity]
|
||||||
return passwordCategoryEntities
|
return passwordCategoryEntities
|
||||||
|
} catch {
|
||||||
|
fatalError("Failed to fetch password categories: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchUnsyncedPasswords() -> [PasswordEntity] {
|
||||||
|
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||||
|
passwordEntityFetchRequest.predicate = NSPredicate(format: "synced = %i", 0)
|
||||||
|
do {
|
||||||
|
let passwordEntities = try context.fetch(passwordEntityFetchRequest) as! [PasswordEntity]
|
||||||
|
return passwordEntities
|
||||||
|
} catch {
|
||||||
|
fatalError("Failed to fetch passwords: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setAllSynced() {
|
||||||
|
let passwordEntities = fetchUnsyncedPasswords()
|
||||||
|
for passwordEntity in passwordEntities {
|
||||||
|
passwordEntity.synced = true
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
try context.save()
|
||||||
|
} catch {
|
||||||
|
fatalError("Failed to save: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNumberOfUnsyncedPasswords() -> Int {
|
||||||
|
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||||
|
do {
|
||||||
|
passwordEntityFetchRequest.predicate = NSPredicate(format: "synced = %i", 0)
|
||||||
|
return try context.count(for: passwordEntityFetchRequest)
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("Failed to fetch employees: \(error)")
|
fatalError("Failed to fetch employees: \(error)")
|
||||||
}
|
}
|
||||||
|
|
@ -205,6 +238,7 @@ class PasswordStore {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func getLocalBranch(withName branchName: String) -> GTBranch? {
|
private func getLocalBranch(withName branchName: String) -> GTBranch? {
|
||||||
do {
|
do {
|
||||||
let reference = GTBranch.localNamePrefix().appending(branchName)
|
let reference = GTBranch.localNamePrefix().appending(branchName)
|
||||||
|
|
@ -235,6 +269,7 @@ class PasswordStore {
|
||||||
let saveURL = storeURL.appendingPathComponent("\(password.name).gpg")
|
let saveURL = storeURL.appendingPathComponent("\(password.name).gpg")
|
||||||
try encryptedData.write(to: saveURL)
|
try encryptedData.write(to: saveURL)
|
||||||
passwordEntity.rawPath = "\(password.name).gpg"
|
passwordEntity.rawPath = "\(password.name).gpg"
|
||||||
|
passwordEntity.synced = false
|
||||||
try context.save()
|
try context.save()
|
||||||
print(saveURL.path)
|
print(saveURL.path)
|
||||||
let _ = createCommitInRepository(message: "Add new password by pass for iOS", fileData: encryptedData, filename: saveURL.lastPathComponent, progressBlock: progressBlock)
|
let _ = createCommitInRepository(message: "Add new password by pass for iOS", fileData: encryptedData, filename: saveURL.lastPathComponent, progressBlock: progressBlock)
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,15 @@
|
||||||
<relationship name="password" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PasswordEntity" inverseName="categories" inverseEntity="PasswordEntity" syncable="YES"/>
|
<relationship name="password" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PasswordEntity" inverseName="categories" inverseEntity="PasswordEntity" syncable="YES"/>
|
||||||
</entity>
|
</entity>
|
||||||
<entity name="PasswordEntity" representedClassName="PasswordEntity" syncable="YES" codeGenerationType="class">
|
<entity name="PasswordEntity" representedClassName="PasswordEntity" syncable="YES" codeGenerationType="class">
|
||||||
<attribute name="image" optional="YES" attributeType="Binary" syncable="YES"/>
|
<attribute name="image" optional="YES" attributeType="Binary" allowsExternalBinaryDataStorage="YES" syncable="YES"/>
|
||||||
<attribute name="name" attributeType="String" syncable="YES"/>
|
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||||
<attribute name="raw" optional="YES" attributeType="Binary" syncable="YES"/>
|
<attribute name="raw" optional="YES" attributeType="Binary" allowsExternalBinaryDataStorage="YES" syncable="YES"/>
|
||||||
<attribute name="rawPath" attributeType="String" syncable="YES"/>
|
<attribute name="rawPath" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="synced" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/>
|
||||||
<relationship name="categories" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PasswordCategoryEntity" inverseName="password" inverseEntity="PasswordCategoryEntity" syncable="YES"/>
|
<relationship name="categories" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PasswordCategoryEntity" inverseName="password" inverseEntity="PasswordCategoryEntity" syncable="YES"/>
|
||||||
</entity>
|
</entity>
|
||||||
<elements>
|
<elements>
|
||||||
<element name="PasswordCategoryEntity" positionX="115" positionY="-9" width="128" height="90"/>
|
<element name="PasswordCategoryEntity" positionX="115" positionY="-9" width="128" height="90"/>
|
||||||
<element name="PasswordEntity" positionX="-63" positionY="-18" width="128" height="120"/>
|
<element name="PasswordEntity" positionX="-63" positionY="-18" width="128" height="135"/>
|
||||||
</elements>
|
</elements>
|
||||||
</model>
|
</model>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue