Fix dashboard refresh
This commit is contained in:
@@ -74,29 +74,21 @@ public struct ActiveDashboardView: View {
|
||||
OverviewView($viewModel.profileList, $viewModel.selectedProfileID, $viewModel.systemProxyAvailable, $viewModel.systemProxyEnabled)
|
||||
#endif
|
||||
}
|
||||
.environmentObject(viewModel.dashboardClient)
|
||||
.onAppear {
|
||||
if ApplicationLibrary.inPreview || profile.status.isConnected {
|
||||
viewModel.dashboardClient.connect()
|
||||
if ApplicationLibrary.inPreview {
|
||||
environments.commandClient.connect()
|
||||
} else {
|
||||
environments.connect()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
viewModel.dashboardClient.disconnect()
|
||||
}
|
||||
.onChangeCompat(of: scenePhase) { newPhase in
|
||||
if newPhase == .active {
|
||||
if profile.status.isConnected {
|
||||
viewModel.dashboardClient.connect()
|
||||
}
|
||||
} else {
|
||||
viewModel.dashboardClient.disconnect()
|
||||
environments.connect()
|
||||
}
|
||||
}
|
||||
.onChangeCompat(of: profile.status) { newStatus in
|
||||
if newStatus.isConnected {
|
||||
viewModel.dashboardClient.connect()
|
||||
} else {
|
||||
viewModel.dashboardClient.disconnect()
|
||||
environments.connect()
|
||||
}
|
||||
}
|
||||
.onReceive(environments.profileUpdate) { _ in
|
||||
|
||||
@@ -12,7 +12,6 @@ final class ActiveDashboardViewModel: ObservableObject {
|
||||
@Published var selection = DashboardPage.overview
|
||||
@Published var systemProxyAvailable = false
|
||||
@Published var systemProxyEnabled = false
|
||||
@Published var dashboardClient = CommandClient([.status, .groups, .clashMode, .connections])
|
||||
|
||||
var onEmptyProfilesChange: ((Bool) -> Void)?
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public struct ClashModeView: View {
|
||||
@EnvironmentObject private var commandClient: CommandClient
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@StateObject private var viewModel = ClashModeViewModel()
|
||||
|
||||
public init() {}
|
||||
@@ -29,7 +29,7 @@ public struct ClashModeView: View {
|
||||
}
|
||||
.padding([.leading, .trailing])
|
||||
.onAppear {
|
||||
viewModel.setCommandClient(commandClient)
|
||||
viewModel.setCommandClient(environments.commandClient)
|
||||
}
|
||||
.alertBinding($viewModel.alert)
|
||||
}
|
||||
|
||||
@@ -32,13 +32,8 @@ class DashboardViewModel: ObservableObject {
|
||||
func handleStatusChange(_ status: NEVPNStatus, profile: ExtensionProfile) {
|
||||
if status == .connected {
|
||||
notStarted = false
|
||||
}
|
||||
if status == .disconnecting || status == .connected {
|
||||
Task {
|
||||
await checkServiceError()
|
||||
if status == .connected {
|
||||
await checkDeprecatedNotes()
|
||||
}
|
||||
await checkDeprecatedNotes()
|
||||
}
|
||||
} else if status == .connecting {
|
||||
notStarted = true
|
||||
@@ -107,17 +102,6 @@ class DashboardViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated func checkServiceError() async {
|
||||
var error: NSError?
|
||||
let message = LibboxReadServiceError(&error)
|
||||
if error != nil {
|
||||
return
|
||||
}
|
||||
await MainActor.run {
|
||||
alert = Alert(title: Text("Service Error"), message: Text(message!.value))
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 16.0, macOS 13.0, tvOS 17.0, *)
|
||||
nonisolated func checkLastDisconnectError(profile: ExtensionProfile) async {
|
||||
var myError: NSError
|
||||
|
||||
@@ -34,6 +34,7 @@ public struct OverviewView: View {
|
||||
VStack {
|
||||
if ApplicationLibrary.inPreview || profile.status.isConnected {
|
||||
ExtensionStatusView()
|
||||
.environmentObject(environments.commandClient)
|
||||
ClashModeView()
|
||||
}
|
||||
if profileList.isEmpty {
|
||||
|
||||
@@ -78,7 +78,7 @@ public struct StartStopButton: View {
|
||||
do {
|
||||
if isEnabled {
|
||||
try await profile.start()
|
||||
await environments.logClient.connect()
|
||||
await environments.commandClient.connect()
|
||||
} else {
|
||||
try await profile.stop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user