mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add error handling to Mac app
This commit is contained in:
parent
15f84b04c0
commit
a43bd801a8
@ -115,6 +115,7 @@ struct WriteFreely_MultiPlatformApp: App {
|
|||||||
}
|
}
|
||||||
.tag(2)
|
.tag(2)
|
||||||
}
|
}
|
||||||
|
.withErrorHandling()
|
||||||
.frame(minWidth: 500, maxWidth: 500, minHeight: 200)
|
.frame(minWidth: 500, maxWidth: 500, minHeight: 200)
|
||||||
.padding()
|
.padding()
|
||||||
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
||||||
|
@ -2,6 +2,7 @@ import SwiftUI
|
|||||||
|
|
||||||
struct PostEditorView: View {
|
struct PostEditorView: View {
|
||||||
@EnvironmentObject var model: WriteFreelyModel
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
|
@EnvironmentObject var errorHandling: ErrorHandling
|
||||||
|
|
||||||
@ObservedObject var post: WFAPost
|
@ObservedObject var post: WFAPost
|
||||||
@State private var isHovering: Bool = false
|
@State private var isHovering: Bool = false
|
||||||
@ -38,6 +39,16 @@ struct PostEditorView: View {
|
|||||||
LocalStorageManager.standard.saveContext()
|
LocalStorageManager.standard.saveContext()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.onChange(of: model.hasError) { value in
|
||||||
|
if value {
|
||||||
|
if let error = model.currentError {
|
||||||
|
self.errorHandling.handle(error: error)
|
||||||
|
} else {
|
||||||
|
self.errorHandling.handle(error: AppError.genericError())
|
||||||
|
}
|
||||||
|
model.hasError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
.onDisappear(perform: {
|
.onDisappear(perform: {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
model.editor.clearLastDraft()
|
model.editor.clearLastDraft()
|
||||||
|
@ -2,11 +2,22 @@ import SwiftUI
|
|||||||
|
|
||||||
struct MacAccountView: View {
|
struct MacAccountView: View {
|
||||||
@EnvironmentObject var model: WriteFreelyModel
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
|
@EnvironmentObject var errorHandling: ErrorHandling
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
AccountView()
|
AccountView()
|
||||||
|
}
|
||||||
|
.onChange(of: model.hasError) { value in
|
||||||
|
if value {
|
||||||
|
if let error = model.currentError {
|
||||||
|
self.errorHandling.handle(error: error)
|
||||||
|
} else {
|
||||||
|
self.errorHandling.handle(error: AppError.genericError())
|
||||||
|
}
|
||||||
|
model.hasError = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct MacPreferencesView: View {
|
struct MacPreferencesView: View {
|
||||||
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
|
@EnvironmentObject var errorHandling: ErrorHandling
|
||||||
|
|
||||||
@ObservedObject var preferences: PreferencesModel
|
@ObservedObject var preferences: PreferencesModel
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -8,6 +11,16 @@ struct MacPreferencesView: View {
|
|||||||
PreferencesView(preferences: preferences)
|
PreferencesView(preferences: preferences)
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
.onChange(of: model.hasError) { value in
|
||||||
|
if value {
|
||||||
|
if let error = model.currentError {
|
||||||
|
self.errorHandling.handle(error: error)
|
||||||
|
} else {
|
||||||
|
self.errorHandling.handle(error: AppError.genericError())
|
||||||
|
}
|
||||||
|
model.hasError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ import SwiftUI
|
|||||||
import Sparkle
|
import Sparkle
|
||||||
|
|
||||||
struct MacUpdatesView: View {
|
struct MacUpdatesView: View {
|
||||||
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
|
@EnvironmentObject var errorHandling: ErrorHandling
|
||||||
|
|
||||||
@ObservedObject var updaterViewModel: MacUpdatesViewModel
|
@ObservedObject var updaterViewModel: MacUpdatesViewModel
|
||||||
|
|
||||||
@AppStorage(WFDefaults.automaticallyChecksForUpdates, store: UserDefaults.shared)
|
@AppStorage(WFDefaults.automaticallyChecksForUpdates, store: UserDefaults.shared)
|
||||||
@ -81,6 +84,16 @@ that can cause crashes and data loss.
|
|||||||
.onChange(of: subscribeToBetaUpdates) { _ in
|
.onChange(of: subscribeToBetaUpdates) { _ in
|
||||||
updaterViewModel.toggleAllowedChannels()
|
updaterViewModel.toggleAllowedChannels()
|
||||||
}
|
}
|
||||||
|
.onChange(of: model.hasError) { value in
|
||||||
|
if value {
|
||||||
|
if let error = model.currentError {
|
||||||
|
self.errorHandling.handle(error: error)
|
||||||
|
} else {
|
||||||
|
self.errorHandling.handle(error: AppError.genericError())
|
||||||
|
}
|
||||||
|
model.hasError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user