refactor: improve alert error context and copy action
This commit is contained in:
@@ -204,7 +204,7 @@ public struct CoreView: View {
|
||||
try await environments.extensionProfile!.stop()
|
||||
await destroyWorkingDirectory()
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "stop service before destroying working directory", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public struct CoreView: View {
|
||||
#endif
|
||||
isLoading = true
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "destroy working directory", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public struct CoreView: View {
|
||||
try await manager.signalEnumerator(for: .workingSet)
|
||||
} catch {
|
||||
await MainActor.run {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "notify Files app about working directory changes", error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public struct CoreView: View {
|
||||
}
|
||||
} catch {
|
||||
await MainActor.run {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "open working directory in Files", error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,14 +109,14 @@ public struct AppView: View {
|
||||
try HelperServiceManager.registerRootHelper()
|
||||
refreshHelperStatus()
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "update helper service", error: error)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label("Update", systemImage: "arrow.down.doc.fill")
|
||||
}
|
||||
FormButton(role: .destructive) {
|
||||
performHelperAction {
|
||||
performHelperAction(actionName: "uninstall helper service") {
|
||||
try HelperServiceManager.unregisterRootHelper()
|
||||
}
|
||||
} label: {
|
||||
@@ -130,7 +130,7 @@ public struct AppView: View {
|
||||
}
|
||||
} else {
|
||||
FormButton {
|
||||
performHelperAction {
|
||||
performHelperAction(actionName: "install helper service") {
|
||||
try HelperServiceManager.registerRootHelper()
|
||||
}
|
||||
} label: {
|
||||
@@ -210,7 +210,7 @@ public struct AppView: View {
|
||||
try SMAppService.mainApp.unregister()
|
||||
}
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "update login items", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ public struct AppView: View {
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "update system extension", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,16 +252,16 @@ public struct AppView: View {
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "uninstall system extension", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func performHelperAction(_ action: () throws -> Void) {
|
||||
private func performHelperAction(actionName: String, _ action: () throws -> Void) {
|
||||
do {
|
||||
try action()
|
||||
refreshHelperStatus()
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: actionName, error: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ public struct OnDemandRulesView: View {
|
||||
await updateService()
|
||||
isLoading = true
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "reset on-demand rules", error: error)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
@@ -289,7 +289,7 @@ public struct OnDemandRulesView: View {
|
||||
let enabled = mode != .disabled
|
||||
try await profile.updateOnDemand(enabled: enabled, useDefaultRules: mode == .alwaysOn)
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "update on-demand rules", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ struct PacketTunnelView: View {
|
||||
do {
|
||||
try await profile.restart()
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "restart service", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public struct ProfileOverrideView: View {
|
||||
do {
|
||||
try await profile.reloadService()
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
alert = AlertState(action: "reload service", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user