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
@@ -9,7 +9,7 @@ public class MainViewModel: ObservableObject {
@Published public var selection = NavigationPage.dashboard
@Published public var importProfile: LibboxProfileContent?
@Published public var importRemoteProfile: LibboxImportRemoteProfile?
@Published public var alert: Alert?
@Published public var alert: AlertState?
public init() {}
@@ -53,7 +53,7 @@ public class MainViewModel: ObservableObject {
await importURLProfile(url)
}
} else {
alert = Alert(errorMessage: String(localized: "Handled unknown URL \(url.absoluteString)"))
alert = AlertState(errorMessage: String(localized: "Handled unknown URL \(url.absoluteString)"))
}
}
@@ -63,7 +63,7 @@ public class MainViewModel: ObservableObject {
importProfile = try await .from(readURL(url))
url.stopAccessingSecurityScopedResource()
} catch {
alert = Alert(error)
alert = AlertState(error: error)
return
}
if selection != .dashboard {
@@ -78,10 +78,10 @@ public class MainViewModel: ObservableObject {
private func checkApplicationPath() {
let directoryName = URL(filePath: Bundle.main.bundlePath).deletingLastPathComponent().pathComponents.last
if directoryName != "Applications" {
alert = Alert(
title: Text("Wrong application location"),
message: Text("This app needs to be placed under the Applications folder to work."),
dismissButton: .default(Text("Ok")) {
alert = AlertState(
title: String(localized: "Wrong application location"),
message: String(localized: "This app needs to be placed under the Applications folder to work."),
dismissButton: .default(String(localized: "Ok")) {
NSWorkspace.shared.selectFile(Bundle.main.bundlePath, inFileViewerRootedAtPath: "")
NSApp.terminate(nil)
}