Prepare system extension support

This commit is contained in:
世界
2023-07-24 20:08:02 +08:00
parent 8a5c1a80d1
commit 12bf02070e
44 changed files with 1469 additions and 382 deletions
@@ -1,12 +1,60 @@
import Library
import SwiftUI
public struct DashboardView: View {
@Environment(\.extensionProfile) private var extensionProfile
#if os(macOS)
@Environment(\.controlActiveState) private var controlActiveState
@State private var isLoading = true
@State private var systemExtensionInstalled = true
#endif
public init() {}
public var body: some View {
viewBuilder {
#if os(macOS)
if Variant.useSystemExtension {
viewBuilder {
if !systemExtensionInstalled {
FormView {
InstallSystemExtensionButton(reload)
}
} else {
DashboardView0()
}
}.onAppear(perform: reload)
} else {
DashboardView0()
}
#else
DashboardView0()
#endif
}
#if os(macOS)
.onChange(of: controlActiveState, perform: { newValue in
if newValue != .inactive {
if Variant.useSystemExtension {
if !isLoading {
reload()
}
}
}
})
#endif
.navigationTitle("Dashboard")
}
#if os(macOS)
private func reload() {
Task {
systemExtensionInstalled = await SystemExtension.isInstalled()
isLoading = false
}
}
#endif
struct DashboardView0: View {
@Environment(\.extensionProfile) private var extensionProfile
var body: some View {
if ApplicationLibrary.inPreview {
ActiveDashboardView()
} else if let profile = extensionProfile.wrappedValue {
@@ -16,6 +64,6 @@ public struct DashboardView: View {
InstallProfileButton()
}
}
}.navigationTitle("Dashboard")
}
}
}