diff --git a/Cartfile b/Cartfile index 0cfaa64..a45819d 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,4 @@ -github "SwiftGit2/SwiftGit2" github "SVProgressHUD/SVProgressHUD" github "radex/SwiftyUserDefaults" +github "libgit2/objective-git" + diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index be630b5..ea2e6c9 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -8,14 +8,14 @@ /* Begin PBXBuildFile section */ 94BA784B85E071D25EE89B59 /* libPods-pass.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */; }; + DC1208561E35D0BA0042942E /* PasswordsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */; }; + DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC1208571E35EBE60042942E /* ObjectiveGit.framework */; }; DC3DC8391E2F63240062A988 /* PasswordDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */; }; - DC6FDBBD1E35CE1E00A280F0 /* PasswordsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6FDBBC1E35CE1E00A280F0 /* PasswordsTableViewController.swift */; }; DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC917BD61E2E8231000FDF54 /* AppDelegate.swift */; }; DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDA1E2E8231000FDF54 /* Main.storyboard */; }; DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; }; DC917BE11E2E8231000FDF54 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDF1E2E8231000FDF54 /* LaunchScreen.storyboard */; }; DC917BEF1E2F38C5000FDF54 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC917BEE1E2F38C5000FDF54 /* Result.framework */; }; - DC917BF11E2F38C9000FDF54 /* SwiftGit2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC917BF01E2F38C9000FDF54 /* SwiftGit2.framework */; }; DCA049961E3357E000522E8F /* SwiftyUserDefaults.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCA049951E3357E000522E8F /* SwiftyUserDefaults.framework */; }; DCA049981E33586A00522E8F /* DefaultKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA049971E33586A00522E8F /* DefaultKeys.swift */; }; DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */; }; @@ -31,9 +31,10 @@ 274CCFCF32444A2FF46BE7F4 /* Pods-pass.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pass.debug.xcconfig"; path = "Pods/Target Support Files/Pods-pass/Pods-pass.debug.xcconfig"; sourceTree = ""; }; ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-pass.a"; sourceTree = BUILT_PRODUCTS_DIR; }; AEAD6B31EAF5D061447A68CC /* Pods-pass.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pass.release.xcconfig"; path = "Pods/Target Support Files/Pods-pass/Pods-pass.release.xcconfig"; sourceTree = ""; }; + DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordsTableViewController.swift; sourceTree = ""; }; + DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = ""; }; DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailViewController.swift; sourceTree = ""; }; DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Objective-CBridgingHeader.h"; sourceTree = ""; }; - DC6FDBBC1E35CE1E00A280F0 /* PasswordsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordsTableViewController.swift; sourceTree = ""; }; DC917BD31E2E8231000FDF54 /* pass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = pass.app; sourceTree = BUILT_PRODUCTS_DIR; }; DC917BD61E2E8231000FDF54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DC917BDB1E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -41,7 +42,6 @@ DC917BE01E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; DC917BE21E2E8231000FDF54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DC917BEE1E2F38C5000FDF54 /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Result.framework; path = Carthage/Build/iOS/Result.framework; sourceTree = ""; }; - DC917BF01E2F38C9000FDF54 /* SwiftGit2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftGit2.framework; path = Carthage/Build/iOS/SwiftGit2.framework; sourceTree = ""; }; DCA049951E3357E000522E8F /* SwiftyUserDefaults.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyUserDefaults.framework; path = Carthage/Build/iOS/SwiftyUserDefaults.framework; sourceTree = ""; }; DCA049971E33586A00522E8F /* DefaultKeys.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultKeys.swift; sourceTree = ""; }; DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitServerSettingTableViewController.swift; sourceTree = ""; }; @@ -59,8 +59,8 @@ buildActionMask = 2147483647; files = ( DC917BEF1E2F38C5000FDF54 /* Result.framework in Frameworks */, - DC917BF11E2F38C9000FDF54 /* SwiftGit2.framework in Frameworks */, DCC408C71E307DBB00F29B0E /* SVProgressHUD.framework in Frameworks */, + DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */, DCA049961E3357E000522E8F /* SwiftyUserDefaults.framework in Frameworks */, 94BA784B85E071D25EE89B59 /* libPods-pass.a in Frameworks */, ); @@ -99,7 +99,7 @@ DC917BD51E2E8231000FDF54 /* pass */ = { isa = PBXGroup; children = ( - DC6FDBBC1E35CE1E00A280F0 /* PasswordsTableViewController.swift */, + DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */, DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */, DC917BD61E2E8231000FDF54 /* AppDelegate.swift */, DC917BDA1E2E8231000FDF54 /* Main.storyboard */, @@ -121,9 +121,9 @@ DC917BED1E2F38C4000FDF54 /* Frameworks */ = { isa = PBXGroup; children = ( + DC1208571E35EBE60042942E /* ObjectiveGit.framework */, DCA049951E3357E000522E8F /* SwiftyUserDefaults.framework */, DCC408C61E307DBB00F29B0E /* SVProgressHUD.framework */, - DC917BF01E2F38C9000FDF54 /* SwiftGit2.framework */, DC917BEE1E2F38C5000FDF54 /* Result.framework */, ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */, ); @@ -254,10 +254,10 @@ files = ( ); inputPaths = ( - "$(SRCROOT)/Carthage/Build/iOS/SwiftGit2.framework", "$(SRCROOT)/Carthage/Build/iOS/Result.framework", "$(SRCROOT)/Carthage/Build/iOS/SVProgressHUD.framework", "$(SRCROOT)/Carthage/Build/iOS/SwiftyUserDefaults.framework", + "$(SRCROOT)/Carthage/Build/iOS/ObjectiveGit.framework", ); outputPaths = ( ); @@ -274,7 +274,7 @@ files = ( DCC408A41E2FCC9E00F29B0E /* PasswordStore.swift in Sources */, DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */, - DC6FDBBD1E35CE1E00A280F0 /* PasswordsTableViewController.swift in Sources */, + DC1208561E35D0BA0042942E /* PasswordsTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */, DCC277D21E30D6EA00402246 /* pass.xcdatamodeld in Sources */, @@ -409,6 +409,13 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_ROOT}/Headers/Public\"", + "\"${PODS_ROOT}/Headers/Public/ObjectivePGP\"", + "\"${PODS_ROOT}/Headers/Public/OpenSSL-Universal\"", + "$(SRCROOT)/Carthage/Build/iOS/ObjectiveGit.framework/Headers/", + ); INFOPLIST_FILE = pass/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.mssun.pass; @@ -429,6 +436,13 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_ROOT}/Headers/Public\"", + "\"${PODS_ROOT}/Headers/Public/ObjectivePGP\"", + "\"${PODS_ROOT}/Headers/Public/OpenSSL-Universal\"", + "$(SRCROOT)/Carthage/Build/iOS/ObjectiveGit.framework/Headers/", + ); INFOPLIST_FILE = pass/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.mssun.pass; diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index f4a8312..d8df061 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -13,7 +13,7 @@ - + @@ -47,7 +47,11 @@ - + + + + + diff --git a/pass/Objective-CBridgingHeader.h b/pass/Objective-CBridgingHeader.h index 945da44..babc42b 100644 --- a/pass/Objective-CBridgingHeader.h +++ b/pass/Objective-CBridgingHeader.h @@ -10,5 +10,6 @@ #define Objective_CBridgingHeader_h #import +#import #endif /* Objective_CBridgingHeader_h */ diff --git a/pass/PasswordStore.swift b/pass/PasswordStore.swift index 303c602..606a2c4 100644 --- a/pass/PasswordStore.swift +++ b/pass/PasswordStore.swift @@ -7,26 +7,28 @@ // import Foundation -import SwiftGit2 import Result import CoreData import UIKit import SwiftyUserDefaults +import ObjectiveGit class PasswordStore { static let shared = PasswordStore() let storeURL = URL(fileURLWithPath: "\(Globals.shared.documentPath)/password-store") - var storeRepo: Repository? + var storeRepository: GTRepository? + let pgp: ObjectivePGP = ObjectivePGP() let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext private init() { - let result = Repository.at(storeURL) - if case .success(let r) = result { - storeRepo = r + do { + try storeRepository = GTRepository.init(url: storeURL) + } catch { + print(error) } if Defaults[.pgpKeyID] != "" { pgp.importKeys(fromFile: Globals.shared.secringPath, allowDuplicates: false) @@ -52,10 +54,10 @@ class PasswordStore { } - func cloneRemoteRepo(remoteRepoURL: URL) -> Bool { + func cloneRepository(remoteRepoURL: URL) -> Bool { print("start cloning remote repo") let fm = FileManager.default - if (storeRepo != nil) { + if (storeRepository != nil) { print("remove item") do { try fm.removeItem(at: storeURL) @@ -63,14 +65,23 @@ class PasswordStore { print(error.debugDescription) } } - let cloneResult = Repository.clone(from: remoteRepoURL, to: storeURL) - switch cloneResult { - case let .success(clonedRepo): - storeRepo = clonedRepo - print("clone repo: \(storeURL) success") + do { + storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: storeURL, options: nil, transferProgressBlock: nil, checkoutProgressBlock: nil) updatePasswordEntityCoreData() return true - case let .failure(error): + } catch { + print(error) + return false + } + } + func pullRepository() -> Bool { + print("pullRepoisitory") + do { + let remote = try GTRemote(name: "origin", in: storeRepository!) + try storeRepository?.pull((storeRepository?.currentBranch())!, from: remote, withOptions: nil, progress: nil) + updatePasswordEntityCoreData() + return true + } catch { print(error) return false } diff --git a/pass/PasswordsTableViewController.swift b/pass/PasswordsTableViewController.swift index 3173c39..4876a10 100644 --- a/pass/PasswordsTableViewController.swift +++ b/pass/PasswordsTableViewController.swift @@ -7,21 +7,25 @@ // import UIKit -import SwiftGit2 import Result import SVProgressHUD -extension PasswordsTableViewController: UISearchResultsUpdating { - func updateSearchResults(for searchController: UISearchController) { - filterContentForSearchText(searchText: searchController.searchBar.text!) - } -} class PasswordsTableViewController: UITableViewController { private var passwordEntities: [PasswordEntity]? var filteredPasswordEntities = [PasswordEntity]() let searchController = UISearchController(searchResultsController: nil) + @IBAction func refreshPasswords(_ sender: UIBarButtonItem) { + DispatchQueue.global(qos: .userInitiated).async { + if PasswordStore.shared.pullRepository() { + print("pull success") + self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData() + self.tableView.reloadData() + } + } + } + override func viewDidLoad() { super.viewDidLoad() passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData() @@ -87,3 +91,10 @@ class PasswordsTableViewController: UITableViewController { } } + +extension PasswordsTableViewController: UISearchResultsUpdating { + func updateSearchResults(for searchController: UISearchController) { + filterContentForSearchText(searchText: searchController.searchBar.text!) + } +} + diff --git a/pass/SettingsTableViewController.swift b/pass/SettingsTableViewController.swift index c462d66..e8e7eea 100644 --- a/pass/SettingsTableViewController.swift +++ b/pass/SettingsTableViewController.swift @@ -27,7 +27,7 @@ class SettingsTableViewController: UITableViewController { SVProgressHUD.show(withStatus: "Cloning Remote Repository") DispatchQueue.global(qos: .userInitiated).async { - let ret = PasswordStore.shared.cloneRemoteRepo(remoteRepoURL: Defaults[.gitRepositoryURL]!) + let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: Defaults[.gitRepositoryURL]!) DispatchQueue.main.async { if ret {