2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// Core+L10n.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/26/22.
|
2024-01-14 13:34:21 +00:00
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// 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 Foundation
|
2022-06-23 21:31:01 +00:00
|
|
|
import PassepartoutLibrary
|
2022-04-12 13:09:14 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension ObservableVPNState: StyledLocalizableEntity {
|
|
|
|
public enum Style {
|
|
|
|
case status(isActiveProfile: Bool, withErrors: Bool, dataCountIfAvailable: Bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(style: Style) -> String {
|
|
|
|
switch style {
|
|
|
|
case .status(let isActiveProfile, let withErrors, let dataCountIfAvailable):
|
|
|
|
return statusDescription(isActiveProfile: isActiveProfile, withErrors: withErrors, dataCountIfAvailable: dataCountIfAvailable)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func statusDescription(isActiveProfile: Bool, withErrors: Bool, dataCountIfAvailable: Bool) -> String {
|
2022-07-03 22:30:20 +00:00
|
|
|
guard isActiveProfile && isEnabled else {
|
2022-04-12 13:09:14 +00:00
|
|
|
return L10n.Tunnelkit.Vpn.disabled
|
|
|
|
}
|
2023-07-02 10:51:50 +00:00
|
|
|
if withErrors, let lastError {
|
|
|
|
return AppError(lastError).localizedDescription
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-04-23 07:46:41 +00:00
|
|
|
if dataCountIfAvailable, vpnStatus == .connected, let dataCount = dataCount {
|
|
|
|
return dataCount.localizedDescription
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-04-23 07:46:41 +00:00
|
|
|
return vpnStatus.localizedDescription
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-16 15:49:09 +00:00
|
|
|
extension Profile: Comparable {
|
2023-03-19 13:41:53 +00:00
|
|
|
public static func < (lhs: Self, rhs: Self) -> Bool {
|
2023-03-16 15:49:09 +00:00
|
|
|
lhs.header < rhs.header
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
extension Profile.Header: Comparable {
|
2023-03-19 13:41:53 +00:00
|
|
|
public static func < (lhs: Self, rhs: Self) -> Bool {
|
2022-09-04 18:09:31 +00:00
|
|
|
lhs.name.lowercased() < rhs.name.lowercased()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-23 06:44:46 +00:00
|
|
|
extension Profile.OpenVPNSettings: StyledOptionalLocalizableEntity {
|
|
|
|
public enum OptionalStyle {
|
|
|
|
case endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(optionalStyle: OptionalStyle) -> String? {
|
|
|
|
switch optionalStyle {
|
|
|
|
case .endpoint:
|
|
|
|
return endpointDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var endpointDescription: String? {
|
2022-09-04 18:09:31 +00:00
|
|
|
customEndpoint?.address ?? configuration.remotes?.first?.address
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-23 06:44:46 +00:00
|
|
|
extension Profile.WireGuardSettings: StyledOptionalLocalizableEntity {
|
|
|
|
public enum OptionalStyle {
|
|
|
|
case endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(optionalStyle: OptionalStyle) -> String? {
|
|
|
|
switch optionalStyle {
|
|
|
|
case .endpoint:
|
|
|
|
return endpointDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var endpointDescription: String? {
|
2022-09-04 18:09:31 +00:00
|
|
|
configuration.tunnelConfiguration.peers.first?.endpoint?.stringRepresentation
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-23 06:44:46 +00:00
|
|
|
extension Profile.OnDemand.Policy: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
|
|
|
switch self {
|
|
|
|
case .any:
|
|
|
|
return L10n.OnDemand.Policy.any
|
|
|
|
|
|
|
|
case .including:
|
|
|
|
return L10n.OnDemand.Policy.including
|
|
|
|
|
|
|
|
case .excluding:
|
|
|
|
return L10n.OnDemand.Policy.excluding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension Network.Choice: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
switch self {
|
|
|
|
case .automatic:
|
|
|
|
return L10n.Global.Strings.automatic
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .manual:
|
|
|
|
return L10n.Global.Strings.manual
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-13 17:34:43 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension Network.DNSSettings.ConfigurationType: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-04-14 05:24:03 +00:00
|
|
|
switch self {
|
|
|
|
case .plain:
|
|
|
|
return Unlocalized.DNS.plain
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
case .https:
|
|
|
|
return Unlocalized.Network.https
|
|
|
|
|
|
|
|
case .tls:
|
|
|
|
return Unlocalized.Network.tls
|
|
|
|
|
|
|
|
case .disabled:
|
|
|
|
return L10n.Global.Strings.disabled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension Network.ProxySettings.ConfigurationType: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-04-13 17:34:43 +00:00
|
|
|
switch self {
|
|
|
|
case .manual:
|
|
|
|
return L10n.Global.Strings.manual
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-13 17:34:43 +00:00
|
|
|
case .pac:
|
|
|
|
return Unlocalized.Network.proxyAutoConfiguration
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-13 17:34:43 +00:00
|
|
|
case .disabled:
|
|
|
|
return L10n.Global.Strings.disabled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 15:18:33 +00:00
|
|
|
|
|
|
|
extension Profile.Account.AuthenticationMethod: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
|
|
|
switch self {
|
|
|
|
case .persistent:
|
|
|
|
return L10n.Account.Items.AuthenticationMethod.persistent
|
|
|
|
|
|
|
|
case .interactive:
|
|
|
|
return L10n.Account.Items.AuthenticationMethod.interactive
|
|
|
|
|
|
|
|
case .totp:
|
|
|
|
return Unlocalized.Other.totp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Int: StyledLocalizableEntity {
|
|
|
|
public enum Style {
|
|
|
|
case mtu
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(style: Style) -> String {
|
|
|
|
switch style {
|
|
|
|
case .mtu:
|
|
|
|
return mtuDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var mtuDescription: String {
|
|
|
|
guard self != 0 else {
|
|
|
|
return L10n.Global.Strings.default
|
|
|
|
}
|
|
|
|
return description
|
|
|
|
}
|
|
|
|
}
|