From 1c95b46252b26032f46b0971d9676bd5637fd0fb Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Thu, 9 Feb 2017 21:45:31 +0800 Subject: [PATCH] re-organize settings --- pass.xcodeproj/project.pbxproj | 8 ++ pass/Base.lproj/Main.storyboard | 122 ++++++++++++------ .../GeneralSettingsTableViewController.swift | 17 +++ ...epositorySettingsTableViewController.swift | 85 ++++++++++++ .../SettingsTableViewController.swift | 59 +-------- .../SpecialThanksTableViewController.swift | 3 +- 6 files changed, 194 insertions(+), 100 deletions(-) create mode 100644 pass/Controllers/GeneralSettingsTableViewController.swift create mode 100644 pass/Controllers/PasswordRepositorySettingsTableViewController.swift diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index cf358dd..14365ec 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ DC037CA81E4B898100609409 /* BasicStaticTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CA71E4B898100609409 /* BasicStaticTableViewController.swift */; }; DC037CAA1E4B8EAE00609409 /* SpecialThanksTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */; }; DC037CAC1E4C1C7100609409 /* FavIcon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC037CAB1E4C1C7100609409 /* FavIcon.framework */; }; + DC037CAE1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CAD1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift */; }; + DC037CB01E4CA51F00609409 /* GeneralSettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CAF1E4CA51F00609409 /* GeneralSettingsTableViewController.swift */; }; DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC1208571E35EBE60042942E /* ObjectiveGit.framework */; }; DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */; }; DC193FFC1E49E0340077E0A3 /* PasscodeLock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC193FFB1E49E0340077E0A3 /* PasscodeLock.framework */; }; @@ -52,6 +54,8 @@ DC037CA71E4B898100609409 /* BasicStaticTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicStaticTableViewController.swift; sourceTree = ""; }; DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpecialThanksTableViewController.swift; sourceTree = ""; }; DC037CAB1E4C1C7100609409 /* FavIcon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FavIcon.framework; path = Carthage/Build/iOS/FavIcon.framework; sourceTree = ""; }; + DC037CAD1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordRepositorySettingsTableViewController.swift; sourceTree = ""; }; + DC037CAF1E4CA51F00609409 /* GeneralSettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralSettingsTableViewController.swift; sourceTree = ""; }; DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = ""; }; DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsTableViewController.swift; sourceTree = ""; }; DC193FFB1E49E0340077E0A3 /* PasscodeLock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PasscodeLock.framework; path = Carthage/Build/iOS/PasscodeLock.framework; sourceTree = ""; }; @@ -117,8 +121,10 @@ DC19400C1E4B39400077E0A3 /* Controllers */ = { isa = PBXGroup; children = ( + DC037CAF1E4CA51F00609409 /* GeneralSettingsTableViewController.swift */, DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */, DC037CA71E4B898100609409 /* BasicStaticTableViewController.swift */, + DC037CAD1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift */, DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */, DC037CA51E4B883900609409 /* OpenSourceComponentsTableViewController.swift */, DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */, @@ -370,6 +376,7 @@ DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */, DCDDEAB31E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift in Sources */, + DC037CAE1E4C9B9B00609409 /* PasswordRepositorySettingsTableViewController.swift in Sources */, DCC277D21E30D6EA00402246 /* pass.xcdatamodeld in Sources */, DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */, DC962CDF1E4B62C10033B5D8 /* AboutTableViewController.swift in Sources */, @@ -377,6 +384,7 @@ DC037CAA1E4B8EAE00609409 /* SpecialThanksTableViewController.swift in Sources */, DC037CA61E4B883900609409 /* OpenSourceComponentsTableViewController.swift in Sources */, DC037CA81E4B898100609409 /* BasicStaticTableViewController.swift in Sources */, + DC037CB01E4CA51F00609409 /* GeneralSettingsTableViewController.swift in Sources */, DC8963BE1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift in Sources */, DC1940001E49E1A60077E0A3 /* PasscodeLockConfiguration.swift in Sources */, DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */, diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index 8326918..51a53a5 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -62,7 +62,7 @@ - + @@ -73,16 +73,16 @@ - + - - + + - + - - + - - + + - + - - + - - - - - - + + - + - - + @@ -151,7 +147,7 @@ - + @@ -175,7 +171,7 @@ - + @@ -196,7 +192,7 @@ - + @@ -220,7 +216,7 @@ - + @@ -250,13 +246,13 @@ - + - + @@ -402,12 +398,12 @@ - + - + @@ -422,7 +418,7 @@ - + @@ -491,7 +487,7 @@ - + @@ -592,7 +588,7 @@ - + @@ -611,7 +607,7 @@ - + @@ -668,7 +664,7 @@ - + @@ -686,7 +682,7 @@ - + @@ -805,7 +801,49 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -823,7 +861,7 @@ - + @@ -867,7 +905,7 @@ - + @@ -890,7 +928,7 @@ - + @@ -909,7 +947,7 @@ - + @@ -928,7 +966,7 @@ - + diff --git a/pass/Controllers/GeneralSettingsTableViewController.swift b/pass/Controllers/GeneralSettingsTableViewController.swift new file mode 100644 index 0000000..746007f --- /dev/null +++ b/pass/Controllers/GeneralSettingsTableViewController.swift @@ -0,0 +1,17 @@ +// +// GeneralSettingsTableViewController.swift +// pass +// +// Created by Mingshen Sun on 9/2/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit + +class GeneralSettingsTableViewController: BasicStaticTableViewController { + + override func viewDidLoad() { + navigationItemTitle = "General" + super.viewDidLoad() + } +} diff --git a/pass/Controllers/PasswordRepositorySettingsTableViewController.swift b/pass/Controllers/PasswordRepositorySettingsTableViewController.swift new file mode 100644 index 0000000..50087ec --- /dev/null +++ b/pass/Controllers/PasswordRepositorySettingsTableViewController.swift @@ -0,0 +1,85 @@ +// +// PasswordRepositorySettingsTableViewController.swift +// pass +// +// Created by Mingshen Sun on 9/2/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit +import SwiftyUserDefaults +import SVProgressHUD + +class PasswordRepositorySettingsTableViewController: BasicStaticTableViewController { + override func viewDidLoad() { + tableData = [ + [[.type: CellDataType.segue, .title: "Git Server", .link: "showGitServerSettingSegue"], + [.type: CellDataType.segue, .title: "SSH Key", .link: "showSSHKeySettingSegue"],], + ] + navigationItemTitle = "Repository" + super.viewDidLoad() + } + + @IBAction func cancelGitServerSetting(segue: UIStoryboardSegue) { + } + + @IBAction func saveGitServerSetting(segue: UIStoryboardSegue) { + if let controller = segue.source as? GitServerSettingTableViewController { + let gitRepostiroyURL = controller.gitRepositoryURLTextField.text! + let username = controller.usernameTextField.text! + let password = controller.passwordTextField.text! + let auth = controller.authenticationMethod + + if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString { + SVProgressHUD.setDefaultMaskType(.black) + SVProgressHUD.setDefaultStyle(.light) + SVProgressHUD.show(withStatus: "Prepare Repository") + var gitCredential: GitCredential + if auth == "Password" { + gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password)) + } else { + gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: username, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL)) + } + + DispatchQueue.global(qos: .userInitiated).async { + do { + try PasswordStore.shared.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!, + credential: gitCredential, + transferProgressBlock:{ (git_transfer_progress, stop) in + DispatchQueue.main.async { + SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository") + } + }, + checkoutProgressBlock: { (path, completedSteps, totalSteps) in + DispatchQueue.main.async { + SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch") + } + }) + + DispatchQueue.main.async { + SVProgressHUD.showSuccess(withStatus: "Done") + SVProgressHUD.dismiss(withDelay: 1) + + Defaults[.lastUpdatedTime] = Date() + + NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) + + } + } catch { + DispatchQueue.main.async { + print(error) + SVProgressHUD.showError(withStatus: error.localizedDescription) + SVProgressHUD.dismiss(withDelay: 1) + } + } + + } + } + + Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL) + Defaults[.gitRepositoryUsername] = username + Defaults[.gitRepositoryPassword] = password + Defaults[.gitRepositoryAuthenticationMethod] = auth + } + } +} diff --git a/pass/Controllers/SettingsTableViewController.swift b/pass/Controllers/SettingsTableViewController.swift index 678e38f..489bee9 100644 --- a/pass/Controllers/SettingsTableViewController.swift +++ b/pass/Controllers/SettingsTableViewController.swift @@ -19,67 +19,12 @@ class SettingsTableViewController: UITableViewController { @IBOutlet weak var pgpKeyTableViewCell: UITableViewCell! @IBOutlet weak var touchIDTableViewCell: UITableViewCell! @IBOutlet weak var passcodeTableViewCell: UITableViewCell! + @IBAction func cancel(segue: UIStoryboardSegue) { } @IBAction func save(segue: UIStoryboardSegue) { - if let controller = segue.source as? GitServerSettingTableViewController { - let gitRepostiroyURL = controller.gitRepositoryURLTextField.text! - let username = controller.usernameTextField.text! - let password = controller.passwordTextField.text! - let auth = controller.authenticationMethod - - if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString { - SVProgressHUD.setDefaultMaskType(.black) - SVProgressHUD.setDefaultStyle(.light) - SVProgressHUD.show(withStatus: "Prepare Repository") - var gitCredential: GitCredential - if auth == "Password" { - gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password)) - } else { - gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: username, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Globals.sshPublicKeyURL, privateKeyFile: Globals.sshPrivateKeyURL)) - } - - DispatchQueue.global(qos: .userInitiated).async { - do { - try PasswordStore.shared.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!, - credential: gitCredential, - transferProgressBlock:{ (git_transfer_progress, stop) in - DispatchQueue.main.async { - SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository") - } - }, - checkoutProgressBlock: { (path, completedSteps, totalSteps) in - DispatchQueue.main.async { - SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch") - } - }) - - DispatchQueue.main.async { - SVProgressHUD.showSuccess(withStatus: "Done") - SVProgressHUD.dismiss(withDelay: 1) - - Defaults[.lastUpdatedTime] = Date() - - NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) - - } - } catch { - DispatchQueue.main.async { - print(error) - SVProgressHUD.showError(withStatus: error.localizedDescription) - SVProgressHUD.dismiss(withDelay: 1) - } - } - - } - } - - Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL) - Defaults[.gitRepositoryUsername] = username - Defaults[.gitRepositoryPassword] = password - Defaults[.gitRepositoryAuthenticationMethod] = auth - } else if let controller = segue.source as? PGPKeySettingTableViewController { + if let controller = segue.source as? PGPKeySettingTableViewController { if Defaults[.pgpKeyURL] != URL(string: controller.pgpKeyURLTextField.text!) || Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text! { diff --git a/pass/Controllers/SpecialThanksTableViewController.swift b/pass/Controllers/SpecialThanksTableViewController.swift index 952f9ab..880d966 100644 --- a/pass/Controllers/SpecialThanksTableViewController.swift +++ b/pass/Controllers/SpecialThanksTableViewController.swift @@ -25,4 +25,5 @@ class SpecialThanksTableViewController: BasicStaticTableViewController { } navigationItemTitle = "Special Thanks" super.viewDidLoad() - }} + } +}