2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// ProfileView+Configuration.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 3/27/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/>.
|
|
|
|
//
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
import PassepartoutLibrary
|
2023-04-04 07:50:45 +00:00
|
|
|
import SwiftUI
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
extension ProfileView {
|
|
|
|
struct ConfigurationSection: View {
|
|
|
|
@ObservedObject private var productManager: ProductManager
|
|
|
|
|
|
|
|
@ObservedObject private var currentProfile: ObservableProfile
|
|
|
|
|
|
|
|
@Binding private var modalType: ModalType?
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
init(currentProfile: ObservableProfile, modalType: Binding<ModalType?>) {
|
|
|
|
productManager = .shared
|
|
|
|
self.currentProfile = currentProfile
|
|
|
|
_modalType = modalType
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
if currentProfile.value.vpnProtocols.count > 1 {
|
|
|
|
themeTextPicker(
|
|
|
|
L10n.Global.Strings.protocol,
|
|
|
|
selection: $currentProfile.value.currentVPNProtocol,
|
|
|
|
values: currentProfile.value.vpnProtocols,
|
|
|
|
description: \.description
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
Label(L10n.Global.Strings.protocol, systemImage: themeVPNProtocolImage)
|
|
|
|
.withTrailingText(currentProfile.value.currentVPNProtocol.description)
|
|
|
|
}
|
2023-12-16 19:58:54 +00:00
|
|
|
#if !os(tvOS)
|
2022-04-12 13:09:14 +00:00
|
|
|
NavigationLink {
|
|
|
|
EndpointView(currentProfile: currentProfile)
|
|
|
|
} label: {
|
|
|
|
Label(L10n.Global.Strings.endpoint, systemImage: themeEndpointImage)
|
|
|
|
}
|
2023-12-16 19:58:54 +00:00
|
|
|
#endif
|
2022-04-12 13:09:14 +00:00
|
|
|
if currentProfile.value.requiresCredentials {
|
|
|
|
NavigationLink {
|
|
|
|
AccountView(
|
|
|
|
providerName: currentProfile.value.header.providerName,
|
|
|
|
vpnProtocol: currentProfile.value.currentVPNProtocol,
|
|
|
|
account: $currentProfile.value.account
|
|
|
|
)
|
|
|
|
} label: {
|
|
|
|
Label(L10n.Account.title, systemImage: themeAccountImage)
|
|
|
|
}
|
|
|
|
}
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
// eligibility: enter network settings or present paywall
|
|
|
|
if isEligibleForNetworkSettings {
|
|
|
|
NavigationLink {
|
|
|
|
NetworkSettingsView(currentProfile: currentProfile)
|
|
|
|
} label: {
|
|
|
|
networkSettingsRow
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button {
|
|
|
|
modalType = .paywallNetworkSettings
|
|
|
|
} label: {
|
|
|
|
networkSettingsRow
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// eligibility: enter trusted networks or present paywall
|
|
|
|
if isEligibleForTrustedNetworks {
|
|
|
|
NavigationLink {
|
|
|
|
OnDemandView(currentProfile: currentProfile)
|
|
|
|
} label: {
|
|
|
|
onDemandRow
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button {
|
|
|
|
modalType = .paywallTrustedNetworks
|
|
|
|
} label: {
|
|
|
|
onDemandRow
|
|
|
|
}
|
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Global.Strings.configuration)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-03 14:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
// MARK: -
|
2022-04-12 13:09:14 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
private extension ProfileView.ConfigurationSection {
|
|
|
|
var networkSettingsRow: some View {
|
|
|
|
Label(L10n.NetworkSettings.title, systemImage: themeNetworkSettingsImage)
|
|
|
|
}
|
|
|
|
|
|
|
|
var onDemandRow: some View {
|
|
|
|
Label(L10n.OnDemand.title, systemImage: themeOnDemandImage)
|
|
|
|
}
|
|
|
|
|
|
|
|
var isEligibleForNetworkSettings: Bool {
|
|
|
|
productManager.isEligible(forFeature: .networkSettings)
|
|
|
|
}
|
|
|
|
|
|
|
|
var isEligibleForTrustedNetworks: Bool {
|
|
|
|
productManager.isEligible(forFeature: .trustedNetworks)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|