passepartout-apple/Passepartout/App/L10n/Core+L10n.swift

112 lines
3.0 KiB
Swift
Raw Normal View History

2022-04-12 13:09:14 +00:00
//
// Core+L10n.swift
// Passepartout
//
// Created by Davide De Rosa on 2/26/22.
2023-03-17 15:56:19 +00:00
// Copyright (c) 2023 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
2022-06-23 21:31:01 +00:00
extension ObservableVPNState {
func localizedStatusDescription(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
}
}
extension Profile: Comparable {
2023-03-19 13:41:53 +00:00
public static func < (lhs: Self, rhs: Self) -> Bool {
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
}
}
extension Profile.OpenVPNSettings {
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
}
}
extension Profile.WireGuardSettings {
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
}
}
extension Network.Choice {
var localizedDescription: String {
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
}
}
}
extension Network.DNSSettings.ConfigurationType {
var localizedDescription: String {
switch self {
case .plain:
return Unlocalized.DNS.plain
2023-03-17 20:55:47 +00:00
case .https:
return Unlocalized.Network.https
case .tls:
return Unlocalized.Network.tls
case .disabled:
return L10n.Global.Strings.disabled
}
}
}
extension Network.ProxySettings.ConfigurationType {
var localizedDescription: String {
switch self {
case .manual:
return L10n.Global.Strings.manual
2023-03-17 20:55:47 +00:00
case .pac:
return Unlocalized.Network.proxyAutoConfiguration
2023-03-17 20:55:47 +00:00
case .disabled:
return L10n.Global.Strings.disabled
}
}
}