mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
models now handle authentication
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// AddFeedlyViewModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
class AddFeedlyViewModel: ObservableObject, OAuthAccountAuthorizationOperationDelegate {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didCreate account: Account) {
|
||||
|
||||
isAuthenticating = false
|
||||
|
||||
// macOS only: `ASWebAuthenticationSession` leaves the browser in the foreground.
|
||||
// Ensure the app is in the foreground so the user can see their Feedly account load.
|
||||
#if os(macOS)
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
#endif
|
||||
|
||||
account.refreshAll { [weak self] result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self?.accountUpdateError = .other(error: error)
|
||||
self?.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error) {
|
||||
isAuthenticating = false
|
||||
|
||||
// macOS only: `ASWebAuthenticationSession` leaves the browser in the foreground.
|
||||
// Ensure the app is in the foreground so the user can see the error.
|
||||
#if os(macOS)
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
#endif
|
||||
|
||||
accountUpdateError = .other(error: error)
|
||||
showError = true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user