Fix a bug when importing SSH Key from URL

This commit is contained in:
Mingshen Sun 2019-07-17 23:43:28 -07:00
parent 7cf9311f95
commit 90bc399c9f
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 8 additions and 8 deletions

View file

@ -1689,7 +1689,7 @@ Secret Question 1: What is your childhood best friend's most bizarre superhero f
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="scanner output" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="U8O-Md-w8e">
<rect key="frame" x="57" y="518" width="300" height="45"/>
<rect key="frame" x="57" y="562" width="300" height="45"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.5" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="JcM-Sy-Hw8"/>
@ -1775,8 +1775,8 @@ Secret Question 1: What is your childhood best friend's most bizarre superhero f
<image name="Settings" width="25" height="25"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="QFy-OX-cAa"/>
<segue reference="oxP-I1-Mke"/>
<segue reference="wCk-aN-a4J"/>
<segue reference="5iZ-y9-FCH"/>
<segue reference="yyD-4H-pLE"/>
</inferredMetricsTieBreakers>
</document>

View file

@ -17,20 +17,20 @@ class SSHKeySettingTableViewController: AutoCellHeightUITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
privateKeyURLTextField.text = SharedDefaults[.gitSSHPrivateKeyURL]?.absoluteString
}
@IBAction func doneButtonTapped(_ sender: UIButton) {
guard let privateKeyURL = URL(string: privateKeyURLTextField.text!.trimmed) else {
Utils.alert(title: "CannotSave".localize(), message: "SetPrivateKeyUrl.".localize(), controller: self, completion: nil)
return
}
SharedDefaults[.gitSSHPrivateKeyURL] = privateKeyURL
do {
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPrivateKeyPath), options: .atomic)
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: SshKey.PRIVATE.getFileSharingPath()), options: .atomic)
try self.passwordStore.gitSSHKeyImportFromFileSharing()
SharedDefaults[.gitSSHKeySource] = "file"
SVProgressHUD.showSuccess(withStatus: "Imported".localize())
SVProgressHUD.dismiss(withDelay: 1)
} catch {
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
}