2024-09-23 13:02:26 +00:00
|
|
|
//
|
|
|
|
// ProfileContainerView.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/16/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-09-23 13:02:26 +00:00
|
|
|
import PassepartoutKit
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-11-01 08:47:50 +00:00
|
|
|
struct ProfileContainerView: View, Routable {
|
2024-09-23 13:02:26 +00:00
|
|
|
let layout: ProfilesLayout
|
|
|
|
|
|
|
|
let profileManager: ProfileManager
|
|
|
|
|
2024-11-01 08:47:50 +00:00
|
|
|
let tunnel: ExtendedTunnel
|
2024-09-23 13:02:26 +00:00
|
|
|
|
|
|
|
let registry: Registry
|
|
|
|
|
|
|
|
@Binding
|
|
|
|
var isImporting: Bool
|
|
|
|
|
2024-11-03 10:12:19 +00:00
|
|
|
@ObservedObject
|
|
|
|
var errorHandler: ErrorHandler
|
|
|
|
|
2024-10-23 15:17:20 +00:00
|
|
|
var flow: ProfileFlow?
|
2024-09-23 13:02:26 +00:00
|
|
|
|
|
|
|
@StateObject
|
|
|
|
private var interactiveManager = InteractiveManager()
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
debugChanges()
|
|
|
|
return innerView
|
|
|
|
.modifier(ContainerModifier(
|
2024-11-16 11:29:03 +00:00
|
|
|
profileManager: profileManager,
|
|
|
|
flow: flow
|
2024-09-23 13:02:26 +00:00
|
|
|
))
|
|
|
|
.modifier(ProfileImporterModifier(
|
|
|
|
profileManager: profileManager,
|
|
|
|
registry: registry,
|
|
|
|
isPresented: $isImporting,
|
|
|
|
errorHandler: errorHandler
|
|
|
|
))
|
|
|
|
.navigationTitle(Strings.Unlocalized.appName)
|
|
|
|
.themeModal(isPresented: $interactiveManager.isPresented, content: interactiveDestination)
|
|
|
|
.withErrorHandler(errorHandler)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension ProfileContainerView {
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var innerView: some View {
|
|
|
|
switch layout {
|
|
|
|
case .list:
|
|
|
|
ProfileListView(
|
|
|
|
profileManager: profileManager,
|
|
|
|
tunnel: tunnel,
|
|
|
|
interactiveManager: interactiveManager,
|
|
|
|
errorHandler: errorHandler,
|
2024-10-22 13:06:13 +00:00
|
|
|
flow: flow
|
2024-09-23 13:02:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
case .grid:
|
|
|
|
ProfileGridView(
|
|
|
|
profileManager: profileManager,
|
|
|
|
tunnel: tunnel,
|
|
|
|
interactiveManager: interactiveManager,
|
|
|
|
errorHandler: errorHandler,
|
2024-10-22 13:06:13 +00:00
|
|
|
flow: flow
|
2024-09-23 13:02:26 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func interactiveDestination() -> some View {
|
2024-11-02 14:24:41 +00:00
|
|
|
InteractiveCoordinator(style: .modal, manager: interactiveManager) {
|
2024-09-23 13:02:26 +00:00
|
|
|
errorHandler.handle(
|
|
|
|
$0,
|
|
|
|
title: Strings.Global.connection,
|
|
|
|
message: Strings.Views.Profiles.Errors.tunnel
|
|
|
|
)
|
|
|
|
}
|
2024-11-02 14:24:41 +00:00
|
|
|
.presentationDetents([.medium])
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ContainerModifier: ViewModifier {
|
|
|
|
|
|
|
|
@ObservedObject
|
|
|
|
var profileManager: ProfileManager
|
|
|
|
|
2024-11-19 10:36:36 +00:00
|
|
|
let flow: ProfileFlow?
|
2024-11-16 11:29:03 +00:00
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
@State
|
|
|
|
private var search = ""
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
debugChanges()
|
2024-11-10 11:00:07 +00:00
|
|
|
return content
|
2024-11-15 15:33:26 +00:00
|
|
|
.themeProgress(
|
|
|
|
if: !profileManager.isReady,
|
|
|
|
isEmpty: !profileManager.hasProfiles,
|
2024-11-16 11:29:03 +00:00
|
|
|
emptyContent: {
|
|
|
|
VStack(spacing: 16) {
|
|
|
|
Text(Strings.Views.Profiles.Folders.noProfiles)
|
|
|
|
.themeEmptyMessage(fullScreen: false)
|
|
|
|
|
|
|
|
Button(Strings.Views.Profiles.Folders.NoProfiles.migrate) {
|
|
|
|
flow?.onMigrateProfiles()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-15 15:33:26 +00:00
|
|
|
)
|
2024-11-10 11:00:07 +00:00
|
|
|
.searchable(text: $search)
|
|
|
|
.onChange(of: search) {
|
|
|
|
profileManager.search(byName: $0)
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
2024-11-11 11:08:22 +00:00
|
|
|
.themeAnimation(on: profileManager.isReady, category: .profiles)
|
2024-11-10 11:00:07 +00:00
|
|
|
.themeAnimation(on: profileManager.headers, category: .profiles)
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Previews
|
|
|
|
|
|
|
|
#Preview("List") {
|
|
|
|
PreviewView(layout: .list)
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview("Grid") {
|
|
|
|
PreviewView(layout: .grid)
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct PreviewView: View {
|
|
|
|
let layout: ProfilesLayout
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationStack {
|
|
|
|
ProfileContainerView(
|
|
|
|
layout: layout,
|
|
|
|
profileManager: .mock,
|
|
|
|
tunnel: .mock,
|
|
|
|
registry: Registry(),
|
2024-11-03 10:12:19 +00:00
|
|
|
isImporting: .constant(false),
|
|
|
|
errorHandler: .default()
|
2024-09-23 13:02:26 +00:00
|
|
|
)
|
|
|
|
}
|
2024-10-02 14:05:40 +00:00
|
|
|
.withMockEnvironment()
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
}
|