2024-11-02 07:41:32 +00:00
|
|
|
//
|
|
|
|
// ProfileListView.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 11/1/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
//
|
|
|
|
|
2024-11-03 12:16:13 +00:00
|
|
|
import CommonLibrary
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonUtils
|
2024-11-02 07:41:32 +00:00
|
|
|
import PassepartoutKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ProfileListView: View {
|
|
|
|
|
|
|
|
@ObservedObject
|
|
|
|
var profileManager: ProfileManager
|
|
|
|
|
|
|
|
@ObservedObject
|
|
|
|
var tunnel: ExtendedTunnel
|
|
|
|
|
|
|
|
@FocusState.Binding
|
|
|
|
var focusedField: ProfileView.Field?
|
|
|
|
|
|
|
|
@ObservedObject
|
|
|
|
var interactiveManager: InteractiveManager
|
|
|
|
|
|
|
|
@ObservedObject
|
|
|
|
var errorHandler: ErrorHandler
|
|
|
|
|
|
|
|
var body: some View {
|
2024-11-22 01:20:41 +00:00
|
|
|
VStack {
|
|
|
|
headerView
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
List {
|
2024-11-22 11:52:51 +00:00
|
|
|
ForEach(previews, id: \.id, content: toggleButton(for:))
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
2024-11-23 22:01:11 +00:00
|
|
|
.themeList()
|
2024-11-22 01:20:41 +00:00
|
|
|
.themeProgress(if: false, isEmpty: !profileManager.hasProfiles) {
|
2024-11-23 19:31:22 +00:00
|
|
|
Text(Strings.Views.App.Folders.noProfiles)
|
2024-11-22 01:20:41 +00:00
|
|
|
.themeEmptyMessage()
|
|
|
|
}
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension ProfileListView {
|
2024-11-22 11:52:51 +00:00
|
|
|
var previews: [ProfilePreview] {
|
|
|
|
profileManager.previews
|
2024-11-03 22:42:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 01:20:41 +00:00
|
|
|
var headerView: some View {
|
2024-11-23 19:31:22 +00:00
|
|
|
Text(Strings.Views.App.Tv.header(Strings.Unlocalized.appName, Strings.Unlocalized.appleTV))
|
2024-11-22 01:20:41 +00:00
|
|
|
.textCase(.none)
|
|
|
|
.foregroundStyle(.primary)
|
|
|
|
.font(.body)
|
|
|
|
}
|
|
|
|
|
2024-11-22 11:52:51 +00:00
|
|
|
func toggleButton(for preview: ProfilePreview) -> some View {
|
2024-11-02 07:41:32 +00:00
|
|
|
TunnelToggleButton(
|
|
|
|
tunnel: tunnel,
|
2024-11-22 11:52:51 +00:00
|
|
|
profile: profileManager.profile(withId: preview.id),
|
2024-11-02 07:41:32 +00:00
|
|
|
nextProfileId: .constant(nil),
|
|
|
|
interactiveManager: interactiveManager,
|
|
|
|
errorHandler: errorHandler,
|
2024-11-22 09:05:46 +00:00
|
|
|
onProviderEntityRequired: onProviderEntityRequired,
|
|
|
|
onPurchaseRequired: onPurchaseRequired,
|
2024-11-02 07:41:32 +00:00
|
|
|
label: { _ in
|
2024-11-22 11:52:51 +00:00
|
|
|
toggleView(for: preview)
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
|
|
|
)
|
2024-11-22 11:52:51 +00:00
|
|
|
.focused($focusedField, equals: .profile(preview.id))
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 11:52:51 +00:00
|
|
|
func toggleView(for preview: ProfilePreview) -> some View {
|
2024-11-02 07:41:32 +00:00
|
|
|
HStack {
|
2024-11-22 11:52:51 +00:00
|
|
|
Text(preview.name)
|
2024-11-02 07:41:32 +00:00
|
|
|
Spacer()
|
2024-11-22 01:20:41 +00:00
|
|
|
ThemeImage(tunnel.statusImageName)
|
2024-11-22 11:52:51 +00:00
|
|
|
.opaque(preview.id == tunnel.currentProfile?.id)
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
|
|
|
.font(.headline)
|
|
|
|
}
|
|
|
|
}
|
2024-11-22 01:20:41 +00:00
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
2024-11-22 09:05:46 +00:00
|
|
|
private extension ProfileListView {
|
|
|
|
func onProviderEntityRequired(_ profile: Profile) {
|
2024-11-23 22:01:11 +00:00
|
|
|
// FIXME: #913, TV missing provider entity
|
2024-11-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func onPurchaseRequired(_ features: Set<AppFeature>) {
|
2024-11-23 22:01:11 +00:00
|
|
|
// FIXME: #913, TV purchase required
|
2024-11-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Previews
|
|
|
|
|
2024-11-22 01:20:41 +00:00
|
|
|
#Preview("List") {
|
|
|
|
ContentPreview(profileManager: .mock)
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview("Empty") {
|
|
|
|
ContentPreview(profileManager: ProfileManager(profiles: []))
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ContentPreview: View {
|
|
|
|
let profileManager: ProfileManager
|
|
|
|
|
|
|
|
@FocusState
|
|
|
|
var focusedField: ProfileView.Field?
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ProfileListView(
|
|
|
|
profileManager: profileManager,
|
|
|
|
tunnel: .mock,
|
|
|
|
focusedField: $focusedField,
|
|
|
|
interactiveManager: InteractiveManager(),
|
|
|
|
errorHandler: .default()
|
|
|
|
)
|
|
|
|
.withMockEnvironment()
|
|
|
|
}
|
|
|
|
}
|