2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// OrganizerViewController.swift
|
2021-01-01 16:53:28 +00:00
|
|
|
// Passepartout
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/2/18.
|
2020-12-27 16:30:25 +00:00
|
|
|
// Copyright (c) 2021 Davide De Rosa. All rights reserved.
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
2018-11-03 21:33:30 +00:00
|
|
|
// https://github.com/passepartoutvpn
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2019-04-09 09:16:15 +00:00
|
|
|
import StoreKit
|
2019-04-07 14:16:59 +00:00
|
|
|
import MessageUI
|
2021-10-27 16:47:08 +00:00
|
|
|
import SystemConfiguration.CaptiveNetwork
|
|
|
|
import PassepartoutConstants
|
2019-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2021-10-27 16:47:08 +00:00
|
|
|
import TunnelKitCore
|
|
|
|
import TunnelKitManager
|
|
|
|
import TunnelKitOpenVPN
|
2019-10-11 08:56:23 +00:00
|
|
|
import Convenience
|
2021-10-27 16:47:08 +00:00
|
|
|
import ConvenienceUI
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// XXX: convoluted due to the separation of provider/host profiles
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
class OrganizerViewController: UITableViewController, StrongTableHost {
|
2018-10-11 07:13:19 +00:00
|
|
|
private let service = TransientStore.shared.service
|
|
|
|
|
2018-10-26 08:00:28 +00:00
|
|
|
private var providers: [String] = []
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-26 08:00:28 +00:00
|
|
|
private var hosts: [String] = []
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-18 07:52:23 +00:00
|
|
|
private var didShowSubreddit = false
|
2020-07-17 11:33:34 +00:00
|
|
|
|
|
|
|
private var importer: HostImporter?
|
|
|
|
|
|
|
|
private var hostParsingResult: OpenVPN.ConfigurationParser.Result?
|
2018-10-18 07:52:23 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
// MARK: StrongTableHost
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-11-02 10:16:14 +00:00
|
|
|
let model: StrongTableModel<SectionType, RowType> = StrongTableModel()
|
|
|
|
|
|
|
|
func reloadModel() {
|
|
|
|
model.clear()
|
2019-04-10 14:38:28 +00:00
|
|
|
model.add(.vpn)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.add(.providers)
|
|
|
|
model.add(.hosts)
|
2019-03-18 19:14:59 +00:00
|
|
|
if #available(iOS 12, *) {
|
|
|
|
model.add(.siri)
|
|
|
|
}
|
2019-04-06 22:45:32 +00:00
|
|
|
model.add(.support)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.add(.about)
|
|
|
|
model.add(.destruction)
|
2021-08-07 11:57:22 +00:00
|
|
|
model.setHeader(L10n.Service.Sections.Vpn.header, forSection: .vpn)
|
|
|
|
model.setHeader(L10n.Organizer.Sections.Providers.header, forSection: .providers)
|
|
|
|
model.setHeader(L10n.Organizer.Sections.Hosts.header, forSection: .hosts)
|
|
|
|
model.setFooter(L10n.Organizer.Sections.Providers.footer, forSection: .providers)
|
|
|
|
model.setFooter(L10n.Organizer.Sections.Hosts.footer, forSection: .hosts)
|
2019-03-18 19:14:59 +00:00
|
|
|
if #available(iOS 12, *) {
|
2021-08-07 11:57:22 +00:00
|
|
|
model.setHeader(L10n.Organizer.Sections.Siri.header, forSection: .siri)
|
|
|
|
model.setFooter(L10n.Organizer.Sections.Siri.footer, forSection: .siri)
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.siriShortcuts], forSection: .siri)
|
2019-03-18 19:14:59 +00:00
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
model.setHeader(L10n.Organizer.Sections.Support.header, forSection: .support)
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.connectionStatus], forSection: .vpn)
|
2021-10-19 07:43:38 +00:00
|
|
|
if ProductManager.shared.isEligibleForFeedback() {
|
|
|
|
model.set([.donate, .joinCommunity, .writeReview], forSection: .support)
|
|
|
|
} else {
|
|
|
|
model.set([.donate, .joinCommunity], forSection: .support)
|
|
|
|
}
|
2019-11-19 22:53:10 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.openAbout], forSection: .about)
|
|
|
|
model.set([.uninstall], forSection: .destruction)
|
2020-12-25 20:04:56 +00:00
|
|
|
if ProductManager.shared.isBeta {
|
2019-03-06 16:44:27 +00:00
|
|
|
model.add(.test)
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader("Beta", forSection: .test)
|
2019-11-05 14:47:08 +00:00
|
|
|
model.set([.testInterfaces, .testDisplayLog, .testTermination], forSection: .test)
|
2019-03-06 16:44:27 +00:00
|
|
|
}
|
2019-11-02 10:16:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2020-02-28 17:32:04 +00:00
|
|
|
providers = service.sortedProviderNames()
|
|
|
|
hosts = service.sortedHostIds()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-26 08:00:28 +00:00
|
|
|
var providerRows = [RowType](repeating: .profile, count: providers.count)
|
|
|
|
var hostRows = [RowType](repeating: .profile, count: hosts.count)
|
|
|
|
providerRows.append(.addProvider)
|
|
|
|
hostRows.append(.addHost)
|
2020-07-17 11:33:34 +00:00
|
|
|
hostRows.append(.importHost)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set(providerRows, forSection: .providers)
|
|
|
|
model.set(hostRows, forSection: .hosts)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UIViewController
|
2018-10-27 18:10:59 +00:00
|
|
|
|
2019-04-10 14:38:28 +00:00
|
|
|
deinit {
|
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
title = GroupConstants.App.title
|
|
|
|
navigationItem.rightBarButtonItem = editButtonItem
|
|
|
|
Cells.destructive.register(with: tableView)
|
|
|
|
reloadModel()
|
|
|
|
tableView.reloadData()
|
|
|
|
|
2019-10-22 21:33:57 +00:00
|
|
|
// XXX: if split vc is collapsed when a profile is in use, this vc
|
|
|
|
// is not loaded on app launch. consequentially, service.delegate remains
|
|
|
|
// nil until the Organizer is entered
|
|
|
|
//
|
|
|
|
// see UISplitViewControllerDelegate in AppDelegate (collapse is now commented out)
|
2018-10-11 07:13:19 +00:00
|
|
|
service.delegate = self
|
2019-04-10 14:38:28 +00:00
|
|
|
|
2019-11-02 10:28:35 +00:00
|
|
|
let nc = NotificationCenter.default
|
2020-06-12 21:30:57 +00:00
|
|
|
nc.addObserver(self, selector: #selector(vpnDidUpdate), name: VPN.didChangeStatus, object: nil)
|
2019-11-02 10:28:35 +00:00
|
|
|
nc.addObserver(self, selector: #selector(productManagerDidReloadReceipt), name: ProductManager.didReloadReceipt, object: nil)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 07:52:23 +00:00
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
2019-03-22 18:09:13 +00:00
|
|
|
if !didShowSubreddit && !TransientStore.didHandleSubreddit {
|
2018-10-18 07:52:23 +00:00
|
|
|
didShowSubreddit = true
|
2020-10-24 20:32:35 +00:00
|
|
|
|
2021-08-07 11:57:22 +00:00
|
|
|
let alert = UIAlertController.asAlert(L10n.Reddit.title, L10n.Reddit.message)
|
|
|
|
alert.addPreferredAction(L10n.Reddit.Buttons.subscribe) {
|
2019-03-22 18:09:13 +00:00
|
|
|
TransientStore.didHandleSubreddit = true
|
2018-10-18 07:52:23 +00:00
|
|
|
self.subscribeSubreddit()
|
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addAction(L10n.Reddit.Buttons.never) {
|
2019-03-22 18:09:13 +00:00
|
|
|
TransientStore.didHandleSubreddit = true
|
2018-10-18 07:52:23 +00:00
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Reddit.Buttons.remind)
|
2018-10-18 07:52:23 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
|
|
|
if let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) {
|
|
|
|
return model.row(at: indexPath) == .profile
|
|
|
|
}
|
|
|
|
|
|
|
|
// fall back to active profile if no selection
|
|
|
|
return service.hasActiveProfile()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
|
|
let destination = (segue.destination as? UINavigationController)?.topViewController
|
|
|
|
|
|
|
|
if let vc = destination as? ServiceViewController {
|
|
|
|
var selectedProfile: ConnectionProfile?
|
|
|
|
|
|
|
|
// XXX: sender can be a cell or a profile
|
|
|
|
selectedProfile = sender as? ConnectionProfile
|
|
|
|
if selectedProfile == nil, let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) {
|
|
|
|
selectedProfile = profile(at: indexPath)
|
|
|
|
}
|
2019-04-11 13:49:15 +00:00
|
|
|
guard selectedProfile != nil else {
|
|
|
|
assertionFailure("No selected profile")
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-03-08 11:50:34 +00:00
|
|
|
vc.setProfile(selectedProfile)
|
2020-07-17 12:20:41 +00:00
|
|
|
} else if let vc = destination as? ImportedHostsViewController {
|
|
|
|
vc.delegate = self
|
2020-07-17 11:33:34 +00:00
|
|
|
} else if let vc = destination as? WizardHostViewController {
|
|
|
|
vc.parsingResult = hostParsingResult
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
2020-10-24 20:32:35 +00:00
|
|
|
|
2019-04-11 13:49:15 +00:00
|
|
|
private func enterProfile(_ profile: ConnectionProfile) {
|
|
|
|
perform(segue: StoryboardSegue.Organizer.selectProfileSegueIdentifier, sender: profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func enterActiveProfile() {
|
|
|
|
guard let activeProfile = service.activeProfile else {
|
2019-04-10 14:38:59 +00:00
|
|
|
return
|
|
|
|
}
|
2019-04-11 13:49:15 +00:00
|
|
|
enterProfile(activeProfile)
|
2019-04-10 14:38:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private func addNewProvider() {
|
2019-11-28 09:27:47 +00:00
|
|
|
guard service.hasAvailableProviders() else {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2021-08-07 11:57:22 +00:00
|
|
|
L10n.Organizer.Sections.Providers.header,
|
|
|
|
L10n.Organizer.Alerts.ExhaustedProviders.message
|
2018-10-11 07:13:19 +00:00
|
|
|
)
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.ok)
|
2018-10-11 07:13:19 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
perform(segue: StoryboardSegue.Organizer.addProviderSegueIdentifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func addNewHost() {
|
2020-07-17 11:33:34 +00:00
|
|
|
let picker = UIDocumentPickerViewController(documentTypes: AppConstants.URLs.filetypes, in: .import)
|
|
|
|
picker.allowsMultipleSelection = false
|
|
|
|
picker.delegate = self
|
|
|
|
present(picker, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func tryParseHostURL(_ url: URL) {
|
|
|
|
importer = HostImporter(withConfigurationURL: url, parentViewController: self)
|
|
|
|
importer?.importHost(withPassphrase: nil, removeOnError: false, removeOnCancel: false) {
|
|
|
|
self.hostParsingResult = $0
|
|
|
|
self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func importNewHost() {
|
2018-10-27 12:40:52 +00:00
|
|
|
perform(segue: StoryboardSegue.Organizer.showImportedHostsSegueIdentifier)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-03-18 19:14:59 +00:00
|
|
|
|
|
|
|
private func addShortcuts() {
|
2021-01-07 22:37:32 +00:00
|
|
|
do {
|
2021-02-02 16:51:09 +00:00
|
|
|
try ProductManager.shared.verifyEligible(forFeature: .siriShortcuts)
|
|
|
|
} catch ProductError.beta {
|
2021-01-07 22:37:32 +00:00
|
|
|
presentBetaFeatureUnavailable("Siri")
|
2019-10-28 09:14:03 +00:00
|
|
|
return
|
2021-02-02 16:51:09 +00:00
|
|
|
} catch {
|
|
|
|
presentPurchaseScreen(forProduct: .siriShortcuts)
|
|
|
|
return
|
2019-10-28 09:14:03 +00:00
|
|
|
}
|
2019-03-18 19:14:59 +00:00
|
|
|
perform(segue: StoryboardSegue.Organizer.siriShortcutsSegueIdentifier)
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-06 21:11:07 +00:00
|
|
|
private func donateToDeveloper() {
|
2019-04-09 09:16:15 +00:00
|
|
|
guard SKPaymentQueue.canMakePayments() else {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2021-08-07 11:57:22 +00:00
|
|
|
L10n.Organizer.Cells.Donate.caption,
|
|
|
|
L10n.Organizer.Alerts.CannotDonate.message
|
2019-04-09 09:16:15 +00:00
|
|
|
)
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.ok)
|
2019-04-09 09:16:15 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
2019-04-06 21:58:19 +00:00
|
|
|
perform(segue: StoryboardSegue.Organizer.donateSegueIdentifier, sender: nil)
|
2019-04-06 21:11:07 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 14:16:59 +00:00
|
|
|
private func offerTranslation() {
|
2019-07-05 09:10:04 +00:00
|
|
|
let V = AppConstants.Translations.Email.self
|
|
|
|
let recipient = V.recipient
|
|
|
|
let subject = V.subject
|
|
|
|
let body = V.body(V.template)
|
|
|
|
|
2019-04-07 14:16:59 +00:00
|
|
|
guard MFMailComposeViewController.canSendMail() else {
|
2019-07-05 09:10:04 +00:00
|
|
|
let app = UIApplication.shared
|
2019-10-11 08:56:23 +00:00
|
|
|
guard let url = URL.mailto(to: recipient, subject: subject, body: body), app.canOpenURL(url) else {
|
2021-08-07 11:57:22 +00:00
|
|
|
let alert = UIAlertController.asAlert(L10n.Translations.title, L10n.Global.emailNotConfigured)
|
|
|
|
alert.addCancelAction(L10n.Global.ok)
|
2019-07-05 09:10:04 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
app.open(url, options: [:], completionHandler: nil)
|
2019-04-07 14:16:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let vc = MFMailComposeViewController()
|
2019-07-05 09:10:04 +00:00
|
|
|
vc.setToRecipients([recipient])
|
|
|
|
vc.setSubject(subject)
|
|
|
|
vc.setMessageBody(body, isHTML: false)
|
2019-04-07 14:16:59 +00:00
|
|
|
vc.mailComposeDelegate = self
|
2019-10-25 17:30:21 +00:00
|
|
|
vc.apply(.current)
|
2019-04-07 14:16:59 +00:00
|
|
|
present(vc, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2019-04-06 22:45:32 +00:00
|
|
|
private func about() {
|
|
|
|
perform(segue: StoryboardSegue.Organizer.aboutSegueIdentifier, sender: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private func removeProfile(at indexPath: IndexPath) {
|
2019-10-11 08:56:23 +00:00
|
|
|
let sectionObject = model.section(forIndex: indexPath.section)
|
2018-10-26 08:00:28 +00:00
|
|
|
let rowProfile = profileKey(at: indexPath)
|
2018-10-11 07:13:19 +00:00
|
|
|
switch sectionObject {
|
|
|
|
case .providers:
|
2018-10-26 08:00:28 +00:00
|
|
|
providers.remove(at: indexPath.row)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .hosts:
|
2018-10-26 08:00:28 +00:00
|
|
|
hosts.remove(at: indexPath.row)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// var fallbackSection: SectionType?
|
|
|
|
|
2018-10-26 08:00:28 +00:00
|
|
|
let total = providers.count + hosts.count
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// removed all profiles
|
|
|
|
if total == 0 {
|
|
|
|
VPN.shared.disconnect(completionHandler: nil)
|
|
|
|
}
|
|
|
|
// removed active profile
|
|
|
|
else if service.isActiveProfile(rowProfile) {
|
|
|
|
// let anyProvider = providerProfiles.first
|
|
|
|
// let anyHost = hostProfiles.first
|
|
|
|
// guard let anyProfile: ConnectionProfile = firstProvider ?? firstHost else {
|
|
|
|
// fatalError("There must be one profile somewhere")
|
|
|
|
// }
|
|
|
|
// fallbackSection = (anyProvider != nil) ? .providers : .hosts
|
|
|
|
// store.service.activateProfile(only)
|
|
|
|
VPN.shared.disconnect(completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
tableView.beginUpdates()
|
2019-10-11 08:56:23 +00:00
|
|
|
model.deleteRow(at: indexPath.row, ofSection: sectionObject)
|
2018-10-11 07:13:19 +00:00
|
|
|
tableView.deleteRows(at: [indexPath], with: .automatic)
|
|
|
|
// if let fallbackSection = fallbackSection {
|
|
|
|
// let section = model.index(ofSection: fallbackSection)
|
|
|
|
// tableView.reloadRows(at: [IndexPath(row: 0, section: section)], with: .none)
|
|
|
|
// }
|
|
|
|
tableView.endUpdates()
|
|
|
|
|
2018-11-03 22:40:07 +00:00
|
|
|
service.removeProfile(rowProfile)
|
2019-03-09 07:42:58 +00:00
|
|
|
if #available(iOS 12, *) {
|
2019-03-18 16:06:19 +00:00
|
|
|
IntentDispatcher.forgetProfile(withKey: rowProfile)
|
2019-03-09 07:42:58 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func confirmVpnProfileDeletion() {
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert(
|
2021-08-07 11:57:22 +00:00
|
|
|
L10n.Organizer.Cells.Uninstall.caption,
|
|
|
|
L10n.Organizer.Alerts.DeleteVpnProfile.message
|
2018-10-11 07:13:19 +00:00
|
|
|
)
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addPreferredAction(L10n.Global.ok) {
|
2018-10-11 07:13:19 +00:00
|
|
|
VPN.shared.uninstall(completionHandler: nil)
|
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.cancel)
|
2018-10-11 07:13:19 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
2018-10-18 07:52:23 +00:00
|
|
|
|
2020-06-01 08:35:11 +00:00
|
|
|
private func becomeSponsor() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.githubSponsors, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-18 07:52:23 +00:00
|
|
|
private func subscribeSubreddit() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.subreddit, options: [:], completionHandler: nil)
|
|
|
|
}
|
2019-03-06 16:44:27 +00:00
|
|
|
|
2019-04-15 12:29:31 +00:00
|
|
|
private func writeReview() {
|
2019-10-11 16:09:46 +00:00
|
|
|
let url = Reviewer.urlForReview(withAppId: AppConstants.App.appStoreId)
|
2019-04-15 12:29:31 +00:00
|
|
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2019-03-07 21:59:46 +00:00
|
|
|
//
|
|
|
|
|
2019-11-05 14:47:08 +00:00
|
|
|
private func testInterfaces() {
|
|
|
|
let alert = UIAlertController.asAlert("Test interfaces", nil)
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.ok)
|
2019-11-05 14:47:08 +00:00
|
|
|
defer {
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
guard let interfaceNames = CNCopySupportedInterfaces() as? [CFString] else {
|
|
|
|
alert.message = "Nil result from CNCopySupportedInterfaces()"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var message = interfaceNames.description
|
|
|
|
message += "\n\n"
|
|
|
|
for name in interfaceNames {
|
|
|
|
message += name as String
|
|
|
|
message += "\n"
|
|
|
|
guard let iface = CNCopyCurrentNetworkInfo(name) else {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
message += (iface as NSDictionary).description
|
|
|
|
message += "\n"
|
|
|
|
}
|
|
|
|
alert.message = message
|
|
|
|
}
|
|
|
|
|
2019-03-07 21:59:46 +00:00
|
|
|
private func testDisplayLog() {
|
|
|
|
guard let log = try? String(contentsOf: AppConstants.Log.fileURL) else {
|
|
|
|
return
|
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
let alert = UIAlertController.asAlert("Debug log", log)
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.ok)
|
2019-03-07 21:59:46 +00:00
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2019-03-06 16:44:27 +00:00
|
|
|
private func testTermination() {
|
|
|
|
exit(0)
|
|
|
|
}
|
2019-04-10 14:38:28 +00:00
|
|
|
|
|
|
|
// MARK: Notifications
|
|
|
|
|
|
|
|
@objc private func vpnDidUpdate() {
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
2019-11-02 10:28:35 +00:00
|
|
|
|
|
|
|
@objc private func productManagerDidReloadReceipt() {
|
|
|
|
reloadModel()
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension OrganizerViewController {
|
|
|
|
enum SectionType: Int {
|
2019-04-10 14:38:28 +00:00
|
|
|
case vpn
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case providers
|
|
|
|
|
|
|
|
case hosts
|
|
|
|
|
2019-03-18 19:14:59 +00:00
|
|
|
case siri
|
|
|
|
|
2019-04-06 22:45:32 +00:00
|
|
|
case support
|
2019-04-15 12:29:31 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case about
|
|
|
|
|
|
|
|
case destruction
|
2019-03-06 16:44:27 +00:00
|
|
|
|
|
|
|
case test
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
2019-04-10 14:38:28 +00:00
|
|
|
case connectionStatus
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case profile
|
|
|
|
|
|
|
|
case addProvider
|
|
|
|
|
|
|
|
case addHost
|
|
|
|
|
2020-07-17 11:33:34 +00:00
|
|
|
case importHost
|
|
|
|
|
2019-03-18 19:14:59 +00:00
|
|
|
case siriShortcuts
|
|
|
|
|
2019-04-06 21:11:07 +00:00
|
|
|
case donate
|
2019-04-06 22:45:32 +00:00
|
|
|
|
2020-06-01 08:35:35 +00:00
|
|
|
case githubSponsors
|
2019-04-07 14:16:59 +00:00
|
|
|
|
|
|
|
case translate
|
2019-04-15 12:29:31 +00:00
|
|
|
|
|
|
|
case joinCommunity
|
|
|
|
|
|
|
|
case writeReview
|
2019-11-19 22:59:05 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case openAbout
|
|
|
|
|
|
|
|
case uninstall
|
2019-03-07 21:59:46 +00:00
|
|
|
|
2019-11-05 14:47:08 +00:00
|
|
|
case testInterfaces
|
|
|
|
|
2019-03-07 21:59:46 +00:00
|
|
|
case testDisplayLog
|
2019-03-06 16:44:27 +00:00
|
|
|
|
|
|
|
case testTermination
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfSections
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.header(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.footer(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 08:24:07 +00:00
|
|
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
|
return model.headerHeight(for: section)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
|
|
return model.footerHeight(for: section)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfRows(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
switch model.row(at: indexPath) {
|
2019-04-10 14:38:28 +00:00
|
|
|
case .connectionStatus:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyVPN(.current, with: VPN.shared.isEnabled ? VPN.shared.status : nil, error: nil)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Service.Cells.ConnectionStatus.caption
|
2019-04-10 14:38:28 +00:00
|
|
|
return cell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .profile:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2018-10-26 08:00:28 +00:00
|
|
|
let rowProfile = profileKey(at: indexPath)
|
2019-11-28 10:42:23 +00:00
|
|
|
if rowProfile.context == .provider {
|
2019-11-30 10:04:16 +00:00
|
|
|
let metadata = InfrastructureFactory.shared.metadata(forName: rowProfile.id)
|
|
|
|
cell.imageView?.image = metadata?.logo
|
2019-04-04 22:18:50 +00:00
|
|
|
} else {
|
|
|
|
cell.imageView?.image = nil
|
|
|
|
}
|
2020-02-28 17:32:04 +00:00
|
|
|
cell.leftText = service.screenTitle(rowProfile)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.rightText = service.isActiveProfile(rowProfile) ? L10n.Organizer.Cells.Profile.Value.current : nil
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .addProvider:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.AddProvider.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .addHost:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.AddHost.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
|
|
|
|
2020-07-17 11:33:34 +00:00
|
|
|
case .importHost:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.applyAction(.current)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.ImportHost.caption
|
2020-07-17 11:33:34 +00:00
|
|
|
return cell
|
|
|
|
|
2019-03-18 19:14:59 +00:00
|
|
|
case .siriShortcuts:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2019-10-25 17:30:21 +00:00
|
|
|
cell.applyAction(.current)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.SiriShortcuts.caption
|
2019-03-18 19:14:59 +00:00
|
|
|
return cell
|
|
|
|
|
2019-04-06 21:11:07 +00:00
|
|
|
case .donate:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.Donate.caption
|
2019-04-06 21:11:07 +00:00
|
|
|
return cell
|
|
|
|
|
2020-06-01 08:35:35 +00:00
|
|
|
case .githubSponsors:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.GithubSponsors.caption
|
2020-06-01 08:35:35 +00:00
|
|
|
return cell
|
2019-04-06 22:45:32 +00:00
|
|
|
|
2019-04-07 14:16:59 +00:00
|
|
|
case .translate:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.Translate.caption
|
2019-04-07 14:16:59 +00:00
|
|
|
return cell
|
2019-04-15 12:29:31 +00:00
|
|
|
|
|
|
|
case .joinCommunity:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.JoinCommunity.caption
|
2019-04-15 12:29:31 +00:00
|
|
|
return cell
|
|
|
|
|
|
|
|
case .writeReview:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.WriteReview.caption
|
2019-04-15 12:29:31 +00:00
|
|
|
return cell
|
2019-11-19 22:59:05 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .openAbout:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.leftText = L10n.Organizer.Cells.About.caption(GroupConstants.App.name)
|
2019-10-11 08:56:23 +00:00
|
|
|
cell.rightText = ApplicationInfo.appVersion
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
2019-04-06 21:11:07 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .uninstall:
|
|
|
|
let cell = Cells.destructive.dequeue(from: tableView, for: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
cell.caption = L10n.Organizer.Cells.Uninstall.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
return cell
|
2019-03-06 16:44:27 +00:00
|
|
|
|
2019-11-05 14:47:08 +00:00
|
|
|
case .testInterfaces:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = "Show interfaces"
|
|
|
|
return cell
|
|
|
|
|
2019-03-07 21:59:46 +00:00
|
|
|
case .testDisplayLog:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = "Display current log"
|
|
|
|
return cell
|
|
|
|
|
2019-03-06 16:44:27 +00:00
|
|
|
case .testTermination:
|
2019-03-07 21:59:46 +00:00
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = "Terminate app"
|
2019-03-06 16:44:27 +00:00
|
|
|
return cell
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
switch model.row(at: indexPath) {
|
2019-04-10 14:38:28 +00:00
|
|
|
case .connectionStatus:
|
2019-04-11 13:49:15 +00:00
|
|
|
enterActiveProfile()
|
2019-04-10 14:38:28 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .profile:
|
2019-04-11 13:49:15 +00:00
|
|
|
enterProfile(profile(at: indexPath))
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .addProvider:
|
|
|
|
addNewProvider()
|
|
|
|
|
|
|
|
case .addHost:
|
|
|
|
addNewHost()
|
|
|
|
|
2020-07-17 11:33:34 +00:00
|
|
|
case .importHost:
|
|
|
|
importNewHost()
|
|
|
|
|
2019-03-18 19:14:59 +00:00
|
|
|
case .siriShortcuts:
|
|
|
|
addShortcuts()
|
|
|
|
|
2019-04-06 21:11:07 +00:00
|
|
|
case .donate:
|
|
|
|
donateToDeveloper()
|
|
|
|
|
2020-06-01 08:35:35 +00:00
|
|
|
case .githubSponsors:
|
|
|
|
becomeSponsor()
|
2019-04-06 22:45:32 +00:00
|
|
|
|
2019-04-07 14:16:59 +00:00
|
|
|
case .translate:
|
|
|
|
offerTranslation()
|
|
|
|
|
2019-04-15 12:29:31 +00:00
|
|
|
case .joinCommunity:
|
|
|
|
subscribeSubreddit()
|
|
|
|
|
|
|
|
case .writeReview:
|
|
|
|
writeReview()
|
2019-11-19 22:59:05 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .openAbout:
|
|
|
|
about()
|
|
|
|
|
|
|
|
case .uninstall:
|
|
|
|
confirmVpnProfileDeletion()
|
2019-03-06 16:44:27 +00:00
|
|
|
|
2019-11-05 14:47:08 +00:00
|
|
|
case .testInterfaces:
|
|
|
|
testInterfaces()
|
|
|
|
|
2019-03-07 21:59:46 +00:00
|
|
|
case .testDisplayLog:
|
|
|
|
testDisplayLog()
|
|
|
|
|
2019-03-06 16:44:27 +00:00
|
|
|
case .testTermination:
|
|
|
|
testTermination()
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
|
|
|
guard tableView.isEditing else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return model.row(at: indexPath) == .profile
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
|
|
|
removeProfile(at: indexPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Helpers
|
|
|
|
|
2018-10-26 08:00:28 +00:00
|
|
|
private func sectionProfiles(at indexPath: IndexPath) -> [String] {
|
|
|
|
let ids: [String]
|
2019-10-11 08:56:23 +00:00
|
|
|
let sectionObject = model.section(forIndex: indexPath.section)
|
2018-10-11 07:13:19 +00:00
|
|
|
switch sectionObject {
|
|
|
|
case .providers:
|
2018-10-26 08:00:28 +00:00
|
|
|
ids = providers
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .hosts:
|
2018-10-26 08:00:28 +00:00
|
|
|
ids = hosts
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
fatalError("Unexpected section: \(sectionObject)")
|
|
|
|
}
|
2018-10-26 08:00:28 +00:00
|
|
|
guard indexPath.row < ids.count else {
|
2018-10-11 07:13:19 +00:00
|
|
|
fatalError("No profile found at \(indexPath), is it an add cell?")
|
|
|
|
}
|
2018-10-26 08:00:28 +00:00
|
|
|
return ids
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 10:08:15 +00:00
|
|
|
private func profileKey(at indexPath: IndexPath) -> ProfileKey {
|
2019-10-11 08:56:23 +00:00
|
|
|
let section = model.section(forIndex: indexPath.section)
|
2018-10-26 08:00:28 +00:00
|
|
|
switch section {
|
|
|
|
case .providers:
|
2018-11-06 10:08:15 +00:00
|
|
|
return ProfileKey(.provider, providers[indexPath.row])
|
2018-10-26 08:00:28 +00:00
|
|
|
|
|
|
|
case .hosts:
|
2018-11-06 10:08:15 +00:00
|
|
|
return ProfileKey(.host, hosts[indexPath.row])
|
2018-10-26 08:00:28 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
fatalError("Profile found in unexpected section: \(section)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private func profile(at indexPath: IndexPath) -> ConnectionProfile {
|
2018-10-26 08:00:28 +00:00
|
|
|
let id = sectionProfiles(at: indexPath)[indexPath.row]
|
2019-10-11 08:56:23 +00:00
|
|
|
let section = model.section(forIndex: indexPath.section)
|
2018-10-26 16:36:41 +00:00
|
|
|
let context: Context
|
2018-10-26 08:00:28 +00:00
|
|
|
switch section {
|
|
|
|
case .providers:
|
|
|
|
context = .provider
|
|
|
|
|
|
|
|
case .hosts:
|
|
|
|
context = .host
|
|
|
|
|
|
|
|
default:
|
|
|
|
fatalError("Profile found in unexpected section: \(section)")
|
|
|
|
}
|
|
|
|
guard let found = service.profile(withContext: context, id: id) else {
|
|
|
|
fatalError("Profile (\(context), \(id)) could not be found, why was it returned?")
|
|
|
|
}
|
|
|
|
return found
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension OrganizerViewController: ConnectionServiceDelegate {
|
2018-11-02 13:20:40 +00:00
|
|
|
func connectionService(didAdd profile: ConnectionProfile) {
|
2018-11-04 13:51:01 +00:00
|
|
|
TransientStore.shared.serialize(withProfiles: false) // add
|
2018-11-02 13:20:40 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
reloadModel()
|
|
|
|
tableView.reloadData()
|
|
|
|
|
2019-03-09 08:53:48 +00:00
|
|
|
if #available(iOS 12, *) {
|
2019-03-19 16:12:24 +00:00
|
|
|
IntentDispatcher.donateEnableVPN()
|
2019-03-09 08:53:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 19:13:21 +00:00
|
|
|
// XXX: hack around bad replace when detail presented in compact view
|
|
|
|
if let detailNav = navigationController?.viewControllers.last as? UINavigationController {
|
|
|
|
var existingServiceVC: ServiceViewController?
|
|
|
|
for vc in detailNav.viewControllers {
|
|
|
|
if let found = vc as? ServiceViewController {
|
|
|
|
existingServiceVC = found
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let serviceVC = existingServiceVC ?? (StoryboardScene.Main.serviceIdentifier.instantiate().topViewController as! ServiceViewController)
|
2019-03-08 11:50:34 +00:00
|
|
|
serviceVC.setProfile(profile)
|
2018-10-27 19:13:21 +00:00
|
|
|
detailNav.setViewControllers([serviceVC], animated: true)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
perform(segue: StoryboardSegue.Organizer.selectProfileSegueIdentifier, sender: profile)
|
|
|
|
}
|
2018-11-02 13:20:40 +00:00
|
|
|
|
2020-02-28 17:32:04 +00:00
|
|
|
func connectionService(didRename profile: ConnectionProfile, to newTitle: String) {
|
2018-11-04 13:51:01 +00:00
|
|
|
TransientStore.shared.serialize(withProfiles: false) // rename
|
2018-11-02 13:20:40 +00:00
|
|
|
|
|
|
|
reloadModel()
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
|
|
|
|
2018-11-06 10:08:15 +00:00
|
|
|
func connectionService(didRemoveProfileWithKey key: ProfileKey) {
|
2018-11-04 13:51:01 +00:00
|
|
|
TransientStore.shared.serialize(withProfiles: false) // delete
|
2018-11-04 08:18:16 +00:00
|
|
|
|
|
|
|
splitViewController?.serviceViewController?.hideProfileIfDeleted()
|
2018-11-02 13:20:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 22:40:07 +00:00
|
|
|
// XXX: deactivate + activate leads to a redundant serialization
|
|
|
|
|
|
|
|
func connectionService(willDeactivate profile: ConnectionProfile) {
|
2018-11-04 13:35:12 +00:00
|
|
|
TransientStore.shared.serialize(withProfiles: false) // deactivate
|
2018-11-03 22:40:07 +00:00
|
|
|
|
2018-11-02 13:20:40 +00:00
|
|
|
tableView.reloadData()
|
|
|
|
}
|
|
|
|
|
|
|
|
func connectionService(didActivate profile: ConnectionProfile) {
|
2018-11-04 13:35:12 +00:00
|
|
|
TransientStore.shared.serialize(withProfiles: false) // activate
|
2018-11-03 22:40:07 +00:00
|
|
|
|
2018-11-02 13:20:40 +00:00
|
|
|
tableView.reloadData()
|
2019-03-09 08:53:48 +00:00
|
|
|
|
|
|
|
if #available(iOS 12, *) {
|
2019-03-19 16:12:24 +00:00
|
|
|
IntentDispatcher.donateEnableVPN()
|
2019-03-09 08:53:48 +00:00
|
|
|
}
|
2018-11-02 13:20:40 +00:00
|
|
|
}
|
2020-12-02 23:07:16 +00:00
|
|
|
|
|
|
|
func connectionService(didUpdate profile: ConnectionProfile) {
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-04-07 14:16:59 +00:00
|
|
|
|
2020-07-17 11:33:34 +00:00
|
|
|
extension OrganizerViewController: UIDocumentPickerDelegate {
|
|
|
|
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
|
|
|
guard let url = urls.first else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tryParseHostURL(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 12:20:41 +00:00
|
|
|
extension OrganizerViewController: ImportedHostsViewControllerDelegate {
|
|
|
|
func importedHostsController(_: ImportedHostsViewController, didImport url: URL) {
|
|
|
|
dismiss(animated: true) {
|
|
|
|
self.tryParseHostURL(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:16:59 +00:00
|
|
|
extension OrganizerViewController: MFMailComposeViewControllerDelegate {
|
|
|
|
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|