refactor: improve alert error context and copy action

This commit is contained in:
世界
2026-02-08 18:25:55 +08:00
parent a86dfc26d1
commit 8897e6deeb
32 changed files with 125 additions and 82 deletions
@@ -195,7 +195,7 @@ public struct ClashModeCard: View {
try LibboxNewStandaloneCommandClient()!.setClashMode(newMode)
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "set clash mode", error: error)
}
}
}
@@ -134,7 +134,7 @@ public struct ProfileCard: View {
) { result in
viewModel.exportDocument = nil
if case let .failure(error) = result {
viewModel.alert = AlertState(error: error)
viewModel.alert = AlertState(action: "export profile", error: error)
}
}
#endif
@@ -371,7 +371,7 @@ public struct ProfileCard: View {
)
#endif
} catch {
viewModel.alert = AlertState(error: error)
viewModel.alert = AlertState(action: "share profile", error: error)
}
}
}
@@ -394,7 +394,7 @@ public struct ProfileCard: View {
}
} catch {
await MainActor.run {
viewModel.alert = AlertState(error: error)
viewModel.alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -427,7 +427,7 @@ public struct ProfileCard: View {
do {
viewModel.qrsShareData = try await profile.origin.encodedContentDataAsync()
} catch {
viewModel.alert = AlertState(error: error)
viewModel.alert = AlertState(action: "prepare QRS share", error: error)
viewModel.showQRSShare = false
}
}
@@ -536,7 +536,7 @@ extension ProfileCard {
try await profile.updateRemoteProfile()
environments.profileUpdate.send()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "update remote profile", error: error)
}
}
}
@@ -402,7 +402,7 @@ struct ProfilePickerSheet: View {
try await profile.origin.updateRemoteProfile()
environments.profileUpdate.send()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "update remote profile", error: error)
}
}
@@ -742,7 +742,7 @@ private struct ProfilePickerRow: View {
) { result in
exportDocument = nil
if case let .failure(error) = result {
alert = AlertState(error: error)
alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -789,7 +789,7 @@ private struct ProfilePickerRow: View {
) { result in
exportDocument = nil
if case let .failure(error) = result {
alert = AlertState(error: error)
alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -919,7 +919,7 @@ private struct ProfilePickerRow: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "prepare QRS share", error: error)
showQRSShare = false
}
}
@@ -1015,7 +1015,7 @@ private struct ProfilePickerRow: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -1067,7 +1067,7 @@ private struct ProfilePickerRow: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "share profile", error: error)
}
}
}
@@ -1091,7 +1091,7 @@ private struct ProfilePickerRow: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -1282,7 +1282,7 @@ private struct ProfilePickerRow: View {
) { result in
exportDocument = nil
if case let .failure(error) = result {
alert = AlertState(error: error)
alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -1336,7 +1336,7 @@ private struct ProfilePickerRow: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "prepare QRS share", error: error)
showQRSShare = false
}
}
@@ -1405,7 +1405,7 @@ private struct ProfilePickerRow: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "export profile", error: error)
}
}
}
@@ -26,7 +26,7 @@ public struct InstallProfileButton: View {
try await ExtensionProfile.install()
await callback()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "install network extension", error: error)
}
}
}
@@ -31,7 +31,7 @@
}
await callback()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "install system extension", error: error)
}
}
}
@@ -165,7 +165,8 @@ public struct StartStopButton: View {
} catch {
await MainActor.run {
isStarting = false
alert = AlertState(error: error)
let action = isEnabled ? "start service" : "stop service"
alert = AlertState(action: action, error: error)
}
}
}
@@ -69,7 +69,7 @@ public final class DashboardViewModel: BaseViewModel {
await SharedPreferences.selectedProfileID.set(selectedProfileID)
}
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "load profile list", error: error)
return
}
}
@@ -109,7 +109,7 @@ extension ExtensionProfile {
)
}
#endif
return AlertState(error: nsError)
return AlertState(action: "fetch last disconnect error", error: nsError)
}
}
@@ -15,7 +15,7 @@ public final class OverviewViewModel: BaseViewModel {
do {
try await profile.reloadService()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "reload service", error: error)
}
}
reasserting = false
@@ -32,7 +32,7 @@ public final class OverviewViewModel: BaseViewModel {
await MainActor.run { reasserting = false }
}
} catch {
await MainActor.run { alert = AlertState(error: error) }
await MainActor.run { alert = AlertState(action: "update system proxy settings", error: error) }
}
}
}