diff options
author | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-05-23 21:49:10 +0200 |
---|---|---|
committer | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-05-23 21:50:42 +0200 |
commit | ae73b78935bf26515eccd1609bcf5bea43cb8451 (patch) | |
tree | 031d1a06c3e7d7b25a9b246a95ce04c81b756f56 /Wireguard | |
parent | Initial commit (diff) | |
download | wireguard-apple-ae73b78935bf26515eccd1609bcf5bea43cb8451.tar.xz wireguard-apple-ae73b78935bf26515eccd1609bcf5bea43cb8451.zip |
Initial project setup.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'Wireguard')
-rw-r--r-- | Wireguard/AppDelegate.swift | 25 | ||||
-rw-r--r-- | Wireguard/Assets.xcassets/AppIcon.appiconset/Contents.json | 98 | ||||
-rw-r--r-- | Wireguard/Assets.xcassets/Contents.json | 6 | ||||
-rw-r--r-- | Wireguard/Base.lproj/LaunchScreen.storyboard | 25 | ||||
-rw-r--r-- | Wireguard/Base.lproj/Main.storyboard | 41 | ||||
-rw-r--r-- | Wireguard/Coordinators/AppCoordinator.swift | 102 | ||||
-rw-r--r-- | Wireguard/Coordinators/Coordinator.swift | 34 | ||||
-rw-r--r-- | Wireguard/Coordinators/RootCoordinator.swift | 19 | ||||
-rw-r--r-- | Wireguard/Info.plist | 43 | ||||
-rw-r--r-- | Wireguard/Models/Profile+CoreDataClass.swift | 16 | ||||
-rw-r--r-- | Wireguard/Models/Profile+CoreDataProperties.swift | 19 | ||||
-rw-r--r-- | Wireguard/Models/Wireguard.xcdatamodeld/Wireguard.xcdatamodel/contents | 7 | ||||
-rw-r--r-- | Wireguard/ViewControllers/ConnectionsTableViewController.swift | 38 | ||||
-rw-r--r-- | Wireguard/ViewControllers/Identifyable.swift | 27 |
14 files changed, 500 insertions, 0 deletions
diff --git a/Wireguard/AppDelegate.swift b/Wireguard/AppDelegate.swift new file mode 100644 index 0000000..4c399e5 --- /dev/null +++ b/Wireguard/AppDelegate.swift @@ -0,0 +1,25 @@ +// +// AppDelegate.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + var appCoordinator: AppCoordinator! + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + + self.window = UIWindow(frame: UIScreen.main.bounds) + self.appCoordinator = AppCoordinator(window: self.window!) + self.appCoordinator.start() + + return true + } +} diff --git a/Wireguard/Assets.xcassets/AppIcon.appiconset/Contents.json b/Wireguard/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/Wireguard/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +}
\ No newline at end of file diff --git a/Wireguard/Assets.xcassets/Contents.json b/Wireguard/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Wireguard/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +}
\ No newline at end of file diff --git a/Wireguard/Base.lproj/LaunchScreen.storyboard b/Wireguard/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..f83f6fd --- /dev/null +++ b/Wireguard/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> + <capability name="Safe area layout guides" minToolsVersion="9.0"/> + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> + </dependencies> + <scenes> + <!--View Controller--> + <scene sceneID="EHf-IW-A2E"> + <objects> + <viewController id="01J-lp-oVM" sceneMemberID="viewController"> + <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> + <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> + <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> + </view> + </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="53" y="375"/> + </scene> + </scenes> +</document> diff --git a/Wireguard/Base.lproj/Main.storyboard b/Wireguard/Base.lproj/Main.storyboard new file mode 100644 index 0000000..5703677 --- /dev/null +++ b/Wireguard/Base.lproj/Main.storyboard @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> + <device id="retina4_7" orientation="portrait"> + <adaptation id="fullscreen"/> + </device> + <dependencies> + <deployment identifier="iOS"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/> + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> + </dependencies> + <scenes> + <!--Connections Table View Controller--> + <scene sceneID="Tud-vM-cYZ"> + <objects> + <tableViewController storyboardIdentifier="ConnectionsTableViewController" id="kTU-BV-32R" customClass="ConnectionsTableViewController" customModule="Wireguard" customModuleProvider="target" sceneMemberID="viewController"> + <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="AJg-r0-KJH"> + <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> + <prototypes> + <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="fM3-cC-KPN"> + <rect key="frame" x="0.0" y="28" width="375" height="44"/> + <autoresizingMask key="autoresizingMask"/> + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="fM3-cC-KPN" id="Rv6-XK-aK2"> + <rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/> + <autoresizingMask key="autoresizingMask"/> + </tableViewCellContentView> + </tableViewCell> + </prototypes> + <connections> + <outlet property="dataSource" destination="kTU-BV-32R" id="E0F-RC-fZE"/> + <outlet property="delegate" destination="kTU-BV-32R" id="b6T-ZR-cmO"/> + </connections> + </tableView> + </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="4uZ-Vv-Fry" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="34" y="154"/> + </scene> + </scenes> +</document> diff --git a/Wireguard/Coordinators/AppCoordinator.swift b/Wireguard/Coordinators/AppCoordinator.swift new file mode 100644 index 0000000..d1fd520 --- /dev/null +++ b/Wireguard/Coordinators/AppCoordinator.swift @@ -0,0 +1,102 @@ +// +// AppCoordinator.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import Foundation + +import CoreData +import BNRCoreDataStack + +class AppCoordinator: RootViewCoordinator { + + let persistentContainer = NSPersistentContainer(name: "Wireguard") + let storyboard = UIStoryboard(name: "Main", bundle: nil) + + // MARK: - Properties + + var childCoordinators: [Coordinator] = [] + + var rootViewController: UIViewController { + return self.connectionsTableViewController + } + + var connectionsTableViewController: ConnectionsTableViewController! + + /// Window to manage + let window: UIWindow + + let navigationController: UINavigationController = { + let navController = UINavigationController() + return navController + }() + + // MARK: - Init + public init(window: UIWindow) { + self.window = window + + self.window.rootViewController = self.navigationController + self.window.makeKeyAndVisible() + } + + // MARK: - Functions + + /// Starts the coordinator + public func start() { + persistentContainer.viewContext.automaticallyMergesChangesFromParent = true + persistentContainer.loadPersistentStores { [weak self] (_, error) in + if let error = error { + print("Unable to Load Persistent Store. \(error), \(error.localizedDescription)") + + } else { + DispatchQueue.main.async { + //start + if let connectionsTableViewController = self?.storyboard.instantiateViewController(type: ConnectionsTableViewController.self) { + self?.connectionsTableViewController = connectionsTableViewController + self?.connectionsTableViewController.viewContext = self?.persistentContainer.viewContext + self?.connectionsTableViewController.delegate = self + self?.navigationController.viewControllers = [connectionsTableViewController] + do { + if let context = self?.persistentContainer.viewContext, try Profile.countInContext(context) == 0 { + print("No profiles ... yet") + } + } catch { + self?.showError(error) + } + } + } + } + } + } + + public func showError(_ error: Error) { + showAlert(title: NSLocalizedString("Error", comment: "Error alert title"), message: error.localizedDescription) + } + + private func showAlert(title: String, message: String) { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "OK button"), style: .default)) + self.navigationController.present(alert, animated: true) + } +} + +extension AppCoordinator: ConnectionsTableViewControllerDelegate { + func addProvider(connectionsTableViewController: ConnectionsTableViewController) { + // TODO implement + } + + func settings(connectionsTableViewController: ConnectionsTableViewController) { + // TODO implement + } + + func connect(profile: Profile) { + // TODO implement + } + + func delete(profile: Profile) { + // TODO implement + } +} diff --git a/Wireguard/Coordinators/Coordinator.swift b/Wireguard/Coordinators/Coordinator.swift new file mode 100644 index 0000000..d1075a3 --- /dev/null +++ b/Wireguard/Coordinators/Coordinator.swift @@ -0,0 +1,34 @@ +// +// Coordinator.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import Foundation + +/// The Coordinator protocol +public protocol Coordinator: class { + + /// Starts the coordinator + func start() + + /// The array containing any child Coordinators + var childCoordinators: [Coordinator] { get set } + +} + +public extension Coordinator { + + /// Add a child coordinator to the parent + public func addChildCoordinator(_ childCoordinator: Coordinator) { + self.childCoordinators.append(childCoordinator) + } + + /// Remove a child coordinator from the parent + public func removeChildCoordinator(_ childCoordinator: Coordinator) { + self.childCoordinators = self.childCoordinators.filter { $0 !== childCoordinator } + } + +} diff --git a/Wireguard/Coordinators/RootCoordinator.swift b/Wireguard/Coordinators/RootCoordinator.swift new file mode 100644 index 0000000..0319fef --- /dev/null +++ b/Wireguard/Coordinators/RootCoordinator.swift @@ -0,0 +1,19 @@ +// +// RootCoordinator.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import Foundation +import UIKit + +public protocol RootViewControllerProvider: class { + // The coordinators 'rootViewController'. It helps to think of this as the view + // controller that can be used to dismiss the coordinator from the view hierarchy. + var rootViewController: UIViewController { get } +} + +/// A Coordinator type that provides a root UIViewController +public typealias RootViewCoordinator = Coordinator & RootViewControllerProvider diff --git a/Wireguard/Info.plist b/Wireguard/Info.plist new file mode 100644 index 0000000..5d036c8 --- /dev/null +++ b/Wireguard/Info.plist @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>$(DEVELOPMENT_LANGUAGE)</string> + <key>CFBundleExecutable</key> + <string>$(EXECUTABLE_NAME)</string> + <key>CFBundleIdentifier</key> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>$(PRODUCT_NAME)</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>auto-generated</string> + <key>LSRequiresIPhoneOS</key> + <true/> + <key>UILaunchStoryboardName</key> + <string>LaunchScreen</string> + <key>UIRequiredDeviceCapabilities</key> + <array> + <string>armv7</string> + </array> + <key>UISupportedInterfaceOrientations</key> + <array> + <string>UIInterfaceOrientationPortrait</string> + <string>UIInterfaceOrientationLandscapeLeft</string> + <string>UIInterfaceOrientationLandscapeRight</string> + </array> + <key>UISupportedInterfaceOrientations~ipad</key> + <array> + <string>UIInterfaceOrientationPortrait</string> + <string>UIInterfaceOrientationPortraitUpsideDown</string> + <string>UIInterfaceOrientationLandscapeLeft</string> + <string>UIInterfaceOrientationLandscapeRight</string> + </array> +</dict> +</plist> diff --git a/Wireguard/Models/Profile+CoreDataClass.swift b/Wireguard/Models/Profile+CoreDataClass.swift new file mode 100644 index 0000000..ab7c2aa --- /dev/null +++ b/Wireguard/Models/Profile+CoreDataClass.swift @@ -0,0 +1,16 @@ +// +// Profile+CoreDataClass.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// +// + +import Foundation +import CoreData + +@objc(Profile) +public class Profile: NSManagedObject { + +} diff --git a/Wireguard/Models/Profile+CoreDataProperties.swift b/Wireguard/Models/Profile+CoreDataProperties.swift new file mode 100644 index 0000000..8e99ac2 --- /dev/null +++ b/Wireguard/Models/Profile+CoreDataProperties.swift @@ -0,0 +1,19 @@ +// +// Profile+CoreDataProperties.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// +// + +import Foundation +import CoreData + +extension Profile { + + @nonobjc public class func fetchRequest() -> NSFetchRequest<Profile> { + return NSFetchRequest<Profile>(entityName: "Profile") + } + +} diff --git a/Wireguard/Models/Wireguard.xcdatamodeld/Wireguard.xcdatamodel/contents b/Wireguard/Models/Wireguard.xcdatamodeld/Wireguard.xcdatamodel/contents new file mode 100644 index 0000000..7bced00 --- /dev/null +++ b/Wireguard/Models/Wireguard.xcdatamodeld/Wireguard.xcdatamodel/contents @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14133" systemVersion="17E202" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier=""> + <entity name="Profile" representedClassName="Profile" syncable="YES"/> + <elements> + <element name="Profile" positionX="-63" positionY="-18" width="128" height="45"/> + </elements> +</model>
\ No newline at end of file diff --git a/Wireguard/ViewControllers/ConnectionsTableViewController.swift b/Wireguard/ViewControllers/ConnectionsTableViewController.swift new file mode 100644 index 0000000..38c0955 --- /dev/null +++ b/Wireguard/ViewControllers/ConnectionsTableViewController.swift @@ -0,0 +1,38 @@ +// +// ConnectionsTableViewController.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import UIKit + +import CoreData +import BNRCoreDataStack + +protocol ConnectionsTableViewControllerDelegate: class { + func addProvider(connectionsTableViewController: ConnectionsTableViewController) + func settings(connectionsTableViewController: ConnectionsTableViewController) + func connect(profile: Profile) + func delete(profile: Profile) +} + +class ConnectionsTableViewController: UITableViewController { + weak var delegate: ConnectionsTableViewControllerDelegate? + + var viewContext: NSManagedObjectContext! + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + +} + +extension ConnectionsTableViewController: Identifyable {} diff --git a/Wireguard/ViewControllers/Identifyable.swift b/Wireguard/ViewControllers/Identifyable.swift new file mode 100644 index 0000000..9312afe --- /dev/null +++ b/Wireguard/ViewControllers/Identifyable.swift @@ -0,0 +1,27 @@ +// +// Identifyable.swift +// Wireguard +// +// Created by Jeroen Leenarts on 23-05-18. +// Copyright © 2018 Wireguard. All rights reserved. +// + +import Foundation +import UIKit + +public protocol Identifyable: class { + static var identifier: String { get } +} + +public extension Identifyable { + static var identifier: String { + return String(describing: Self.self) + } +} + +extension UIStoryboard { + + public func instantiateViewController<T: Identifyable>(type: T.Type) -> T where T: UIViewController { + return self.instantiateViewController(withIdentifier: type.identifier) as! T // swiftlint:disable:this force_cast + } +} |