forked from duckduckgo/iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Network Protection debug menu (duckduckgo#1910)
Task/Issue URL: https://app.asana.com/0/0/1205084446087078/f Description: Until now, the option to clear the auth token (thus resetting the invite flow) was in the status view. Now that we’re moving to an actual MVP, it makes sense to move this functionality to a debug menu item. I give you: the NetworkProtectionDebugViewController
- Loading branch information
Showing
4 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// NetworkProtectionDebugViewController.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import UIKit | ||
import NetworkProtection | ||
|
||
final class NetworkProtectionDebugViewController: UITableViewController { | ||
private let titles = [ | ||
Sections.keychain: "Keychain" | ||
] | ||
|
||
enum Sections: Int, CaseIterable { | ||
|
||
case keychain | ||
|
||
} | ||
|
||
enum KeychainRows: Int, CaseIterable { | ||
|
||
case clearAuthToken | ||
|
||
} | ||
|
||
private let tokenStore: NetworkProtectionTokenStore | ||
|
||
init?(coder: NSCoder, | ||
tokenStore: NetworkProtectionTokenStore) { | ||
|
||
self.tokenStore = tokenStore | ||
|
||
super.init(coder: coder) | ||
} | ||
|
||
required convenience init?(coder: NSCoder) { | ||
self.init(coder: coder, tokenStore: NetworkProtectionKeychainTokenStore()) | ||
} | ||
|
||
override func numberOfSections(in tableView: UITableView) -> Int { | ||
return Sections.allCases.count | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | ||
guard let section = Sections(rawValue: section) else { return nil } | ||
return titles[section] | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) | ||
|
||
cell.detailTextLabel?.text = nil | ||
|
||
switch Sections(rawValue: indexPath.section) { | ||
|
||
case .keychain: | ||
switch KeychainRows(rawValue: indexPath.row) { | ||
case .clearAuthToken: | ||
cell.textLabel?.text = "Clear auth token" | ||
case .none: | ||
break | ||
} | ||
|
||
default: break | ||
} | ||
|
||
return cell | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
switch Sections(rawValue: section) { | ||
case .keychain: return KeychainRows.allCases.count | ||
case .none: return 0 | ||
} | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
switch Sections(rawValue: indexPath.section) { | ||
case .keychain: | ||
switch KeychainRows(rawValue: indexPath.row) { | ||
case .clearAuthToken: | ||
try? tokenStore.deleteToken() | ||
default: break | ||
} | ||
default: break | ||
} | ||
|
||
tableView.deselectRow(at: indexPath, animated: true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters