Drop return in one-line functions

This commit is contained in:
Davide De Rosa 2022-09-04 20:09:31 +02:00
parent ca2c2b9d9c
commit 092d4f5de2
62 changed files with 140 additions and 147 deletions

View File

@ -204,11 +204,11 @@ extension Constants {
private static let githubRawRoot = URL(string: "https://\(Domain.name)/")! private static let githubRawRoot = URL(string: "https://\(Domain.name)/")!
private static func github(repo: String) -> URL { private static func github(repo: String) -> URL {
return githubRoot.appendingPathComponent(repo) githubRoot.appendingPathComponent(repo)
} }
private static func githubRaw(repo: String) -> URL { private static func githubRaw(repo: String) -> URL {
return githubRawRoot.appendingPathComponent(repo) githubRawRoot.appendingPathComponent(repo)
} }
static let apple = github(repo: "passepartout-apple") static let apple = github(repo: "passepartout-apple")

View File

@ -28,10 +28,10 @@ import PassepartoutLibrary
extension DebugLog { extension DebugLog {
func decoratedString() -> String { func decoratedString() -> String {
return decoratedString(Constants.Global.appName, Constants.Global.appVersionString) decoratedString(Constants.Global.appName, Constants.Global.appVersionString)
} }
func decoratedData() -> Data { func decoratedData() -> Data {
return decoratedData(Constants.Global.appName, Constants.Global.appVersionString) decoratedData(Constants.Global.appName, Constants.Global.appVersionString)
} }
} }

View File

@ -28,18 +28,18 @@ import TunnelKitCore
extension Endpoint: Identifiable { extension Endpoint: Identifiable {
public var id: String { public var id: String {
return "\(address):\(proto.port):\(proto.socketType.rawValue)" "\(address):\(proto.port):\(proto.socketType.rawValue)"
} }
} }
extension IPv4Settings.Route: Identifiable { extension IPv4Settings.Route: Identifiable {
public var id: String { public var id: String {
return "\(destination):\(mask):\(gateway)" "\(destination):\(mask):\(gateway)"
} }
} }
extension IPv6Settings.Route: Identifiable { extension IPv6Settings.Route: Identifiable {
public var id: String { public var id: String {
return "\(destination):\(prefixLength):\(gateway)" "\(destination):\(prefixLength):\(gateway)"
} }
} }

View File

@ -98,19 +98,19 @@ struct LocalProduct: RawRepresentable, Equatable, Hashable {
// MARK: All // MARK: All
static var all: [LocalProduct] { static var all: [LocalProduct] {
return allDonations + allFeatures// + allProviders allDonations + allFeatures// + allProviders
} }
var isDonation: Bool { var isDonation: Bool {
return rawValue.hasPrefix(LocalProduct.donationsBundle) rawValue.hasPrefix(LocalProduct.donationsBundle)
} }
var isFeature: Bool { var isFeature: Bool {
return rawValue.hasPrefix(LocalProduct.featuresBundle) rawValue.hasPrefix(LocalProduct.featuresBundle)
} }
var isProvider: Bool { var isProvider: Bool {
return rawValue.hasPrefix(LocalProduct.providersBundle) rawValue.hasPrefix(LocalProduct.providersBundle)
} }
// MARK: RawRepresentable // MARK: RawRepresentable
@ -124,7 +124,7 @@ struct LocalProduct: RawRepresentable, Equatable, Hashable {
extension LocalProduct { extension LocalProduct {
func matchesStoreKitProduct(_ skProduct: SKProduct) -> Bool { func matchesStoreKitProduct(_ skProduct: SKProduct) -> Bool {
return skProduct.productIdentifier == rawValue skProduct.productIdentifier == rawValue
} }
} }

View File

@ -114,11 +114,11 @@ class ProductManager: NSObject, ObservableObject {
} }
func product(withIdentifier identifier: LocalProduct) -> SKProduct? { func product(withIdentifier identifier: LocalProduct) -> SKProduct? {
return inApp.product(withIdentifier: identifier) inApp.product(withIdentifier: identifier)
} }
func featureProducts(including: [LocalProduct]) -> [SKProduct] { func featureProducts(including: [LocalProduct]) -> [SKProduct] {
return inApp.products.filter { inApp.products.filter {
guard let p = LocalProduct(rawValue: $0.productIdentifier) else { guard let p = LocalProduct(rawValue: $0.productIdentifier) else {
return false return false
} }
@ -133,7 +133,7 @@ class ProductManager: NSObject, ObservableObject {
} }
func featureProducts(excluding: [LocalProduct]) -> [SKProduct] { func featureProducts(excluding: [LocalProduct]) -> [SKProduct] {
return inApp.products.filter { inApp.products.filter {
guard let p = LocalProduct(rawValue: $0.productIdentifier) else { guard let p = LocalProduct(rawValue: $0.productIdentifier) else {
return false return false
} }
@ -203,19 +203,19 @@ class ProductManager: NSObject, ObservableObject {
} }
func isEligibleForFeedback() -> Bool { func isEligibleForFeedback() -> Bool {
return appType == .beta || !purchasedFeatures.isEmpty appType == .beta || !purchasedFeatures.isEmpty
} }
func hasPurchased(_ product: LocalProduct) -> Bool { func hasPurchased(_ product: LocalProduct) -> Bool {
return purchasedFeatures.contains(product) purchasedFeatures.contains(product)
} }
func isCancelledPurchase(_ product: LocalProduct) -> Bool { func isCancelledPurchase(_ product: LocalProduct) -> Bool {
return cancelledPurchases.contains(product) cancelledPurchases.contains(product)
} }
func purchaseDate(forProduct product: LocalProduct) -> Date? { func purchaseDate(forProduct product: LocalProduct) -> Date? {
return purchaseDates[product] purchaseDates[product]
} }
func reloadReceipt(andNotify: Bool = true) { func reloadReceipt(andNotify: Bool = true) {

View File

@ -53,27 +53,27 @@ class IntentDispatcher {
} }
static func intentEnable() -> EnableVPNIntent { static func intentEnable() -> EnableVPNIntent {
return EnableVPNIntent() EnableVPNIntent()
} }
static func intentDisable() -> DisableVPNIntent { static func intentDisable() -> DisableVPNIntent {
return DisableVPNIntent() DisableVPNIntent()
} }
static func intentTrustWiFi() -> TrustCurrentNetworkIntent { static func intentTrustWiFi() -> TrustCurrentNetworkIntent {
return TrustCurrentNetworkIntent() TrustCurrentNetworkIntent()
} }
static func intentUntrustWiFi() -> UntrustCurrentNetworkIntent { static func intentUntrustWiFi() -> UntrustCurrentNetworkIntent {
return UntrustCurrentNetworkIntent() UntrustCurrentNetworkIntent()
} }
static func intentTrustCellular() -> TrustCellularNetworkIntent { static func intentTrustCellular() -> TrustCellularNetworkIntent {
return TrustCellularNetworkIntent() TrustCellularNetworkIntent()
} }
static func intentUntrustCellular() -> UntrustCellularNetworkIntent { static func intentUntrustCellular() -> UntrustCellularNetworkIntent {
return UntrustCellularNetworkIntent() UntrustCellularNetworkIntent()
} }
// MARK: Donations // MARK: Donations

View File

@ -32,7 +32,7 @@ struct ActivityView: UIViewControllerRepresentable {
let applicationActivities: [UIActivity]? = nil let applicationActivities: [UIActivity]? = nil
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityView>) -> UIActivityViewController { func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityView>) -> UIActivityViewController {
return UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities) UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities)
} }
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityView>) { func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityView>) {

View File

@ -158,7 +158,7 @@ extension EditableTextList {
private func binding(toEditedElement element: IdentifiableString) -> Binding<String> { private func binding(toEditedElement element: IdentifiableString) -> Binding<String> {
// print(">>> <-> \(element)") // print(">>> <-> \(element)")
return .init { .init {
editedTextStrings[element.id] ?? element.string editedTextStrings[element.id] ?? element.string
} set: { } set: {
editedTextStrings[element.id] = $0 editedTextStrings[element.id] = $0

View File

@ -59,19 +59,19 @@ struct GenericCreditsView: View {
} }
private var sortedLicenses: [License] { private var sortedLicenses: [License] {
return licenses.sorted { licenses.sorted {
$0.0.lowercased() < $1.0.lowercased() $0.0.lowercased() < $1.0.lowercased()
} }
} }
private var sortedNotices: [Notice] { private var sortedNotices: [Notice] {
return notices.sorted { notices.sorted {
$0.0.lowercased() < $1.0.lowercased() $0.0.lowercased() < $1.0.lowercased()
} }
} }
private var sortedLanguages: [String] { private var sortedLanguages: [String] {
return translations.keys.sorted { translations.keys.sorted {
$0.localizedAsCountryCode < $1.localizedAsCountryCode $0.localizedAsCountryCode < $1.localizedAsCountryCode
} }
} }
@ -174,6 +174,6 @@ extension GenericCreditsView {
private extension String { private extension String {
var localizedAsCountryCode: String { var localizedAsCountryCode: String {
return Locale.current.localizedString(forLanguageCode: self)?.capitalized ?? self Locale.current.localizedString(forLanguageCode: self)?.capitalized ?? self
} }
} }

View File

@ -33,7 +33,7 @@ public struct IntentActivity<UserObject> {
extension View { extension View {
public func onIntentActivity<UserObject>(_ activity: IntentActivity<UserObject>, object: UserObject) -> some View { public func onIntentActivity<UserObject>(_ activity: IntentActivity<UserObject>, object: UserObject) -> some View {
return onContinueUserActivity(activity.name) { onContinueUserActivity(activity.name) {
activity.handler($0, object) activity.handler($0, object)
} }
} }

View File

@ -43,7 +43,7 @@ public class Reviewer: ObservableObject {
@discardableResult @discardableResult
public func reportEvent() -> Bool { public func reportEvent() -> Bool {
return reportEvents(1) reportEvents(1)
} }
@discardableResult @discardableResult
@ -88,6 +88,6 @@ public class Reviewer: ObservableObject {
} }
public static func urlForReview(withAppId appId: String) -> URL { public static func urlForReview(withAppId appId: String) -> URL {
return URL(string: "https://apps.apple.com/app/id\(appId)?action=write-review")! URL(string: "https://apps.apple.com/app/id\(appId)?action=write-review")!
} }
} }

View File

@ -34,15 +34,15 @@ struct Shortcut: Identifiable, Hashable, Comparable {
} }
var id: UUID { var id: UUID {
return native.identifier native.identifier
} }
static func ==(lhs: Self, rhs: Self) -> Bool { static func ==(lhs: Self, rhs: Self) -> Bool {
return lhs.phrase == rhs.phrase lhs.phrase == rhs.phrase
} }
static func <(lhs: Self, rhs: Self) -> Bool { static func <(lhs: Self, rhs: Self) -> Bool {
return lhs.phrase < rhs.phrase lhs.phrase < rhs.phrase
} }
func hash(into hasher: inout Hasher) { func hash(into hasher: inout Hasher) {
@ -50,6 +50,6 @@ struct Shortcut: Identifiable, Hashable, Comparable {
} }
private var phrase: String { private var phrase: String {
return native.invocationPhrase.lowercased() native.invocationPhrase.lowercased()
} }
} }

View File

@ -159,7 +159,7 @@ extension AddHostView {
} }
private func alertOverwriteExistingProfile() -> Alert { private func alertOverwriteExistingProfile() -> Alert {
return Alert( Alert(
title: Text(L10n.AddProfile.Shared.title), title: Text(L10n.AddProfile.Shared.title),
message: Text(L10n.AddProfile.Shared.Alerts.Overwrite.message), message: Text(L10n.AddProfile.Shared.Alerts.Overwrite.message),
primaryButton: .destructive(Text(L10n.Global.Strings.ok)) { primaryButton: .destructive(Text(L10n.Global.Strings.ok)) {

View File

@ -158,6 +158,6 @@ extension AddProviderView {
private extension ProviderMetadata { private extension ProviderMetadata {
var navigationId: String { var navigationId: String {
return "navigation.\(name)" "navigation.\(name)"
} }
} }

View File

@ -162,7 +162,7 @@ extension DiagnosticsView.OpenVPNView {
} }
private var debugLogURL: URL? { private var debugLogURL: URL? {
return vpnManager.debugLogURL(forProtocol: vpnProtocol) vpnManager.debugLogURL(forProtocol: vpnProtocol)
} }
} }

View File

@ -57,7 +57,7 @@ extension DiagnosticsView {
} }
private var debugLogURL: URL? { private var debugLogURL: URL? {
return vpnManager.debugLogURL(forProtocol: .wireGuard) vpnManager.debugLogURL(forProtocol: .wireGuard)
} }
} }
} }

View File

@ -148,7 +148,7 @@ extension DonateView {
private extension ProductManager { private extension ProductManager {
var donations: [SKProduct] { var donations: [SKProduct] {
return products.filter { product in products.filter { product in
LocalProduct.allDonations.contains { LocalProduct.allDonations.contains {
$0.matchesStoreKitProduct(product) $0.matchesStoreKitProduct(product)
} }

View File

@ -267,7 +267,7 @@ extension EndpointView.OpenVPNView {
} }
private var filteredRemotes: [Endpoint]? { private var filteredRemotes: [Endpoint]? {
return builder.remotes?.filter { builder.remotes?.filter {
$0.proto.socketType == selectedSocketType && $0.proto.port == selectedPort $0.proto.socketType == selectedSocketType && $0.proto.port == selectedPort
} }
} }

View File

@ -194,9 +194,9 @@ extension PaywallView.PurchaseView {
private var skPlatformVersion: SKProduct? { private var skPlatformVersion: SKProduct? {
#if targetEnvironment(macCatalyst) #if targetEnvironment(macCatalyst)
return productManager.product(withIdentifier: .fullVersion_macOS) productManager.product(withIdentifier: .fullVersion_macOS)
#else #else
return productManager.product(withIdentifier: .fullVersion_iOS) productManager.product(withIdentifier: .fullVersion_iOS)
#endif #endif
} }
@ -215,7 +215,7 @@ extension PaywallView.PurchaseView {
} }
private var platformVersionExtra: [String] { private var platformVersionExtra: [String] {
return productManager.featureProducts(excluding: [ productManager.featureProducts(excluding: [
.fullVersion, .fullVersion,
.fullVersion_iOS, .fullVersion_iOS,
.fullVersion_macOS .fullVersion_macOS
@ -227,7 +227,7 @@ extension PaywallView.PurchaseView {
} }
private var fullVersionExtra: [String] { private var fullVersionExtra: [String] {
return productManager.featureProducts(including: [ productManager.featureProducts(including: [
.fullVersion_iOS, .fullVersion_iOS,
.fullVersion_macOS .fullVersion_macOS
]).map { ]).map {

View File

@ -107,7 +107,7 @@ extension ProfileView {
} }
private var currentProviderServerDescription: String? { private var currentProviderServerDescription: String? {
return profile.providerServer(providerManager)?.localizedLongDescription profile.providerServer(providerManager)?.localizedLongDescription
} }
private var currentProviderCountryImage: Image? { private var currentProviderCountryImage: Image? {
@ -118,11 +118,11 @@ extension ProfileView {
} }
private var currentProviderPreset: String? { private var currentProviderPreset: String? {
return providerManager.localizedPreset(forProfile: profile) providerManager.localizedPreset(forProfile: profile)
} }
private var lastInfrastructureUpdate: String? { private var lastInfrastructureUpdate: String? {
return providerManager.localizedInfrastructureUpdate(forProfile: profile) providerManager.localizedInfrastructureUpdate(forProfile: profile)
} }
private func refreshInfrastructure() { private func refreshInfrastructure() {

View File

@ -63,7 +63,7 @@ extension ProfileView {
} }
private func alertOverwriteExistingProfile() -> Alert { private func alertOverwriteExistingProfile() -> Alert {
return Alert( Alert(
title: Text(L10n.Profile.Alerts.Rename.title), title: Text(L10n.Profile.Alerts.Rename.title),
message: Text(L10n.AddProfile.Shared.Alerts.Overwrite.message), message: Text(L10n.AddProfile.Shared.Alerts.Overwrite.message),
primaryButton: .destructive(Text(L10n.Global.Strings.ok)) { primaryButton: .destructive(Text(L10n.Global.Strings.ok)) {

View File

@ -39,7 +39,7 @@ struct ProfileView: View {
case paywallTrustedNetworks case paywallTrustedNetworks
var id: Int { var id: Int {
return rawValue rawValue
} }
} }

View File

@ -225,7 +225,7 @@ extension ProviderLocationView {
} }
private func isFavoriteLocation(_ location: ProviderLocation) -> Bool { private func isFavoriteLocation(_ location: ProviderLocation) -> Bool {
return favoriteLocationIds?.contains(location.id) ?? false favoriteLocationIds?.contains(location.id) ?? false
} }
private func toggleFavoriteLocation(_ location: ProviderLocation) { private func toggleFavoriteLocation(_ location: ProviderLocation) {
@ -295,7 +295,7 @@ extension ProviderLocationView {
} }
private var servers: [ProviderServer] { private var servers: [ProviderServer] {
return providerManager.servers(forLocation: location).sorted() providerManager.servers(forLocation: location).sorted()
} }
} }
} }

View File

@ -99,6 +99,6 @@ struct ProviderPresetView: View {
// some providers (e.g. NordVPN) have specific presets based on selected server // some providers (e.g. NordVPN) have specific presets based on selected server
private var availablePresets: [ProviderServer.Preset] { private var availablePresets: [ProviderServer.Preset] {
return server?.presets?.sorted() ?? [] server?.presets?.sorted() ?? []
} }
} }

View File

@ -41,7 +41,7 @@ struct VPNStatusText: View {
} }
private var statusText: String { private var statusText: String {
return currentVPNState.localizedStatusDescription( currentVPNState.localizedStatusDescription(
isActiveProfile: isActiveProfile, isActiveProfile: isActiveProfile,
withErrors: true, withErrors: true,
dataCountIfAvailable: true dataCountIfAvailable: true

View File

@ -76,19 +76,19 @@ extension ObservableVPNState {
extension Profile.Header: Comparable { extension Profile.Header: Comparable {
public static func <(lhs: Self, rhs: Self) -> Bool { public static func <(lhs: Self, rhs: Self) -> Bool {
return lhs.name.lowercased() < rhs.name.lowercased() lhs.name.lowercased() < rhs.name.lowercased()
} }
} }
extension Profile.OpenVPNSettings { extension Profile.OpenVPNSettings {
var endpointDescription: String? { var endpointDescription: String? {
return customEndpoint?.address ?? configuration.remotes?.first?.address customEndpoint?.address ?? configuration.remotes?.first?.address
} }
} }
extension Profile.WireGuardSettings { extension Profile.WireGuardSettings {
var endpointDescription: String? { var endpointDescription: String? {
return configuration.tunnelConfiguration.peers.first?.endpoint?.stringRepresentation configuration.tunnelConfiguration.peers.first?.endpoint?.stringRepresentation
} }
} }

View File

@ -57,7 +57,7 @@ enum Unlocalized {
enum Keychain { enum Keychain {
static func passwordLabel(_ profileName: String, vpnProtocol: VPNProtocolType) -> String { static func passwordLabel(_ profileName: String, vpnProtocol: VPNProtocolType) -> String {
return "\(Constants.Global.appName): \(profileName) (\(vpnProtocol.description))" "\(Constants.Global.appName): \(profileName) (\(vpnProtocol.description))"
} }
} }
@ -67,7 +67,7 @@ enum Unlocalized {
static let subject = "\(appName) - Report issue" static let subject = "\(appName) - Report issue"
static func body(_ description: String, _ metadata: String) -> String { static func body(_ description: String, _ metadata: String) -> String {
return "Hi,\n\n\(description)\n\n\(metadata)\n\nRegards" "Hi,\n\n\(description)\n\n\(metadata)\n\nRegards"
} }
static let template = "description of the issue: " static let template = "description of the issue: "
@ -123,7 +123,7 @@ enum Unlocalized {
static let subject = "\(appName) - Translations" static let subject = "\(appName) - Translations"
static func body(_ description: String) -> String { static func body(_ description: String) -> String {
return "Hi,\n\n\(description)\n\nRegards" "Hi,\n\n\(description)\n\nRegards"
} }
static let template = "I offer to translate to: " static let template = "I offer to translate to: "

View File

@ -41,11 +41,7 @@ struct ProfileItemGroup: ItemGroup {
func asMenuItems(withParent parent: NSMenu) -> [NSMenuItem] { func asMenuItems(withParent parent: NSMenu) -> [NSMenuItem] {
profileManager.profiles.map { profileManager.profiles.map {
if $0.isProvider { $0.isProvider ? providerItem(withProfile: $0, parent: parent) : hostItem(withProfile: $0, parent: parent)
return providerItem(withProfile: $0, parent: parent)
} else {
return hostItem(withProfile: $0, parent: parent)
}
} }
} }

View File

@ -40,7 +40,7 @@ extension ProviderLocationItem {
} }
var isActiveLocation: Bool { var isActiveLocation: Bool {
return location.id == profile.providerServer?.locationId location.id == profile.providerServer?.locationId
} }
var isOnlyServer: Bool { var isOnlyServer: Bool {

View File

@ -58,7 +58,7 @@ extension Profile {
public var hostWireGuardSettings: WireGuardSettings? { public var hostWireGuardSettings: WireGuardSettings? {
get { get {
return host?.wgSettings host?.wgSettings
} }
set { set {
host?.wgSettings = newValue host?.wgSettings = newValue

View File

@ -27,7 +27,7 @@ import Foundation
extension Profile { extension Profile {
public var isProvider: Bool { public var isProvider: Bool {
return provider != nil provider != nil
} }
public var vpnProtocols: [VPNProtocolType] { public var vpnProtocols: [VPNProtocolType] {

View File

@ -46,7 +46,7 @@ extension Profile {
} }
public func providerServerId() -> String? { public func providerServerId() -> String? {
return provider?.vpnSettings[currentVPNProtocol]?.serverId provider?.vpnSettings[currentVPNProtocol]?.serverId
} }
public mutating func setProviderServer(_ server: ProviderServer) { public mutating func setProviderServer(_ server: ProviderServer) {
@ -72,7 +72,7 @@ extension Profile {
} }
public func providerFavoriteLocationIds() -> Set<String>? { public func providerFavoriteLocationIds() -> Set<String>? {
return provider?.vpnSettings[currentVPNProtocol]?.favoriteLocationIds provider?.vpnSettings[currentVPNProtocol]?.favoriteLocationIds
} }
public mutating func setProviderFavoriteLocationIds(_ ids: Set<String>?) { public mutating func setProviderFavoriteLocationIds(_ ids: Set<String>?) {
@ -80,7 +80,7 @@ extension Profile {
} }
public func providerCustomEndpoint() -> Endpoint? { public func providerCustomEndpoint() -> Endpoint? {
return provider?.vpnSettings[currentVPNProtocol]?.customEndpoint provider?.vpnSettings[currentVPNProtocol]?.customEndpoint
} }
public mutating func setProviderCustomEndpoint(_ endpoint: Endpoint?) { public mutating func setProviderCustomEndpoint(_ endpoint: Endpoint?) {
@ -88,7 +88,7 @@ extension Profile {
} }
public func providerAccount() -> Profile.Account? { public func providerAccount() -> Profile.Account? {
return provider?.vpnSettings[currentVPNProtocol]?.account provider?.vpnSettings[currentVPNProtocol]?.account
} }
public mutating func setProviderAccount(_ account: Profile.Account?) { public mutating func setProviderAccount(_ account: Profile.Account?) {

View File

@ -33,6 +33,6 @@ public struct DebugLog {
} }
public var contentData: Data? { public var contentData: Data? {
return content.data(using: .utf8) content.data(using: .utf8)
} }
} }

View File

@ -64,7 +64,7 @@ extension Profile {
// MARK: Identifiable // MARK: Identifiable
public var id: UUID { public var id: UUID {
return uuid uuid
} }
} }
} }

View File

@ -29,7 +29,7 @@ import TunnelKitOpenVPN
extension Profile { extension Profile {
public struct OpenVPNSettings: Codable, Equatable, VPNProtocolProviding { public struct OpenVPNSettings: Codable, Equatable, VPNProtocolProviding {
public var vpnProtocol: VPNProtocolType { public var vpnProtocol: VPNProtocolType {
return .openVPN .openVPN
} }
public var configuration: OpenVPN.Configuration public var configuration: OpenVPN.Configuration

View File

@ -29,7 +29,7 @@ import TunnelKitWireGuard
extension Profile { extension Profile {
public struct WireGuardSettings: Codable, Equatable, VPNProtocolProviding { public struct WireGuardSettings: Codable, Equatable, VPNProtocolProviding {
public var vpnProtocol: VPNProtocolType { public var vpnProtocol: VPNProtocolType {
return .wireGuard .wireGuard
} }
public var configuration: WireGuard.Configuration public var configuration: WireGuard.Configuration

View File

@ -111,7 +111,7 @@ public struct Profile: Identifiable, Codable, Equatable {
// MARK: Identifiable // MARK: Identifiable
public var id: UUID { public var id: UUID {
return header.id header.id
} }
} }

View File

@ -89,7 +89,7 @@ public struct ProviderServer: Identifiable {
} }
public func preset(withId presetId: String) -> Preset? { public func preset(withId presetId: String) -> Preset? {
return presets?.first { presets?.first {
$0.id == presetId $0.id == presetId
} }
} }

View File

@ -104,7 +104,7 @@ extension UpgradeManager {
} }
private var appGroup: String { private var appGroup: String {
return "group.com.algoritmico.Passepartout" "group.com.algoritmico.Passepartout"
} }
func doMigrateToV2() -> [Profile] { func doMigrateToV2() -> [Profile] {
@ -368,7 +368,7 @@ extension UpgradeManager {
} }
private func migratedV1Choice(_ map: Map, key: String) -> Network.Choice { private func migratedV1Choice(_ map: Map, key: String) -> Network.Choice {
return (map[key] as? String) == "manual" ? .manual : .automatic (map[key] as? String) == "manual" ? .manual : .automatic
} }
} }

View File

@ -32,12 +32,12 @@ extension Profile.OpenVPNSettings: GatewaySettingsProviding {
// route-gateway // route-gateway
public var isDefaultIPv4: Bool { public var isDefaultIPv4: Bool {
return configuration.routingPolicies?.contains(.IPv4) ?? false configuration.routingPolicies?.contains(.IPv4) ?? false
} }
// ifconfig-ipv6 // ifconfig-ipv6
public var isDefaultIPv6: Bool { public var isDefaultIPv6: Bool {
return configuration.routingPolicies?.contains(.IPv6) ?? false configuration.routingPolicies?.contains(.IPv6) ?? false
} }
} }
@ -45,27 +45,27 @@ extension Profile.OpenVPNSettings: DNSSettingsProviding {
// not a dhcp-option // not a dhcp-option
public var dnsProtocol: DNSProtocol? { public var dnsProtocol: DNSProtocol? {
return (configuration.isDNSEnabled ?? true) ? .plain : nil (configuration.isDNSEnabled ?? true) ? .plain : nil
} }
// dhcp-option DNS // dhcp-option DNS
public var dnsServers: [String]? { public var dnsServers: [String]? {
return configuration.dnsServers configuration.dnsServers
} }
// dhcp-option DOMAIN/DOMAIN-SEARCH // dhcp-option DOMAIN/DOMAIN-SEARCH
public var dnsSearchDomains: [String]? { public var dnsSearchDomains: [String]? {
return configuration.searchDomains configuration.searchDomains
} }
// not a dhcp-option // not a dhcp-option
public var dnsHTTPSURL: URL? { public var dnsHTTPSURL: URL? {
return nil nil
} }
// not a dhcp-option // not a dhcp-option
public var dnsTLSServerName: String? { public var dnsTLSServerName: String? {
return nil nil
} }
} }
@ -73,17 +73,17 @@ extension Profile.OpenVPNSettings: ProxySettingsProviding {
// dhcp-option PROXY_HTTP[S] // dhcp-option PROXY_HTTP[S]
public var proxyServer: Proxy? { public var proxyServer: Proxy? {
return configuration.httpsProxy ?? configuration.httpProxy configuration.httpsProxy ?? configuration.httpProxy
} }
// dhcp-option PROXY_BYPASS // dhcp-option PROXY_BYPASS
public var proxyBypassDomains: [String]? { public var proxyBypassDomains: [String]? {
return configuration.proxyBypassDomains configuration.proxyBypassDomains
} }
// dhcp-option PROXY_AUTO_CONFIG_URL // dhcp-option PROXY_AUTO_CONFIG_URL
public var proxyAutoConfigurationURL: URL? { public var proxyAutoConfigurationURL: URL? {
return configuration.proxyAutoConfigurationURL configuration.proxyAutoConfigurationURL
} }
} }
@ -91,6 +91,6 @@ extension Profile.OpenVPNSettings: MTUSettingsProviding {
public var mtuBytes: Int { public var mtuBytes: Int {
// tun-mtu // tun-mtu
return configuration.mtu ?? 0 configuration.mtu ?? 0
} }
} }

View File

@ -28,12 +28,12 @@ import PassepartoutCore
extension Profile.Header { extension Profile.Header {
public var logDescription: String { public var logDescription: String {
return "{\(id), '\(name)'}" "{\(id), '\(name)'}"
} }
} }
extension Profile { extension Profile {
public var logDescription: String { public var logDescription: String {
return header.logDescription header.logDescription
} }
} }

View File

@ -30,28 +30,28 @@ import PassepartoutCore
extension Profile.WireGuardSettings: DNSSettingsProviding { extension Profile.WireGuardSettings: DNSSettingsProviding {
public var dnsProtocol: DNSProtocol? { public var dnsProtocol: DNSProtocol? {
return .plain .plain
} }
public var dnsServers: [String]? { public var dnsServers: [String]? {
return configuration.dnsServers configuration.dnsServers
} }
public var dnsSearchDomains: [String]? { public var dnsSearchDomains: [String]? {
return configuration.dnsSearchDomains configuration.dnsSearchDomains
} }
public var dnsHTTPSURL: URL? { public var dnsHTTPSURL: URL? {
return nil nil
} }
public var dnsTLSServerName: String? { public var dnsTLSServerName: String? {
return nil nil
} }
} }
extension Profile.WireGuardSettings: MTUSettingsProviding { extension Profile.WireGuardSettings: MTUSettingsProviding {
public var mtuBytes: Int { public var mtuBytes: Int {
return Int(configuration.mtu ?? 0) Int(configuration.mtu ?? 0)
} }
} }

View File

@ -82,7 +82,7 @@ extension ProfileManager {
private extension Profile { private extension Profile {
var keychainEntry: String? { var keychainEntry: String? {
return "\(id.uuidString):\(currentVPNProtocol.description):\(account.username)" "\(id.uuidString):\(currentVPNProtocol.description):\(account.username)"
} }
} }

View File

@ -130,11 +130,11 @@ struct ServerMapper: DTOMapper, ModelMapper {
private extension WSProviderServer { private extension WSProviderServer {
var encodedExtraCountryCodes: String? { var encodedExtraCountryCodes: String? {
return extraCountryCodes?.joined(separator: ",") extraCountryCodes?.joined(separator: ",")
} }
var encodedTags: String? { var encodedTags: String? {
return tags?.joined(separator: ",") tags?.joined(separator: ",")
} }
var encodedIPAddresses: String? { var encodedIPAddresses: String? {
@ -149,18 +149,15 @@ private extension WSProviderServer {
private extension CDInfrastructureServer { private extension CDInfrastructureServer {
var decodedExtraCountryCodes: [String]? { var decodedExtraCountryCodes: [String]? {
return extraCountryCodes? extraCountryCodes?.components(separatedBy: ",")
.components(separatedBy: ",")
} }
var decodedTags: [String]? { var decodedTags: [String]? {
return tags? tags?.components(separatedBy: ",")
.components(separatedBy: ",")
} }
var decodedIPAddresses: [String] { var decodedIPAddresses: [String] {
return ipAddresses? ipAddresses?.components(separatedBy: ",") ?? []
.components(separatedBy: ",") ?? []
} }
} }

View File

@ -50,7 +50,7 @@ public struct WSProvidersIndex: Codable {
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
public var description: String { public var description: String {
return fullName fullName
} }
} }

View File

@ -48,13 +48,13 @@ public class DefaultWebServices: WebServices {
} }
private var fileType: String { private var fileType: String {
return "json" "json"
} }
// MARK: GenericWebEndpoint // MARK: GenericWebEndpoint
var path: String { var path: String {
return "\(pathName).\(fileType)" "\(pathName).\(fileType)"
} }
} }

View File

@ -35,7 +35,7 @@ public enum WebError: GenericWebServicesError, LocalizedError {
case unknown case unknown
public static func httpStatus(_ status: Int) -> WebError { public static func httpStatus(_ status: Int) -> WebError {
return .http(status) .http(status)
} }
public var errorDescription: String? { public var errorDescription: String? {

View File

@ -35,11 +35,11 @@ public class GenericWebParser {
}() }()
public static func lastModifiedDate(string: String) -> Date? { public static func lastModifiedDate(string: String) -> Date? {
return lmFormatter.date(from: string) lmFormatter.date(from: string)
} }
public static func lastModifiedString(date: Date) -> String { public static func lastModifiedString(date: Date) -> String {
return lmFormatter.string(from: date) lmFormatter.string(from: date)
} }
public static func lastModifiedString(ofFileURL url: URL) -> String? { public static func lastModifiedString(ofFileURL url: URL) -> String? {

View File

@ -40,6 +40,6 @@ public struct GenericWebResponse<T> {
public let isCached: Bool public let isCached: Bool
public static func empty() -> GenericWebResponse { public static func empty() -> GenericWebResponse {
return GenericWebResponse(value: nil, lastModifiedString: nil, isCached: false) GenericWebResponse(value: nil, lastModifiedString: nil, isCached: false)
} }
} }

View File

@ -51,7 +51,7 @@ public class InApp<PID: Hashable & RawRepresentable>: NSObject,
private var productsMap: [PID: SKProduct] private var productsMap: [PID: SKProduct]
public var products: [SKProduct] { public var products: [SKProduct] {
return [SKProduct](productsMap.values) [SKProduct](productsMap.values)
} }
private var productObservers: [ProductObserver] private var productObservers: [ProductObserver]
@ -110,7 +110,7 @@ public class InApp<PID: Hashable & RawRepresentable>: NSObject,
} }
public func product(withIdentifier productIdentifier: PID) -> SKProduct? { public func product(withIdentifier productIdentifier: PID) -> SKProduct? {
return productsMap[productIdentifier] productsMap[productIdentifier]
} }
// MARK: SKProductsRequestDelegate // MARK: SKProductsRequestDelegate
@ -218,6 +218,6 @@ extension SKProduct {
} }
public var localizedPrice: String? { public var localizedPrice: String? {
return localizedCurrencyFormatter.string(from: price) localizedCurrencyFormatter.string(from: price)
} }
} }

View File

@ -31,11 +31,11 @@ public class KeyedCache<K: Hashable, V> {
private var store: [K: V] = [:] private var store: [K: V] = [:]
public var isEmpty: Bool { public var isEmpty: Bool {
return store.isEmpty store.isEmpty
} }
public var storeValues: [V] { public var storeValues: [V] {
return Array(store.values) Array(store.values)
} }
public init(_ query: String) { public init(_ query: String) {

View File

@ -33,6 +33,6 @@ extension JSON {
} }
public func encoded() throws -> Data { public func encoded() throws -> Data {
return try JSONEncoder().encode(self) try JSONEncoder().encode(self)
} }
} }

View File

@ -40,7 +40,7 @@ private let componentsFormatter: DateComponentsFormatter = {
extension Date { extension Date {
public var timestamp: String { public var timestamp: String {
return timestampFormatter.string(from: self) timestampFormatter.string(from: self)
} }
} }

View File

@ -33,7 +33,7 @@ import CoreWLAN
extension Utils { extension Utils {
#if targetEnvironment(simulator) #if targetEnvironment(simulator)
public static func hasCellularData() -> Bool { public static func hasCellularData() -> Bool {
return true true
} }
#else #else
public static func hasCellularData() -> Bool { public static func hasCellularData() -> Bool {

View File

@ -45,7 +45,7 @@ extension Utils {
extension String: StrippableContent { extension String: StrippableContent {
public var stripped: String { public var stripped: String {
return trimmingCharacters(in: .whitespacesAndNewlines) trimmingCharacters(in: .whitespacesAndNewlines)
} }
public var strippedNotEmpty: String? { public var strippedNotEmpty: String? {
@ -59,13 +59,13 @@ extension String: StrippableContent {
extension StringProtocol where Index == String.Index { extension StringProtocol where Index == String.Index {
public func nsRange(from range: Range<Index>) -> NSRange { public func nsRange(from range: Range<Index>) -> NSRange {
return NSRange(range, in: self) NSRange(range, in: self)
} }
} }
extension String { extension String {
public var localizedAsCountryCode: String { public var localizedAsCountryCode: String {
return Locale.current.localizedString(forRegionCode: self) ?? self Locale.current.localizedString(forRegionCode: self) ?? self
} }
} }

View File

@ -31,7 +31,7 @@ import Foundation
extension Bundle { extension Bundle {
public var isTestFlight: Bool { public var isTestFlight: Bool {
#if targetEnvironment(simulator) #if targetEnvironment(simulator)
return true true
#elseif targetEnvironment(macCatalyst) || os(macOS) #elseif targetEnvironment(macCatalyst) || os(macOS)
var status = noErr var status = noErr
@ -64,9 +64,9 @@ extension Bundle {
) )
return status == errSecSuccess return status == errSecSuccess
#elseif os(iOS) #elseif os(iOS)
return appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
#else #else
return false false
#endif #endif
} }
} }

View File

@ -48,7 +48,7 @@ extension URL {
UIApplication.shared.open(url) UIApplication.shared.open(url)
return true return true
#else #else
return NSWorkspace.shared.open(url) NSWorkspace.shared.open(url)
#endif #endif
} }

View File

@ -83,6 +83,6 @@ extension Profile.OnDemand {
} }
private var policyRule: NEOnDemandRule { private var policyRule: NEOnDemandRule {
return disconnectsIfNotMatching ? NEOnDemandRuleDisconnect() : NEOnDemandRuleIgnore() disconnectsIfNotMatching ? NEOnDemandRuleDisconnect() : NEOnDemandRuleIgnore()
} }
} }

View File

@ -30,36 +30,36 @@ import PassepartoutCore
extension VPNProtocolType: Comparable { extension VPNProtocolType: Comparable {
public static func <(lhs: Self, rhs: Self) -> Bool { public static func <(lhs: Self, rhs: Self) -> Bool {
return lhs.description < rhs.description lhs.description < rhs.description
} }
} }
extension OpenVPN.ProviderConfiguration: VPNProtocolProviding { extension OpenVPN.ProviderConfiguration: VPNProtocolProviding {
public var vpnProtocol: VPNProtocolType { public var vpnProtocol: VPNProtocolType {
return .openVPN .openVPN
} }
} }
extension WireGuard.ProviderConfiguration: VPNProtocolProviding { extension WireGuard.ProviderConfiguration: VPNProtocolProviding {
public var vpnProtocol: VPNProtocolType { public var vpnProtocol: VPNProtocolType {
return .wireGuard .wireGuard
} }
} }
extension VPNProtocolType { extension VPNProtocolType {
public var supportsGateway: Bool { public var supportsGateway: Bool {
return true true
} }
public var supportsDNS: Bool { public var supportsDNS: Bool {
return true true
} }
public var supportsProxy: Bool { public var supportsProxy: Bool {
return self == .openVPN self == .openVPN
} }
public var supportsMTU: Bool { public var supportsMTU: Bool {
return true true
} }
} }

View File

@ -117,10 +117,10 @@ public class MockVPNManagerStrategy: VPNManagerStrategy {
} }
public func serverConfiguration(forProtocol vpnProtocol: VPNProtocolType) -> Any? { public func serverConfiguration(forProtocol vpnProtocol: VPNProtocolType) -> Any? {
return nil nil
} }
public func debugLogURL(forProtocol vpnProtocol: VPNProtocolType) -> URL? { public func debugLogURL(forProtocol vpnProtocol: VPNProtocolType) -> URL? {
return nil nil
} }
} }

View File

@ -122,11 +122,11 @@ public final class VPNManager: ObservableObject {
} }
public func serverConfiguration(forProtocol vpnProtocol: VPNProtocolType) -> Any? { public func serverConfiguration(forProtocol vpnProtocol: VPNProtocolType) -> Any? {
return strategy.serverConfiguration(forProtocol: vpnProtocol) strategy.serverConfiguration(forProtocol: vpnProtocol)
} }
public func debugLogURL(forProtocol vpnProtocol: VPNProtocolType) -> URL? { public func debugLogURL(forProtocol vpnProtocol: VPNProtocolType) -> URL? {
return strategy.debugLogURL(forProtocol: vpnProtocol) strategy.debugLogURL(forProtocol: vpnProtocol)
} }
private func clearLastError() { private func clearLastError() {

View File

@ -62,8 +62,8 @@ class UtilsTests: XCTestCase {
} }
private func privateSortedLanguages(_ languages: [String], with locale: Locale) -> [String] { private func privateSortedLanguages(_ languages: [String], with locale: Locale) -> [String] {
return languages.sorted { languages.sorted {
return locale.localizedString(forLanguageCode: $0)! < locale.localizedString(forLanguageCode: $1)! locale.localizedString(forLanguageCode: $0)! < locale.localizedString(forLanguageCode: $1)!
} }
} }
} }