2024-10-29 10:40:11 +00:00
|
|
|
//
|
2024-10-29 13:30:41 +00:00
|
|
|
// AppCoordinator.swift
|
2024-10-29 10:40:11 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 10/29/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-24 00:01:04 +00:00
|
|
|
import CommonUtils
|
2024-10-29 10:40:11 +00:00
|
|
|
import PassepartoutKit
|
|
|
|
import SwiftUI
|
2024-11-24 00:01:04 +00:00
|
|
|
import UILibrary
|
2024-10-29 10:40:11 +00:00
|
|
|
|
2024-10-31 13:30:22 +00:00
|
|
|
public struct AppCoordinator: View, AppCoordinatorConforming {
|
2024-10-29 13:30:41 +00:00
|
|
|
private let profileManager: ProfileManager
|
|
|
|
|
2024-11-01 08:47:50 +00:00
|
|
|
private let tunnel: ExtendedTunnel
|
2024-10-29 10:40:11 +00:00
|
|
|
|
2024-10-29 13:30:41 +00:00
|
|
|
private let registry: Registry
|
|
|
|
|
2024-11-24 00:01:04 +00:00
|
|
|
@State
|
|
|
|
private var paywallReason: PaywallReason?
|
|
|
|
|
|
|
|
@StateObject
|
|
|
|
private var errorHandler: ErrorHandler = .default()
|
|
|
|
|
2024-11-01 08:47:50 +00:00
|
|
|
public init(profileManager: ProfileManager, tunnel: ExtendedTunnel, registry: Registry) {
|
2024-10-29 13:30:41 +00:00
|
|
|
self.profileManager = profileManager
|
|
|
|
self.tunnel = tunnel
|
|
|
|
self.registry = registry
|
2024-10-29 10:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public var body: some View {
|
2024-11-02 07:41:32 +00:00
|
|
|
debugChanges()
|
2024-11-23 22:01:11 +00:00
|
|
|
return NavigationStack {
|
|
|
|
TabView {
|
|
|
|
profileView
|
|
|
|
.tabItem {
|
|
|
|
Text(Strings.Global.Nouns.profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
// searchView
|
|
|
|
// .tabItem {
|
|
|
|
// ThemeImage(.search)
|
|
|
|
// }
|
|
|
|
|
|
|
|
settingsView
|
|
|
|
.tabItem {
|
|
|
|
ThemeImage(.settings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationDestination(for: AppCoordinatorRoute.self, destination: pushDestination)
|
2024-11-24 00:01:04 +00:00
|
|
|
.modifier(PaywallModifier(reason: $paywallReason))
|
2024-11-24 19:01:30 +00:00
|
|
|
.withErrorHandler(errorHandler)
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
2024-10-29 10:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-02 07:41:32 +00:00
|
|
|
private extension AppCoordinator {
|
|
|
|
var profileView: some View {
|
2024-11-24 00:01:04 +00:00
|
|
|
ProfileView(
|
|
|
|
profileManager: profileManager,
|
|
|
|
tunnel: tunnel,
|
|
|
|
errorHandler: errorHandler,
|
|
|
|
flow: .init(
|
|
|
|
onProviderEntityRequired: onProviderEntityRequired,
|
|
|
|
onPurchaseRequired: onPurchaseRequired
|
|
|
|
)
|
|
|
|
)
|
2024-11-02 07:41:32 +00:00
|
|
|
}
|
2024-10-29 10:40:11 +00:00
|
|
|
|
2024-11-02 14:24:41 +00:00
|
|
|
// var searchView: some View {
|
|
|
|
// VStack {
|
|
|
|
// Text("Search")
|
|
|
|
// }
|
|
|
|
// }
|
2024-10-29 10:40:11 +00:00
|
|
|
|
2024-11-02 07:41:32 +00:00
|
|
|
var settingsView: some View {
|
2024-11-23 22:01:11 +00:00
|
|
|
SettingsView(tunnel: tunnel)
|
2024-10-29 10:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
2024-11-22 01:20:41 +00:00
|
|
|
|
2024-11-23 22:01:11 +00:00
|
|
|
private extension AppCoordinator {
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
func pushDestination(_ item: AppCoordinatorRoute?) -> some View {
|
|
|
|
switch item {
|
|
|
|
case .appLog:
|
|
|
|
DebugLogView(withAppParameters: Constants.shared.log) {
|
|
|
|
DebugLogContentView(lines: $0)
|
|
|
|
}
|
|
|
|
|
|
|
|
case .credits:
|
|
|
|
CreditsView()
|
|
|
|
.resized(width: 0.5)
|
|
|
|
.themeList()
|
|
|
|
|
|
|
|
case .donate:
|
|
|
|
DonateView(modifier: DonateViewModifier())
|
|
|
|
|
2024-11-25 18:17:18 +00:00
|
|
|
case .purchased:
|
|
|
|
PurchasedView()
|
|
|
|
.resized(width: 0.5)
|
|
|
|
.themeList()
|
|
|
|
|
2024-11-23 22:01:11 +00:00
|
|
|
case .tunnelLog:
|
|
|
|
DebugLogView(withTunnel: tunnel, parameters: Constants.shared.log) {
|
|
|
|
DebugLogContentView(lines: $0)
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-24 00:01:04 +00:00
|
|
|
private extension AppCoordinator {
|
|
|
|
func onProviderEntityRequired(_ profile: Profile) {
|
|
|
|
errorHandler.handle(
|
|
|
|
title: profile.name,
|
|
|
|
message: Strings.Alerts.Providers.MissingServer.message
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func onPurchaseRequired(_ features: Set<AppFeature>) {
|
2024-11-24 19:01:30 +00:00
|
|
|
paywallReason = .init(features, needsConfirmation: true)
|
2024-11-24 00:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-23 22:01:11 +00:00
|
|
|
// MARK: -
|
|
|
|
|
2024-11-22 01:20:41 +00:00
|
|
|
#Preview {
|
|
|
|
AppCoordinator(
|
|
|
|
profileManager: .mock,
|
|
|
|
tunnel: .mock,
|
|
|
|
registry: Registry()
|
|
|
|
)
|
|
|
|
.withMockEnvironment()
|
|
|
|
}
|