Disable start button if profiles is empty on macOS

This commit is contained in:
世界
2024-02-21 14:14:39 +08:00
parent e9d55c6125
commit be67111425
5 changed files with 8 additions and 2 deletions
@@ -120,8 +120,10 @@ public struct ActiveDashboardView: View {
} catch { } catch {
alert = Alert(error) alert = Alert(error)
return
} }
} }
environments.emptyProfiles = profileList.isEmpty
} }
private nonisolated func doReloadSystemProxy() async { private nonisolated func doReloadSystemProxy() async {
@@ -36,6 +36,7 @@ public struct StartStopButton: View {
#endif #endif
} }
} }
.disabled(environments.emptyProfiles)
} }
private struct Button0: View { private struct Button0: View {
@@ -207,6 +207,7 @@ public struct ProfileView: View {
return return
} }
} }
environments.emptyProfiles = profileList.isEmpty
} }
private func updateProfile(_ profile: Profile) async { private func updateProfile(_ profile: Profile) async {
@@ -254,6 +255,7 @@ public struct ProfileView: View {
profileList[index].origin profileList[index].origin
} }
profileList.remove(atOffsets: profileIndex) profileList.remove(atOffsets: profileIndex)
environments.emptyProfiles = profileList.isEmpty
Task { Task {
do { do {
_ = try await ProfileManager.delete(profileToDelete) _ = try await ProfileManager.delete(profileToDelete)
@@ -5,6 +5,7 @@ public class ExtensionEnvironments: ObservableObject {
@Published public var logClient = CommandClient(.log) @Published public var logClient = CommandClient(.log)
@Published public var extensionProfileLoading = true @Published public var extensionProfileLoading = true
@Published public var extensionProfile: ExtensionProfile? @Published public var extensionProfile: ExtensionProfile?
@Published public var emptyProfiles = false
public let profileUpdate = ObjectWillChangePublisher() public let profileUpdate = ObjectWillChangePublisher()
public let selectedProfileUpdate = ObjectWillChangePublisher() public let selectedProfileUpdate = ObjectWillChangePublisher()
+2 -2
View File
@@ -77,11 +77,11 @@ open class ExtensionProvider: NEPacketTunnelProvider {
do { do {
profile = try await ProfileManager.get(Int64(SharedPreferences.selectedProfileID.get())) profile = try await ProfileManager.get(Int64(SharedPreferences.selectedProfileID.get()))
} catch { } catch {
writeFatalError("(packet-tunnel) error: missing default profile: \(error.localizedDescription)") writeFatalError("(packet-tunnel) error: read selected profile: \(error.localizedDescription)")
return return
} }
guard let profile else { guard let profile else {
writeFatalError("(packet-tunnel) error: missing default profile") writeFatalError("(packet-tunnel) error: missing selected profile")
return return
} }
let configContent: String let configContent: String