Merge pull request #2623 from stuartbreckenridge/swift-ui-target-fixes
Multiplatform Updates
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// AddAccountSignUp.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 06/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
#if os(iOS)
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
|
||||
/// Helper functions common to most account services.
|
||||
protocol AddAccountSignUp {
|
||||
func presentSignUpOption(_ accountType: AccountType)
|
||||
}
|
||||
|
||||
|
||||
extension AddAccountSignUp {
|
||||
func presentSignUpOption(_ accountType: AccountType) {
|
||||
#if os(macOS)
|
||||
switch accountType {
|
||||
case .bazQux:
|
||||
NSWorkspace.shared.open(URL(string: "https://bazqux.com")!)
|
||||
case .feedbin:
|
||||
NSWorkspace.shared.open(URL(string: "https://feedbin.com/signup")!)
|
||||
case .feedly:
|
||||
NSWorkspace.shared.open(URL(string: "https://feedly.com")!)
|
||||
case .feedWrangler:
|
||||
NSWorkspace.shared.open(URL(string: "https://feedwrangler.net/users/new")!)
|
||||
case .freshRSS:
|
||||
NSWorkspace.shared.open(URL(string: "https://freshrss.org")!)
|
||||
case .inoreader:
|
||||
NSWorkspace.shared.open(URL(string: "https://www.inoreader.com")!)
|
||||
case .newsBlur:
|
||||
NSWorkspace.shared.open(URL(string: "https://newsblur.com")!)
|
||||
case .theOldReader:
|
||||
NSWorkspace.shared.open(URL(string: "https://theoldreader.com")!)
|
||||
default:
|
||||
return
|
||||
}
|
||||
#else
|
||||
switch accountType {
|
||||
case .bazQux:
|
||||
UIApplication.shared.open(URL(string: "https://bazqux.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .feedbin:
|
||||
UIApplication.shared.open(URL(string: "https://feedbin.com/signup")!, options: [:], completionHandler: nil)
|
||||
case .feedly:
|
||||
UIApplication.shared.open(URL(string: "https://feedly.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .feedWrangler:
|
||||
UIApplication.shared.open(URL(string: "https://feedwrangler.net/users/new")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .freshRSS:
|
||||
UIApplication.shared.open(URL(string: "https://freshrss.org")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .inoreader:
|
||||
UIApplication.shared.open(URL(string: "https://www.inoreader.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .newsBlur:
|
||||
UIApplication.shared.open(URL(string: "https://newsblur.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
case .theOldReader:
|
||||
UIApplication.shared.open(URL(string: "https://theoldreader.com")!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : false], completionHandler: nil)
|
||||
default:
|
||||
return
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// AddFeedWranglerViewModel.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 AddFeedWranglerViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateFeedWrangler() {
|
||||
|
||||
isAuthenticating = true
|
||||
let credentials = Credentials(type: .feedWranglerBasic, username: username, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .feedWrangler, credentials: credentials) { result in
|
||||
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .feedWrangler)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .feedWranglerBasic)
|
||||
try account.removeCredentials(type: .feedWranglerToken)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// AddFeedbinViewModel.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 AddFeedbinViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateFeedbin() {
|
||||
isAuthenticating = true
|
||||
let credentials = Credentials(type: .basic, username: username, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .feedbin, credentials: credentials) { result in
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .feedbin)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .basic)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.isAuthenticating = false
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// 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, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
|
||||
func authenticateFeedly() {
|
||||
isAuthenticating = true
|
||||
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
|
||||
addAccount.delegate = self
|
||||
#if os(macOS)
|
||||
addAccount.presentationAnchor = NSApplication.shared.windows.last
|
||||
#else
|
||||
addAccount.presentationAnchor = UIApplication.shared.windows.last
|
||||
#endif
|
||||
MainThreadOperationQueue.shared.add(addAccount)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// AddNewsBlurViewModel.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 AddNewsBlurViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateNewsBlur() {
|
||||
isAuthenticating = true
|
||||
let credentials = Credentials(type: .newsBlurBasic, username: username, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .newsBlur, credentials: credentials) { result in
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .newsBlur)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .newsBlurBasic)
|
||||
try account.removeCredentials(type: .newsBlurSessionId)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// AddReaderAPIViewModel.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 AddReaderAPIViewModel: ObservableObject, AddAccountSignUp {
|
||||
@Published var isAuthenticating: Bool = false
|
||||
@Published var accountUpdateError: AccountUpdateErrors = .none
|
||||
@Published var showError: Bool = false
|
||||
@Published var username: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var apiUrl: String = ""
|
||||
@Published var canDismiss: Bool = false
|
||||
@Published var showPassword: Bool = false
|
||||
|
||||
func authenticateReaderAccount(_ accountType: AccountType) {
|
||||
isAuthenticating = true
|
||||
|
||||
let credentials = Credentials(type: .readerBasic, username: username, secret: password)
|
||||
|
||||
if accountType == .freshRSS {
|
||||
Account.validateCredentials(type: accountType, credentials: credentials, endpoint: URL(string: apiUrl)!) { result in
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .freshRSS)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .readerBasic)
|
||||
try account.removeCredentials(type: .readerAPIKey)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Account.validateCredentials(type: accountType, credentials: credentials) { result in
|
||||
|
||||
self.isAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.accountUpdateError = .invalidUsernamePassword
|
||||
self.showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .freshRSS)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .readerBasic)
|
||||
try account.removeCredentials(type: .readerAPIKey)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.canDismiss = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.accountUpdateError = .other(error: error)
|
||||
self.showError = true
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.accountUpdateError = .keyChainError
|
||||
self.showError = true
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.accountUpdateError = .networkError
|
||||
self.showError = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// AddCloudKitAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
|
||||
struct AddCloudKitAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
|
||||
var body: some View {
|
||||
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, footer: formFooter, content: {
|
||||
Button(action: {
|
||||
_ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(AccountManager.shared.activeAccounts.filter({ $0.type == .cloudKit }).count > 0)
|
||||
})
|
||||
}.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(AccountType.cloudKit.localizedAccountName()))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.cloudKit.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your iCloud account.")
|
||||
.font(.headline)
|
||||
|
||||
Text("This account syncs across your Mac and iOS devices using your iCloud account.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
_ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Create")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(AccountManager.shared.activeAccounts.filter({ $0.type == .cloudKit }).count > 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, maxHeight: 150)
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.cloudKit.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("This account syncs across your Mac and iOS devices using your iCloud account.").foregroundColor(.secondary)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
}
|
||||
|
||||
struct AddCloudKitAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddCloudKitAccountView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// AddFeedWranglerAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
|
||||
struct AddFeedWranglerAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedWranglerViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateFeedWrangler()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text("Feed Wrangler"))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedWrangler.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feed Wrangler account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don't have a Feed Wrangler account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedWrangler)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedWrangler()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.feedWrangler.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feed Wrangler account and sync your subscriptions across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don't have a Feed Wrangler account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedWrangler)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedWranglerAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedWranglerAccountView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
//
|
||||
// AddFeedbinAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 02/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddFeedbinAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedbinViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateFeedbin()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text("Feedbin"))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedbin.image()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feedbin account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don't have a Feedbin account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedbin)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedbin()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.feedbin.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feedbin account and sync your subscriptions across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don't have a Feedbin account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedbin)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedbinAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedbinAccountView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// AddFeedlyAccountView.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
|
||||
|
||||
struct AddFeedlyAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddFeedlyViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateFeedly()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
})
|
||||
})
|
||||
}.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(AccountType.feedly.localizedAccountName()))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.feedly.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your Feedly account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don't have a Feedly account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedly)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateFeedly()
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(AccountManager.shared.activeAccounts.filter({ $0.type == .cloudKit }).count > 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, maxHeight: 150)
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.feedly.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your Feedly account and sync your subscriptions across your devices. Your username and password will be encrypted and stored in Keychain.\n\nDon't have an Feedly account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.feedly)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedlyAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedlyAccountView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
//
|
||||
// AddLocalAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 02/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
struct AddLocalAccountView: View {
|
||||
|
||||
@State private var newAccountName: String = ""
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Account Name", text: $newAccountName)
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
let newAccount = AccountManager.shared.createAccount(type: .onMyMac)
|
||||
newAccount.name = newAccountName
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
})
|
||||
})
|
||||
}.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(AccountType.onMyMac.localizedAccountName()))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.onMyMac.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Create a local account on your Mac.")
|
||||
.font(.headline)
|
||||
Text("Local accounts store their data on your Mac. They do not sync across your devices.")
|
||||
.font(.callout)
|
||||
.foregroundColor(.secondary)
|
||||
HStack {
|
||||
Text("Name: ")
|
||||
TextField("Account Name", text: $newAccountName)
|
||||
}.padding(.top, 8)
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
let newAccount = AccountManager.shared.createAccount(type: .onMyMac)
|
||||
newAccount.name = newAccountName
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Create")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.defaultAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.onMyMac.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Local accounts do not sync your subscriptions across devices.").foregroundColor(.secondary)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddLocalAccount_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddLocalAccountView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// AddNewsBlurAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddNewsBlurAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddNewsBlurViewModel()
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateNewsBlur()
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text("NewsBlur"))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
AccountType.newsBlur.image()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your NewsBlur account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Text("Don't have a NewsBlur account?")
|
||||
.font(.callout)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.newsBlur)
|
||||
}, label: {
|
||||
Text("Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateNewsBlur()
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(model.username.isEmpty || model.password.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AccountType.newsBlur.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your NewsBlur account and sync your subscriptions across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don't have a NewsBlur account?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(.newsBlur)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
}
|
||||
|
||||
struct AddNewsBlurAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddNewsBlurAccountView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// AddReaderAPIAccountView.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 03/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Secrets
|
||||
|
||||
struct AddReaderAPIAccountView: View {
|
||||
|
||||
@Environment (\.presentationMode) var presentationMode
|
||||
@StateObject private var model = AddReaderAPIViewModel()
|
||||
public var accountType: AccountType
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
macBody
|
||||
#else
|
||||
NavigationView {
|
||||
iosBody
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var iosBody: some View {
|
||||
List {
|
||||
Section(header: formHeader, content: {
|
||||
TextField("Email", text: $model.username)
|
||||
if model.showPassword == false {
|
||||
ZStack {
|
||||
HStack {
|
||||
SecureField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZStack {
|
||||
HStack {
|
||||
TextField("Password", text: $model.password)
|
||||
Spacer()
|
||||
Image(systemName: "eye.slash.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.onTapGesture {
|
||||
model.showPassword = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if accountType == .freshRSS {
|
||||
TextField("API URL", text: $model.apiUrl)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Section(footer: formFooter, content: {
|
||||
Button(action: {
|
||||
model.authenticateReaderAccount(accountType)
|
||||
}, label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Add Account")
|
||||
Spacer()
|
||||
}
|
||||
}).disabled(createDisabled())
|
||||
})
|
||||
|
||||
}
|
||||
.navigationBarItems(leading:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
}))
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(Text(accountType.localizedAccountName()))
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
var macBody: some View {
|
||||
VStack {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading) {
|
||||
accountType.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
Spacer()
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Sign in to your \(accountType.localizedAccountName()) account.")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
if accountType == .freshRSS {
|
||||
Text("Don't have a \(accountType.localizedAccountName()) instance?")
|
||||
.font(.callout)
|
||||
} else {
|
||||
Text("Don't have an \(accountType.localizedAccountName()) account?")
|
||||
.font(.callout)
|
||||
}
|
||||
Button(action: {
|
||||
model.presentSignUpOption(accountType)
|
||||
}, label: {
|
||||
Text(accountType == .freshRSS ? "Find out more." : "Sign up here.").font(.callout)
|
||||
}).buttonStyle(LinkButtonStyle())
|
||||
}
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .trailing, spacing: 14) {
|
||||
Text("Email")
|
||||
Text("Password")
|
||||
if accountType == .freshRSS {
|
||||
Text("API URL")
|
||||
}
|
||||
}
|
||||
VStack(spacing: 8) {
|
||||
TextField("me@email.com", text: $model.username)
|
||||
SecureField("•••••••••••", text: $model.password)
|
||||
if accountType == .freshRSS {
|
||||
TextField("https://myfreshrss.rocks", text: $model.apiUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text("Your username and password will be encrypted and stored in Keychain.")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.callout)
|
||||
.lineLimit(2)
|
||||
.padding(.top, 4)
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 8) {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.scaleEffect(CGSize(width: 0.5, height: 0.5))
|
||||
.hidden(!model.isAuthenticating)
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 60)
|
||||
}).keyboardShortcut(.cancelAction)
|
||||
|
||||
Button(action: {
|
||||
model.authenticateReaderAccount(accountType)
|
||||
}, label: {
|
||||
Text("Sign In")
|
||||
.frame(width: 60)
|
||||
})
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(createDisabled())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(width: 400, height: height())
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.alert(isPresented: $model.showError, content: {
|
||||
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
|
||||
})
|
||||
.onReceive(model.$canDismiss, perform: { value in
|
||||
if value == true {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
func createDisabled() -> Bool {
|
||||
if accountType == .freshRSS {
|
||||
return model.username.isEmpty || model.password.isEmpty || !model.apiUrl.mayBeURL
|
||||
}
|
||||
return model.username.isEmpty || model.password.isEmpty
|
||||
}
|
||||
|
||||
func height() -> CGFloat {
|
||||
if accountType == .freshRSS {
|
||||
return 260
|
||||
}
|
||||
return 230
|
||||
}
|
||||
|
||||
var formHeader: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
accountType.image()
|
||||
.resizable()
|
||||
.frame(width: 50, height: 50)
|
||||
}
|
||||
Spacer()
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
var formFooter: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(spacing: 8) {
|
||||
Text("Sign in to your \(accountType.localizedAccountName()) account and sync your subscriptions across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
|
||||
Text("Don't have a \(accountType.localizedAccountName()) instance?").foregroundColor(.secondary)
|
||||
Button(action: {
|
||||
model.presentSignUpOption(accountType)
|
||||
}, label: {
|
||||
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
|
||||
})
|
||||
ProgressView().hidden(!model.isAuthenticating)
|
||||
}
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption2)
|
||||
Spacer()
|
||||
|
||||
}.padding(.vertical)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct AddReaderAPIAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddReaderAPIAccountView(accountType: .freshRSS)
|
||||
//AddReaderAPIAccountView(accountType: .inoreader)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Authentication.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 05/12/2020.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol AccountUpdater {
|
||||
var authenticationError: AccountUpdateErrors { get set }
|
||||
}
|
||||
@@ -18,40 +18,53 @@ struct AppAssets {
|
||||
}()
|
||||
#endif
|
||||
|
||||
static var accountBazQux: RSImage! = {
|
||||
return RSImage(named: "accountBazQux")
|
||||
}()
|
||||
|
||||
|
||||
static var accountLocalMacImage: RSImage! = {
|
||||
return RSImage(named: "AccountLocalMac")
|
||||
return RSImage(named: "accountLocalMac")
|
||||
}()
|
||||
|
||||
static var accountLocalPadImage: RSImage = {
|
||||
return RSImage(named: "AccountLocalPad")!
|
||||
return RSImage(named: "accountLocalPad")!
|
||||
}()
|
||||
|
||||
static var accountLocalPhoneImage: RSImage = {
|
||||
return RSImage(named: "AccountLocalPhone")!
|
||||
return RSImage(named: "accountLocalPhone")!
|
||||
}()
|
||||
|
||||
static var accountCloudKitImage: RSImage = {
|
||||
return RSImage(named: "AccountCloudKit")!
|
||||
return RSImage(named: "accountCloudKit")!
|
||||
}()
|
||||
|
||||
static var accountFeedbinImage: RSImage = {
|
||||
return RSImage(named: "AccountFeedbin")!
|
||||
return RSImage(named: "accountFeedbin")!
|
||||
}()
|
||||
|
||||
static var accountFeedlyImage: RSImage = {
|
||||
return RSImage(named: "AccountFeedly")!
|
||||
return RSImage(named: "accountFeedly")!
|
||||
}()
|
||||
|
||||
static var accountFeedWranglerImage: RSImage = {
|
||||
return RSImage(named: "AccountFeedWrangler")!
|
||||
return RSImage(named: "accountFeedWrangler")!
|
||||
}()
|
||||
|
||||
static var accountFreshRSSImage: RSImage = {
|
||||
return RSImage(named: "AccountFreshRSS")!
|
||||
return RSImage(named: "accountFreshRSS")!
|
||||
}()
|
||||
|
||||
static var accountInoreader: RSImage! = {
|
||||
return RSImage(named: "accountInoreader")
|
||||
}()
|
||||
|
||||
static var accountNewsBlurImage: RSImage = {
|
||||
return RSImage(named: "AccountNewsBlur")!
|
||||
return RSImage(named: "accountNewsBlur")!
|
||||
}()
|
||||
|
||||
static var accountTheOldReader: RSImage! = {
|
||||
return RSImage(named: "accountTheOldReader")
|
||||
}()
|
||||
|
||||
static var addMenuImage: Image = {
|
||||
@@ -325,6 +338,8 @@ struct AppAssets {
|
||||
return AppAssets.accountLocalPhoneImage
|
||||
}
|
||||
#endif
|
||||
case .bazQux:
|
||||
return AppAssets.accountBazQux
|
||||
case .cloudKit:
|
||||
return AppAssets.accountCloudKitImage
|
||||
case .feedbin:
|
||||
@@ -337,6 +352,11 @@ struct AppAssets {
|
||||
return AppAssets.accountFreshRSSImage
|
||||
case .newsBlur:
|
||||
return AppAssets.accountNewsBlurImage
|
||||
case .inoreader:
|
||||
return AppAssets.accountInoreader
|
||||
case .theOldReader:
|
||||
return AppAssets.accountTheOldReader
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icloud.pdf",
|
||||
"filename" : "icloud-any.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "icloud-dark.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -10,6 +20,6 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountCloudKit.imageset/icloud-any.pdf
vendored
Normal file
BIN
Multiplatform/Shared/Assets.xcassets/AccountCloudKit.imageset/icloud-dark.pdf
vendored
Normal file
@@ -1,8 +1,52 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "outline-512.png",
|
||||
"idiom" : "universal"
|
||||
"filename" : "feedwranger-any-slice.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "feedwranger-dark-slice.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "feedwranger-any-slice@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "feedwranger-dark-slice@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "feedwranger-any-slice@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "feedwranger-dark-slice@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
@@ -10,6 +54,6 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedWrangler.imageset/feedwranger-any-slice.png
vendored
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedWrangler.imageset/feedwranger-any-slice@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedWrangler.imageset/feedwranger-any-slice@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 153 KiB |
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedWrangler.imageset/feedwranger-dark-slice.png
vendored
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedWrangler.imageset/feedwranger-dark-slice@2x.png
vendored
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedWrangler.imageset/feedwranger-dark-slice@3x.png
vendored
Normal file
|
After Width: | Height: | Size: 153 KiB |
|
Before Width: | Height: | Size: 48 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "feedbin-logo.pdf",
|
||||
"filename" : "feedbin.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -11,6 +11,6 @@
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedbin.imageset/feedbin.pdf
vendored
Normal file
@@ -1,7 +1,17 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "accountFeedly.pdf",
|
||||
"filename" : "feedly-logo-any.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "feedly-logo-dark.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -10,6 +20,6 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedly.imageset/feedly-logo-any.pdf
vendored
Normal file
BIN
Multiplatform/Shared/Assets.xcassets/AccountFeedly.imageset/feedly-logo-dark.pdf
vendored
Normal file
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "accountFreshRSS.pdf",
|
||||
"filename" : "FreshRSS.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -10,6 +10,6 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountFreshRSS.imageset/FreshRSS.pdf
vendored
Normal file
@@ -1,7 +1,17 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "ipad.pdf",
|
||||
"filename" : "ipad-any-slice.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "ipad-dark-slice.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -11,6 +21,6 @@
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountLocalPad.imageset/ipad-any-slice.pdf
vendored
Normal file
BIN
Multiplatform/Shared/Assets.xcassets/AccountLocalPad.imageset/ipad-dark-slice.pdf
vendored
Normal file
@@ -1,7 +1,17 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "phone.pdf",
|
||||
"filename" : "iphone-any-slice.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "iphone-dark-slice.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -11,6 +21,6 @@
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountLocalPhone.imageset/iphone-any-slice.pdf
vendored
Normal file
BIN
Multiplatform/Shared/Assets.xcassets/AccountLocalPhone.imageset/iphone-dark-slice.pdf
vendored
Normal file
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "newsblur-512.png",
|
||||
"filename" : "Newsblur-any.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -10,6 +10,6 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/AccountNewsBlur.imageset/Newsblur-any.pdf
vendored
Normal file
|
Before Width: | Height: | Size: 53 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "mac.pdf",
|
||||
"filename" : "bazqux-any.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/accountBazQux.imageset/bazqux-any.pdf
vendored
Normal file
26
Multiplatform/Shared/Assets.xcassets/accountInoreader.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "inoreader_logo-any.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "inoreader_logo-dark.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/accountInoreader.imageset/inoreader_logo-any.pdf
vendored
Normal file
BIN
Multiplatform/Shared/Assets.xcassets/accountInoreader.imageset/inoreader_logo-dark.pdf
vendored
Normal file
25
Multiplatform/Shared/Assets.xcassets/accountLocal.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "localAccountLight.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "localAccountDark-1.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
25
Multiplatform/Shared/Assets.xcassets/accountLocalMac.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "localAccountLight.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "localAccountDark-1.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/accountLocalMac.imageset/localAccountLight.pdf
vendored
Normal file
26
Multiplatform/Shared/Assets.xcassets/accountTheOldReader.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "oldreader-icon-any.pdf",
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "oldreader-icon-dark.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "original"
|
||||
}
|
||||
}
|
||||
BIN
Multiplatform/Shared/Assets.xcassets/accountTheOldReader.imageset/oldreader-icon-any.pdf
vendored
Normal file
BIN
Multiplatform/Shared/Assets.xcassets/accountTheOldReader.imageset/oldreader-icon-dark.pdf
vendored
Normal file
@@ -27,15 +27,21 @@ struct SettingsAddAccountView: View {
|
||||
}
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.sheet(isPresented: $model.isAddPresented) {
|
||||
switch model.selectedAccountType {
|
||||
switch model.selectedAccountType! {
|
||||
case .onMyMac:
|
||||
SettingsLocalAccountView()
|
||||
case .feedbin, .feedWrangler, .newsBlur, .freshRSS:
|
||||
SettingsCredentialsAccountView(accountType: model.selectedAccountType!)
|
||||
AddLocalAccountView()
|
||||
case .feedbin:
|
||||
AddFeedbinAccountView()
|
||||
case .cloudKit:
|
||||
SettingsCloudKitAccountView()
|
||||
AddCloudKitAccountView()
|
||||
case .feedWrangler:
|
||||
AddFeedWranglerAccountView()
|
||||
case .newsBlur:
|
||||
AddNewsBlurAccountView()
|
||||
case .feedly:
|
||||
AddFeedlyAccountView()
|
||||
default:
|
||||
EmptyView()
|
||||
AddReaderAPIAccountView(accountType: model.selectedAccountType!)
|
||||
}
|
||||
}
|
||||
.navigationBarTitle(Text("Add Account"), displayMode: .inline)
|
||||
|
||||
@@ -10,12 +10,22 @@ import Foundation
|
||||
import Account
|
||||
import Combine
|
||||
|
||||
class AccountsPreferencesModel: ObservableObject {
|
||||
public enum AccountConfigurationSheets: Equatable {
|
||||
case addAccountPicker, addSelectedAccount(AccountType), credentials, none
|
||||
|
||||
enum AccountConfigurationSheets {
|
||||
case add, credentials, none
|
||||
public static func == (lhs: AccountConfigurationSheets, rhs: AccountConfigurationSheets) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case (let .addSelectedAccount(lhsType), let .addSelectedAccount(rhsType)):
|
||||
return lhsType == rhsType
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AccountsPreferencesModel: ObservableObject {
|
||||
|
||||
// Selected Account
|
||||
public private(set) var account: Account?
|
||||
|
||||
@@ -57,7 +67,7 @@ class AccountsPreferencesModel: ObservableObject {
|
||||
@Published var showSheet: Bool = false
|
||||
@Published var sheetToShow: AccountConfigurationSheets = .none {
|
||||
didSet {
|
||||
showSheet = sheetToShow != .none
|
||||
if sheetToShow == .none { showSheet = false } else { showSheet = true }
|
||||
}
|
||||
}
|
||||
@Published var showDeleteConfirmation: Bool = false
|
||||
|
||||
@@ -29,14 +29,29 @@ struct AccountsPreferencesView: View {
|
||||
onDismiss: { viewModel.sheetToShow = .none },
|
||||
content: {
|
||||
switch viewModel.sheetToShow {
|
||||
case .add:
|
||||
AddAccountView(preferencesModel: viewModel)
|
||||
.frame(width: 300, height: 200)
|
||||
.padding()
|
||||
case .addAccountPicker:
|
||||
AddAccountView(accountToAdd: $viewModel.sheetToShow)
|
||||
case .credentials:
|
||||
EditAccountCredentialsView(viewModel: viewModel)
|
||||
case .none:
|
||||
EmptyView()
|
||||
case .addSelectedAccount(let type):
|
||||
switch type {
|
||||
case .onMyMac:
|
||||
AddLocalAccountView()
|
||||
case .feedbin:
|
||||
AddFeedbinAccountView()
|
||||
case .cloudKit:
|
||||
AddCloudKitAccountView()
|
||||
case .feedWrangler:
|
||||
AddFeedWranglerAccountView()
|
||||
case .newsBlur:
|
||||
AddNewsBlurAccountView()
|
||||
case .feedly:
|
||||
AddFeedlyAccountView()
|
||||
default:
|
||||
AddReaderAPIAccountView(accountType: type)
|
||||
}
|
||||
}
|
||||
})
|
||||
.alert(isPresented: $viewModel.showDeleteConfirmation, content: {
|
||||
@@ -71,7 +86,7 @@ struct AccountsPreferencesView: View {
|
||||
Divider()
|
||||
HStack(alignment: .center, spacing: 4) {
|
||||
Button(action: {
|
||||
viewModel.sheetToShow = .add
|
||||
viewModel.sheetToShow = .addAccountPicker
|
||||
}, label: {
|
||||
Image(systemName: "plus")
|
||||
.font(.title)
|
||||
|
||||
@@ -1,307 +0,0 @@
|
||||
//
|
||||
// AddAccountModel.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 13/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
import RSWeb
|
||||
import Secrets
|
||||
import RSCore
|
||||
|
||||
class AddAccountModel: ObservableObject {
|
||||
|
||||
#if DEBUG
|
||||
let addableAccountTypes: [AccountType] = [.onMyMac, .feedbin, .feedly, .feedWrangler, .freshRSS, .cloudKit, .newsBlur]
|
||||
#else
|
||||
let addableAccountTypes: [AccountType] = [.onMyMac, .feedbin, .feedly]
|
||||
#endif
|
||||
|
||||
// Add Accounts
|
||||
@Published var selectedAddAccount: AccountType = .onMyMac
|
||||
@Published var userName: String = ""
|
||||
@Published var password: String = ""
|
||||
@Published var apiUrl: String = ""
|
||||
@Published var newLocalAccountName: String = ""
|
||||
@Published var accountIsAuthenticating: Bool = false
|
||||
@Published var addAccountError: AccountUpdateErrors = .none {
|
||||
didSet {
|
||||
if addAccountError == .none {
|
||||
showError = false
|
||||
} else {
|
||||
showError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@Published var showError: Bool = false
|
||||
@Published var accountAdded: Bool = false
|
||||
|
||||
func resetUserEntries() {
|
||||
userName = ""
|
||||
password = ""
|
||||
newLocalAccountName = ""
|
||||
apiUrl = ""
|
||||
}
|
||||
|
||||
func authenticateAccount() {
|
||||
switch selectedAddAccount {
|
||||
case .onMyMac:
|
||||
addLocalAccount()
|
||||
case .cloudKit:
|
||||
authenticateCloudKit()
|
||||
case .feedbin:
|
||||
authenticateFeedbin()
|
||||
case .feedWrangler:
|
||||
authenticateFeedWrangler()
|
||||
case .freshRSS:
|
||||
authenticateFreshRSS()
|
||||
case .feedly:
|
||||
authenticateFeedly()
|
||||
case .newsBlur:
|
||||
authenticateNewsBlur()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK:- Authentication APIs
|
||||
|
||||
extension AddAccountModel {
|
||||
|
||||
private func addLocalAccount() {
|
||||
let account = AccountManager.shared.createAccount(type: .onMyMac)
|
||||
account.name = newLocalAccountName
|
||||
accountAdded = true
|
||||
}
|
||||
|
||||
private func authenticateFeedbin() {
|
||||
accountIsAuthenticating = true
|
||||
let credentials = Credentials(type: .basic, username: userName, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .feedbin, credentials: credentials) { [weak self] result in
|
||||
|
||||
guard let self = self else { return }
|
||||
|
||||
self.accountIsAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.addAccountError = .invalidUsernamePassword
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .feedbin)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .basic)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.accountAdded = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.addAccountError = .other(error: error)
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.addAccountError = .keyChainError
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.addAccountError = .networkError
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func authenticateFeedWrangler() {
|
||||
|
||||
accountIsAuthenticating = true
|
||||
let credentials = Credentials(type: .feedWranglerBasic, username: userName, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .feedWrangler, credentials: credentials) { [weak self] result in
|
||||
|
||||
guard let self = self else { return }
|
||||
|
||||
self.accountIsAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.addAccountError = .invalidUsernamePassword
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .feedWrangler)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .feedWranglerBasic)
|
||||
try account.removeCredentials(type: .feedWranglerToken)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.accountAdded = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.addAccountError = .other(error: error)
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.addAccountError = .keyChainError
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.addAccountError = .networkError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func authenticateNewsBlur() {
|
||||
accountIsAuthenticating = true
|
||||
let credentials = Credentials(type: .newsBlurBasic, username: userName, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .newsBlur, credentials: credentials) { [weak self] result in
|
||||
|
||||
guard let self = self else { return }
|
||||
|
||||
self.accountIsAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.addAccountError = .invalidUsernamePassword
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .newsBlur)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .newsBlurBasic)
|
||||
try account.removeCredentials(type: .newsBlurSessionId)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.accountAdded = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.addAccountError = .other(error: error)
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.addAccountError = .keyChainError
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.addAccountError = .networkError
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func authenticateFreshRSS() {
|
||||
accountIsAuthenticating = true
|
||||
let credentials = Credentials(type: .readerBasic, username: userName, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .freshRSS, credentials: credentials, endpoint: URL(string: apiUrl)!) { [weak self] result in
|
||||
|
||||
guard let self = self else { return }
|
||||
|
||||
self.accountIsAuthenticating = false
|
||||
|
||||
switch result {
|
||||
case .success(let validatedCredentials):
|
||||
|
||||
guard let validatedCredentials = validatedCredentials else {
|
||||
self.addAccountError = .invalidUsernamePassword
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.createAccount(type: .freshRSS)
|
||||
|
||||
do {
|
||||
try account.removeCredentials(type: .readerBasic)
|
||||
try account.removeCredentials(type: .readerAPIKey)
|
||||
try account.storeCredentials(credentials)
|
||||
try account.storeCredentials(validatedCredentials)
|
||||
self.accountAdded = true
|
||||
account.refreshAll(completion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self.addAccountError = .other(error: error)
|
||||
}
|
||||
})
|
||||
|
||||
} catch {
|
||||
self.addAccountError = .keyChainError
|
||||
}
|
||||
|
||||
case .failure:
|
||||
self.addAccountError = .networkError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func authenticateCloudKit() {
|
||||
let _ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
self.accountAdded = true
|
||||
}
|
||||
|
||||
private func authenticateFeedly() {
|
||||
accountIsAuthenticating = true
|
||||
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
|
||||
addAccount.delegate = self
|
||||
addAccount.presentationAnchor = NSApplication.shared.windows.last
|
||||
MainThreadOperationQueue.shared.add(addAccount)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK:- OAuthAccountAuthorizationOperationDelegate
|
||||
extension AddAccountModel: OAuthAccountAuthorizationOperationDelegate {
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didCreate account: Account) {
|
||||
|
||||
accountIsAuthenticating = false
|
||||
accountAdded = true
|
||||
|
||||
// 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.
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
|
||||
account.refreshAll { [weak self] result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
self?.addAccountError = .other(error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error) {
|
||||
accountIsAuthenticating = false
|
||||
|
||||
// macOS only: `ASWebAuthenticationSession` leaves the browser in the foreground.
|
||||
// Ensure the app is in the foreground so the user can see the error.
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
|
||||
addAccountError = .other(error: error)
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// AddAccountPickerRow.swift
|
||||
// Multiplatform macOS
|
||||
//
|
||||
// Created by Stuart Breckenridge on 13/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
|
||||
struct AddAccountPickerRow: View {
|
||||
|
||||
var accountType: AccountType
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
// if let img = AppAssets.image(for: accountType) {
|
||||
// Image(rsImage: img)
|
||||
// .resizable()
|
||||
// .aspectRatio(contentMode: .fit)
|
||||
// .frame(width: 15, height: 15)
|
||||
// }
|
||||
|
||||
switch accountType {
|
||||
case .onMyMac:
|
||||
Text(Account.defaultLocalAccountName)
|
||||
case .cloudKit:
|
||||
Text("iCloud")
|
||||
case .feedbin:
|
||||
Text("Feedbin")
|
||||
case .feedWrangler:
|
||||
Text("FeedWrangler")
|
||||
case .freshRSS:
|
||||
Text("FreshRSS")
|
||||
case .feedly:
|
||||
Text("Feedly")
|
||||
case .newsBlur:
|
||||
Text("NewsBlur")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AddAccountPickerRow_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddAccountPickerRow(accountType: .onMyMac)
|
||||
}
|
||||
}
|
||||
@@ -1,150 +1,274 @@
|
||||
//
|
||||
// AddAccountView.swift
|
||||
// Multiplatform macOS
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 13/7/20.
|
||||
// Created by Stuart Breckenridge on 28/10/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
|
||||
enum AddAccountSections: Int, CaseIterable {
|
||||
case local = 0
|
||||
case icloud
|
||||
case web
|
||||
case selfhosted
|
||||
case allOrdered
|
||||
|
||||
var sectionHeader: String {
|
||||
switch self {
|
||||
case .local:
|
||||
return NSLocalizedString("Local", comment: "Local Account")
|
||||
case .icloud:
|
||||
return NSLocalizedString("iCloud", comment: "iCloud Account")
|
||||
case .web:
|
||||
return NSLocalizedString("Web", comment: "Web Account")
|
||||
case .selfhosted:
|
||||
return NSLocalizedString("Self-hosted", comment: "Self hosted Account")
|
||||
case .allOrdered:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
var sectionFooter: String {
|
||||
switch self {
|
||||
case .local:
|
||||
return NSLocalizedString("Local accounts do not sync subscriptions across devices.", comment: "Local Account")
|
||||
case .icloud:
|
||||
return NSLocalizedString("Use your iCloud account to sync your subscriptions across your iOS and macOS devices.", comment: "iCloud Account")
|
||||
case .web:
|
||||
return NSLocalizedString("Web accounts sync your subscriptions across all your devices.", comment: "Web Account")
|
||||
case .selfhosted:
|
||||
return NSLocalizedString("Self-hosted accounts sync your subscriptions across all your devices.", comment: "Self hosted Account")
|
||||
case .allOrdered:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
var sectionContent: [AccountType] {
|
||||
switch self {
|
||||
case .local:
|
||||
return [.onMyMac]
|
||||
case .icloud:
|
||||
return [.cloudKit]
|
||||
case .web:
|
||||
#if DEBUG
|
||||
return [.bazQux, .feedbin, .feedly, .feedWrangler, .inoreader, .newsBlur, .theOldReader]
|
||||
#else
|
||||
return [.bazQux, .feedbin, .feedly, .feedWrangler, .inoreader, .newsBlur, .theOldReader]
|
||||
#endif
|
||||
case .selfhosted:
|
||||
return [.freshRSS]
|
||||
case .allOrdered:
|
||||
return AddAccountSections.local.sectionContent +
|
||||
AddAccountSections.icloud.sectionContent +
|
||||
AddAccountSections.web.sectionContent +
|
||||
AddAccountSections.selfhosted.sectionContent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AddAccountView: View {
|
||||
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
@ObservedObject var preferencesModel: AccountsPreferencesModel
|
||||
@StateObject private var viewModel = AddAccountModel()
|
||||
|
||||
@State private var selectedAccount: AccountType = .onMyMac
|
||||
@Binding public var accountToAdd: AccountConfigurationSheets
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Choose an account type to add...")
|
||||
.font(.headline)
|
||||
.padding()
|
||||
|
||||
Form {
|
||||
Text("Add an Account").font(.headline)
|
||||
localAccount
|
||||
icloudAccount
|
||||
webAccounts
|
||||
selfhostedAccounts
|
||||
|
||||
Picker("Account Type",
|
||||
selection: $viewModel.selectedAddAccount,
|
||||
content: {
|
||||
ForEach(0..<viewModel.addableAccountTypes.count, content: { i in
|
||||
AddAccountPickerRow(accountType: viewModel.addableAccountTypes[i]).tag(viewModel.addableAccountTypes[i])
|
||||
})
|
||||
}).pickerStyle(MenuPickerStyle())
|
||||
|
||||
switch viewModel.selectedAddAccount {
|
||||
case .onMyMac:
|
||||
addLocalAccountView
|
||||
case .cloudKit:
|
||||
iCloudAccountView
|
||||
case .feedbin:
|
||||
userNameAndPasswordView
|
||||
case .feedWrangler:
|
||||
userNameAndPasswordView
|
||||
case .freshRSS:
|
||||
userNamePasswordAndAPIUrlView
|
||||
case .feedly:
|
||||
oAuthView
|
||||
case .newsBlur:
|
||||
userNameAndPasswordView
|
||||
}
|
||||
|
||||
Spacer()
|
||||
HStack {
|
||||
if viewModel.accountIsAuthenticating {
|
||||
ProgressView("Adding Account")
|
||||
}
|
||||
HStack(spacing: 12) {
|
||||
Spacer()
|
||||
Button(action: { presentationMode.wrappedValue.dismiss() }, label: {
|
||||
Text("Cancel")
|
||||
})
|
||||
|
||||
switch viewModel.selectedAddAccount {
|
||||
case .onMyMac:
|
||||
Button("Add Account", action: {
|
||||
viewModel.authenticateAccount()
|
||||
if #available(OSX 11.0, *) {
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 80)
|
||||
})
|
||||
.help("Cancel")
|
||||
.keyboardShortcut(.cancelAction)
|
||||
|
||||
} else {
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.frame(width: 80)
|
||||
})
|
||||
.accessibility(label: Text("Add Account"))
|
||||
}
|
||||
if #available(OSX 11.0, *) {
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
|
||||
accountToAdd = AccountConfigurationSheets.addSelectedAccount(selectedAccount)
|
||||
})
|
||||
case .feedly:
|
||||
Button("Authenticate", action: {
|
||||
viewModel.authenticateAccount()
|
||||
})
|
||||
case .cloudKit:
|
||||
Button("Add Account", action: {
|
||||
viewModel.authenticateAccount()
|
||||
})
|
||||
case .freshRSS:
|
||||
Button("Add Account", action: {
|
||||
viewModel.authenticateAccount()
|
||||
})
|
||||
.disabled(viewModel.userName.count == 0 || viewModel.password.count == 0 || viewModel.apiUrl.count == 0)
|
||||
default:
|
||||
Button("Add Account", action: {
|
||||
viewModel.authenticateAccount()
|
||||
})
|
||||
.disabled(viewModel.userName.count == 0 || viewModel.password.count == 0)
|
||||
}, label: {
|
||||
Text("Continue")
|
||||
.frame(width: 80)
|
||||
})
|
||||
.help("Add Account")
|
||||
.keyboardShortcut(.defaultAction)
|
||||
|
||||
} else {
|
||||
Button(action: {
|
||||
accountToAdd = AccountConfigurationSheets.addSelectedAccount(selectedAccount)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
|
||||
}, label: {
|
||||
Text("Continue")
|
||||
.frame(width: 80)
|
||||
})
|
||||
}
|
||||
}
|
||||
.padding(.top, 12)
|
||||
.padding(.bottom, 4)
|
||||
}
|
||||
.pickerStyle(RadioGroupPickerStyle())
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.frame(width: 420)
|
||||
.padding()
|
||||
}
|
||||
|
||||
var localAccount: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Local")
|
||||
.font(.headline)
|
||||
.padding(.horizontal)
|
||||
|
||||
Picker(selection: $selectedAccount, label: Text(""), content: {
|
||||
ForEach(AddAccountSections.local.sectionContent, id: \.self, content: { account in
|
||||
HStack(alignment: .center) {
|
||||
account.image()
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 25, height: 25, alignment: .center)
|
||||
.padding(.leading, 4)
|
||||
Text(account.localizedAccountName())
|
||||
}
|
||||
.tag(account)
|
||||
})
|
||||
})
|
||||
.pickerStyle(RadioGroupPickerStyle())
|
||||
.offset(x: 7.5, y: 0)
|
||||
|
||||
Text(AddAccountSections.local.sectionFooter).foregroundColor(.gray)
|
||||
.font(.caption)
|
||||
.padding(.horizontal)
|
||||
|
||||
.onChange(of: viewModel.selectedAddAccount) { _ in
|
||||
viewModel.resetUserEntries()
|
||||
}
|
||||
.onChange(of: viewModel.accountAdded) { value in
|
||||
if value == true {
|
||||
preferencesModel.showAddAccountView = false
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $viewModel.showError) {
|
||||
Alert(title: Text("Error Adding Account"),
|
||||
message: Text(viewModel.addAccountError.description),
|
||||
dismissButton: .default(Text("Dismiss"),
|
||||
action: {
|
||||
viewModel.addAccountError = .none
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
var icloudAccount: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text("iCloud")
|
||||
.font(.headline)
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 8)
|
||||
|
||||
Picker(selection: $selectedAccount, label: Text(""), content: {
|
||||
ForEach(AddAccountSections.icloud.sectionContent, id: \.self, content: { account in
|
||||
HStack(alignment: .center) {
|
||||
account.image()
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 25, height: 25, alignment: .center)
|
||||
.padding(.leading, 4)
|
||||
|
||||
Text(account.localizedAccountName())
|
||||
}
|
||||
.tag(account)
|
||||
})
|
||||
})
|
||||
.offset(x: 7.5, y: 0)
|
||||
.disabled(isCloudInUse())
|
||||
|
||||
Text(AddAccountSections.icloud.sectionFooter).foregroundColor(.gray)
|
||||
.font(.caption)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var addLocalAccountView: some View {
|
||||
Group {
|
||||
TextField("Account Name", text: $viewModel.newLocalAccountName)
|
||||
Text("This account stores all of its data on your device. It does not sync.")
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.leading)
|
||||
}.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
var webAccounts: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Web")
|
||||
.font(.headline)
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 8)
|
||||
|
||||
Picker(selection: $selectedAccount, label: Text(""), content: {
|
||||
ForEach(AddAccountSections.web.sectionContent, id: \.self, content: { account in
|
||||
|
||||
HStack(alignment: .center) {
|
||||
account.image()
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 25, height: 25, alignment: .center)
|
||||
.padding(.leading, 4)
|
||||
|
||||
Text(account.localizedAccountName())
|
||||
}
|
||||
.tag(account)
|
||||
|
||||
})
|
||||
})
|
||||
.offset(x: 7.5, y: 0)
|
||||
|
||||
Text(AddAccountSections.web.sectionFooter).foregroundColor(.gray)
|
||||
.font(.caption)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
|
||||
var iCloudAccountView: some View {
|
||||
Group {
|
||||
Text("This account syncs across your devices using your iCloud account.")
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.leading)
|
||||
}.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
var selfhostedAccounts: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Self-hosted")
|
||||
.font(.headline)
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 8)
|
||||
|
||||
Picker(selection: $selectedAccount, label: Text(""), content: {
|
||||
ForEach(AddAccountSections.selfhosted.sectionContent, id: \.self, content: { account in
|
||||
HStack(alignment: .center) {
|
||||
account.image()
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 25, height: 25, alignment: .center)
|
||||
.padding(.leading, 4)
|
||||
|
||||
Text(account.localizedAccountName())
|
||||
}.tag(account)
|
||||
})
|
||||
})
|
||||
.offset(x: 7.5, y: 0)
|
||||
|
||||
Text(AddAccountSections.selfhosted.sectionFooter).foregroundColor(.gray)
|
||||
.font(.caption)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
|
||||
var userNameAndPasswordView: some View {
|
||||
Group {
|
||||
TextField("Email", text: $viewModel.userName)
|
||||
SecureField("Password", text: $viewModel.password)
|
||||
}.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
private func isCloudInUse() -> Bool {
|
||||
AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit })
|
||||
}
|
||||
|
||||
var userNamePasswordAndAPIUrlView: some View {
|
||||
Group {
|
||||
TextField("Email", text: $viewModel.userName)
|
||||
SecureField("Password", text: $viewModel.password)
|
||||
TextField("API URL", text: $viewModel.apiUrl)
|
||||
}.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}
|
||||
|
||||
var oAuthView: some View {
|
||||
Group {
|
||||
Text("Click Authenticate")
|
||||
}.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
struct AddAccountView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddAccountView(preferencesModel: AccountsPreferencesModel())
|
||||
private func isRestricted(_ accountType: AccountType) -> Bool {
|
||||
if AppDefaults.shared.isDeveloperBuild && (accountType == .feedly || accountType == .feedWrangler || accountType == .inoreader) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,9 +42,15 @@ class EditAccountCredentialsModel: ObservableObject {
|
||||
case .feedly:
|
||||
updateFeedly(account)
|
||||
case .freshRSS:
|
||||
updateFreshRSS(account)
|
||||
updateReaderAccount(account)
|
||||
case .newsBlur:
|
||||
updateNewsblur(account)
|
||||
case .inoreader:
|
||||
updateReaderAccount(account)
|
||||
case .bazQux:
|
||||
updateReaderAccount(account)
|
||||
case .theOldReader:
|
||||
updateReaderAccount(account)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,11 +174,11 @@ extension EditAccountCredentialsModel {
|
||||
MainThreadOperationQueue.shared.add(updateAccount)
|
||||
}
|
||||
|
||||
func updateFreshRSS(_ account: Account) {
|
||||
func updateReaderAccount(_ account: Account) {
|
||||
accountIsUpdatingCredentials = true
|
||||
let credentials = Credentials(type: .readerBasic, username: userName, secret: password)
|
||||
|
||||
Account.validateCredentials(type: .freshRSS, credentials: credentials) { [weak self] result in
|
||||
Account.validateCredentials(type: account.type, credentials: credentials) { [weak self] result in
|
||||
|
||||
guard let self = self else { return }
|
||||
|
||||
|
||||