Merge branch 'add-vpn-status-shortcut'
This commit is contained in:
commit
2e305b4e82
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- VPN status shortcut, enters active profile on selection.
|
||||
|
||||
## 1.4.0 Beta 1657 (2019-04-08)
|
||||
|
||||
### Added
|
||||
|
|
|
@ -45,6 +45,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
|
||||
let model: TableModel<SectionType, RowType> = {
|
||||
let model: TableModel<SectionType, RowType> = TableModel()
|
||||
model.add(.vpn)
|
||||
model.add(.providers)
|
||||
model.add(.hosts)
|
||||
if #available(iOS 12, *) {
|
||||
|
@ -53,6 +54,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
model.add(.support)
|
||||
model.add(.about)
|
||||
model.add(.destruction)
|
||||
model.setHeader(L10n.Service.Sections.Vpn.header, for: .vpn)
|
||||
model.setHeader(L10n.Organizer.Sections.Providers.header, for: .providers)
|
||||
model.setHeader(L10n.Organizer.Sections.Hosts.header, for: .hosts)
|
||||
model.setFooter(L10n.Organizer.Sections.Providers.footer, for: .providers)
|
||||
|
@ -63,6 +65,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
model.set([.siriShortcuts], in: .siri)
|
||||
}
|
||||
model.setHeader(L10n.Organizer.Sections.Support.header, for: .support)
|
||||
model.set([.connectionStatus], in: .vpn)
|
||||
model.set([.donate, .patreon, .translate], in: .support)
|
||||
model.set([.openAbout], in: .about)
|
||||
model.set([.uninstall], in: .destruction)
|
||||
|
@ -89,6 +92,10 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
|
||||
// MARK: UIViewController
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
|
@ -102,13 +109,11 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
navigationItem.rightBarButtonItem = editButtonItem
|
||||
Cells.destructive.register(with: tableView)
|
||||
reloadModel()
|
||||
|
||||
tableView.reloadData()
|
||||
if let ip = selectedIndexPath {
|
||||
tableView.scrollToRowAsync(at: ip)
|
||||
}
|
||||
|
||||
service.delegate = self
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(vpnDidUpdate), name: .VPNDidChangeStatus, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
|
@ -160,6 +165,13 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
|
||||
// MARK: Actions
|
||||
|
||||
private func selectActiveProfile() {
|
||||
guard let activeIndexPath = activeIndexPath, let cell = tableView.cellForRow(at: activeIndexPath) else {
|
||||
return
|
||||
}
|
||||
perform(segue: StoryboardSegue.Organizer.selectProfileSegueIdentifier, sender: cell)
|
||||
}
|
||||
|
||||
private func addNewProvider() {
|
||||
var names = Set(InfrastructureFactory.shared.allNames)
|
||||
var createdNames: [Infrastructure.Name] = []
|
||||
|
@ -310,12 +322,20 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
private func testTermination() {
|
||||
exit(0)
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc private func vpnDidUpdate() {
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
extension OrganizerViewController {
|
||||
enum SectionType: Int {
|
||||
case vpn
|
||||
|
||||
case providers
|
||||
|
||||
case hosts
|
||||
|
@ -332,6 +352,8 @@ extension OrganizerViewController {
|
|||
}
|
||||
|
||||
enum RowType: Int {
|
||||
case connectionStatus
|
||||
|
||||
case profile
|
||||
|
||||
case addProvider
|
||||
|
@ -355,19 +377,19 @@ extension OrganizerViewController {
|
|||
case testTermination
|
||||
}
|
||||
|
||||
private var selectedIndexPath: IndexPath? {
|
||||
private var activeIndexPath: IndexPath? {
|
||||
guard let active = service.activeProfileKey else {
|
||||
return nil
|
||||
}
|
||||
switch active.context {
|
||||
case .provider:
|
||||
if let row = providers.index(where: { $0 == active.id }) {
|
||||
return IndexPath(row: row, section: 0)
|
||||
return IndexPath(row: row, section: model.index(ofSection: .providers))
|
||||
}
|
||||
|
||||
case .host:
|
||||
if let row = hosts.index(where: { $0 == active.id }) {
|
||||
return IndexPath(row: row, section: 1)
|
||||
return IndexPath(row: row, section: model.index(ofSection: .hosts))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -391,6 +413,12 @@ extension OrganizerViewController {
|
|||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
switch model.row(at: indexPath) {
|
||||
case .connectionStatus:
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
cell.applyVPN(Theme.current, with: VPN.shared.isEnabled ? VPN.shared.status : nil, error: nil)
|
||||
cell.leftText = L10n.Service.Cells.ConnectionStatus.caption
|
||||
return cell
|
||||
|
||||
case .profile:
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
let rowProfile = profileKey(at: indexPath)
|
||||
|
@ -461,6 +489,9 @@ extension OrganizerViewController {
|
|||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
switch model.row(at: indexPath) {
|
||||
case .connectionStatus:
|
||||
selectActiveProfile()
|
||||
|
||||
case .profile:
|
||||
// selectedProfileId = profile(at: indexPath).id
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue