Refactor Git URL related code, fix #336
This commit is contained in:
parent
e83a2f941e
commit
258906fdbb
8 changed files with 119 additions and 105 deletions
|
|
@ -319,15 +319,15 @@
|
||||||
<sections>
|
<sections>
|
||||||
<tableViewSection headerTitle="Git Repository URL" id="pbe-W6-w4V">
|
<tableViewSection headerTitle="Git Repository URL" id="pbe-W6-w4V">
|
||||||
<cells>
|
<cells>
|
||||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="gitRepositoryURLTabelViewCell" id="FRr-pf-aPO">
|
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="detailButton" indentationWidth="10" reuseIdentifier="gitRepositoryURLTabelViewCell" id="FRr-pf-aPO">
|
||||||
<rect key="frame" x="0.0" y="55.333332061767578" width="414" height="44"/>
|
<rect key="frame" x="0.0" y="55.333332061767578" width="414" height="44"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" tableViewCell="FRr-pf-aPO" id="60A-PS-qGe">
|
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" tableViewCell="FRr-pf-aPO" id="60A-PS-qGe">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
|
<rect key="frame" x="0.0" y="0.0" width="370" height="44"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Git Repository URL" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="EVT-VU-sCi">
|
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Git Repository URL" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="EVT-VU-sCi">
|
||||||
<rect key="frame" x="20" y="11" width="374" height="22"/>
|
<rect key="frame" x="20" y="11" width="342" height="22"/>
|
||||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||||
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="URL" returnKeyType="next"/>
|
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="URL" returnKeyType="next"/>
|
||||||
<connections>
|
<connections>
|
||||||
|
|
@ -488,6 +488,8 @@
|
||||||
<outlet property="authPasswordCell" destination="KrP-nb-haa" id="zjH-sg-dfJ"/>
|
<outlet property="authPasswordCell" destination="KrP-nb-haa" id="zjH-sg-dfJ"/>
|
||||||
<outlet property="authSSHKeyCell" destination="Qmt-bo-CuJ" id="11L-Tt-MgM"/>
|
<outlet property="authSSHKeyCell" destination="Qmt-bo-CuJ" id="11L-Tt-MgM"/>
|
||||||
<outlet property="branchNameTextField" destination="VVI-gJ-e37" id="XLA-8I-yPm"/>
|
<outlet property="branchNameTextField" destination="VVI-gJ-e37" id="XLA-8I-yPm"/>
|
||||||
|
<outlet property="gitRepositoryURLTabelViewCell" destination="FRr-pf-aPO" id="aSz-4u-NZl"/>
|
||||||
|
<outlet property="gitURLCell" destination="FRr-pf-aPO" id="O1e-kc-5tT"/>
|
||||||
<outlet property="gitURLTextField" destination="EVT-VU-sCi" id="XdU-3l-Nsv"/>
|
<outlet property="gitURLTextField" destination="EVT-VU-sCi" id="XdU-3l-Nsv"/>
|
||||||
<outlet property="usernameTextField" destination="TMg-Gk-7nG" id="htL-4C-WJF"/>
|
<outlet property="usernameTextField" destination="TMg-Gk-7nG" id="htL-4C-WJF"/>
|
||||||
<segue destination="7K9-cE-9qq" kind="unwind" identifier="saveGitServerSettingSegue" unwindAction="saveGitServerSettingWithSegue:" id="5UN-sC-xCA"/>
|
<segue destination="7K9-cE-9qq" kind="unwind" identifier="saveGitServerSettingSegue" unwindAction="saveGitServerSettingWithSegue:" id="5UN-sC-xCA"/>
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
let passwords = self.numberOfPasswordsString()
|
let passwords = self.numberOfPasswordsString()
|
||||||
let size = self.sizeOfRepositoryString()
|
let size = self.sizeOfRepositoryString()
|
||||||
let localCommits = self.numberOfLocalCommitsString()
|
let localCommits = self.passwordStore.numberOfLocalCommits
|
||||||
let lastSynced = self.lastSyncedTimeString()
|
let lastSynced = self.lastSyncedTimeString()
|
||||||
let commits = self.numberOfCommitsString()
|
let commits = self.numberOfCommitsString()
|
||||||
|
|
||||||
|
|
@ -86,13 +86,6 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
return ByteCountFormatter.string(fromByteCount: Int64(self.passwordStore.sizeOfRepositoryByteCount), countStyle: ByteCountFormatter.CountStyle.file)
|
return ByteCountFormatter.string(fromByteCount: Int64(self.passwordStore.sizeOfRepositoryByteCount), countStyle: ByteCountFormatter.CountStyle.file)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func numberOfLocalCommitsString() -> String {
|
|
||||||
if let numberOfLocalCommits = passwordStore.numberOfLocalCommits {
|
|
||||||
return String(numberOfLocalCommits)
|
|
||||||
}
|
|
||||||
return AboutRepositoryTableViewController.VALUE_NOT_AVAILABLE
|
|
||||||
}
|
|
||||||
|
|
||||||
private func lastSyncedTimeString() -> String {
|
private func lastSyncedTimeString() -> String {
|
||||||
guard let date = self.passwordStore.lastSyncedTime else {
|
guard let date = self.passwordStore.lastSyncedTime else {
|
||||||
return "SyncAgain?".localize()
|
return "SyncAgain?".localize()
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import UIKit
|
||||||
import SVProgressHUD
|
import SVProgressHUD
|
||||||
import passKit
|
import passKit
|
||||||
|
|
||||||
|
|
||||||
class GitServerSettingTableViewController: UITableViewController {
|
class GitServerSettingTableViewController: UITableViewController {
|
||||||
|
|
||||||
@IBOutlet weak var gitURLTextField: UITextField!
|
@IBOutlet weak var gitURLTextField: UITextField!
|
||||||
|
|
@ -17,25 +18,50 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
@IBOutlet weak var branchNameTextField: UITextField!
|
@IBOutlet weak var branchNameTextField: UITextField!
|
||||||
@IBOutlet weak var authSSHKeyCell: UITableViewCell!
|
@IBOutlet weak var authSSHKeyCell: UITableViewCell!
|
||||||
@IBOutlet weak var authPasswordCell: UITableViewCell!
|
@IBOutlet weak var authPasswordCell: UITableViewCell!
|
||||||
let passwordStore = PasswordStore.shared
|
@IBOutlet weak var gitURLCell: UITableViewCell!
|
||||||
var sshLabel: UILabel? = nil
|
@IBOutlet weak var gitRepositoryURLTabelViewCell: UITableViewCell!
|
||||||
|
private let passwordStore = PasswordStore.shared
|
||||||
|
private var sshLabel: UILabel? = nil
|
||||||
|
|
||||||
var authenticationMethod = SharedDefaults[.gitAuthenticationMethod] ?? "Password"
|
private var gitAuthenticationMethod: GitAuthenticationMethod {
|
||||||
|
get { SharedDefaults[.gitAuthenticationMethod] }
|
||||||
|
set { SharedDefaults[.gitAuthenticationMethod] = newValue }
|
||||||
|
}
|
||||||
|
private var gitUrl: URL {
|
||||||
|
get { SharedDefaults[.gitURL] }
|
||||||
|
set { SharedDefaults[.gitURL] = newValue }
|
||||||
|
}
|
||||||
|
private var gitBranchName: String {
|
||||||
|
get { SharedDefaults[.gitBranchName] }
|
||||||
|
set { SharedDefaults[.gitBranchName] = newValue }
|
||||||
|
}
|
||||||
|
private var gitUsername: String {
|
||||||
|
get { SharedDefaults[.gitUsername] }
|
||||||
|
set { SharedDefaults[.gitUsername] = newValue }
|
||||||
|
}
|
||||||
|
private var gitCredential: GitCredential {
|
||||||
|
get {
|
||||||
|
switch SharedDefaults[.gitAuthenticationMethod] {
|
||||||
|
case .password:
|
||||||
|
return GitCredential(credential: .http(userName: SharedDefaults[.gitUsername]))
|
||||||
|
case .key:
|
||||||
|
let privateKey: String = AppKeychain.shared.get(for: SshKey.PRIVATE.getKeychainKey()) ?? ""
|
||||||
|
return GitCredential(credential: .ssh(userName: SharedDefaults[.gitUsername], privateKey: privateKey))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func checkAuthenticationMethod(method: String) {
|
private func checkAuthenticationMethod() {
|
||||||
let passwordCheckView = authPasswordCell.viewWithTag(1001)!
|
let passwordCheckView = authPasswordCell.viewWithTag(1001)!
|
||||||
let sshKeyCheckView = authSSHKeyCell.viewWithTag(1001)!
|
let sshKeyCheckView = authSSHKeyCell.viewWithTag(1001)!
|
||||||
|
|
||||||
switch method {
|
switch self.gitAuthenticationMethod {
|
||||||
case "Password":
|
case .password:
|
||||||
passwordCheckView.isHidden = false
|
passwordCheckView.isHidden = false
|
||||||
sshKeyCheckView.isHidden = true
|
sshKeyCheckView.isHidden = true
|
||||||
case "SSH Key":
|
case .key:
|
||||||
passwordCheckView.isHidden = true
|
passwordCheckView.isHidden = true
|
||||||
sshKeyCheckView.isHidden = false
|
sshKeyCheckView.isHidden = false
|
||||||
default:
|
|
||||||
passwordCheckView.isHidden = false
|
|
||||||
sshKeyCheckView.isHidden = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,13 +74,11 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
if let url = SharedDefaults[.gitURL] {
|
gitURLTextField.text = self.gitUrl.absoluteString
|
||||||
gitURLTextField.text = url.absoluteString
|
usernameTextField.text = self.gitUsername
|
||||||
}
|
branchNameTextField.text = self.gitBranchName
|
||||||
usernameTextField.text = SharedDefaults[.gitUsername]
|
|
||||||
branchNameTextField.text = SharedDefaults[.gitBranchName]
|
|
||||||
sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel
|
sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel
|
||||||
checkAuthenticationMethod(method: authenticationMethod)
|
checkAuthenticationMethod()
|
||||||
authSSHKeyCell.accessoryType = .detailButton
|
authSSHKeyCell.accessoryType = .detailButton
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,9 +86,17 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
let cell = tableView.cellForRow(at: indexPath)
|
let cell = tableView.cellForRow(at: indexPath)
|
||||||
if cell == authSSHKeyCell {
|
if cell == authSSHKeyCell {
|
||||||
showSSHKeyActionSheet()
|
showSSHKeyActionSheet()
|
||||||
|
} else if cell == gitURLCell {
|
||||||
|
showGitURLFormatHelp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func showGitURLFormatHelp() {
|
||||||
|
let alert = UIAlertController(title: "Git URL Format", message: "https://example.com[:port]/project.git\nssh://[user@]server[:port]/project.git\n[user@]server:project.git (no scheme)", preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in }))
|
||||||
|
self.present(alert, animated: true, completion: nil)
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
|
|
@ -76,36 +108,15 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func cloneAndSegueIfSuccess() {
|
private func cloneAndSegueIfSuccess() {
|
||||||
// try to clone
|
|
||||||
let gitRepostiroyURL = gitURLTextField.text!.trimmed
|
|
||||||
let username = usernameTextField.text!.trimmed
|
|
||||||
let branchName = branchNameTextField.text!.trimmed
|
|
||||||
let auth = authenticationMethod
|
|
||||||
|
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
|
||||||
SVProgressHUD.show(withStatus: "PrepareRepository".localize())
|
|
||||||
var gitCredential: GitCredential
|
|
||||||
let privateKey: String? = AppKeychain.shared.get(for: SshKey.PRIVATE.getKeychainKey())
|
|
||||||
if auth == "Password" || privateKey == nil {
|
|
||||||
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username))
|
|
||||||
} else {
|
|
||||||
gitCredential = GitCredential(
|
|
||||||
credential: GitCredential.Credential.ssh(
|
|
||||||
userName: username,
|
|
||||||
privateKey: privateKey!
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// Remember git credential password/passphrase temporarily, ask whether users want this after a successful clone.
|
// Remember git credential password/passphrase temporarily, ask whether users want this after a successful clone.
|
||||||
SharedDefaults[.isRememberGitCredentialPassphraseOn] = true
|
SharedDefaults[.isRememberGitCredentialPassphraseOn] = true
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
|
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
|
||||||
dispatchQueue.async(group: group) {
|
dispatchQueue.async(group: group) {
|
||||||
do {
|
do {
|
||||||
try self.passwordStore.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
|
try self.passwordStore.cloneRepository(remoteRepoURL: self.gitUrl,
|
||||||
credential: gitCredential,
|
credential: self.gitCredential,
|
||||||
branchName: branchName,
|
branchName: self.gitBranchName,
|
||||||
requestGitPassword: self.requestGitPassword,
|
requestGitPassword: self.requestGitPassword,
|
||||||
transferProgressBlock: { (git_transfer_progress, stop) in
|
transferProgressBlock: { (git_transfer_progress, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
@ -113,7 +124,7 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
checkoutProgressBlock: { (path, completedSteps, totalSteps) in
|
checkoutProgressBlock: { (path, completedSteps, totalSteps) in
|
||||||
DispatchQueue.main.async { SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "CheckingOutBranch".localize(branchName))
|
DispatchQueue.main.async { SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "CheckingOutBranch".localize(self.gitBranchName))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -130,10 +141,6 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
group.notify(queue: dispatchQueue) {
|
group.notify(queue: dispatchQueue) {
|
||||||
NSLog("clone done")
|
NSLog("clone done")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SharedDefaults[.gitURL] = URL(string: gitRepostiroyURL)
|
|
||||||
SharedDefaults[.gitUsername] = username
|
|
||||||
SharedDefaults[.gitBranchName] = branchName
|
|
||||||
SharedDefaults[.gitAuthenticationMethod] = auth
|
|
||||||
SVProgressHUD.dismiss {
|
SVProgressHUD.dismiss {
|
||||||
let savePassphraseAlert = UIAlertController(title: "Done".localize(), message: "WantToSaveGitCredential?".localize(), preferredStyle: UIAlertController.Style.alert)
|
let savePassphraseAlert = UIAlertController(title: "Done".localize(), message: "WantToSaveGitCredential?".localize(), preferredStyle: UIAlertController.Style.alert)
|
||||||
// no
|
// no
|
||||||
|
|
@ -157,24 +164,23 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
let cell = tableView.cellForRow(at: indexPath)
|
let cell = tableView.cellForRow(at: indexPath)
|
||||||
if cell == authPasswordCell {
|
if cell == authPasswordCell {
|
||||||
authenticationMethod = "Password"
|
self.gitAuthenticationMethod = .password
|
||||||
} else if cell == authSSHKeyCell {
|
} else if cell == authSSHKeyCell {
|
||||||
|
|
||||||
if !AppKeychain.shared.contains(key: SshKey.PRIVATE.getKeychainKey()) {
|
if !AppKeychain.shared.contains(key: SshKey.PRIVATE.getKeychainKey()) {
|
||||||
Utils.alert(title: "CannotSelectSshKey".localize(), message: "PleaseSetupSshKeyFirst.".localize(), controller: self, completion: nil)
|
Utils.alert(title: "CannotSelectSshKey".localize(), message: "PleaseSetupSshKeyFirst.".localize(), controller: self, completion: nil)
|
||||||
authenticationMethod = "Password"
|
gitAuthenticationMethod = .password
|
||||||
} else {
|
} else {
|
||||||
authenticationMethod = "SSH Key"
|
gitAuthenticationMethod = .key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkAuthenticationMethod(method: authenticationMethod)
|
checkAuthenticationMethod()
|
||||||
tableView.deselectRow(at: indexPath, animated: true)
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func save(_ sender: Any) {
|
@IBAction func save(_ sender: Any) {
|
||||||
|
|
||||||
// some sanity checks
|
guard let gitURLTextFieldText = gitURLTextField.text, let gitURL = URL(string: gitURLTextFieldText) else {
|
||||||
guard let gitURL = URL(string: gitURLTextField.text!) else {
|
|
||||||
Utils.alert(title: "CannotSave".localize(), message: "SetGitRepositoryUrl".localize(), controller: self, completion: nil)
|
Utils.alert(title: "CannotSave".localize(), message: "SetGitRepositoryUrl".localize(), controller: self, completion: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -184,25 +190,29 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch gitURL.scheme {
|
func checkUsername() {
|
||||||
case let val where val == "https":
|
if gitURL.user == nil && usernameTextField.text == nil {
|
||||||
break
|
|
||||||
case let val where val == "ssh":
|
|
||||||
guard let sshUsername = gitURL.user, sshUsername.isEmpty == false else {
|
|
||||||
Utils.alert(title: "CannotSave".localize(), message: "CannotFindUsername.".localize(), controller: self, completion: nil)
|
Utils.alert(title: "CannotSave".localize(), message: "CannotFindUsername.".localize(), controller: self, completion: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard let username = usernameTextField.text, username == sshUsername else {
|
if let urlUsername = gitURL.user, let textFieldUsername = usernameTextField.text, urlUsername != textFieldUsername.trimmed {
|
||||||
Utils.alert(title: "CannotSave".localize(), message: "CheckEnteredUsername.".localize(), controller: self, completion: nil)
|
Utils.alert(title: "CannotSave".localize(), message: "CheckEnteredUsername.".localize(), controller: self, completion: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case let val where val == "http":
|
}
|
||||||
Utils.alert(title: "CannotSave".localize(), message: "UseHttps.".localize(), controller: self, completion: nil)
|
|
||||||
return
|
if let scheme = gitURL.scheme {
|
||||||
|
switch scheme {
|
||||||
|
case "ssh", "http", "https", "file": checkUsername()
|
||||||
default:
|
default:
|
||||||
Utils.alert(title: "CannotSave".localize(), message: "SpecifySchema.".localize(), controller: self, completion: nil)
|
Utils.alert(title: "CannotSave".localize(), message: "Protocol is not supported", controller: self, completion: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.gitUrl = gitURL
|
||||||
|
self.gitBranchName = branchName
|
||||||
|
self.gitUsername = (gitURL.user ?? usernameTextField.text ?? "git").trimmed
|
||||||
|
|
||||||
if passwordStore.repositoryExisted() {
|
if passwordStore.repositoryExisted() {
|
||||||
let alert = UIAlertController(title: "Overwrite?".localize(), message: "OperationWillOverwriteData.".localize(), preferredStyle: UIAlertController.Style.alert)
|
let alert = UIAlertController(title: "Overwrite?".localize(), message: "OperationWillOverwriteData.".localize(), preferredStyle: UIAlertController.Style.alert)
|
||||||
|
|
@ -272,7 +282,7 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
SharedDefaults[.gitSSHKeySource] = nil
|
SharedDefaults[.gitSSHKeySource] = nil
|
||||||
if let sshLabel = self.sshLabel {
|
if let sshLabel = self.sshLabel {
|
||||||
sshLabel.isEnabled = false
|
sshLabel.isEnabled = false
|
||||||
self.checkAuthenticationMethod(method: "Password".localize())
|
self.checkAuthenticationMethod()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
optionMenu.addAction(deleteAction)
|
optionMenu.addAction(deleteAction)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,18 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
case unsynced
|
case unsynced
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var gitCredential: GitCredential {
|
||||||
|
get {
|
||||||
|
switch SharedDefaults[.gitAuthenticationMethod] {
|
||||||
|
case .password:
|
||||||
|
return GitCredential(credential: .http(userName: SharedDefaults[.gitUsername]))
|
||||||
|
case .key:
|
||||||
|
let privateKey: String = AppKeychain.shared.get(for: SshKey.PRIVATE.getKeychainKey()) ?? ""
|
||||||
|
return GitCredential(credential: .ssh(userName: SharedDefaults[.gitUsername], privateKey: privateKey))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private lazy var searchController: UISearchController = {
|
private lazy var searchController: UISearchController = {
|
||||||
let uiSearchController = UISearchController(searchResultsController: nil)
|
let uiSearchController = UISearchController(searchResultsController: nil)
|
||||||
uiSearchController.searchResultsUpdater = self
|
uiSearchController.searchResultsUpdater = self
|
||||||
|
|
@ -173,27 +185,17 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
SVProgressHUD.setDefaultStyle(.light)
|
||||||
SVProgressHUD.show(withStatus: "SyncingPasswordStore".localize())
|
SVProgressHUD.show(withStatus: "SyncingPasswordStore".localize())
|
||||||
var gitCredential: GitCredential
|
|
||||||
let privateKey: String? = self.keychain.get(for: SshKey.PRIVATE.getKeychainKey())
|
|
||||||
if SharedDefaults[.gitAuthenticationMethod] == "Password" || privateKey == nil {
|
|
||||||
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: SharedDefaults[.gitUsername]!))
|
|
||||||
} else {
|
|
||||||
gitCredential = GitCredential(
|
|
||||||
credential: GitCredential.Credential.ssh(
|
|
||||||
userName: SharedDefaults[.gitUsername]!,
|
|
||||||
privateKey: privateKey!
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
do {
|
do {
|
||||||
try self.passwordStore.pullRepository(credential: gitCredential, requestGitPassword: self.requestGitPassword(credential:lastPassword:), transferProgressBlock: {(git_transfer_progress, stop) in
|
try self.passwordStore.pullRepository(credential: self.gitCredential, requestGitPassword: self.requestGitPassword(credential:lastPassword:), transferProgressBlock: {(git_transfer_progress, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "PullingFromRemoteRepository".localize())
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "PullingFromRemoteRepository".localize())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if self.passwordStore.numberOfLocalCommits ?? 0 > 0 {
|
if self.passwordStore.numberOfLocalCommits > 0 {
|
||||||
try self.passwordStore.pushRepository(credential: gitCredential, requestGitPassword: self.requestGitPassword(credential:lastPassword:), transferProgressBlock: {(current, total, bytes, stop) in
|
try self.passwordStore.pushRepository(credential: self.gitCredential, requestGitPassword: self.requestGitPassword(credential:lastPassword:), transferProgressBlock: {(current, total, bytes, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(Float(current)/Float(total), status: "PushingToRemoteRepository".localize())
|
SVProgressHUD.showProgress(Float(current)/Float(total), status: "PushingToRemoteRepository".localize())
|
||||||
}
|
}
|
||||||
|
|
@ -215,7 +217,6 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
message = message | "UnderlyingError".localize(underlyingError.localizedDescription)
|
message = message | "UnderlyingError".localize(underlyingError.localizedDescription)
|
||||||
if underlyingError.localizedDescription.contains("WrongPassphrase".localize()) {
|
if underlyingError.localizedDescription.contains("WrongPassphrase".localize()) {
|
||||||
message = message | "RecoverySuggestion.".localize()
|
message = message | "RecoverySuggestion.".localize()
|
||||||
gitCredential.delete()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(800)) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(800)) {
|
||||||
|
|
@ -593,8 +594,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
|
|
||||||
private func reloadTableView(data: [PasswordsTableEntry], label: PasswordLabel = .all, anim: CAAnimation? = nil) {
|
private func reloadTableView(data: [PasswordsTableEntry], label: PasswordLabel = .all, anim: CAAnimation? = nil) {
|
||||||
// set navigation item
|
// set navigation item
|
||||||
if let numberOfLocalCommits = passwordStore.numberOfLocalCommits, numberOfLocalCommits != 0 {
|
if passwordStore.numberOfLocalCommits != 0 {
|
||||||
navigationController?.tabBarItem.badgeValue = "\(numberOfLocalCommits)"
|
navigationController?.tabBarItem.badgeValue = "\(passwordStore.numberOfLocalCommits)"
|
||||||
} else {
|
} else {
|
||||||
navigationController?.tabBarItem.badgeValue = nil
|
navigationController?.tabBarItem.badgeValue = nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func saveGitServerSetting(segue: UIStoryboardSegue) {
|
@IBAction func saveGitServerSetting(segue: UIStoryboardSegue) {
|
||||||
self.passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL]?.host
|
self.passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL].host
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
@ -115,7 +115,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil)
|
||||||
self.passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL]?.host
|
self.passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL].host
|
||||||
setPGPKeyTableViewCellDetailText()
|
setPGPKeyTableViewCellDetailText()
|
||||||
setPasswordRepositoryTableViewCellDetailText()
|
setPasswordRepositoryTableViewCellDetailText()
|
||||||
setPasscodeLockCell()
|
setPasscodeLockCell()
|
||||||
|
|
@ -139,11 +139,15 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setPasswordRepositoryTableViewCellDetailText() {
|
private func setPasswordRepositoryTableViewCellDetailText() {
|
||||||
if SharedDefaults[.gitURL] == nil {
|
let host: String? = {
|
||||||
passwordRepositoryTableViewCell.detailTextLabel?.text = "NotSet".localize()
|
let gitURL = SharedDefaults[.gitURL]
|
||||||
|
if gitURL.scheme == nil {
|
||||||
|
return URL(string: "scheme://" + gitURL.absoluteString)?.host
|
||||||
} else {
|
} else {
|
||||||
passwordRepositoryTableViewCell.detailTextLabel?.text = SharedDefaults[.gitURL]!.host
|
return gitURL.host
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
passwordRepositoryTableViewCell.detailTextLabel?.text = host
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func actOnPasswordStoreErasedNotification() {
|
@objc func actOnPasswordStoreErasedNotification() {
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ public extension DefaultsKeys {
|
||||||
static let gitSSHPrivateKeyArmor = DefaultsKey<String?>("gitSSHPrivateKeyArmor")
|
static let gitSSHPrivateKeyArmor = DefaultsKey<String?>("gitSSHPrivateKeyArmor")
|
||||||
static let passcodeKey = DefaultsKey<String?>("passcodeKey")
|
static let passcodeKey = DefaultsKey<String?>("passcodeKey")
|
||||||
|
|
||||||
static let gitURL = DefaultsKey<URL?>("gitURL")
|
static let gitURL = DefaultsKey<URL>("gitURL", defaultValue: URL(string: "https://")!)
|
||||||
static let gitAuthenticationMethod = DefaultsKey<String?>("gitAuthenticationMethod")
|
static let gitAuthenticationMethod = DefaultsKey<GitAuthenticationMethod>("gitAuthenticationMethod", defaultValue: GitAuthenticationMethod.password)
|
||||||
static let gitUsername = DefaultsKey<String?>("gitUsername")
|
static let gitUsername = DefaultsKey<String>("gitUsername", defaultValue: "git")
|
||||||
static let gitBranchName = DefaultsKey<String>("gitBranchName", defaultValue: "master")
|
static let gitBranchName = DefaultsKey<String>("gitBranchName", defaultValue: "master")
|
||||||
static let gitSSHPrivateKeyURL = DefaultsKey<URL?>("gitSSHPrivateKeyURL")
|
static let gitSSHPrivateKeyURL = DefaultsKey<URL?>("gitSSHPrivateKeyURL")
|
||||||
static let gitSSHKeySource = DefaultsKey<String?>("gitSSHKeySource")
|
static let gitSSHKeySource = DefaultsKey<String?>("gitSSHKeySource")
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ import UIKit
|
||||||
import SwiftyUserDefaults
|
import SwiftyUserDefaults
|
||||||
import ObjectiveGit
|
import ObjectiveGit
|
||||||
|
|
||||||
|
public enum GitAuthenticationMethod: String, DefaultsSerializable {
|
||||||
|
case password, key
|
||||||
|
}
|
||||||
|
|
||||||
public struct GitCredential {
|
public struct GitCredential {
|
||||||
private var credential: Credential
|
private var credential: Credential
|
||||||
private let passwordStore = PasswordStore.shared
|
private let passwordStore = PasswordStore.shared
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,8 @@ public class PasswordStore {
|
||||||
return (try? fm.allocatedSizeOfDirectoryAtURL(directoryURL: self.storeURL)) ?? 0
|
return (try? fm.allocatedSizeOfDirectoryAtURL(directoryURL: self.storeURL)) ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public var numberOfLocalCommits: Int? {
|
public var numberOfLocalCommits: Int {
|
||||||
return (try? getLocalCommits())?.flatMap { $0.count }
|
return (try? getLocalCommits())?.flatMap { $0.count } ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public var lastSyncedTime: Date? {
|
public var lastSyncedTime: Date? {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue