Add profile sharing

This commit is contained in:
世界
2023-07-30 14:13:57 +08:00
parent 27ffee06e2
commit 2ca6c515b9
25 changed files with 675 additions and 123 deletions
+22 -5
View File
@@ -10,8 +10,9 @@ public struct MainView: View {
@State private var extensionProfile: ExtensionProfile?
@State private var profileLoading = true
@State private var logClient: LogClient!
@State private var alert: Alert?
@State private var importProfile: LibboxProfileContent?
@State private var importRemoteProfile: LibboxImportRemoteProfile?
@State private var alert: Alert?
public init() {}
public var body: some View {
@@ -48,23 +49,25 @@ public struct MainView: View {
StartStopButton()
}
}
.onChange(of: controlActiveState, perform: { newValue in
.onChangeComat(of: controlActiveState) { newValue in
if newValue != .inactive {
Task {
await loadProfile()
connectLog()
}
}
})
.onChange(of: selection, perform: { value in
}
.onChangeCompat(of: selection) { value in
if value == .logs {
connectLog()
}
})
}
.formStyle(.grouped)
.environment(\.selection, $selection)
.environment(\.extensionProfile, $extensionProfile)
.environment(\.logClient, $logClient)
.environment(\.importProfile, $importProfile)
.environment(\.importRemoteProfile, $importRemoteProfile)
.handlesExternalEvents(preferring: [], allowing: ["*"])
.onOpenURL(perform: openURL)
@@ -80,6 +83,20 @@ public struct MainView: View {
if selection != .profiles {
selection = .profiles
}
} else if url.pathExtension == "bpf" {
do {
_ = url.startAccessingSecurityScopedResource()
importProfile = try .from(Data(contentsOf: url))
url.stopAccessingSecurityScopedResource()
} catch {
alert = Alert(error)
return
}
if selection != .profiles {
selection = .profiles
}
} else {
alert = Alert(errorMessage: "Handled unknown URL \(url.absoluteString)")
}
}
+1 -1
View File
@@ -137,7 +137,7 @@ public struct MenuView: View {
}
}
.pickerStyle(.inline)
.onChange(of: selectedProfileID) { _ in
.onChangeCompat(of: selectedProfileID) {
reasserting = true
Task.detached {
await switchProfile(selectedProfileID!)
+1 -1
View File
@@ -26,7 +26,7 @@ public struct SidebarView: View {
it.visible(extensionProfile)
}, selection: selection) { it in
it.label
}.onChange(of: extensionProfile.status) { _ in
}.onChangeCompat(of: extensionProfile.status) {
if !selection.wrappedValue.visible(extensionProfile) {
selection.wrappedValue = NavigationPage.dashboard
}