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
@@ -85,7 +85,7 @@ public final class EditProfileContentViewModel: BaseViewModel {
do {
try await loadContentBackground()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "load profile content", error: error)
}
isLoading = false
}
@@ -111,7 +111,7 @@ public final class EditProfileContentViewModel: BaseViewModel {
do {
try await saveContentBackground(profile)
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "save profile content", error: error)
return
}
isChanged = false
@@ -21,7 +21,7 @@ public final class EditProfileViewModel: BaseViewModel {
try await profile.updateRemoteProfile()
environments.profileUpdate.send()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "update remote profile", error: error)
}
}
@@ -29,7 +29,7 @@ public final class EditProfileViewModel: BaseViewModel {
do {
try await ProfileManager.delete(profile)
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "delete profile", error: error)
return
}
environments.profileUpdate.send()
@@ -46,7 +46,7 @@ public final class EditProfileViewModel: BaseViewModel {
#endif
try await profile.onProfileUpdated()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "save profile", error: error)
return
}
isChanged = false
@@ -38,7 +38,7 @@
case let .failed(error):
DispatchQueue.main.async { [self] in
reset()
alert = AlertState(error: error)
alert = AlertState(action: "connect to import source", error: error)
}
default: break
}
@@ -47,7 +47,7 @@
do {
try await loopMessages(environments: environments)
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "import profile from device", error: error)
reset()
}
}
@@ -121,7 +121,7 @@
try await socket.write(request.encode())
} catch {
isImporting = false
alert = AlertState(error: error)
alert = AlertState(action: "request profile content from device", error: error)
reset()
}
}
@@ -223,14 +223,14 @@ public struct NewProfileMenuView: View {
environments.profileUpdate.send()
dismiss()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "import profile", error: error)
}
}
},
secondaryButton: .cancel()
)
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "read imported profile file", error: error)
}
}
}
@@ -250,7 +250,7 @@ public struct NewProfileMenuView: View {
var error: NSError?
let remoteProfile = LibboxParseRemoteProfileImportLink(string, &error)
if let error {
alert = AlertState(error: error)
alert = AlertState(action: "parse QR code profile link", error: error)
return
}
guard let remoteProfile else {
@@ -274,14 +274,14 @@ public struct NewProfileMenuView: View {
environments.profileUpdate.send()
dismiss()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "import profile", error: error)
}
}
},
secondaryButton: .cancel()
)
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "decode QRS profile data", error: error)
}
}
#endif
@@ -185,7 +185,7 @@ public struct NewProfileView: View {
viewModel.fileURL = urls[0]
}
} catch {
viewModel.alert = AlertState(error: error)
viewModel.alert = AlertState(action: "read imported profile file", error: error)
return
}
}
@@ -213,7 +213,7 @@ public struct NewProfileView: View {
viewModel.fileURL = urls[0]
}
} catch {
viewModel.alert = AlertState(error: error)
viewModel.alert = AlertState(action: "read imported profile file", error: error)
return
}
}
@@ -72,7 +72,7 @@ public final class NewProfileViewModel: BaseViewModel {
do {
createdProfile = try await createProfileBackground()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: "create profile", error: error)
return
}