Adds Error Display for the handle(_: URL) function

Additionally, shortens validation code in AddAccount
This commit is contained in:
Stuart Breckenridge
2022-12-21 21:01:58 +08:00
parent 12b17e3f36
commit 7dc5845f4e
3 changed files with 12 additions and 15 deletions

View File

@@ -60,21 +60,12 @@ struct NewsBlurAddAccountView: View, Logging {
func retreiveCredentials() {
if let account = account {
do {
let credentials = try account.retrieveCredentials(type: .newsBlurBasic)
if let credentials = credentials {
self.accountUserName = credentials.username
self.accountPassword = credentials.secret
} else {
print("No cred")
}
} catch {
print(error.localizedDescription)
let credentials = try? account.retrieveCredentials(type: .newsBlurBasic)
if let credentials = credentials {
self.accountUserName = credentials.username
self.accountPassword = credentials.secret
}
} else {
print("No account")
}
}
var accountDetails: some View {

View File

@@ -26,6 +26,11 @@ struct EnableExtensionPointView: View {
}, message: {
Text(extensionError.0?.localizedDescription ?? "Unknown Error")
})
.alert(Text("Error", comment: "Alert title: Error"), isPresented: $viewModel.showExtensionError.1, actions: {
Button(action: {}, label: { Text("Dismiss", comment: "Button title") })
}, message: {
Text(viewModel.showExtensionError.0?.localizedDescription ?? "Unknown Error")
})
.navigationTitle(extensionPoint.title)
.navigationBarTitleDisplayMode(.inline)
.dismissOnExternalContextLaunch()

View File

@@ -13,9 +13,10 @@ import OAuthSwift
import Secrets
import RSCore
@MainActor
public final class EnableExtensionViewModel: NSObject, ObservableObject, OAuthSwiftURLHandlerType, ASWebAuthenticationPresentationContextProviding, Logging {
@Published public var showExtensionError: (Error?, Bool) = (nil, false)
private var extensionPointType: ExtensionPoint.Type?
private var oauth: OAuthSwift?
private var callbackURL: URL? = nil
@@ -146,7 +147,7 @@ public final class EnableExtensionViewModel: NSObject, ObservableObject, OAuthSw
if case ASWebAuthenticationSessionError.canceledLogin = error {
print("Login cancelled.")
} else {
//self.presentError(error)
self.showExtensionError = (error, true)
}
})