Skip to content

Commit

Permalink
Add Help view controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
happylance committed Mar 5, 2017
1 parent cf0dbbf commit 0e81980
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 21 deletions.
20 changes: 20 additions & 0 deletions MacKey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
403692841E35A17200571EB5 /* ReSwiftRxBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 403692831E35A17200571EB5 /* ReSwiftRxBridge.swift */; };
403692861E35A1B300571EB5 /* ReactiveReSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 403692851E35A1B300571EB5 /* ReactiveReSwift.framework */; };
404B99541E666C0E009312F3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4007F09C1E5FD7D400463D8D /* Localizable.strings */; };
404B99591E67A631009312F3 /* Help.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 404B99571E67A631009312F3 /* Help.storyboard */; };
404B995B1E67AB63009312F3 /* HelpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 404B995A1E67AB63009312F3 /* HelpViewController.swift */; };
404E057A1E4FC3AF002F8A95 /* HostsReducerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 404E05791E4FC3AF002F8A95 /* HostsReducerTests.swift */; };
404E057B1E4FC6C4002F8A95 /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 40A8B6641E34132600C71EE7 /* RxCocoa.framework */; };
408150571E5A65F1005AD37B /* Upgrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408150561E5A65F1005AD37B /* Upgrade.swift */; };
Expand Down Expand Up @@ -140,6 +142,10 @@
404B99521E666393009312F3 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Upgrade.strings"; sourceTree = "<group>"; };
404B99551E666CFF009312F3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
404B99561E666D01009312F3 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
404B99581E67A631009312F3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Storyboards/Base.lproj/Help.storyboard; sourceTree = "<group>"; };
404B995A1E67AB63009312F3 /* HelpViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HelpViewController.swift; path = ViewControllers/HelpViewController.swift; sourceTree = "<group>"; };
404B995D1E67B9C5009312F3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = Storyboards/en.lproj/Help.strings; sourceTree = "<group>"; };
404B995F1E67B9C6009312F3 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "Storyboards/zh-Hans.lproj/Help.strings"; sourceTree = "<group>"; };
404E05791E4FC3AF002F8A95 /* HostsReducerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HostsReducerTests.swift; sourceTree = "<group>"; };
408150561E5A65F1005AD37B /* Upgrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Upgrade.swift; path = Actions/Upgrade.swift; sourceTree = "<group>"; };
4081505F1E5A6931005AD37B /* UpgradeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UpgradeService.swift; path = Services/UpgradeService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -273,6 +279,7 @@
408507CB1E2ACFD300C2E0D1 /* ViewControllers */ = {
isa = PBXGroup;
children = (
404B995A1E67AB63009312F3 /* HelpViewController.swift */,
40BD24F01E330BFE004C8BD8 /* HostDetailsViewController.swift */,
400E70991E4AA10200B5477B /* HostDetailsViewModel.swift */,
408507CC1E2ACFFE00C2E0D1 /* MasterViewController.swift */,
Expand Down Expand Up @@ -308,6 +315,7 @@
children = (
4007F0941E5FD6FA00463D8D /* HostDetails.storyboard */,
4007F0971E5FD71500463D8D /* Upgrade.storyboard */,
404B99571E67A631009312F3 /* Help.storyboard */,
);
name = Storyboards;
sourceTree = "<group>";
Expand Down Expand Up @@ -561,6 +569,7 @@
buildActionMask = 2147483647;
files = (
404B99541E666C0E009312F3 /* Localizable.strings in Resources */,
404B99591E67A631009312F3 /* Help.storyboard in Resources */,
4007F0921E5FD6FA00463D8D /* HostDetails.storyboard in Resources */,
4007F0951E5FD71500463D8D /* Upgrade.storyboard in Resources */,
40C4AB1F1CE758F400ED92C5 /* Assets.xcassets in Resources */,
Expand Down Expand Up @@ -639,6 +648,7 @@
400E708C1E42CCCC00B5477B /* TouchIDService.swift in Sources */,
408507CA1E2ACFCA00C2E0D1 /* State.swift in Sources */,
408150601E5A6931005AD37B /* UpgradeService.swift in Sources */,
404B995B1E67AB63009312F3 /* HelpViewController.swift in Sources */,
40A645AC1E3E721400CB62B1 /* SSHService.swift in Sources */,
408508071E2C495200C2E0D1 /* UserDefaultsServivce.swift in Sources */,
408507DE1E2BB9AB00C2E0D1 /* HostInfo.swift in Sources */,
Expand Down Expand Up @@ -720,6 +730,16 @@
name = Localizable.strings;
sourceTree = "<group>";
};
404B99571E67A631009312F3 /* Help.storyboard */ = {
isa = PBXVariantGroup;
children = (
404B99581E67A631009312F3 /* Base */,
404B995D1E67B9C5009312F3 /* en */,
404B995F1E67B9C6009312F3 /* zh-Hans */,
);
name = Help.storyboard;
sourceTree = "<group>";
};
40C4AB1B1CE758F400ED92C5 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
11 changes: 10 additions & 1 deletion MacKey/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Created by Liu Liang on 23/02/2017.
Copyright © 2017 Liu Liang. All rights reserved.
*/
"Are you sure that you want to delete \"%@\"" = "Are you sure that you want to delete \"%@\"";
" > System Preferences > Sharing > RemoteLogin" = " > System Preferences > Sharing > RemoteLogin";
"Alias" = "Alias";
"Are you sure that you want to delete '%@'" = "Are you sure that you want to delete '%@'";
"Alias is already taken" = "Alias is already taken";
"App cancelled authentication" = "App cancelled authentication";
"Authentication failed" = "Authentication failed";
Expand All @@ -15,11 +17,15 @@
"Connection failed" = "Connection failed";
"Could not retrieve product info" = "Could not retrieve product info";
"Delete" = "Delete";
"Delete '%@'" = "Delete '%@'";
"Edit" = "Edit";
"Edit host" = "Edit host";
"Error" = "Error";
"Failed to create NMSSHSession" = "Failed to create NMSSHSession";
"Failed to unlock Mac" = "Failed to unlock Mac";
"Help" = "Help";
"HelpText" = "Tap the + button. Input the following information.\n1. Alias: This can be any string which you would like to name your mac.\n2. Host name or IP address: You can get it from your Mac by going to %@.\n3. Username: This is the username of your account for your mac.\n4. Password: This is the password of your account for your mac.\n\nIf connection is failed, please check the following conditions.\n1. Please make sure your Mac and your iOS device are within the same WiFi network.\n2. Please make sure remote login is enabled on your Mac by going to %@.\n3. Please make sure the IP address, username and password for your Mac are correct.";
"Host name or IP address" = "Host name or IP address";
"Invalid authentication context" = "Invalid authentication context";
"Invalid product ID: %@" = "Invalid product ID: %@";
"Invalid product identifier: %@" = "Invalid product identifier: %@";
Expand All @@ -29,6 +35,7 @@
"New host" = "New host";
"Nothing to restore" = "Nothing to restore";
"OK" = "OK";
"Password" = "Password";
"Payment not allowed" = "Payment not allowed";
"Purchase Failed" = "Purchase Failed";
"Require touch ID" = "Require touch ID";
Expand All @@ -38,11 +45,13 @@
"System cancelled authetication" = "System cancelled authetication";
"Touch ID error" = "Touch ID error";
"Touch ID is not available on this device" = "Touch ID is not available on this device";
"unlocked" = "unlocked";
"Unlocking..." = "Unlocking...";
"Unknown error has occurred" = "Unknown error has occurred";
"User cancelled authentication" = "User cancelled authentication";
"User has not enrolled for Touch ID" = "User has not enrolled for Touch ID";
"User is locked out of Touch ID" = "User is locked out of Touch ID";
"User opted for fallback authentication" = "User opted for fallback authentication";
"User's passcode not set" = "User's passcode not set";
"Username" = "Username";
"You purchased another product but not this one" = "You purchased another product but not this one";
16 changes: 15 additions & 1 deletion MacKey/Routes/MasterViewController+Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import UIKit
import Localize_Swift

let helpStoryboard = UIStoryboard(name: "Help", bundle: nil)
let hostDetailsStoryboard = UIStoryboard(name: "HostDetails", bundle: nil)
let upgradeStoryboard = UIStoryboard(name: "Upgrade", bundle: nil)

let helpControllerIdentifier = "HelpViewController"
let hostDetailsControllerIdentifier = "HostDetailsViewController"
let upgradeControllerIdentifier = "UpgradeViewController"


extension MasterViewController {
public func showHostDetailsViewController(animated: Bool, forNewHost:Bool) -> HostDetailsViewController? {
let hostDetailsViewController = hostDetailsStoryboard
Expand All @@ -28,6 +29,19 @@ extension MasterViewController {

return hostDetailsViewController as? HostDetailsViewController
}

@discardableResult
public func showHelpViewController(animated: Bool) -> UIViewController? {
let helpViewController = helpStoryboard
.instantiateViewController(withIdentifier: helpControllerIdentifier)

let navController = UINavigationController(rootViewController: helpViewController)
navController.view.backgroundColor = UIColor.white

present(navController, animated: animated, completion: nil)

return helpViewController
}
}

extension UIViewController {
Expand Down
2 changes: 1 addition & 1 deletion MacKey/Services/SSHService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension SSHSessionError: CustomDebugStringConvertible {
case .failedToCreateSession:
return "Failed to create NMSSHSession"
case let .failedWithError(error):
return "SSH request failed with error: `\(error.description)`"
return String(format:"SSH request failed with error: `%@`".localized(), error.description)
case let .failedWithResponse(response):
return "SSH request failed with response: `\(response)`"
case .noResponse:
Expand Down
7 changes: 4 additions & 3 deletions MacKey/Services/TouchIDService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class TouchIDService {
return Observable.create { observer in
let context = LAContext()
context.localizedFallbackTitle = ""
let reason = "Authentication required to unlock '\(host.alias)'"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: reason) { success, error in
context.evaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
localizedReason: String(format:"Authentication required to unlock '%@'".localized(), host.alias))
{ success, error in
observer.onNext((success, error))
observer.onCompleted()
}
Expand Down
109 changes: 109 additions & 0 deletions MacKey/Storyboards/Base.lproj/Help.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina5_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Help-->
<scene sceneID="jwQ-zf-biz">
<objects>
<viewController storyboardIdentifier="HelpViewController" automaticallyAdjustsScrollViewInsets="NO" useStoryboardIdentifierAsRestorationIdentifier="YES" id="weS-vQ-Af8" customClass="HelpViewController" customModule="MacKey" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Z4o-Bw-qyI"/>
<viewControllerLayoutGuide type="bottom" id="pbz-xI-Hu5"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="xOb-bN-RG7">
<rect key="frame" x="0.0" y="64" width="414" height="672"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView multipleTouchEnabled="YES" contentMode="scaleToFill" directionalLockEnabled="YES" bounces="NO" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" minimumZoomScale="0.5" maximumZoomScale="2" translatesAutoresizingMaskIntoConstraints="NO" id="0dj-xU-EXD">
<rect key="frame" x="20" y="0.0" width="374" height="672"/>
<subviews>
<textView multipleTouchEnabled="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" minimumZoomScale="0.5" maximumZoomScale="2" bouncesZoom="NO" editable="NO" usesAttributedText="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fPB-aB-23J">
<rect key="frame" x="0.0" y="0.0" width="394" height="147"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<attributedString key="attributedText">
<fragment>
<mutableString key="content">Tap on "+" button. Input the following information.

1. Alias: This can be any string which you would like to use as an alias of your mac.
2. Host: This can be the IP address or machine name of your mac. You can get it from SystemPreferences -&gt; Sharing -&gt; RemoteLogin on your Mac. You can find the IP address or machine name under 'Computers on your local network can access your computer at:'.
3. Username: This is the username of your account for your mac.
4. Password: This is the password of your account for your mac.

If connection is failed, please check the following conditions.
1. Please make sure your Mac and your iOS device are within the same WiFi network.
2. Please make sure remote login is enabled in SystemPreferences-&gt;Sharing on your Mac.
</mutableString>
<attributes>
<font key="NSFont" size="10" name=".AppleSystemUIFont"/>
</attributes>
</fragment>
<fragment content="3. Please make sure the IP address, username and password for your Mac are correct.">
<attributes>
<font key="NSFont" size="10" name=".AppleSystemUIFont"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
</attributedString>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<constraints>
<constraint firstItem="fPB-aB-23J" firstAttribute="top" secondItem="0dj-xU-EXD" secondAttribute="top" id="7gD-46-cS5"/>
<constraint firstAttribute="bottom" secondItem="fPB-aB-23J" secondAttribute="bottom" id="V6V-oz-adr"/>
<constraint firstAttribute="trailing" secondItem="fPB-aB-23J" secondAttribute="trailing" constant="-20" id="rut-G0-6kf"/>
<constraint firstItem="fPB-aB-23J" firstAttribute="leading" secondItem="0dj-xU-EXD" secondAttribute="leading" id="xBv-36-Bk0"/>
</constraints>
</scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="0dj-xU-EXD" firstAttribute="top" secondItem="Z4o-Bw-qyI" secondAttribute="bottom" id="2fh-MF-0va"/>
<constraint firstItem="pbz-xI-Hu5" firstAttribute="top" secondItem="0dj-xU-EXD" secondAttribute="bottom" id="FwD-N5-z25"/>
<constraint firstAttribute="trailingMargin" secondItem="0dj-xU-EXD" secondAttribute="trailing" id="LFp-Xb-i5T"/>
<constraint firstItem="0dj-xU-EXD" firstAttribute="leading" secondItem="xOb-bN-RG7" secondAttribute="leadingMargin" id="QDI-Dm-epT"/>
<constraint firstAttribute="trailing" secondItem="fPB-aB-23J" secondAttribute="trailing" id="xso-h2-hM1"/>
</constraints>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
<navigationItem key="navigationItem" title="Help" id="sz2-ye-69Z">
<barButtonItem key="leftBarButtonItem" title="Close" id="Mnz-7J-BCM"/>
</navigationItem>
<nil key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="closeOutlet" destination="Mnz-7J-BCM" id="kLe-gs-mIR"/>
<outlet property="textViewOutlet" destination="fPB-aB-23J" id="OJq-nb-SYD"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="D0N-RK-4H2" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1066.6666666666667" y="144.29347826086956"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="6O9-H4-Adf">
<objects>
<navigationController storyboardIdentifier="HelpNavigationVC" automaticallyAdjustsScrollViewInsets="NO" id="XhY-ed-vhc" sceneMemberID="viewController">
<extendedEdge key="edgesForExtendedLayout"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="8yN-Wx-84z">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="weS-vQ-Af8" kind="relationship" relationship="rootViewController" id="jax-wO-kFc"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="D4E-T0-A9e" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="128.80000000000001" y="146.17691154422789"/>
</scene>
</scenes>
</document>
6 changes: 6 additions & 0 deletions MacKey/Storyboards/en.lproj/Help.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/* Class = "UIBarButtonItem"; title = "Close"; ObjectID = "Mnz-7J-BCM"; */
"Mnz-7J-BCM.title" = "Close";

/* Class = "UINavigationItem"; title = "Help"; ObjectID = "sz2-ye-69Z"; */
"sz2-ye-69Z.title" = "Help";
6 changes: 6 additions & 0 deletions MacKey/Storyboards/zh-Hans.lproj/Help.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/* Class = "UIBarButtonItem"; title = "Close"; ObjectID = "Mnz-7J-BCM"; */
"Mnz-7J-BCM.title" = "关闭";

/* Class = "UINavigationItem"; title = "Help"; ObjectID = "sz2-ye-69Z"; */
"sz2-ye-69Z.title" = "帮助";
Loading

0 comments on commit 0e81980

Please sign in to comment.