Refactor Alerts

This commit is contained in:
世界
2025-12-01 18:22:06 +08:00
parent 8e764c56eb
commit 4ddfcdb324
40 changed files with 324 additions and 224 deletions
+7 -7
View File
@@ -72,7 +72,7 @@ public struct MenuView: View {
private struct StatusSwitch: View {
@ObservedObject private var profile: ExtensionProfile
@State private var alert: Alert?
@State private var alert: AlertState?
init(_ profile: ExtensionProfile) {
self.profile = profile
@@ -88,7 +88,7 @@ public struct MenuView: View {
})) {}
.toggleStyle(.switch)
.disabled(!profile.status.isEnabled)
.alertBinding($alert)
.alert($alert)
}
private func switchProfile(_ isEnabled: Bool) async {
@@ -99,7 +99,7 @@ public struct MenuView: View {
try await profile.stop()
}
} catch {
alert = Alert(error)
alert = AlertState(error: error)
return
}
}
@@ -117,7 +117,7 @@ public struct MenuView: View {
@State private var profileList: [ProfilePreview] = []
@State private var selectedProfileID: Int64 = 0
@State private var reasserting = false
@State private var alert: Alert?
@State private var alert: AlertState?
private var selectedProfileIDLocal: Binding<Int64> {
$selectedProfileID.withSetter { newValue in
@@ -161,7 +161,7 @@ public struct MenuView: View {
selectedProfileID = await SharedPreferences.selectedProfileID.get()
}
}
.alertBinding($alert)
.alert($alert)
}
private func doReload() async {
@@ -171,7 +171,7 @@ public struct MenuView: View {
do {
profileList = try await ProfileManager.list().map { ProfilePreview($0) }
} catch {
alert = Alert(error)
alert = AlertState(error: error)
return
}
if profileList.isEmpty {
@@ -194,7 +194,7 @@ public struct MenuView: View {
do {
try await serviceReload()
} catch {
alert = Alert(error)
alert = AlertState(error: error)
}
}
reasserting = false