2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// Theme+Cells.swift
|
|
|
|
// Passepartout-iOS
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 6/25/18.
|
2019-03-09 10:44:44 +00:00
|
|
|
// Copyright (c) 2019 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
|
2018-10-21 21:53:20 +00:00
|
|
|
import TunnelKit
|
2019-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-14 22:08:39 +00:00
|
|
|
extension UITableViewCell {
|
|
|
|
func applyChecked(_ checked: Bool, _ theme: Theme) {
|
|
|
|
accessoryType = checked ? .checkmark : .none
|
2019-04-08 20:44:57 +00:00
|
|
|
tintColor = Theme.current.palette.accessory
|
2018-10-14 22:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
extension DestructiveTableViewCell {
|
|
|
|
func apply(_ theme: Theme) {
|
|
|
|
accessoryType = .none
|
|
|
|
selectionStyle = .default
|
2019-04-08 20:44:57 +00:00
|
|
|
captionColor = theme.palette.destructive
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension FieldTableViewCell {
|
|
|
|
func apply(_ theme: Theme) {
|
2019-04-08 20:44:57 +00:00
|
|
|
captionColor = theme.palette.primaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension SettingTableViewCell {
|
|
|
|
func apply(_ theme: Theme) {
|
2019-04-08 20:44:57 +00:00
|
|
|
leftTextColor = theme.palette.primaryText
|
|
|
|
rightTextColor = theme.palette.secondaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ToggleTableViewCell {
|
|
|
|
func apply(_ theme: Theme) {
|
2019-04-08 20:44:57 +00:00
|
|
|
captionColor = theme.palette.primaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 19:10:28 +00:00
|
|
|
extension ActivityTableViewCell {
|
|
|
|
func apply(_ theme: Theme) {
|
|
|
|
textLabel?.text = nil
|
|
|
|
detailTextLabel?.text = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
extension SettingTableViewCell {
|
|
|
|
func applyAction(_ theme: Theme) {
|
2019-04-08 20:44:57 +00:00
|
|
|
leftTextColor = theme.palette.action
|
2018-10-11 07:13:19 +00:00
|
|
|
rightTextColor = nil
|
|
|
|
accessoryType = .none
|
|
|
|
}
|
|
|
|
|
2019-05-23 21:13:45 +00:00
|
|
|
func applyVPN(_ theme: Theme, with vpnStatus: VPNStatus?, error: OpenVPNTunnelProvider.ProviderError?) {
|
2019-04-08 20:44:57 +00:00
|
|
|
leftTextColor = theme.palette.primaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
guard let vpnStatus = vpnStatus else {
|
2019-06-21 21:15:43 +00:00
|
|
|
rightText = L10n.Core.Vpn.disabled
|
2019-04-08 20:44:57 +00:00
|
|
|
rightTextColor = theme.palette.secondaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch vpnStatus {
|
|
|
|
case .connecting:
|
2019-06-21 21:15:43 +00:00
|
|
|
rightText = L10n.Core.Vpn.connecting
|
2019-04-08 20:44:57 +00:00
|
|
|
rightTextColor = theme.palette.indeterminate
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .connected:
|
2019-06-21 21:15:43 +00:00
|
|
|
rightText = L10n.Core.Vpn.active
|
2019-04-08 20:44:57 +00:00
|
|
|
rightTextColor = theme.palette.on
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-21 21:53:20 +00:00
|
|
|
case .disconnecting, .disconnected:
|
|
|
|
var disconnectionReason: String?
|
|
|
|
if let error = error {
|
|
|
|
switch error {
|
|
|
|
case .socketActivity, .timeout:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.timeout
|
2018-10-21 21:53:20 +00:00
|
|
|
|
|
|
|
case .dnsFailure:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.dns
|
2018-10-21 21:53:20 +00:00
|
|
|
|
2018-10-23 21:17:16 +00:00
|
|
|
case .tlsInitialization, .tlsServerVerification, .tlsHandshake:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.tls
|
2018-10-21 21:53:20 +00:00
|
|
|
|
2018-10-23 21:17:16 +00:00
|
|
|
case .authentication:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.auth
|
2018-10-21 21:53:20 +00:00
|
|
|
|
2018-10-23 21:17:16 +00:00
|
|
|
case .encryptionInitialization, .encryptionData:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.encryption
|
2018-10-23 21:17:16 +00:00
|
|
|
|
2019-02-25 22:13:12 +00:00
|
|
|
case .serverCompression:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.compression
|
2019-02-25 22:13:12 +00:00
|
|
|
|
2018-10-21 21:53:20 +00:00
|
|
|
case .networkChanged:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.network
|
2018-10-21 21:53:20 +00:00
|
|
|
|
2019-04-19 07:48:24 +00:00
|
|
|
case .routing:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.routing
|
2019-04-19 07:48:24 +00:00
|
|
|
|
2019-05-11 15:43:30 +00:00
|
|
|
case .gatewayUnattainable:
|
2019-06-21 21:15:43 +00:00
|
|
|
disconnectionReason = L10n.Core.Vpn.Errors.gateway
|
2019-05-11 15:43:30 +00:00
|
|
|
|
2018-10-21 21:53:20 +00:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch vpnStatus {
|
|
|
|
case .disconnecting:
|
2019-06-21 21:15:43 +00:00
|
|
|
rightText = disconnectionReason ?? L10n.Core.Vpn.disconnecting
|
2019-04-08 20:44:57 +00:00
|
|
|
rightTextColor = theme.palette.indeterminate
|
2018-10-21 21:53:20 +00:00
|
|
|
|
|
|
|
case .disconnected:
|
2019-06-21 21:15:43 +00:00
|
|
|
rightText = disconnectionReason ?? L10n.Core.Vpn.inactive
|
2019-04-08 20:44:57 +00:00
|
|
|
rightTextColor = theme.palette.off
|
2018-10-21 21:53:20 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|