Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 2337cf6

Browse files
authored
Revert "Update routes to final form (#2374)" (#2381)
This reverts commit e9d5463.
1 parent e9d5463 commit 2337cf6

20 files changed

+4102
-4143
lines changed

Classes/Systems/AppDelegate.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2323
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
2424

2525
appController.appDidFinishLaunching(with: window)
26+
appController.setupRoutes()
2627

2728
// setup fabric
2829
Fabric.with([Crashlytics.self])
@@ -49,7 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4950
}
5051

5152
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
52-
appController.router.handle(path: shortcutItem.type, params: shortcutItem.params)
53+
appController.handle(path: shortcutItem.type, params: shortcutItem.params)
5354
}
5455

5556
func applicationDidBecomeActive(_ application: UIApplication) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// AppController+SetupRoutes.swift
3+
// Freetime
4+
//
5+
// Created by Ryan Nystrom on 10/7/18.
6+
// Copyright © 2018 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import GitHawkRoutes
11+
12+
extension AppController {
13+
14+
func setupRoutes() {
15+
register(route: BookmarkShortcutRoute.self)
16+
register(route: SwitchAccountShortcutRoute.self)
17+
register(route: SearchShortcutRoute.self)
18+
register(route: IssueRoute.self)
19+
register(route: RepoRoute.self)
20+
}
21+
22+
}

Classes/Systems/AppRouter/AppController+UNUserNotificationCenterDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension AppController: UNUserNotificationCenterDelegate {
3333
case UNNotificationDismissActionIdentifier: break
3434
case UNNotificationDefaultActionIdentifier:
3535
if let (path, params) = response.notification.request.content.routableUserInfo {
36-
router.handle(path: path, params: params)
36+
handle(path: path, params: params)
3737
}
3838
default: print(response.actionIdentifier)
3939
}

Classes/Systems/AppRouter/AppController.swift

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ import GitHubSession
1111
import GitHubAPI
1212
import GitHawkRoutes
1313

14-
final class AppController: NSObject,
15-
LoginSplashViewControllerDelegate,
16-
GitHubSessionListener,
17-
RouterDelegate {
18-
19-
public private(set) lazy var router = {
20-
return Router(delegate: self)
21-
}()
14+
final class AppController: NSObject, LoginSplashViewControllerDelegate, GitHubSessionListener {
2215

2316
private var splitViewController: AppSplitViewController!
2417
private let sessionManager = GitHubSessionManager()
2518
private weak var loginViewController: LoginSplashViewController?
2619
private var appClient: GithubClient?
2720
private var settingsNavigationController: UINavigationController?
2821
private var watchAppSync: WatchAppUserSessionSync?
22+
private var routes = [String: (Routable & RoutePerformable).Type]()
2923

3024
override init() {
3125
super.init()
@@ -62,6 +56,34 @@ RouterDelegate {
6256
appClient?.badge.fetch(application: application, handler: completion)
6357
}
6458

59+
@discardableResult
60+
func handle(url: URL) -> Bool {
61+
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
62+
else { return false }
63+
var params = [String: String]()
64+
for item in components.queryItems ?? [] {
65+
params[item.name] = item.value
66+
}
67+
return handle(path: url.path, params: params)
68+
}
69+
70+
@discardableResult
71+
func handle(path: String, params: [String: String]) -> Bool {
72+
guard let routeType = routes[path],
73+
let route = routeType.from(params: params),
74+
let client = appClient
75+
else { return false }
76+
return route.perform(
77+
sessionManager: sessionManager,
78+
splitViewController: splitViewController,
79+
client: client
80+
)
81+
}
82+
83+
func register<T: Routable & RoutePerformable>(route: T.Type) {
84+
routes[T.path] = T.self
85+
}
86+
6587
private func resetWatchSync(userSession: GitHubUserSession) {
6688
watchAppSync = WatchAppUserSessionSync(userSession: userSession)
6789
watchAppSync?.start()
@@ -140,15 +162,4 @@ RouterDelegate {
140162
showLogin(animated: trueUnlessReduceMotionEnabled)
141163
}
142164

143-
// MARK: RouteHandlerDelegate
144-
145-
func perform(route: RoutePerformable, router: Router) -> Bool {
146-
guard let client = appClient else { return false }
147-
return route.perform(
148-
sessionManager: sessionManager,
149-
splitViewController: splitViewController,
150-
client: client
151-
)
152-
}
153-
154165
}

Classes/Systems/AppRouter/Router.swift

Lines changed: 0 additions & 59 deletions
This file was deleted.

Freetime.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
290CA772216AE93E00DE04F8 /* SwitchAccountShortcutRoute+RoutePerformable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290CA771216AE93E00DE04F8 /* SwitchAccountShortcutRoute+RoutePerformable.swift */; };
3131
290CA774216AE94D00DE04F8 /* BookmarkShortcutRoute+RoutePerformable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290CA773216AE94D00DE04F8 /* BookmarkShortcutRoute+RoutePerformable.swift */; };
3232
290CA778216AFAE600DE04F8 /* RoutePerformable+RoutePerformable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290CA777216AFAE600DE04F8 /* RoutePerformable+RoutePerformable.swift */; };
33+
290CA77A216AFC1300DE04F8 /* AppController+SetupRoutes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290CA779216AFC1300DE04F8 /* AppController+SetupRoutes.swift */; };
3334
290D2A3D1F044CB20082E6CC /* UIViewController+SmartDeselection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */; };
3435
290D2A421F04D3470082E6CC /* IssueStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A411F04D3470082E6CC /* IssueStatus.swift */; };
3536
290EF56A1F06A821006A2160 /* Notification+NotificationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290EF5691F06A7E1006A2160 /* Notification+NotificationViewModel.swift */; };
@@ -270,7 +271,6 @@
270271
298BA0971EC947F100B01946 /* SegmentedControlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298BA0951EC947F100B01946 /* SegmentedControlCell.swift */; };
271272
298BA0981EC947F100B01946 /* SegmentedControlSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298BA0961EC947F100B01946 /* SegmentedControlSectionController.swift */; };
272273
298BA09A1EC947FC00B01946 /* SegmentedControlModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298BA0991EC947FC00B01946 /* SegmentedControlModel.swift */; };
273-
2990B9DB218BF23D009865EB /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2990B9DA218BF23D009865EB /* Router.swift */; };
274274
29921BCC1EF624D400C1E848 /* UIFont+MutableTraits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29921BCB1EF624D400C1E848 /* UIFont+MutableTraits.swift */; };
275275
299304691FBA8A88007B9737 /* IssueManagingSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299304681FBA8A88007B9737 /* IssueManagingSectionController.swift */; };
276276
2993046B1FBA8C04007B9737 /* IssueManagingExpansionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2993046A1FBA8C04007B9737 /* IssueManagingExpansionCell.swift */; };
@@ -571,6 +571,7 @@
571571
290CA771216AE93E00DE04F8 /* SwitchAccountShortcutRoute+RoutePerformable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwitchAccountShortcutRoute+RoutePerformable.swift"; sourceTree = "<group>"; };
572572
290CA773216AE94D00DE04F8 /* BookmarkShortcutRoute+RoutePerformable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BookmarkShortcutRoute+RoutePerformable.swift"; sourceTree = "<group>"; };
573573
290CA777216AFAE600DE04F8 /* RoutePerformable+RoutePerformable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RoutePerformable+RoutePerformable.swift"; sourceTree = "<group>"; };
574+
290CA779216AFC1300DE04F8 /* AppController+SetupRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppController+SetupRoutes.swift"; sourceTree = "<group>"; };
574575
290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+SmartDeselection.swift"; sourceTree = "<group>"; };
575576
290D2A411F04D3470082E6CC /* IssueStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueStatus.swift; sourceTree = "<group>"; };
576577
290EF5691F06A7E1006A2160 /* Notification+NotificationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+NotificationViewModel.swift"; sourceTree = "<group>"; };
@@ -818,7 +819,6 @@
818819
298BA0951EC947F100B01946 /* SegmentedControlCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlCell.swift; sourceTree = "<group>"; };
819820
298BA0961EC947F100B01946 /* SegmentedControlSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlSectionController.swift; sourceTree = "<group>"; };
820821
298BA0991EC947FC00B01946 /* SegmentedControlModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlModel.swift; sourceTree = "<group>"; };
821-
2990B9DA218BF23D009865EB /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
822822
29921BCB1EF624D400C1E848 /* UIFont+MutableTraits.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+MutableTraits.swift"; sourceTree = "<group>"; };
823823
299304681FBA8A88007B9737 /* IssueManagingSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueManagingSectionController.swift; sourceTree = "<group>"; };
824824
2993046A1FBA8C04007B9737 /* IssueManagingExpansionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueManagingExpansionCell.swift; sourceTree = "<group>"; };
@@ -1122,13 +1122,13 @@
11221122
isa = PBXGroup;
11231123
children = (
11241124
290CA7632169799600DE04F8 /* AppController.swift */,
1125+
290CA779216AFC1300DE04F8 /* AppController+SetupRoutes.swift */,
11251126
29A10544216D9515004734A0 /* AppController+UNUserNotificationCenterDelegate.swift */,
11261127
290CA76521697A7900DE04F8 /* AppSplitViewController.swift */,
11271128
290CA773216AE94D00DE04F8 /* BookmarkShortcutRoute+RoutePerformable.swift */,
11281129
29A10540216D912F004734A0 /* IssueRoute+RoutePerformable.swift */,
11291130
2962505F217D53C000EA6164 /* RepoRoute+RoutePerformable.swift */,
11301131
290CA777216AFAE600DE04F8 /* RoutePerformable+RoutePerformable.swift */,
1131-
2990B9DA218BF23D009865EB /* Router.swift */,
11321132
290CA769216AC82700DE04F8 /* SearchShortcutRoute+RoutePerformable.swift */,
11331133
290CA771216AE93E00DE04F8 /* SwitchAccountShortcutRoute+RoutePerformable.swift */,
11341134
29A10542216D9381004734A0 /* UNMutableNotificationContent+Routable.swift */,
@@ -2815,7 +2815,6 @@
28152815
297DD5E11F061BBE006E7E63 /* CreateProfileViewController.swift in Sources */,
28162816
29B205FA217B8B9100E4DD9F /* PathCommitCell.swift in Sources */,
28172817
29AAB7171FB4A2AE001D5E6A /* BoundedImageSize.swift in Sources */,
2818-
2990B9DB218BF23D009865EB /* Router.swift in Sources */,
28192818
29A4768E1ED07A23005D0953 /* DateDetailsFormatter.swift in Sources */,
28202819
29AF1E8C1F8ABC5A0008A0EF /* RepositoryCodeDirectoryViewController.swift in Sources */,
28212820
291929611F3FD2960012067B /* DiffString.swift in Sources */,
@@ -2951,6 +2950,7 @@
29512950
DCA5ED141FAEE8030072F074 /* Bookmark.swift in Sources */,
29522951
299F4A89204CEDDC004BA4F0 /* Client+AccessToken.swift in Sources */,
29532952
2931892F1F539C0E00EF0911 /* IssueMilestoneSectionController.swift in Sources */,
2953+
290CA77A216AFC1300DE04F8 /* AppController+SetupRoutes.swift in Sources */,
29542954
29BBD82920CAC7D5004D62FE /* NotificationViewModel.swift in Sources */,
29552955
299F63E2205DE1470015D901 /* UIView+DateDetails.swift in Sources */,
29562956
9870B9031FC73EE70009719C /* Secrets.swift in Sources */,

FreetimeTests/DetectShortlinkTests.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ class DetectShortlinkTests: XCTestCase {
6969
XCTAssertEqual(containsLink.linkText, "#345")
7070
XCTAssertEqual(containsLink.issueNumber, 345)
7171
XCTAssertEqual(builder.allText, testString)
72-
72+
7373
testString =
7474
"""
7575
#345
7676
newLine
7777
"""
78-
78+
7979
builder = setupBuilder(with: testString)
8080
containsLink = checkForIssueLink(builder.styledTexts)[0]
8181
XCTAssertEqual(containsLink.linkText, "#345")
@@ -124,18 +124,18 @@ class DetectShortlinkTests: XCTestCase {
124124
XCTAssertEqual(containsLink.issueNumber, 4)
125125
XCTAssertEqual(builder.allText, testString)
126126
}
127-
127+
128128
func test_ConsecutivePositiveMatches() {
129129
var testString = "#100 #150 #200"
130130
var builder = setupBuilder(with: testString)
131131
var links = checkForIssueLink(builder.styledTexts)
132-
132+
133133
XCTAssertEqual(links[0].issueNumber, 100)
134134
XCTAssertEqual(links[0].linkText, "#100")
135-
135+
136136
XCTAssertEqual(links[1].issueNumber, 150)
137137
XCTAssertEqual(links[1].linkText, "#150")
138-
138+
139139
XCTAssertEqual(links[2].issueNumber, 200)
140140
XCTAssertEqual(links[2].linkText, "#200")
141141
}
@@ -158,4 +158,3 @@ class DetectShortlinkTests: XCTestCase {
158158
XCTAssertEqual(containsLink.count, 0)
159159
}
160160
}
161-

Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PODS:
2424
- FMDB (2.7.2):
2525
- FMDB/standard (= 2.7.2)
2626
- FMDB/standard (2.7.2)
27-
- GitHawkRoutes (0.1.1)
27+
- GitHawkRoutes (0.1.0)
2828
- GitHubAPI (0.1.0):
2929
- Alamofire (~> 4.4.0)
3030
- Apollo (~> 0.8.0)
@@ -170,7 +170,7 @@ CHECKOUT OPTIONS:
170170
:commit: beb697643eea11f40bb66683d1576a2772080d9d
171171
:git: https://github.com/GitHawkApp/FlatCache.git
172172
GitHawkRoutes:
173-
:commit: 26e45170b4ba06843d7a034f4a321a5797c77ec8
173+
:commit: 1947e45203b81c1bfed2c8427a395afb7917e6ca
174174
:git: https://github.com/GitHawkApp/GitHawkRoutes.git
175175
Highlightr:
176176
:commit: 4f7e90477619b8dc4b9e641efd10952c22150c5c
@@ -204,7 +204,7 @@ SPEC CHECKSUMS:
204204
FlatCache: e67d3d45a0f76b93e66883b802051dcbf9d50649
205205
FLEX: bd1a39e55b56bb413b6f1b34b3c10a0dc44ef079
206206
FMDB: 6198a90e7b6900cfc046e6bc0ef6ebb7be9236aa
207-
GitHawkRoutes: 468138c117a6fbe79bdd9ba7390bf45d363bc69b
207+
GitHawkRoutes: 6a2a20e756143cb1c87bdf1d7f33a7256cfc6722
208208
GitHubAPI: 44a907f9699210536d65179d3d0dc0dc70dde7a1
209209
GitHubSession: 60c7bbd84fb915a0bd911a367c9661418ccfd7ae
210210
Highlightr: 70c4df19e4aa55aa1b4387fb98182abce1dec9da

Pods/GitHawkRoutes/GitHawkRoutes/IssueRoute.swift

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/GitHawkRoutes/GitHawkRoutes/RepoRoute.swift

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)