Merge pull request #4 from keeshux/optional-account

Optional account
This commit is contained in:
Davide De Rosa 2018-10-19 02:22:17 +02:00 committed by GitHub
commit 67de4ea3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 33 deletions

View File

@ -190,10 +190,10 @@ class ServiceViewController: UIViewController, TableModelHost {
private func toggleVpnService(cell: ToggleTableViewCell) { private func toggleVpnService(cell: ToggleTableViewCell) {
if cell.isOn { if cell.isOn {
guard service.canActivate(uncheckedProfile) else { guard !service.needsCredentials(for: uncheckedProfile) else {
let alert = Macros.alert( let alert = Macros.alert(
L10n.Service.Sections.Vpn.header, L10n.Service.Sections.Vpn.header,
L10n.Service.Alerts.ConfigurationNeeded.message L10n.Service.Alerts.CredentialsNeeded.message
) )
alert.addCancelAction(L10n.Global.ok) { alert.addCancelAction(L10n.Global.ok) {
cell.setOn(false, animated: true) cell.setOn(false, animated: true)
@ -522,7 +522,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil) cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil)
cell.leftText = L10n.Service.Cells.ConnectionStatus.caption cell.leftText = L10n.Service.Cells.ConnectionStatus.caption
cell.accessoryType = .none cell.accessoryType = .none
cell.isTappable = service.canActivate(uncheckedProfile) && vpn.isEnabled cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled
return cell return cell
case .useProfile: case .useProfile:

View File

@ -98,7 +98,7 @@
"service.cells.data_count.caption" = "Exchanged bytes count"; "service.cells.data_count.caption" = "Exchanged bytes count";
"service.cells.debug_log.caption" = "Debug log"; "service.cells.debug_log.caption" = "Debug log";
"service.alerts.configuration_needed.message" = "You need to finish configuration first."; "service.alerts.credentials_needed.message" = "You need to enter account credentials first.";
"service.alerts.reconnect_vpn.message" = "Do you want to reconnect to the VPN?"; "service.alerts.reconnect_vpn.message" = "Do you want to reconnect to the VPN?";
"service.alerts.trusted.no_network.message" = "You are not connected to any Wi-Fi network."; "service.alerts.trusted.no_network.message" = "You are not connected to any Wi-Fi network.";
"service.alerts.trusted.will_disconnect_trusted.message" = "By trusting this network, the VPN may be disconnected. Continue?"; "service.alerts.trusted.will_disconnect_trusted.message" = "By trusting this network, the VPN may be disconnected. Continue?";

View File

@ -30,12 +30,6 @@ enum ApplicationError: Error {
case missingCredentials case missingCredentials
case providerPool
case providerPreset
case hostEndpoints
case missingCA case missingCA
case emptyRemotes case emptyRemotes

View File

@ -34,7 +34,7 @@ protocol ConnectionProfile: class, EndpointDataSource {
var username: String? { get set } var username: String? { get set }
var isConfigured: Bool { get } var requiresCredentials: Bool { get }
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration
} }

View File

@ -180,21 +180,20 @@ class ConnectionService: Codable {
return profile.id == activeProfileId return profile.id == activeProfileId
} }
func canActivate(_ profile: ConnectionProfile) -> Bool {
return profile.isConfigured && hasCredentials(for: profile)
}
func activateProfile(_ profile: ConnectionProfile) { func activateProfile(_ profile: ConnectionProfile) {
activeProfileId = profile.id activeProfileId = profile.id
} }
// MARK: Credentials // MARK: Credentials
func hasCredentials(for profile: ConnectionProfile) -> Bool { func needsCredentials(for profile: ConnectionProfile) -> Bool {
guard let creds = credentials(for: profile) else { guard profile.requiresCredentials else {
return false return false
} }
return !creds.isEmpty guard let creds = credentials(for: profile) else {
return true
}
return creds.isEmpty
} }
func credentials(for profile: ConnectionProfile) -> Credentials? { func credentials(for profile: ConnectionProfile) -> Credentials? {

View File

@ -47,14 +47,12 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
var username: String? var username: String?
var isConfigured: Bool { var requiresCredentials: Bool {
return !parameters.endpointProtocols.isEmpty return false
} }
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
guard !parameters.endpointProtocols.isEmpty else { precondition(!parameters.endpointProtocols.isEmpty)
throw ApplicationError.hostEndpoints
}
// XXX: copy paste, error prone // XXX: copy paste, error prone
var builder = parameters.builder() var builder = parameters.builder()

View File

@ -40,7 +40,7 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
} }
var pool: Pool? { var pool: Pool? {
return infrastructure.pool(for: poolId) return infrastructure.pool(for: poolId) ?? infrastructure.pool(for: infrastructure.defaults.pool)
} }
var presetId: String { var presetId: String {
@ -101,16 +101,16 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
var username: String? var username: String?
var isConfigured: Bool { var requiresCredentials: Bool {
return (pool != nil) && (preset != nil) return true
} }
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
guard let pool = pool else { guard let pool = pool else {
throw ApplicationError.providerPool preconditionFailure("Nil pool?")
} }
guard let preset = preset else { guard let preset = preset else {
throw ApplicationError.providerPreset preconditionFailure("Nil preset?")
} }
// assert(!pool.numericAddresses.isEmpty) // assert(!pool.numericAddresses.isEmpty)

View File

@ -423,9 +423,9 @@ internal enum L10n {
internal enum Alerts { internal enum Alerts {
internal enum ConfigurationNeeded { internal enum CredentialsNeeded {
/// You need to finish configuration first. /// You need to enter account credentials first.
internal static let message = L10n.tr("Localizable", "service.alerts.configuration_needed.message") internal static let message = L10n.tr("Localizable", "service.alerts.credentials_needed.message")
} }
internal enum DataCount { internal enum DataCount {

View File

@ -40,4 +40,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: f6888fe9e046f88d139af75dd5308916c5be8b7b PODFILE CHECKSUM: f6888fe9e046f88d139af75dd5308916c5be8b7b
COCOAPODS: 1.6.0.beta.1 COCOAPODS: 1.6.0.beta.2