refactor: Fix macOS standalone application
This commit is contained in:
@@ -1,6 +1,26 @@
|
||||
import Library
|
||||
import SwiftUI
|
||||
|
||||
#if os(macOS)
|
||||
private struct SettingsNavigationPathKey: EnvironmentKey {
|
||||
static let defaultValue: Binding<NavigationPath>? = nil
|
||||
}
|
||||
|
||||
public extension EnvironmentValues {
|
||||
var settingsNavigationPath: Binding<NavigationPath>? {
|
||||
get { self[SettingsNavigationPathKey.self] }
|
||||
set { self[SettingsNavigationPathKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
public enum SettingsPage: Hashable {
|
||||
case app
|
||||
case core, packetTunnel, onDemandRules, profileOverride, sponsors
|
||||
}
|
||||
#endif
|
||||
|
||||
public struct SettingView: View {
|
||||
private enum Tabs: Int, CaseIterable, Identifiable {
|
||||
var id: Self {
|
||||
@@ -13,6 +33,25 @@ public struct SettingView: View {
|
||||
|
||||
case core, packetTunnel, onDemandRules, profileOverride, sponsors
|
||||
|
||||
#if os(macOS)
|
||||
var page: SettingsPage {
|
||||
switch self {
|
||||
case .app:
|
||||
return .app
|
||||
case .core:
|
||||
return .core
|
||||
case .packetTunnel:
|
||||
return .packetTunnel
|
||||
case .onDemandRules:
|
||||
return .onDemandRules
|
||||
case .profileOverride:
|
||||
return .profileOverride
|
||||
case .sponsors:
|
||||
return .sponsors
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
var label: some View {
|
||||
Label(title, systemImage: iconImage)
|
||||
}
|
||||
@@ -83,16 +122,45 @@ public struct SettingView: View {
|
||||
|
||||
@MainActor
|
||||
var navigationLink: some View {
|
||||
FormNavigationLink {
|
||||
contentView
|
||||
} label: {
|
||||
label
|
||||
}
|
||||
#if os(macOS)
|
||||
FormNavigationLink(value: page) {
|
||||
label
|
||||
}
|
||||
#else
|
||||
FormNavigationLink {
|
||||
contentView
|
||||
} label: {
|
||||
label
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@StateObject private var viewModel = SettingViewModel()
|
||||
#if os(macOS)
|
||||
@MainActor
|
||||
@ViewBuilder
|
||||
private static func destinationView(for page: SettingsPage) -> some View {
|
||||
Group {
|
||||
switch page {
|
||||
case .app:
|
||||
AppView()
|
||||
case .core:
|
||||
CoreView()
|
||||
case .packetTunnel:
|
||||
PacketTunnelView()
|
||||
case .onDemandRules:
|
||||
OnDemandRulesView()
|
||||
case .profileOverride:
|
||||
ProfileOverrideView()
|
||||
case .sponsors:
|
||||
SponsorsView()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
}
|
||||
#endif
|
||||
|
||||
@StateObject private var viewModel = SettingViewModel()
|
||||
public init() {}
|
||||
public var body: some View {
|
||||
FormView {
|
||||
@@ -159,5 +227,10 @@ public struct SettingView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
#if os(macOS)
|
||||
.formNavigationDestination(for: SettingsPage.self) { page in
|
||||
Self.destinationView(for: page)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user