Rename Account.type to Account.accountType.

This commit is contained in:
Brent Simmons 2024-06-09 22:53:19 -07:00
parent 96fefbc800
commit c1f6026495
16 changed files with 35 additions and 32 deletions

View File

@ -17,7 +17,7 @@ import ParserObjC
import Database
import ArticlesDatabase
import Web
import os.log
import os
import Secrets
import Core
import CommonErrors
@ -95,7 +95,7 @@ public enum FetchType {
return defaultName
}()
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "account")
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Account")
public var isDeleted = false
@ -107,7 +107,7 @@ public enum FetchType {
return self
}
public let accountID: String
public let type: AccountType
public let accountType: AccountType
public var nameForDisplay: String {
guard let name = name, !name.isEmpty else {
return defaultName
@ -295,7 +295,7 @@ public enum FetchType {
self.delegate.accountMetadata = metadata
self.accountID = accountID
self.type = type
self.accountType = type
self.dataFolder = dataFolder
let databasePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3")
@ -751,6 +751,9 @@ public enum FetchType {
public func structureDidChange() {
// Feeds were added or deleted. Or folders added or deleted.
// Or feeds inside folders were added or deleted.
logger.info("structureDidChange in account \(self.accountID)")
Task { @MainActor in
opmlFile.markAsDirty()
flattenedFeedsNeedUpdate = true
@ -762,7 +765,7 @@ public enum FetchType {
func update(feed: Feed, with parsedFeed: ParsedFeed) async throws -> ArticleChanges {
precondition(Thread.isMainThread)
precondition(type == .onMyMac || type == .cloudKit)
precondition(accountType == .onMyMac || accountType == .cloudKit)
feed.takeSettings(from: parsedFeed)
@ -777,7 +780,7 @@ public enum FetchType {
func update(feedID: String, with parsedItems: Set<ParsedItem>, deleteOlder: Bool = true) async throws -> ArticleChanges {
precondition(Thread.isMainThread)
precondition(type == .onMyMac || type == .cloudKit)
precondition(accountType == .onMyMac || accountType == .cloudKit)
let articleChanges = try await database.update(parsedItems: parsedItems, feedID: feedID, deleteOlder: deleteOlder)
self.sendNotificationAbout(articleChanges)
@ -787,8 +790,8 @@ public enum FetchType {
func update(feedIDsAndItems: [String: Set<ParsedItem>], defaultRead: Bool) async throws {
precondition(Thread.isMainThread)
precondition(type != .onMyMac && type != .cloudKit)
precondition(accountType != .onMyMac && accountType != .cloudKit)
guard !feedIDsAndItems.isEmpty else {
return
}

View File

@ -176,7 +176,7 @@ import Secrets
return false
}
for account in accounts {
if account.type == type && username == account.username {
if account.accountType == type && username == account.username {
return true
}
}
@ -414,7 +414,7 @@ private extension AccountManager {
}
func duplicateServiceAccount(_ account: Account) -> Bool {
return duplicateServiceAccount(type: account.type, username: account.username)
return duplicateServiceAccount(type: account.accountType, username: account.username)
}
func sortByName(_ accounts: [Account]) -> [Account] {

View File

@ -24,7 +24,7 @@ import Core
continue
}
if restrictToSpecialAccounts && !(account.type == .onMyMac || account.type == .cloudKit) {
if restrictToSpecialAccounts && !(account.accountType == .onMyMac || account.accountType == .cloudKit) {
continue
}

View File

@ -207,7 +207,7 @@ extension Feed: PasteboardWriterOwner {
private extension FeedPasteboardWriter {
var pasteboardFeed: PasteboardFeed {
return PasteboardFeed(url: feed.url, feedID: feed.feedID, homePageURL: feed.homePageURL, name: feed.name, editedName: feed.editedName, accountID: feed.account?.accountID, accountType: feed.account?.type)
return PasteboardFeed(url: feed.url, feedID: feed.feedID, homePageURL: feed.homePageURL, name: feed.name, editedName: feed.editedName, accountID: feed.account?.accountID, accountType: feed.account?.accountType)
}
var exportDictionary: PasteboardFeedDictionary {

View File

@ -32,7 +32,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
guard let account = account else {
return true
}
switch account.type {
switch account.accountType {
case .onMyMac, .cloudKit, .feedly:
return true
default:
@ -66,7 +66,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
guard let account else { return }
switch account.type {
switch account.accountType {
case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
@ -76,7 +76,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
case .inoreader, .bazQux, .theOldReader, .freshRSS:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsReaderAPIWindowController.accountType = account.type
accountsReaderAPIWindowController.accountType = account.accountType
accountsReaderAPIWindowController.account = account
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsReaderAPIWindowController

View File

@ -118,7 +118,7 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
cell.textField?.stringValue = account.nameForDisplay
cell.imageView?.image = account.smallIcon?.image
if account.type == .feedbin {
if account.accountType == .feedbin {
cell.isImageTemplateCapable = false
}

View File

@ -22,7 +22,7 @@ struct AddAccountHelpView: View {
ForEach(accountTypes, id: \.self) { accountType in
if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) {
Button(action: {
if accountType == .cloudKit && AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) {
if accountType == .cloudKit && AccountManager.shared.accounts.contains(where: { $0.accountType == .cloudKit }) {
iCloudUnavailableError = true
} else {
delegate?.presentSheetForAccount(accountType)

View File

@ -260,7 +260,7 @@ struct AddAccountsView: View {
}
@MainActor private func isCloudInUse() -> Bool {
AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit })
AccountManager.shared.accounts.contains(where: { $0.accountType == .cloudKit })
}
private func chunkedWebAccounts() -> [[AccountType]] {

View File

@ -156,7 +156,7 @@ import Core
@objc(accountType)
var accountType:OSType {
var osType:String = ""
switch self.account.type {
switch self.account.accountType {
case .onMyMac:
osType = "Locl"
case .cloudKit:

View File

@ -18,7 +18,7 @@ protocol SmallIconProvider {
extension Account: SmallIconProvider {
var smallIcon: IconImage? {
if let image = AppAssets.image(for: type) {
if let image = AppAssets.image(for: accountType) {
return IconImage(image)
}
return nil

View File

@ -58,7 +58,7 @@ struct ExtensionContainers: Codable {
init(account: Account) {
self.name = account.nameForDisplay
self.accountID = account.accountID
self.type = account.type
self.type = account.accountType
self.disallowFeedInRootFolder = account.behaviors.contains(.disallowFeedInRootFolder)
self.containerID = account.containerID
self.folders = account.sortedFolders?.map { ExtensionFolder(folder: $0) } ?? [ExtensionFolder]()

View File

@ -30,7 +30,7 @@ final class AddFeedFolderViewController: UITableViewController {
if addFeedType == .web {
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts
} else {
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts.filter { $0.type == .onMyMac || $0.type == .cloudKit }
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts.filter { $0.accountType == .onMyMac || $0.accountType == .cloudKit }
}
for account in sortedActiveAccounts {

View File

@ -32,8 +32,8 @@ class AccountInspectorViewController: UITableViewController {
navigationItem.title = account.nameForDisplay
if account.type != .onMyMac {
deleteAccountButton.setTitle(NSLocalizedString("Remove Account", comment: "Remove Account"), for: .normal)
if account.accountType != .onMyMac {
deleteAccountButton.setTitle(NSLocalizedString("Remove Account", comment: "Remove Account"), for: .normal)
}
if isModal {
@ -56,7 +56,7 @@ class AccountInspectorViewController: UITableViewController {
@IBAction func credentials(_ sender: Any) {
guard let account = account else { return }
switch account.type {
switch account.accountType {
case .feedbin:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "FeedbinAccountNavigationViewController") as! UINavigationController
let addViewController = navController.topViewController as! FeedbinAccountViewController
@ -72,7 +72,7 @@ class AccountInspectorViewController: UITableViewController {
case .inoreader, .bazQux, .theOldReader, .freshRSS:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "ReaderAPIAccountNavigationViewController") as! UINavigationController
let addViewController = navController.topViewController as! ReaderAPIAccountViewController
addViewController.accountType = account.type
addViewController.accountType = account.accountType
addViewController.account = account
navController.modalPresentationStyle = .currentContext
present(navController, animated: true)
@ -88,7 +88,7 @@ class AccountInspectorViewController: UITableViewController {
let title = NSLocalizedString("Remove Account", comment: "Remove Account")
let message: String = {
switch account.type {
switch account.accountType {
case .feedly:
return NSLocalizedString("Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again.", comment: "Log Out and Remove Account")
default:
@ -125,7 +125,7 @@ extension AccountInspectorViewController {
guard let account = account else {
return true
}
switch account.type {
switch account.accountType {
case .onMyMac, .cloudKit, .feedly:
return true
default:
@ -154,7 +154,7 @@ extension AccountInspectorViewController {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: account.type)
headerView.imageView.image = AppAssets.image(for: account.accountType)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)

View File

@ -137,7 +137,7 @@ final class AddAccountViewController: UITableViewController, AddAccountDismissDe
case AddAccountSections.icloud.rawValue:
cell.comboNameLabel?.text = AddAccountSections.icloud.sectionContent[indexPath.row].localizedAccountName()
cell.comboImage?.image = AppAssets.image(for: AddAccountSections.icloud.sectionContent[indexPath.row])
if AppDefaults.shared.isDeveloperBuild || AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) {
if AppDefaults.shared.isDeveloperBuild || AccountManager.shared.accounts.contains(where: { $0.accountType == .cloudKit }) {
cell.isUserInteractionEnabled = false
cell.comboNameLabel?.isEnabled = false
}

View File

@ -146,7 +146,7 @@ final class SettingsViewController: UITableViewController {
let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsComboTableViewCell", for: indexPath) as! SettingsComboTableViewCell
acctCell.applyThemeProperties()
let account = sortedAccounts[indexPath.row]
acctCell.comboImage?.image = AppAssets.image(for: account.type)
acctCell.comboImage?.image = AppAssets.image(for: account.accountType)
acctCell.comboNameLabel?.text = account.nameForDisplay
cell = acctCell
}

View File

@ -60,7 +60,7 @@ private extension UIViewController {
let title = NSLocalizedString("Account Error", comment: "Account Error")
let alertController = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert)
if error.account?.type == .feedbin {
if error.account?.accountType == .feedbin {
let credentialsTitle = NSLocalizedString("Update Credentials", comment: "Update Credentials")
let credentialsAction = UIAlertAction(title: credentialsTitle, style: .default) { [weak self] _ in