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
@@ -7,24 +7,24 @@ open class BaseViewModel: ObservableObject {
public init() {}
public func showError(_ error: Error) {
alert = AlertState(error: error)
public func showError(_ error: Error, action: String) {
alert = AlertState(action: action, error: error)
}
public func execute(_ operation: () async throws -> Void) async {
public func execute(_ operation: () async throws -> Void, action: String) async {
do {
try await operation()
} catch {
alert = AlertState(error: error)
alert = AlertState(action: action, error: error)
}
}
public func executeOnBackground(_ operation: @escaping @Sendable () async throws -> Void) async {
public func executeOnBackground(_ operation: @escaping @Sendable () async throws -> Void, action: String) async {
do {
try await operation()
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: action, error: error)
}
}
}
@@ -105,7 +105,7 @@ public struct GlobalChecksModifier: ViewModifier {
try await profile.importProfile()
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "import profile", error: error)
}
return
}
@@ -174,7 +174,7 @@ public struct GlobalChecksModifier: ViewModifier {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "check deprecated notes", error: error)
}
}
}
@@ -86,7 +86,7 @@ public struct ShareButtonCompat<Label: View>: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "prepare share file", error: error)
}
}
}
@@ -117,7 +117,7 @@ public struct ShareButtonCompat<Label: View>: View {
}
} catch {
await MainActor.run {
alert = AlertState(error: error)
alert = AlertState(action: "prepare share file", error: error)
}
}
}