mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 08:42:51 +00:00
Clean whitespace-only lines.
This commit is contained in:
1 parent
9827300a9a
commit
9efde554d4
452 files changed
+5354
-5354
No files matched your search
@@ -9,16 +9,16 @@
|
||||
import Intents
|
||||
|
||||
public enum AddWebFeedIntentHandlerError: LocalizedError {
|
||||
|
||||
|
||||
case communicationFailure
|
||||
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .communicationFailure:
|
||||
return NSLocalizedString("Unable to communicate with NetNewsWire.", comment: "Communication failure")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
@@ -26,7 +26,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
public func resolveUrl(for intent: AddWebFeedIntent, with completion: @escaping (AddWebFeedUrlResolutionResult) -> Void) {
|
||||
guard let url = intent.url else {
|
||||
completion(.unsupported(forReason: .required))
|
||||
@@ -34,7 +34,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
}
|
||||
completion(.success(with: url))
|
||||
}
|
||||
|
||||
|
||||
public func provideAccountNameOptions(for intent: AddWebFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) {
|
||||
guard let extensionContainers = ExtensionContainersFile.read() else {
|
||||
completion(nil, AddWebFeedIntentHandlerError.communicationFailure)
|
||||
@@ -44,7 +44,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
let accountNames = extensionContainers.accounts.map { $0.name }
|
||||
completion(accountNames, nil)
|
||||
}
|
||||
|
||||
|
||||
public func resolveAccountName(for intent: AddWebFeedIntent, with completion: @escaping (AddWebFeedAccountNameResolutionResult) -> Void) {
|
||||
guard let accountName = intent.accountName else {
|
||||
completion(AddWebFeedAccountNameResolutionResult.notRequired())
|
||||
@@ -62,7 +62,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
completion(.success(with: accountName))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func provideFolderNameOptions(for intent: AddWebFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) {
|
||||
guard let extensionContainers = ExtensionContainersFile.read() else {
|
||||
completion(nil, AddWebFeedIntentHandlerError.communicationFailure)
|
||||
@@ -77,13 +77,13 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
let folderNames = account.folders.map { $0.name }
|
||||
completion(folderNames, nil)
|
||||
}
|
||||
|
||||
|
||||
public func resolveFolderName(for intent: AddWebFeedIntent, with completion: @escaping (AddWebFeedFolderNameResolutionResult) -> Void) {
|
||||
guard let accountName = intent.accountName, let folderName = intent.folderName else {
|
||||
completion(AddWebFeedFolderNameResolutionResult.notRequired())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard let extensionContainers = ExtensionContainersFile.read() else {
|
||||
completion(.unsupported(forReason: .communication))
|
||||
return
|
||||
@@ -93,7 +93,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
completion(.unsupported(forReason: .invalid))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if account.findFolder(forName: folderName) == nil {
|
||||
completion(.unsupported(forReason: .invalid))
|
||||
} else {
|
||||
@@ -102,13 +102,13 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
|
||||
public func handle(intent: AddWebFeedIntent, completion: @escaping (AddWebFeedIntentResponse) -> Void) {
|
||||
guard let url = intent.url, let extensionContainers = ExtensionContainersFile.read() else {
|
||||
completion(AddWebFeedIntentResponse(code: .failure, userActivity: nil))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let account: ExtensionAccount? = {
|
||||
if let accountName = intent.accountName {
|
||||
return extensionContainers.findAccount(forName: accountName)
|
||||
@@ -139,5 +139,5 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
ExtensionFeedAddRequestFile.save(request)
|
||||
completion(AddWebFeedIntentResponse(code: .success, userActivity: nil))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
import Cocoa
|
||||
|
||||
class AboutWindowController: NSWindowController {
|
||||
|
||||
|
||||
@IBOutlet weak var appIconImageView: NSImageView!
|
||||
@IBOutlet weak var appTitleLabel: NSTextField!
|
||||
@IBOutlet weak var versionLabel: NSTextField!
|
||||
@@ -22,7 +22,7 @@ class AboutWindowController: NSWindowController {
|
||||
configureWindow()
|
||||
updateUI()
|
||||
}
|
||||
|
||||
|
||||
func configureWindow() {
|
||||
window?.isOpaque = false
|
||||
window?.backgroundColor = .clear
|
||||
@@ -36,22 +36,22 @@ class AboutWindowController: NSWindowController {
|
||||
contentView.addSubview(visualEffectView, positioned: .below, relativeTo: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updateUI() {
|
||||
|
||||
|
||||
// App Icon
|
||||
appIconImageView.image = NSApp.applicationIconImage
|
||||
|
||||
|
||||
// Version
|
||||
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown"
|
||||
let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "Unknown"
|
||||
let versionString = "Version \(version) (Build \(build))"
|
||||
versionLabel.stringValue = versionString
|
||||
|
||||
|
||||
// Copyright
|
||||
let copyright = Bundle.main.infoDictionary?["NSHumanReadableCopyright"] as? String ?? "Copyright © 2002-2025 Brent Simmons. All rights reserved."
|
||||
copyrightLabel.stringValue = copyright
|
||||
|
||||
|
||||
// Credits
|
||||
if let creditsURL = Bundle.main.url(forResource: "Credits", withExtension: "rtf"),
|
||||
let creditsData = try? Data(contentsOf: creditsURL),
|
||||
@@ -60,12 +60,12 @@ class AboutWindowController: NSWindowController {
|
||||
} else {
|
||||
creditsTextView.string = "Credits not available."
|
||||
}
|
||||
|
||||
|
||||
let fullRange = NSRange(location: 0, length: creditsTextView.string.utf16.count)
|
||||
let leadingParagraphStyle = NSMutableParagraphStyle()
|
||||
leadingParagraphStyle.alignment = .left
|
||||
creditsTextView.textStorage?.addAttribute(.paragraphStyle, value: leadingParagraphStyle, range: fullRange)
|
||||
|
||||
|
||||
// URL
|
||||
let url = URL(string: "https://inessential.com")!
|
||||
let attributedString = NSMutableAttributedString(string: "inessential.com")
|
||||
@@ -74,5 +74,5 @@ class AboutWindowController: NSWindowController {
|
||||
attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: attributedString.length))
|
||||
websiteLabel.attributedStringValue = attributedString
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
class LinkLabel: NSTextField {
|
||||
|
||||
|
||||
/// pièces de résistance -- keeping it a mac-assed mac app.
|
||||
override func resetCursorRects() {
|
||||
addCursorRect(bounds, cursor: .pointingHand)
|
||||
|
||||
+44
-44
@@ -23,11 +23,11 @@ struct AppAssets {
|
||||
static var accountFeedbin: RSImage! = {
|
||||
return RSImage(named: "accountFeedbin")
|
||||
}()
|
||||
|
||||
|
||||
static var accountFeedly: RSImage! = {
|
||||
return RSImage(named: "accountFeedly")
|
||||
}()
|
||||
|
||||
|
||||
static var accountFreshRSS: RSImage! = {
|
||||
return RSImage(named: "accountFreshRSS")
|
||||
}()
|
||||
@@ -43,14 +43,14 @@ struct AppAssets {
|
||||
static var accountNewsBlur: RSImage! = {
|
||||
return RSImage(named: "accountNewsBlur")
|
||||
}()
|
||||
|
||||
|
||||
static var accountTheOldReader: RSImage! = {
|
||||
return RSImage(named: "accountTheOldReader")
|
||||
}()
|
||||
|
||||
static let nnwFeedIcon = RSImage(named: "nnwFeedIcon")!
|
||||
|
||||
|
||||
|
||||
static var addNewSidebarItemImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "plus", accessibilityDescription: nil)!
|
||||
}()
|
||||
@@ -67,20 +67,20 @@ struct AppAssets {
|
||||
return RSImage(named: "articleExtractorOn")!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var articleTheme: RSImage = {
|
||||
return NSImage(systemSymbolName: "doc.richtext", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var cleanUpImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "bubbles.and.sparkles", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var copyImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "document.on.document", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var deleteImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "xmark.bin", accessibilityDescription: nil)!
|
||||
}()
|
||||
@@ -88,11 +88,11 @@ struct AppAssets {
|
||||
static var marsEditIcon: RSImage = {
|
||||
return RSImage(named: "MarsEditIcon")!
|
||||
}()
|
||||
|
||||
|
||||
static var microblogIcon: RSImage = {
|
||||
return RSImage(named: "MicroblogIcon")!
|
||||
}()
|
||||
|
||||
|
||||
static var faviconTemplateImage: RSImage = {
|
||||
return RSImage(named: "faviconTemplateImage")!
|
||||
}()
|
||||
@@ -112,67 +112,67 @@ struct AppAssets {
|
||||
static var iconDarkBackgroundColor: NSColor = {
|
||||
return NSColor(named: NSColor.Name("iconDarkBackgroundColor"))!
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractor: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractor")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorError: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorError")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorInactiveDark: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorInactiveDark")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorInactiveLight: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorInactiveLight")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorProgress1: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorProgress1")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorProgress2: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorProgress2")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorProgress3: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorProgress3")
|
||||
}()
|
||||
|
||||
|
||||
static var legacyArticleExtractorProgress4: RSImage! = {
|
||||
return RSImage(named: "legacyArticleExtractorProgress4")
|
||||
}()
|
||||
|
||||
|
||||
static var mainFolderImage: IconImage {
|
||||
let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)!
|
||||
let preferredColor = NSColor(named: "AccentColor")!
|
||||
return IconImage(image, isSymbol: true, isBackgroundSuppressed: true, preferredColor: preferredColor.cgColor)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static var markAllAsReadMenuImage: RSImage = {
|
||||
let image = RSImage(named: "markAllAsRead")
|
||||
return image!
|
||||
}()
|
||||
|
||||
|
||||
static var markAllAsReadImage: RSImage = {
|
||||
let image = RSImage(named: "markAllAsRead")
|
||||
return image!
|
||||
}()
|
||||
|
||||
|
||||
static var markBelowAsReadImage: RSImage = {
|
||||
let image = RSImage(named: "markBelowAsRead")
|
||||
return image!
|
||||
}()
|
||||
|
||||
|
||||
static var markAboveAsReadImage: RSImage = {
|
||||
let image = RSImage(named: "markAboveAsRead")
|
||||
return image!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var nextUnreadImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "chevron.down.circle", accessibilityDescription: nil)!
|
||||
}()
|
||||
@@ -180,7 +180,7 @@ struct AppAssets {
|
||||
static var notificationImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "bell.badge", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var openInBrowserImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "safari", accessibilityDescription: nil)!
|
||||
}()
|
||||
@@ -188,58 +188,58 @@ struct AppAssets {
|
||||
static var preferencesToolbarAccountsImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "at", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var preferencesToolbarGeneralImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "gearshape", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var preferencesToolbarAdvancedImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "gearshape.2", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var readClosedImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var readOpenImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "circle", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
|
||||
static var refreshImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "arrow.clockwise", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var renameImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "pencil", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var searchFeedImage: IconImage = {
|
||||
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true, isBackgroundSuppressed: true)
|
||||
}()
|
||||
|
||||
|
||||
|
||||
|
||||
static var shareImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "square.and.arrow.up", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var sidebarToggleImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "sidebar.left", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
|
||||
static var starClosedImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
|
||||
static var starOpenImage: RSImage = {
|
||||
return NSImage(systemSymbolName: "star", accessibilityDescription: nil)!
|
||||
}()
|
||||
|
||||
|
||||
static var starredFeedImage: IconImage = {
|
||||
let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
|
||||
let preferredColor = NSColor(named: "StarColor")!
|
||||
@@ -249,7 +249,7 @@ struct AppAssets {
|
||||
static var timelineSeparatorColor: NSColor = {
|
||||
return NSColor(named: "timelineSeparatorColor")!
|
||||
}()
|
||||
|
||||
|
||||
static var timelineStarSelected: RSImage! = {
|
||||
return RSImage(named: "timelineStar")?.tinted(with: .white)
|
||||
}()
|
||||
@@ -285,11 +285,11 @@ struct AppAssets {
|
||||
static var swipeMarkUnstarredImage: RSImage = {
|
||||
return RSImage(systemSymbolName: "star", accessibilityDescription: "Unstar")!
|
||||
}()
|
||||
|
||||
|
||||
static var starColor: NSColor = {
|
||||
return NSColor(named: NSColor.Name("StarColor"))!
|
||||
}()
|
||||
|
||||
|
||||
static func image(for accountType: AccountType) -> NSImage? {
|
||||
switch accountType {
|
||||
case .onMyMac:
|
||||
@@ -312,5 +312,5 @@ struct AppAssets {
|
||||
return AppAssets.accountTheOldReader
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+17
-17
@@ -16,7 +16,7 @@ enum FontSize: Int {
|
||||
}
|
||||
|
||||
final class AppDefaults {
|
||||
|
||||
|
||||
static let defaultThemeName = "Default"
|
||||
|
||||
static let shared = AppDefaults()
|
||||
@@ -63,7 +63,7 @@ final class AppDefaults {
|
||||
}
|
||||
return false
|
||||
}()
|
||||
|
||||
|
||||
var isFirstRun: Bool = {
|
||||
if let _ = UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date {
|
||||
return false
|
||||
@@ -101,7 +101,7 @@ final class AppDefaults {
|
||||
AppDefaults.setDate(for: Key.lastImageCacheFlushDate, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var openInBrowserInBackground: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.openInBrowserInBackground)
|
||||
@@ -167,7 +167,7 @@ final class AppDefaults {
|
||||
AppDefaults.setString(for: Key.addFeedAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var addFeedFolderName: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.addFeedFolderName)
|
||||
@@ -185,7 +185,7 @@ final class AppDefaults {
|
||||
AppDefaults.setString(for: Key.addFolderAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var importOPMLAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.importOPMLAccountID)
|
||||
@@ -194,7 +194,7 @@ final class AppDefaults {
|
||||
AppDefaults.setString(for: Key.importOPMLAccountID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var exportOPMLAccountID: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.exportOPMLAccountID)
|
||||
@@ -212,7 +212,7 @@ final class AppDefaults {
|
||||
AppDefaults.setString(for: Key.defaultBrowserID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var currentThemeName: String? {
|
||||
get {
|
||||
return AppDefaults.string(for: Key.currentThemeName)
|
||||
@@ -221,7 +221,7 @@ final class AppDefaults {
|
||||
AppDefaults.setString(for: Key.currentThemeName, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var showTitleOnMainWindow: Bool {
|
||||
return AppDefaults.bool(for: Key.showTitleOnMainWindow)
|
||||
}
|
||||
@@ -256,7 +256,7 @@ final class AppDefaults {
|
||||
AppDefaults.setBool(for: Key.webInspectorEnabled, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var webInspectorStartsAttached: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.webInspectorStartsAttached)
|
||||
@@ -274,7 +274,7 @@ final class AppDefaults {
|
||||
AppDefaults.setSortDirection(for: Key.timelineSortDirection, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var timelineGroupByFeed: Bool {
|
||||
get {
|
||||
return AppDefaults.bool(for: Key.timelineGroupByFeed)
|
||||
@@ -283,7 +283,7 @@ final class AppDefaults {
|
||||
AppDefaults.setBool(for: Key.timelineGroupByFeed, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var timelineShowsSeparators: Bool {
|
||||
return AppDefaults.bool(for: Key.timelineShowsSeparators)
|
||||
}
|
||||
@@ -391,19 +391,19 @@ private extension AppDefaults {
|
||||
// }
|
||||
// return FontSize(rawValue: rawFontSize)!
|
||||
}
|
||||
|
||||
|
||||
static func setFontSize(for key: String, _ fontSize: FontSize) {
|
||||
setInt(for: key, fontSize.rawValue)
|
||||
}
|
||||
|
||||
|
||||
static func string(for key: String) -> String? {
|
||||
return UserDefaults.standard.string(forKey: key)
|
||||
}
|
||||
|
||||
|
||||
static func setString(for key: String, _ value: String?) {
|
||||
UserDefaults.standard.set(value, forKey: key)
|
||||
}
|
||||
|
||||
|
||||
static func bool(for key: String) -> Bool {
|
||||
return UserDefaults.standard.bool(forKey: key)
|
||||
}
|
||||
@@ -415,11 +415,11 @@ private extension AppDefaults {
|
||||
static func int(for key: String) -> Int {
|
||||
return UserDefaults.standard.integer(forKey: key)
|
||||
}
|
||||
|
||||
|
||||
static func setInt(for key: String, _ x: Int) {
|
||||
UserDefaults.standard.set(x, forKey: key)
|
||||
}
|
||||
|
||||
|
||||
static func date(for key: String) -> Date? {
|
||||
return UserDefaults.standard.object(forKey: key) as? Date
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ struct Browser {
|
||||
/// to open in the background.
|
||||
static func open(_ urlString: String, inBackground: Bool) {
|
||||
guard let url = URL(string: urlString), let preparedURL = url.preparedForOpeningInBrowser() else { return }
|
||||
|
||||
|
||||
let configuration = NSWorkspace.OpenConfiguration()
|
||||
configuration.requiresUniversalLinks = true
|
||||
configuration.promptsUserIfNeeded = false
|
||||
|
||||
@@ -41,7 +41,7 @@ struct CrashReporter {
|
||||
} else {
|
||||
runCrashReporterWindow(crashLogText)
|
||||
}
|
||||
|
||||
|
||||
crashReporter.purgePendingCrashReport()
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ final class BuiltinSmartFeedInspectorViewController: NSViewController, Inspector
|
||||
|
||||
@IBOutlet var nameTextField: NSTextField?
|
||||
@IBOutlet weak var smartFeedImageView: NSImageView!
|
||||
|
||||
|
||||
private var smartFeed: PseudoFeed? {
|
||||
didSet {
|
||||
updateUI()
|
||||
|
||||
@@ -19,7 +19,7 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
@IBOutlet weak var urlTextField: NSTextField?
|
||||
@IBOutlet weak var isNotifyAboutNewArticlesCheckBox: NSButton!
|
||||
@IBOutlet weak var isReaderViewAlwaysOnCheckBox: NSButton?
|
||||
|
||||
|
||||
private var feed: Feed? {
|
||||
didSet {
|
||||
if feed != oldValue {
|
||||
@@ -52,15 +52,15 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: .DidUpdateFeedPreferencesFromContextMenu, object: nil)
|
||||
}
|
||||
|
||||
|
||||
override func viewDidAppear() {
|
||||
updateNotificationSettings()
|
||||
}
|
||||
|
||||
|
||||
override func viewDidDisappear() {
|
||||
renameFeedIfNecessary()
|
||||
}
|
||||
|
||||
|
||||
// MARK: Actions
|
||||
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
|
||||
guard userNotificationSettings != nil else {
|
||||
@@ -69,10 +69,10 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
|
||||
self.updateNotificationSettings()
|
||||
|
||||
|
||||
if settings.authorizationStatus == .denied {
|
||||
DispatchQueue.main.async {
|
||||
self.isNotifyAboutNewArticlesCheckBox.setNextState()
|
||||
@@ -99,17 +99,17 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func isReaderViewAlwaysOnChanged(_ sender: Any) {
|
||||
feed?.isArticleExtractorAlwaysOn = (isReaderViewAlwaysOnCheckBox?.state ?? .off) == .on ? true : false
|
||||
}
|
||||
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func imageDidBecomeAvailable(_ note: Notification) {
|
||||
updateImage()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension FeedInspectorViewController: NSTextFieldDelegate {
|
||||
@@ -117,7 +117,7 @@ extension FeedInspectorViewController: NSTextFieldDelegate {
|
||||
func controlTextDidEndEditing(_ note: Notification) {
|
||||
renameFeedIfNecessary()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension FeedInspectorViewController {
|
||||
@@ -130,7 +130,7 @@ private extension FeedInspectorViewController {
|
||||
feed = singleFeed
|
||||
}
|
||||
|
||||
|
||||
|
||||
@objc func updateUI() {
|
||||
updateImage()
|
||||
updateName()
|
||||
@@ -209,7 +209,7 @@ private extension FeedInspectorViewController {
|
||||
feed.nameForDisplay != nameTextField.stringValue else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
account.renameFeed(feed, to: nameTextField.stringValue) { [weak self] result in
|
||||
if case .failure(let error) = result {
|
||||
self?.presentError(error)
|
||||
@@ -218,5 +218,5 @@ private extension FeedInspectorViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ final class FolderInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
@IBOutlet var nameTextField: NSTextField?
|
||||
@IBOutlet weak var folderImageView: NSImageView!
|
||||
|
||||
|
||||
private var folder: Folder? {
|
||||
didSet {
|
||||
if folder != oldValue {
|
||||
@@ -46,18 +46,18 @@ final class FolderInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
override func viewDidLoad() {
|
||||
updateUI()
|
||||
|
||||
|
||||
let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)!
|
||||
folderImageView.image = image
|
||||
folderImageView.contentTintColor = NSColor.controlAccentColor
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidDisappear() {
|
||||
renameFolderIfNecessary()
|
||||
}
|
||||
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func displayNameDidChange(_ note: Notification) {
|
||||
@@ -73,7 +73,7 @@ extension FolderInspectorViewController: NSTextFieldDelegate {
|
||||
func controlTextDidEndEditing(_ obj: Notification) {
|
||||
renameFolderIfNecessary()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension FolderInspectorViewController {
|
||||
@@ -104,7 +104,7 @@ private extension FolderInspectorViewController {
|
||||
}
|
||||
windowTitle = folder?.nameForDisplay ?? NSLocalizedString("Folder Inspector", comment: "Folder Inspector window title")
|
||||
}
|
||||
|
||||
|
||||
func renameFolderIfNecessary() {
|
||||
guard let folder = folder,
|
||||
let account = folder.account,
|
||||
@@ -112,7 +112,7 @@ private extension FolderInspectorViewController {
|
||||
folder.nameForDisplay != nameTextField.stringValue else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
account.renameFolder(folder, to: nameTextField.stringValue) { [weak self] result in
|
||||
if case .failure(let error) = result {
|
||||
self?.presentError(error)
|
||||
@@ -121,5 +121,5 @@ private extension FolderInspectorViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -121,7 +121,7 @@ private extension InspectorWindowController {
|
||||
window.contentViewController = inspector
|
||||
window.makeFirstResponder(nil)
|
||||
}
|
||||
|
||||
|
||||
window.layoutIfNeeded()
|
||||
if let flippedOrigin = flippedOrigin {
|
||||
window.setFlippedOriginAdjustingForScreen(flippedOrigin)
|
||||
|
||||
@@ -28,7 +28,7 @@ final class AddFeedController: AddFeedWindowControllerDelegate {
|
||||
private var addFeedWindowController: AddFeedWindowController?
|
||||
private var foundFeedURLString: String?
|
||||
private var titleFromFeed: String?
|
||||
|
||||
|
||||
init(hostWindow: NSWindow) {
|
||||
self.hostWindow = hostWindow
|
||||
}
|
||||
@@ -63,11 +63,11 @@ final class AddFeedController: AddFeedWindowControllerDelegate {
|
||||
}
|
||||
|
||||
account.createFeed(url: url.absoluteString, name: title, container: container, validateFeed: true) { result in
|
||||
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.endShowingProgress()
|
||||
}
|
||||
|
||||
|
||||
switch result {
|
||||
case .success(let feed):
|
||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
||||
@@ -83,9 +83,9 @@ final class AddFeedController: AddFeedWindowControllerDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
beginShowingProgress()
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ private extension AddFeedController {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
struct AccountAndFolderSpecifier {
|
||||
let account: Account
|
||||
let folder: Folder?
|
||||
@@ -159,11 +159,11 @@ private extension AddFeedController {
|
||||
func beginShowingProgress() {
|
||||
runIndeterminateProgressWithMessage(NSLocalizedString("Finding feed…", comment:"Feed finder"))
|
||||
}
|
||||
|
||||
|
||||
func endShowingProgress() {
|
||||
stopIndeterminateProgress()
|
||||
hostWindow.makeKeyAndOrderFront(self)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
var hostWindow: NSWindow!
|
||||
|
||||
convenience init(urlString: String?, name: String?, account: Account?, folder: Folder?, folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) {
|
||||
@@ -52,7 +52,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
self.delegate = delegate
|
||||
self.folderTreeController = folderTreeController
|
||||
}
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
guard let window else {
|
||||
return
|
||||
@@ -70,7 +70,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
}
|
||||
|
||||
folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode)
|
||||
|
||||
|
||||
if let account = initialAccount {
|
||||
FolderTreeMenu.select(account: account, folder: initialFolder, in: folderPopupButton)
|
||||
} else if let container = AddFeedDefaultContainer.defaultContainer {
|
||||
@@ -82,16 +82,16 @@ final class AddFeedWindowController : NSWindowController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateUI()
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
|
||||
@IBAction func cancel(_ sender: Any?) {
|
||||
cancelSheet()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func addFeed(_ sender: Any?) {
|
||||
let urlString = urlTextField.stringValue
|
||||
let normalizedURLString = urlString.normalizedURL
|
||||
@@ -104,19 +104,19 @@ final class AddFeedWindowController : NSWindowController {
|
||||
cancelSheet()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard let container = selectedContainer() else { return }
|
||||
AddFeedDefaultContainer.saveDefaultContainer(container)
|
||||
|
||||
delegate?.addFeedWindowController(self, userEnteredURL: url, userEnteredTitle: userEnteredTitle, container: container)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@IBAction func localShowFeedList(_ sender: Any?) {
|
||||
NSApplication.shared.sendAction(NSSelectorFromString("showFeedList:"), to: nil, from: sender)
|
||||
hostWindow.endSheet(window!, returnCode: NSApplication.ModalResponse.continue)
|
||||
}
|
||||
|
||||
|
||||
// MARK: NSTextFieldDelegate
|
||||
|
||||
@objc func controlTextDidEndEditing(_ obj: Notification) {
|
||||
@@ -129,7 +129,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
}
|
||||
|
||||
private extension AddFeedWindowController {
|
||||
|
||||
|
||||
private func updateUI() {
|
||||
addButton.isEnabled = urlTextField.stringValue.mayBeURL && selectedContainer() != nil
|
||||
}
|
||||
|
||||
@@ -14,34 +14,34 @@ import Account
|
||||
final class FolderTreeMenu {
|
||||
|
||||
static func createFolderPopupMenu(with rootNode: Node, restrictToSpecialAccounts: Bool = false) -> NSMenu {
|
||||
|
||||
|
||||
let menu = NSMenu(title: "Folders")
|
||||
menu.autoenablesItems = false
|
||||
|
||||
|
||||
for childNode in rootNode.childNodes {
|
||||
|
||||
|
||||
guard let account = childNode.representedObject as? Account else {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if restrictToSpecialAccounts && !(account.type == .onMyMac || account.type == .cloudKit) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
let menuItem = NSMenuItem(title: account.nameForDisplay, action: nil, keyEquivalent: "")
|
||||
menuItem.representedObject = childNode.representedObject
|
||||
|
||||
|
||||
if account.behaviors.contains(.disallowFeedInRootFolder) {
|
||||
menuItem.isEnabled = false
|
||||
}
|
||||
|
||||
|
||||
menu.addItem(menuItem)
|
||||
|
||||
let childNodes = childNode.childNodes
|
||||
addFolderItemsToMenuWithNodes(menu: menu, nodes: childNodes, indentationLevel: 1)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return menu
|
||||
}
|
||||
|
||||
@@ -61,21 +61,21 @@ final class FolderTreeMenu {
|
||||
}
|
||||
|
||||
private static func addFolderItemsToMenuWithNodes(menu: NSMenu, nodes: [Node], indentationLevel: Int) {
|
||||
|
||||
|
||||
nodes.forEach { (oneNode) in
|
||||
|
||||
|
||||
if let nameProvider = oneNode.representedObject as? DisplayNameProvider {
|
||||
|
||||
|
||||
let menuItem = NSMenuItem(title: nameProvider.nameForDisplay, action: nil, keyEquivalent: "")
|
||||
menuItem.indentationLevel = indentationLevel
|
||||
menuItem.representedObject = oneNode.representedObject
|
||||
menu.addItem(menuItem)
|
||||
|
||||
|
||||
if oneNode.numberOfChildNodes > 0 {
|
||||
addFolderItemsToMenuWithNodes(menu: menu, nodes: oneNode.childNodes, indentationLevel: indentationLevel + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import Articles
|
||||
import Account
|
||||
|
||||
final class AddFolderWindowController : NSWindowController {
|
||||
|
||||
|
||||
@IBOutlet var folderNameTextField: NSTextField!
|
||||
@IBOutlet var accountPopupButton: NSPopUpButton!
|
||||
@IBOutlet var addFolderButton: NSButton!
|
||||
@@ -22,7 +22,7 @@ final class AddFolderWindowController : NSWindowController {
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
guard let window else {
|
||||
return
|
||||
@@ -37,33 +37,33 @@ final class AddFolderWindowController : NSWindowController {
|
||||
}
|
||||
|
||||
// MARK: - NSViewController
|
||||
|
||||
|
||||
override func windowDidLoad() {
|
||||
let preferredAccountID = AppDefaults.shared.addFolderAccountID
|
||||
accountPopupButton.removeAllItems()
|
||||
|
||||
|
||||
let menu = NSMenu()
|
||||
accountPopupButton.menu = menu
|
||||
|
||||
|
||||
let accounts = AccountManager.shared
|
||||
.sortedActiveAccounts
|
||||
.filter { !$0.behaviors.contains(.disallowFolderManagement) }
|
||||
|
||||
|
||||
for oneAccount in accounts {
|
||||
|
||||
|
||||
let oneMenuItem = NSMenuItem()
|
||||
oneMenuItem.title = oneAccount.nameForDisplay
|
||||
oneMenuItem.representedObject = oneAccount
|
||||
menu.addItem(oneMenuItem)
|
||||
|
||||
|
||||
if oneAccount.accountID == preferredAccountID {
|
||||
accountPopupButton.select(oneMenuItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
|
||||
@IBAction func cancel(_ sender: Any?) {
|
||||
guard let hostWindow, let window else {
|
||||
return
|
||||
@@ -71,7 +71,7 @@ final class AddFolderWindowController : NSWindowController {
|
||||
hostWindow.endSheet(window, returnCode: .cancel)
|
||||
self.hostWindow = nil
|
||||
}
|
||||
|
||||
|
||||
@IBAction func addFolder(_ sender: Any?) {
|
||||
guard let hostWindow, let window else {
|
||||
return
|
||||
|
||||
@@ -16,9 +16,9 @@ enum ArticleExtractorButtonState {
|
||||
}
|
||||
|
||||
final class ArticleExtractorButton: NSButton {
|
||||
|
||||
|
||||
private var animatedLayer: CALayer?
|
||||
|
||||
|
||||
var buttonState: ArticleExtractorButtonState = .off {
|
||||
didSet {
|
||||
if buttonState != oldValue {
|
||||
@@ -39,7 +39,7 @@ final class ArticleExtractorButton: NSButton {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override func accessibilityLabel() -> String? {
|
||||
switch buttonState {
|
||||
case .error:
|
||||
@@ -57,12 +57,12 @@ final class ArticleExtractorButton: NSButton {
|
||||
super.init(frame: frameRect)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
|
||||
private func commonInit() {
|
||||
wantsLayer = true
|
||||
bezelStyle = .texturedRounded
|
||||
@@ -70,7 +70,7 @@ final class ArticleExtractorButton: NSButton {
|
||||
imageScaling = .scaleProportionallyDown
|
||||
widthAnchor.constraint(equalTo: heightAnchor).isActive = true
|
||||
}
|
||||
|
||||
|
||||
override func layout() {
|
||||
super.layout()
|
||||
guard case .animated = buttonState else {
|
||||
@@ -79,31 +79,31 @@ final class ArticleExtractorButton: NSButton {
|
||||
stripAnimatedSublayer()
|
||||
addAnimatedSublayer(to: layer!)
|
||||
}
|
||||
|
||||
|
||||
private func stripAnimatedSublayer() {
|
||||
animatedLayer?.removeFromSuperlayer()
|
||||
}
|
||||
|
||||
|
||||
private func addAnimatedSublayer(to hostedLayer: CALayer) {
|
||||
let image1 = AppAssets.articleExtractorOff.tinted(with: NSColor.controlTextColor)
|
||||
let image2 = AppAssets.articleExtractorOn.tinted(with: NSColor.controlTextColor)
|
||||
let images = [image1, image2, image1]
|
||||
|
||||
|
||||
animatedLayer = CALayer()
|
||||
let imageSize = AppAssets.articleExtractorOff.size
|
||||
animatedLayer!.bounds = CGRect(x: 0, y: 0, width: imageSize.width, height: imageSize.height)
|
||||
animatedLayer!.position = CGPoint(x: bounds.midX, y: bounds.midY)
|
||||
|
||||
|
||||
hostedLayer.addSublayer(animatedLayer!)
|
||||
|
||||
|
||||
let animation = CAKeyframeAnimation(keyPath: "contents")
|
||||
animation.calculationMode = CAAnimationCalculationMode.linear
|
||||
animation.keyTimes = [0, 0.5, 1]
|
||||
animation.duration = 2
|
||||
animation.values = images
|
||||
animation.repeatCount = HUGE
|
||||
|
||||
|
||||
animatedLayer!.add(animation, forKey: "contents")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,9 +11,9 @@ import WebKit
|
||||
import Articles
|
||||
|
||||
final class DetailIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
|
||||
|
||||
var currentArticle: Article?
|
||||
|
||||
|
||||
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
||||
|
||||
guard let responseURL = urlSchemeTask.request.url, let iconImage = self.currentArticle?.iconImage() else {
|
||||
@@ -24,12 +24,12 @@ final class DetailIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
let iconView = IconView(frame: CGRect(x: 0, y: 0, width: 48, height: 48))
|
||||
iconView.iconImage = iconImage
|
||||
let renderedImage = iconView.asImage()
|
||||
|
||||
|
||||
guard let data = renderedImage.dataRepresentation() else {
|
||||
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let headerFields = ["Cache-Control": "no-cache"]
|
||||
if let response = HTTPURLResponse(url: responseURL, statusCode: 200, httpVersion: nil, headerFields: headerFields) {
|
||||
urlSchemeTask.didReceive(response)
|
||||
@@ -38,9 +38,9 @@ final class DetailIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
||||
urlSchemeTask.didFailWithError(URLError(.unknown))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@ final class DetailStatusBarView: NSView {
|
||||
override var isOpaque: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
override var isFlipped: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
||||
var windowState: DetailWindowState {
|
||||
currentWebViewController.windowState
|
||||
}
|
||||
|
||||
|
||||
private var currentWebViewController: DetailWebViewController! {
|
||||
didSet {
|
||||
let webview = currentWebViewController.view
|
||||
@@ -86,7 +86,7 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
||||
func stopMediaPlayback() {
|
||||
currentWebViewController.stopMediaPlayback()
|
||||
}
|
||||
|
||||
|
||||
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
||||
currentWebViewController.canScrollDown(callback)
|
||||
}
|
||||
@@ -102,9 +102,9 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
||||
override func scrollPageUp(_ sender: Any?) {
|
||||
currentWebViewController.scrollPageUp(sender)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Navigation
|
||||
|
||||
|
||||
func focus() {
|
||||
guard let window = currentWebViewController.webView.window else {
|
||||
return
|
||||
|
||||
@@ -13,13 +13,13 @@ import RSCore
|
||||
final class DetailWebView: WKWebView {
|
||||
|
||||
weak var keyboardDelegate: KeyboardDelegate?
|
||||
|
||||
|
||||
override func accessibilityLabel() -> String? {
|
||||
return NSLocalizedString("Article", comment: "Article")
|
||||
}
|
||||
|
||||
// MARK: - NSResponder
|
||||
|
||||
|
||||
override func keyDown(with event: NSEvent) {
|
||||
if keyboardDelegate?.keydown(event, in: self) ?? false {
|
||||
return
|
||||
|
||||
@@ -34,11 +34,11 @@ final class DetailWebViewController: NSViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var windowState: DetailWindowState {
|
||||
DetailWindowState(isShowingExtractedArticle: isShowingExtractedArticle, windowScrollY: windowScrollY ?? 0)
|
||||
}
|
||||
|
||||
|
||||
var article: Article? {
|
||||
switch state {
|
||||
case .article(let article, _):
|
||||
@@ -49,7 +49,7 @@ final class DetailWebViewController: NSViewController {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var articleTextSize = AppDefaults.shared.articleTextSize
|
||||
|
||||
private var webInspectorEnabled: Bool {
|
||||
@@ -118,7 +118,7 @@ final class DetailWebViewController: NSViewController {
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
|
||||
@objc func feedIconDidBecomeAvailable(_ note: Notification) {
|
||||
reloadArticleImage()
|
||||
}
|
||||
@@ -130,24 +130,24 @@ final class DetailWebViewController: NSViewController {
|
||||
@objc func faviconDidBecomeAvailable(_ note: Notification) {
|
||||
reloadArticleImage()
|
||||
}
|
||||
|
||||
|
||||
@objc func userDefaultsDidChange(_ note: Notification) {
|
||||
if articleTextSize != AppDefaults.shared.articleTextSize {
|
||||
articleTextSize = AppDefaults.shared.articleTextSize
|
||||
reloadHTMLMaintainingScrollPosition()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func currentArticleThemeDidChangeNotification(_ note: Notification) {
|
||||
reloadHTMLMaintainingScrollPosition()
|
||||
}
|
||||
|
||||
|
||||
// MARK: Media Functions
|
||||
|
||||
|
||||
func stopMediaPlayback() {
|
||||
webView.evaluateJavaScript("stopMediaPlayback();")
|
||||
}
|
||||
|
||||
|
||||
// MARK: Scrolling
|
||||
|
||||
func canScrollDown(_ completion: @escaping (Bool) -> Void) {
|
||||
@@ -236,7 +236,7 @@ extension DetailWebViewController: WKNavigationDelegate, WKUIDelegate {
|
||||
}
|
||||
|
||||
// WKUIDelegate
|
||||
|
||||
|
||||
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
|
||||
// This method is reached when WebKit handles a JavaScript based window.open() invocation, for example. One
|
||||
// example where this is used is in YouTube's embedded video player when a user clicks on the video's title
|
||||
@@ -256,16 +256,16 @@ private extension DetailWebViewController {
|
||||
|
||||
func reloadArticleImage() {
|
||||
guard let article = article else { return }
|
||||
|
||||
|
||||
var components = URLComponents()
|
||||
components.scheme = ArticleRenderer.imageIconScheme
|
||||
components.path = article.articleID
|
||||
|
||||
|
||||
if let imageSrc = components.string {
|
||||
webView?.evaluateJavaScript("reloadArticleImage(\"\(imageSrc)\")")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func reloadHTMLMaintainingScrollPosition() {
|
||||
fetchScrollInfo() { scrollInfo in
|
||||
self.windowScrollY = scrollInfo?.offsetY
|
||||
@@ -275,7 +275,7 @@ private extension DetailWebViewController {
|
||||
|
||||
func reloadHTML() {
|
||||
delegate?.mouseDidExit(self)
|
||||
|
||||
|
||||
let theme = ArticleThemesManager.shared.currentTheme
|
||||
let rendering: ArticleRenderer.Rendering
|
||||
|
||||
@@ -293,14 +293,14 @@ private extension DetailWebViewController {
|
||||
detailIconSchemeHandler.currentArticle = article
|
||||
rendering = ArticleRenderer.articleHTML(article: article, extractedArticle: extractedArticle, theme: theme)
|
||||
}
|
||||
|
||||
|
||||
let substitutions = [
|
||||
"title": rendering.title,
|
||||
"baseURL": rendering.baseURL,
|
||||
"style": rendering.style,
|
||||
"body": rendering.html
|
||||
]
|
||||
|
||||
|
||||
var html = try! MacroProcessor.renderedText(withTemplate: ArticleRenderer.page.html, substitutions: substitutions)
|
||||
html = ArticleRenderingSpecialCases.filterHTMLIfNeeded(baseURL: rendering.baseURL, html: html)
|
||||
webView.loadHTMLString(html, baseURL: URL(string: rendering.baseURL))
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
import Foundation
|
||||
|
||||
final class DetailWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
|
||||
static let supportsSecureCoding = true
|
||||
|
||||
let isShowingExtractedArticle: Bool
|
||||
let windowScrollY: CGFloat
|
||||
|
||||
|
||||
init(isShowingExtractedArticle: Bool, windowScrollY: CGFloat) {
|
||||
self.isShowingExtractedArticle = isShowingExtractedArticle
|
||||
self.windowScrollY = windowScrollY
|
||||
@@ -29,7 +29,7 @@ final class DetailWindowState: NSObject, NSSecureCoding {
|
||||
isShowingExtractedArticle = coder.decodeBool(forKey: Key.isShowingExtractedArticle)
|
||||
windowScrollY = CGFloat(coder.decodeDouble(forKey: Key.windowScrollY))
|
||||
}
|
||||
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(isShowingExtractedArticle, forKey: Key.isShowingExtractedArticle)
|
||||
coder.encode(Double(windowScrollY), forKey: Key.windowScrollY)
|
||||
|
||||
@@ -39,7 +39,7 @@ final class IconView: NSView {
|
||||
}
|
||||
|
||||
private var isDiscernable = true
|
||||
|
||||
|
||||
override var isFlipped: Bool {
|
||||
return true
|
||||
}
|
||||
@@ -108,7 +108,7 @@ private extension IconView {
|
||||
guard !(iconImage?.isSymbol ?? false) else {
|
||||
return NSMakeRect(0.0, 0.0, bounds.size.width, bounds.size.height)
|
||||
}
|
||||
|
||||
|
||||
guard let image = iconImage?.image else {
|
||||
return NSRect.zero
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
final class LegacyArticleExtractorButton: NSButton {
|
||||
|
||||
|
||||
var isError = false {
|
||||
didSet {
|
||||
if isError != oldValue {
|
||||
@@ -17,7 +17,7 @@ final class LegacyArticleExtractorButton: NSButton {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isInProgress = false {
|
||||
didSet {
|
||||
if isInProgress != oldValue {
|
||||
@@ -25,12 +25,12 @@ final class LegacyArticleExtractorButton: NSButton {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override init(frame frameRect: NSRect) {
|
||||
super.init(frame: frameRect)
|
||||
wantsLayer = true
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
wantsLayer = true
|
||||
@@ -38,7 +38,7 @@ final class LegacyArticleExtractorButton: NSButton {
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
|
||||
guard let hostedLayer = self.layer else {
|
||||
return
|
||||
}
|
||||
@@ -52,7 +52,7 @@ final class LegacyArticleExtractorButton: NSButton {
|
||||
}
|
||||
|
||||
let opacity: Float = isEnabled ? 1.0 : 0.5
|
||||
|
||||
|
||||
switch true {
|
||||
case isError:
|
||||
addImageSublayer(to: hostedLayer, image: AppAssets.legacyArticleExtractorError, opacity: opacity)
|
||||
@@ -70,42 +70,42 @@ final class LegacyArticleExtractorButton: NSButton {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func makeLayerForImage(_ image: NSImage) -> CALayer {
|
||||
let imageLayer = CALayer()
|
||||
imageLayer.bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
|
||||
imageLayer.position = CGPoint(x: bounds.midX, y: floor(bounds.midY))
|
||||
return imageLayer
|
||||
}
|
||||
|
||||
|
||||
private func addImageSublayer(to hostedLayer: CALayer, image: NSImage, opacity: Float = 1.0) {
|
||||
let imageLayer = makeLayerForImage(image)
|
||||
imageLayer.contents = image
|
||||
imageLayer.opacity = opacity
|
||||
hostedLayer.addSublayer(imageLayer)
|
||||
}
|
||||
|
||||
|
||||
private func addAnimatedSublayer(to hostedLayer: CALayer) {
|
||||
let imageProgress1 = AppAssets.legacyArticleExtractorProgress1
|
||||
let imageProgress2 = AppAssets.legacyArticleExtractorProgress2
|
||||
let imageProgress3 = AppAssets.legacyArticleExtractorProgress3
|
||||
let imageProgress4 = AppAssets.legacyArticleExtractorProgress4
|
||||
let images = [imageProgress1, imageProgress2, imageProgress3, imageProgress4, imageProgress3, imageProgress2, imageProgress1]
|
||||
|
||||
|
||||
let imageLayer = CALayer()
|
||||
imageLayer.bounds = CGRect(x: 0, y: 0, width: imageProgress1?.size.width ?? 0, height: imageProgress1?.size.height ?? 0)
|
||||
imageLayer.position = CGPoint(x: bounds.midX, y: floor(bounds.midY))
|
||||
|
||||
|
||||
hostedLayer.addSublayer(imageLayer)
|
||||
|
||||
|
||||
let animation = CAKeyframeAnimation(keyPath: "contents")
|
||||
animation.calculationMode = CAAnimationCalculationMode.linear
|
||||
animation.keyTimes = [0, 0.16, 0.32, 0.50, 0.66, 0.82, 1]
|
||||
animation.duration = 2
|
||||
animation.values = images as [Any]
|
||||
animation.repeatCount = HUGE
|
||||
|
||||
|
||||
imageLayer.add(animation, forKey: "contents")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ enum TimelineSourceMode {
|
||||
final class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
@IBOutlet weak var articleThemePopUpButton: NSPopUpButton?
|
||||
|
||||
|
||||
private var activityManager = ActivityManager()
|
||||
|
||||
private var isShowingExtractedArticle = false
|
||||
@@ -36,7 +36,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
}
|
||||
return selectedObjects.first
|
||||
}
|
||||
|
||||
|
||||
private var shareToolbarItem: NSToolbarItem? {
|
||||
return window?.toolbar?.existingItem(withIdentifier: .share)
|
||||
}
|
||||
@@ -100,10 +100,10 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(articleThemeNamesDidChangeNotification(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(currentArticleThemeDidChangeNotification(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil)
|
||||
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.updateWindowTitle()
|
||||
}
|
||||
@@ -135,7 +135,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
AppDefaults.shared.secureWindowState = data
|
||||
window?.saveFrame(usingName: windowAutosaveName)
|
||||
}
|
||||
|
||||
|
||||
func restoreStateFromUserDefaults() {
|
||||
if let data = AppDefaults.shared.secureWindowState,
|
||||
let state = try? NSKeyedUnarchiver.unarchivedObject(ofClass: MainWindowState.self, from: data) {
|
||||
@@ -158,7 +158,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
@objc func unreadCountDidChange(_ note: Notification) {
|
||||
updateWindowTitleIfNecessary(note.object)
|
||||
}
|
||||
|
||||
|
||||
@objc func displayNameDidChange(_ note: Notification) {
|
||||
updateWindowTitleIfNecessary(note.object)
|
||||
}
|
||||
@@ -172,21 +172,21 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
}
|
||||
|
||||
private func updateWindowTitleIfNecessary(_ noteObject: Any?) {
|
||||
|
||||
|
||||
if let folder = currentFeedOrFolder as? Folder, let noteObject = noteObject as? Folder {
|
||||
if folder == noteObject {
|
||||
updateWindowTitle()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let feed = currentFeedOrFolder as? Feed, let noteObject = noteObject as? Feed {
|
||||
if feed == noteObject {
|
||||
updateWindowTitle()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If we don't recognize the changed object, we will test it for identity instead
|
||||
// of equality. This works well for us if the window title is displaying a
|
||||
// PsuedoFeed object.
|
||||
@@ -195,28 +195,28 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
updateWindowTitle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Toolbar
|
||||
|
||||
|
||||
@objc func makeToolbarValidate() {
|
||||
|
||||
|
||||
window?.toolbar?.validateVisibleItems()
|
||||
}
|
||||
|
||||
// MARK: - NSUserInterfaceValidations
|
||||
|
||||
|
||||
public func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
||||
|
||||
|
||||
if item.action == #selector(copyArticleURL(_:)) {
|
||||
return canCopyArticleURL()
|
||||
}
|
||||
|
||||
|
||||
if item.action == #selector(copyExternalURL(_:)) {
|
||||
return canCopyExternalURL()
|
||||
}
|
||||
|
||||
|
||||
if item.action == #selector(openArticleInBrowser(_:)) {
|
||||
if let item = item as? NSMenuItem, item.keyEquivalentModifierMask.contains(.shift) {
|
||||
item.title = Browser.titleForOpenInBrowserInverted
|
||||
@@ -224,11 +224,11 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
|
||||
return currentLink != nil
|
||||
}
|
||||
|
||||
|
||||
if item.action == #selector(nextUnread(_:)) {
|
||||
return canGoToNextUnread(wrappingToTop: true)
|
||||
}
|
||||
|
||||
|
||||
if item.action == #selector(markAllAsRead(_:)) {
|
||||
return canMarkAllAsRead()
|
||||
}
|
||||
@@ -252,7 +252,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
if item.action == #selector(toggleArticleExtractor(_:)) {
|
||||
return validateToggleArticleExtractor(item)
|
||||
}
|
||||
|
||||
|
||||
if item.action == #selector(toolbarShowShareMenu(_:)) {
|
||||
return canShowShareMenu()
|
||||
}
|
||||
@@ -398,7 +398,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
}
|
||||
|
||||
@IBAction func toggleArticleExtractor(_ sender: Any?) {
|
||||
|
||||
|
||||
guard let currentLink = currentLink, let article = oneSelectedArticle else {
|
||||
return
|
||||
}
|
||||
@@ -406,12 +406,12 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
defer {
|
||||
makeToolbarValidate()
|
||||
}
|
||||
|
||||
|
||||
if articleExtractor?.state == .failedToParse {
|
||||
startArticleExtractorForCurrentLink()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard articleExtractor?.state != .processing else {
|
||||
articleExtractor?.cancel()
|
||||
articleExtractor = nil
|
||||
@@ -419,13 +419,13 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
detailViewController?.setState(DetailState.article(article, nil), mode: timelineSourceMode)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard !isShowingExtractedArticle else {
|
||||
isShowingExtractedArticle = false
|
||||
detailViewController?.setState(DetailState.article(article, nil), mode: timelineSourceMode)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let articleExtractor = articleExtractor, let extractedArticle = articleExtractor.article {
|
||||
if currentLink == articleExtractor.articleLink {
|
||||
isShowingExtractedArticle = true
|
||||
@@ -435,7 +435,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
} else {
|
||||
startArticleExtractorForCurrentLink()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@IBAction func markAllAsReadAndGoToNextUnread(_ sender: Any?) {
|
||||
@@ -457,7 +457,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
@IBAction func markOlderArticlesAsRead(_ sender: Any?) {
|
||||
currentTimelineViewController?.markOlderArticlesRead()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func markAboveArticlesAsRead(_ sender: Any?) {
|
||||
currentTimelineViewController?.markAboveArticlesRead()
|
||||
}
|
||||
@@ -477,7 +477,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
@IBAction func navigateToDetail(_ sender: Any?) {
|
||||
detailViewController?.focus()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func goToPreviousSubscription(_ sender: Any?) {
|
||||
sidebarViewController?.outlineView.selectPreviousRow(sender)
|
||||
}
|
||||
@@ -529,25 +529,25 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
@IBAction func cleanUp(_ sender: Any?) {
|
||||
timelineContainerViewController?.cleanUp()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func toggleReadFeedsFilter(_ sender: Any?) {
|
||||
sidebarViewController?.toggleReadFilter()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func toggleReadArticlesFilter(_ sender: Any?) {
|
||||
timelineContainerViewController?.toggleReadFilter()
|
||||
}
|
||||
|
||||
|
||||
@objc func selectArticleTheme(_ menuItem: NSMenuItem) {
|
||||
ArticleThemesManager.shared.currentThemeName = menuItem.title
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: NSWindowDelegate
|
||||
|
||||
extension MainWindowController: NSWindowDelegate {
|
||||
|
||||
|
||||
func window(_ window: NSWindow, willEncodeRestorableState coder: NSCoder) {
|
||||
coder.encode(savableState(), forKey: UserInfoKey.windowState)
|
||||
}
|
||||
@@ -561,7 +561,7 @@ extension MainWindowController: NSWindowDelegate {
|
||||
detailViewController?.stopMediaPlayback()
|
||||
appDelegate.removeMainWindow(self)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - SidebarDelegate
|
||||
@@ -588,11 +588,11 @@ extension MainWindowController: SidebarDelegate {
|
||||
}
|
||||
return timelineViewController.unreadCount
|
||||
}
|
||||
|
||||
|
||||
func sidebarInvalidatedRestorationState(_: SidebarViewController) {
|
||||
invalidateRestorableState()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TimelineContainerViewControllerDelegate
|
||||
@@ -601,12 +601,12 @@ extension MainWindowController: TimelineContainerViewControllerDelegate {
|
||||
|
||||
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode) {
|
||||
activityManager.invalidateReading()
|
||||
|
||||
|
||||
articleExtractor?.cancel()
|
||||
articleExtractor = nil
|
||||
isShowingExtractedArticle = false
|
||||
makeToolbarValidate()
|
||||
|
||||
|
||||
let detailState: DetailState
|
||||
if let articles = articles {
|
||||
if articles.count == 1 {
|
||||
@@ -631,11 +631,11 @@ extension MainWindowController: TimelineContainerViewControllerDelegate {
|
||||
func timelineRequestedFeedSelection(_: TimelineContainerViewController, feed: Feed) {
|
||||
sidebarViewController?.selectFeed(feed)
|
||||
}
|
||||
|
||||
|
||||
func timelineInvalidatedRestorationState(_: TimelineContainerViewController) {
|
||||
invalidateRestorableState()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - NSSearchFieldDelegate
|
||||
@@ -708,11 +708,11 @@ extension MainWindowController: NSSearchFieldDelegate {
|
||||
// MARK: - ArticleExtractorDelegate
|
||||
|
||||
extension MainWindowController: ArticleExtractorDelegate {
|
||||
|
||||
|
||||
func articleExtractionDidFail(with: Error) {
|
||||
makeToolbarValidate()
|
||||
}
|
||||
|
||||
|
||||
func articleExtractionDidComplete(extractedArticle: ExtractedArticle) {
|
||||
if let article = oneSelectedArticle, articleExtractor?.state != .cancelled {
|
||||
isShowingExtractedArticle = true
|
||||
@@ -722,7 +722,7 @@ extension MainWindowController: ArticleExtractorDelegate {
|
||||
makeToolbarValidate()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Scripting Access
|
||||
@@ -730,7 +730,7 @@ extension MainWindowController: ArticleExtractorDelegate {
|
||||
/*
|
||||
the ScriptingMainWindowController protocol exposes a narrow set of accessors with
|
||||
internal visibility which are very similar to some private vars.
|
||||
|
||||
|
||||
These would be unnecessary if the similar accessors were marked internal rather than private,
|
||||
but for now, we'll keep the stratification of visibility
|
||||
*/
|
||||
@@ -852,7 +852,7 @@ extension MainWindowController: NSToolbarDelegate {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
[
|
||||
NSToolbarItem.Identifier.toggleSidebar,
|
||||
@@ -954,7 +954,7 @@ private extension MainWindowController {
|
||||
var detailSplitViewItem: NSSplitViewItem? {
|
||||
return splitViewController?.splitViewItems[2]
|
||||
}
|
||||
|
||||
|
||||
var selectedArticles: [Article]? {
|
||||
return currentTimelineViewController?.selectedArticles
|
||||
}
|
||||
@@ -971,10 +971,10 @@ private extension MainWindowController {
|
||||
}
|
||||
|
||||
// MARK: - State Restoration
|
||||
|
||||
|
||||
func savableState() -> MainWindowState {
|
||||
let isFullScreen = window?.styleMask.contains(.fullScreen) ?? false
|
||||
|
||||
|
||||
let splitViewWidths: [Int]
|
||||
if let splitView = splitViewController?.splitView {
|
||||
splitViewWidths = splitView.arrangedSubviews.map{ Int(floor($0.frame.width)) }
|
||||
@@ -997,9 +997,9 @@ private extension MainWindowController {
|
||||
window?.toggleFullScreen(self)
|
||||
}
|
||||
restoreSplitViewState(from: state)
|
||||
|
||||
|
||||
sidebarViewController?.restoreState(from: state.sidebarWindowState)
|
||||
|
||||
|
||||
timelineContainerViewController?.restoreState(from: state.timelineWindowState)
|
||||
restoreArticleWindowScrollY = state.detailWindowState?.windowScrollY
|
||||
|
||||
@@ -1036,7 +1036,7 @@ private extension MainWindowController {
|
||||
}
|
||||
|
||||
// MARK: - Command Validation
|
||||
|
||||
|
||||
func canCopyArticleURL() -> Bool {
|
||||
guard let selectedArticles else {
|
||||
return false
|
||||
@@ -1049,7 +1049,7 @@ private extension MainWindowController {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func canCopyExternalURL() -> Bool {
|
||||
guard let selectedArticles else {
|
||||
return false
|
||||
@@ -1064,25 +1064,25 @@ private extension MainWindowController {
|
||||
}
|
||||
|
||||
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
||||
|
||||
|
||||
guard let timelineViewController = currentTimelineViewController, let sidebarViewController = sidebarViewController else {
|
||||
return false
|
||||
}
|
||||
// TODO: handle search mode
|
||||
return timelineViewController.canGoToNextUnread(wrappingToTop: wrapping) || sidebarViewController.canGoToNextUnread(wrappingToTop: wrapping)
|
||||
}
|
||||
|
||||
|
||||
func canMarkAllAsRead() -> Bool {
|
||||
|
||||
|
||||
return currentTimelineViewController?.canMarkAllAsRead() ?? false
|
||||
}
|
||||
|
||||
|
||||
func validateToggleRead(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
||||
|
||||
let validationStatus = currentTimelineViewController?.markReadCommandStatus() ?? .canDoNothing
|
||||
let markingRead: Bool
|
||||
let result: Bool
|
||||
|
||||
|
||||
switch validationStatus {
|
||||
case .canMark:
|
||||
markingRead = true
|
||||
@@ -1094,21 +1094,21 @@ private extension MainWindowController {
|
||||
markingRead = true
|
||||
result = false
|
||||
}
|
||||
|
||||
|
||||
let commandName = markingRead ? NSLocalizedString("Mark as Read", comment: "Command") : NSLocalizedString("Mark as Unread", comment: "Command")
|
||||
|
||||
|
||||
if let toolbarItem = item as? NSToolbarItem {
|
||||
toolbarItem.toolTip = commandName
|
||||
}
|
||||
|
||||
|
||||
if let menuItem = item as? NSMenuItem {
|
||||
menuItem.title = commandName
|
||||
}
|
||||
|
||||
|
||||
if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton {
|
||||
button.image = markingRead ? AppAssets.readClosedImage : AppAssets.readOpenImage
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1152,7 +1152,7 @@ private extension MainWindowController {
|
||||
func canMarkBelowArticlesAsRead() -> Bool {
|
||||
return currentTimelineViewController?.canMarkBelowArticlesAsRead() ?? false
|
||||
}
|
||||
|
||||
|
||||
func canShowShareMenu() -> Bool {
|
||||
|
||||
guard let selectedArticles = selectedArticles else {
|
||||
@@ -1195,7 +1195,7 @@ private extension MainWindowController {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
func validateCleanUp(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
||||
return timelineContainerViewController?.isCleanUpAvailable ?? false
|
||||
}
|
||||
@@ -1235,7 +1235,7 @@ private extension MainWindowController {
|
||||
button.image = AppAssets.filterInactive
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1268,7 +1268,7 @@ private extension MainWindowController {
|
||||
window?.subtitle = ""
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func setSubtitle(_ count: Int) {
|
||||
let localizedLabel = NSLocalizedString("%d unread", comment: "Unread")
|
||||
let formattedLabel = NSString.localizedStringWithFormat(localizedLabel as NSString, count)
|
||||
@@ -1368,13 +1368,13 @@ private extension MainWindowController {
|
||||
func buildToolbarButton(_ itemIdentifier: NSToolbarItem.Identifier, _ title: String, _ image: NSImage, _ selector: String) -> NSToolbarItem {
|
||||
let toolbarItem = RSToolbarItem(itemIdentifier: itemIdentifier)
|
||||
toolbarItem.autovalidates = true
|
||||
|
||||
|
||||
let button = NSButton()
|
||||
button.bezelStyle = .texturedRounded
|
||||
button.image = image
|
||||
button.imageScaling = .scaleProportionallyDown
|
||||
button.action = Selector((selector))
|
||||
|
||||
|
||||
toolbarItem.view = button
|
||||
toolbarItem.toolTip = title
|
||||
toolbarItem.label = title
|
||||
@@ -1383,23 +1383,23 @@ private extension MainWindowController {
|
||||
|
||||
func buildNewSidebarItemMenu() -> NSMenu {
|
||||
let menu = NSMenu()
|
||||
|
||||
|
||||
let newFeedItem = NSMenuItem()
|
||||
newFeedItem.title = NSLocalizedString("New Feed…", comment: "New Feed")
|
||||
newFeedItem.action = Selector(("showAddFeedWindow:"))
|
||||
menu.addItem(newFeedItem)
|
||||
|
||||
|
||||
let newFolderFeedItem = NSMenuItem()
|
||||
newFolderFeedItem.title = NSLocalizedString("New Folder…", comment: "New Folder")
|
||||
newFolderFeedItem.action = Selector(("showAddFolderWindow:"))
|
||||
menu.addItem(newFolderFeedItem)
|
||||
|
||||
|
||||
return menu
|
||||
}
|
||||
|
||||
func updateArticleThemeMenu() {
|
||||
let articleThemeMenu = NSMenu()
|
||||
|
||||
|
||||
let defaultThemeItem = NSMenuItem()
|
||||
defaultThemeItem.title = ArticleTheme.defaultTheme.name
|
||||
defaultThemeItem.action = #selector(selectArticleTheme(_:))
|
||||
|
||||
@@ -74,7 +74,7 @@ private extension NNW3ImportController {
|
||||
panel.accessoryView = accessoryViewController.view
|
||||
panel.isAccessoryViewDisclosed = true
|
||||
panel.title = NSLocalizedString("Choose a Subscriptions.plist file:", comment: "NNW3 Import")
|
||||
|
||||
|
||||
panel.beginSheetModal(for: window) { modalResult in
|
||||
guard modalResult == .OK, let subscriptionsPlistURL = panel.url else {
|
||||
return
|
||||
|
||||
@@ -22,7 +22,7 @@ final class NNW3OpenPanelAccessoryViewController: NSViewController {
|
||||
}
|
||||
|
||||
// MARK: - NSViewController
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
preconditionFailure("NNW3OpenPanelAccessoryViewController.init(coder) not implemented by design.")
|
||||
}
|
||||
|
||||
@@ -14,24 +14,24 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet weak var accountPopUpButton: NSPopUpButton!
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("ExportOPMLSheet"))
|
||||
}
|
||||
|
||||
|
||||
override func windowDidLoad() {
|
||||
accountPopUpButton.removeAllItems()
|
||||
|
||||
let menu = NSMenu()
|
||||
accountPopUpButton.menu = menu
|
||||
|
||||
|
||||
for oneAccount in AccountManager.shared.sortedAccounts {
|
||||
|
||||
|
||||
let oneMenuItem = NSMenuItem()
|
||||
oneMenuItem.title = oneAccount.nameForDisplay
|
||||
oneMenuItem.representedObject = oneAccount
|
||||
menu.addItem(oneMenuItem)
|
||||
|
||||
|
||||
if oneAccount.accountID == AppDefaults.shared.exportOPMLAccountID {
|
||||
accountPopUpButton.select(oneMenuItem)
|
||||
}
|
||||
@@ -40,14 +40,14 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
guard let window else {
|
||||
return
|
||||
}
|
||||
|
||||
self.hostWindow = hostWindow
|
||||
|
||||
|
||||
if AccountManager.shared.accounts.count == 1 {
|
||||
let account = AccountManager.shared.accounts.first!
|
||||
exportOPML(account: account)
|
||||
@@ -55,13 +55,13 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
hostWindow.beginSheet(window)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
|
||||
@IBAction func cancel(_ sender: Any) {
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func exportOPML(_ sender: Any) {
|
||||
|
||||
guard let menuItem = accountPopUpButton.selectedItem else {
|
||||
@@ -72,11 +72,11 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
AppDefaults.shared.exportOPMLAccountID = account.accountID
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
exportOPML(account: account)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func exportOPML(account: Account) {
|
||||
|
||||
|
||||
let panel = NSSavePanel()
|
||||
panel.allowedContentTypes = [UTType.opml]
|
||||
panel.allowsOtherFileTypes = false
|
||||
@@ -85,10 +85,10 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
panel.nameFieldLabel = NSLocalizedString("Export to:", comment: "Export OPML")
|
||||
panel.message = NSLocalizedString("Choose a location for the exported OPML file.", comment: "Export OPML")
|
||||
panel.isExtensionHidden = false
|
||||
|
||||
|
||||
let accountName = account.nameForDisplay.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: .whitespaces)
|
||||
panel.nameFieldStringValue = "Subscriptions-\(accountName).opml"
|
||||
|
||||
|
||||
panel.beginSheetModal(for: hostWindow!) { result in
|
||||
if result == NSApplication.ModalResponse.OK, let url = panel.url {
|
||||
DispatchQueue.main.async {
|
||||
@@ -103,7 +103,7 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,44 +14,44 @@ final class ImportOPMLWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet weak var accountPopUpButton: NSPopUpButton!
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("ImportOPMLSheet"))
|
||||
}
|
||||
|
||||
|
||||
override func windowDidLoad() {
|
||||
accountPopUpButton.removeAllItems()
|
||||
|
||||
|
||||
let menu = NSMenu()
|
||||
accountPopUpButton.menu = menu
|
||||
|
||||
for oneAccount in AccountManager.shared.sortedActiveAccounts {
|
||||
|
||||
|
||||
if oneAccount.behaviors.contains(.disallowOPMLImports) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
let oneMenuItem = NSMenuItem()
|
||||
oneMenuItem.title = oneAccount.nameForDisplay
|
||||
oneMenuItem.representedObject = oneAccount
|
||||
menu.addItem(oneMenuItem)
|
||||
|
||||
|
||||
if oneAccount.accountID == AppDefaults.shared.importOPMLAccountID {
|
||||
accountPopUpButton.select(oneMenuItem)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: API
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
guard let window else {
|
||||
return
|
||||
}
|
||||
|
||||
self.hostWindow = hostWindow
|
||||
|
||||
|
||||
if AccountManager.shared.activeAccounts.count == 1 {
|
||||
let account = AccountManager.shared.activeAccounts.first!
|
||||
importOPML(account: account)
|
||||
@@ -59,28 +59,28 @@ final class ImportOPMLWindowController: NSWindowController {
|
||||
hostWindow.beginSheet(window)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
|
||||
@IBAction func cancel(_ sender: Any) {
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func importOPML(_ sender: Any) {
|
||||
|
||||
guard let menuItem = accountPopUpButton.selectedItem else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let account = menuItem.representedObject as! Account
|
||||
AppDefaults.shared.importOPMLAccountID = account.accountID
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
importOPML(account: account)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func importOPML(account: Account) {
|
||||
|
||||
|
||||
let panel = NSOpenPanel()
|
||||
panel.canDownloadUbiquitousContents = true
|
||||
panel.canResolveUbiquitousConflicts = true
|
||||
@@ -90,7 +90,7 @@ final class ImportOPMLWindowController: NSWindowController {
|
||||
panel.resolvesAliases = true
|
||||
panel.allowedContentTypes = [UTType.opml, UTType.xml]
|
||||
panel.allowsOtherFileTypes = false
|
||||
|
||||
|
||||
panel.beginSheetModal(for: hostWindow!) { modalResult in
|
||||
if modalResult == NSApplication.ModalResponse.OK, let url = panel.url {
|
||||
account.importOPML(url) { result in
|
||||
@@ -103,7 +103,7 @@ final class ImportOPMLWindowController: NSWindowController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import AppKit
|
||||
@objc final class SharingServiceDelegate: NSObject, NSSharingServiceDelegate {
|
||||
|
||||
weak var window: NSWindow?
|
||||
|
||||
|
||||
init(_ window: NSWindow?) {
|
||||
self.window = window
|
||||
}
|
||||
@@ -24,9 +24,9 @@ import AppKit
|
||||
}
|
||||
.joined(separator: ", ")
|
||||
}
|
||||
|
||||
|
||||
func sharingService(_ sharingService: NSSharingService, sourceWindowForShareItems items: [Any], sharingContentScope: UnsafeMutablePointer<NSSharingService.SharingContentScope>) -> NSWindow? {
|
||||
return window
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,13 +10,13 @@ import AppKit
|
||||
import RSCore
|
||||
|
||||
@objc final class SharingServicePickerDelegate: NSObject, NSSharingServicePickerDelegate {
|
||||
|
||||
|
||||
private let sharingServiceDelegate: SharingServiceDelegate
|
||||
|
||||
|
||||
init(_ window: NSWindow?) {
|
||||
sharingServiceDelegate = SharingServiceDelegate(window)
|
||||
}
|
||||
|
||||
|
||||
func sharingServicePicker(_ sharingServicePicker: NSSharingServicePicker, sharingServicesForItems items: [Any], proposedSharingServices proposedServices: [NSSharingService]) -> [NSSharingService] {
|
||||
let filteredServices = proposedServices.filter { $0.menuItemTitle != "NetNewsWire" }
|
||||
return filteredServices + SharingServicePickerDelegate.customSharingServices(for: items)
|
||||
@@ -34,7 +34,7 @@ import RSCore
|
||||
guard let object = items.first else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
guard sendToCommand.canSendObject(object, selectedText: nil) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ final class SidebarCell : NSTableCellView {
|
||||
unreadCountView.isSelected = (backgroundStyle != .normal)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override var isFlipped: Bool {
|
||||
return true
|
||||
}
|
||||
@@ -90,7 +90,7 @@ final class SidebarCell : NSTableCellView {
|
||||
super.init(frame: frameRect)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
commonInit()
|
||||
@@ -139,10 +139,10 @@ private extension SidebarCell {
|
||||
titleView.setFrame(ifNotEqualTo: layout.titleRect)
|
||||
unreadCountView.setFrame(ifNotEqualTo: layout.unreadCountRect)
|
||||
}
|
||||
|
||||
|
||||
func updateFaviconImage() {
|
||||
var updatedIconImage = iconImage
|
||||
|
||||
|
||||
if let iconImage = iconImage, iconImage.isSymbol {
|
||||
var tintColor: CGColor
|
||||
if backgroundStyle != .normal {
|
||||
@@ -163,5 +163,5 @@ private extension SidebarCell {
|
||||
faviconImageView.iconImage = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ struct SidebarCellAppearance: Equatable {
|
||||
imageSize = CGSize(width: 19, height: 19)
|
||||
textFieldFontSize = 13
|
||||
}
|
||||
|
||||
|
||||
self.textFieldFont = NSFont.systemFont(ofSize: textFieldFontSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ struct SidebarCellLayout {
|
||||
let faviconRect: CGRect
|
||||
let titleRect: CGRect
|
||||
let unreadCountRect: CGRect
|
||||
|
||||
|
||||
init(appearance: SidebarCellAppearance, cellSize: NSSize, shouldShowImage: Bool, textField: NSTextField, unreadCountView: UnreadCountView) {
|
||||
|
||||
let bounds = NSRect(x: 0.0, y: 0.0, width: floor(cellSize.width), height: floor(cellSize.height))
|
||||
|
||||
@@ -23,7 +23,7 @@ import RSCore
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
func keydown(_ event: NSEvent, in view: NSView) -> Bool {
|
||||
|
||||
if MainWindowKeyboardHandler.shared.keydown(event, in: view) {
|
||||
|
||||
@@ -67,7 +67,7 @@ struct PasteboardFeed: Hashable {
|
||||
if let accountTypeString = dictionary[Key.accountType], let accountTypeInt = Int(accountTypeString) {
|
||||
accountType = AccountType(rawValue: accountTypeInt)
|
||||
}
|
||||
|
||||
|
||||
let containerName = dictionary[Key.containerName]
|
||||
self.init(url: url, feedID: feedID, homePageURL: homePageURL, name: name, editedName: editedName, accountID: accountID, accountType: accountType, containerName: containerName)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import RSCore
|
||||
typealias PasteboardFolderDictionary = [String: String]
|
||||
|
||||
struct PasteboardFolder: Hashable {
|
||||
|
||||
|
||||
private struct Key {
|
||||
static let name = "name"
|
||||
// Internal
|
||||
@@ -21,30 +21,30 @@ struct PasteboardFolder: Hashable {
|
||||
static let accountID = "accountID"
|
||||
}
|
||||
|
||||
|
||||
|
||||
let name: String
|
||||
let folderID: String?
|
||||
let accountID: String?
|
||||
|
||||
|
||||
init(name: String, folderID: String?, accountID: String?) {
|
||||
self.name = name
|
||||
self.folderID = folderID
|
||||
self.accountID = accountID
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Reading
|
||||
|
||||
|
||||
init?(dictionary: PasteboardFolderDictionary) {
|
||||
guard let name = dictionary[Key.name] else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let folderID = dictionary[Key.folderID]
|
||||
let accountID = dictionary[Key.accountID]
|
||||
|
||||
|
||||
self.init(name: name, folderID: folderID, accountID: accountID)
|
||||
}
|
||||
|
||||
|
||||
init?(pasteboardItem: NSPasteboardItem) {
|
||||
var pasteboardType: NSPasteboard.PasteboardType?
|
||||
if pasteboardItem.types.contains(FolderPasteboardWriter.folderUTIInternalType) {
|
||||
@@ -57,10 +57,10 @@ struct PasteboardFolder: Hashable {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
static func pasteboardFolders(with pasteboard: NSPasteboard) -> Set<PasteboardFolder>? {
|
||||
guard let items = pasteboard.pasteboardItems else {
|
||||
return nil
|
||||
@@ -68,9 +68,9 @@ struct PasteboardFolder: Hashable {
|
||||
let folders = items.compactMap { PasteboardFolder(pasteboardItem: $0) }
|
||||
return folders.isEmpty ? nil : Set(folders)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Writing
|
||||
|
||||
|
||||
func internalDictionary() -> PasteboardFolderDictionary {
|
||||
var d = PasteboardFeedDictionary()
|
||||
d[PasteboardFolder.Key.name] = name
|
||||
@@ -130,7 +130,7 @@ private extension FolderPasteboardWriter {
|
||||
var pasteboardFolder: PasteboardFolder {
|
||||
return PasteboardFolder(name: folder.name ?? "", folderID: String(folder.folderID), accountID: folder.account?.accountID)
|
||||
}
|
||||
|
||||
|
||||
var internalDictionary: PasteboardFeedDictionary {
|
||||
return pasteboardFolder.internalDictionary()
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ final class RenameWindowController: NSWindowController {
|
||||
@IBOutlet var renamePrompt: NSTextField!
|
||||
@IBOutlet var newTitleTextField: NSTextField!
|
||||
@IBOutlet var renameButton: NSButton!
|
||||
|
||||
|
||||
private var originalTitle: String?
|
||||
private var representedObject: Any?
|
||||
private var delegate: RenameWindowControllerDelegate?
|
||||
|
||||
@@ -11,12 +11,12 @@ import RSTree
|
||||
import Account
|
||||
|
||||
enum SidebarDeleteItemsAlert {
|
||||
|
||||
|
||||
/// Builds a delete confirmation dialog for the supplied nodes
|
||||
static func build(_ nodes: [Node]) -> NSAlert {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
|
||||
|
||||
if nodes.count == 1 {
|
||||
if let folder = nodes.first?.representedObject as? Folder {
|
||||
alert.messageText = NSLocalizedString("Delete Folder", comment: "Delete Folder")
|
||||
@@ -32,11 +32,11 @@ enum SidebarDeleteItemsAlert {
|
||||
let localizedInformativeText = NSLocalizedString("Are you sure you want to delete the %d selected items?", comment: "Items delete text")
|
||||
alert.informativeText = NSString.localizedStringWithFormat(localizedInformativeText as NSString, nodes.count) as String
|
||||
}
|
||||
|
||||
|
||||
alert.addButton(withTitle: NSLocalizedString("Delete", comment: "Delete Account"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel Delete Account"))
|
||||
|
||||
|
||||
return alert
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import Account
|
||||
guard var pasteboardWriter = (node.representedObject as? PasteboardWriterOwner)?.pasteboardWriter else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Feed objects don't have knowledge of their parent so we inject parent container information
|
||||
// into FeedPasteboardWriter instance and it adds this field to the PasteboardFeed objects it writes.
|
||||
// Add similar to FolderPasteboardWriter if/when we allow sub-folders
|
||||
@@ -76,7 +76,7 @@ import Account
|
||||
return validateLocalFoldersDrop(outlineView, draggedFolders, parentNode, index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let draggedFeeds = draggedFeeds {
|
||||
let contentsType = draggedFeedContentsType(draggedFeeds)
|
||||
|
||||
@@ -96,7 +96,7 @@ import Account
|
||||
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
}
|
||||
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
|
||||
let draggedFolders = PasteboardFolder.pasteboardFolders(with: info.draggingPasteboard)
|
||||
let draggedFeeds = PasteboardFeed.pasteboardFeeds(with: info.draggingPasteboard)
|
||||
@@ -108,7 +108,7 @@ import Account
|
||||
if let draggedFolders = draggedFolders {
|
||||
return acceptLocalFoldersDrop(outlineView, draggedFolders, parentNode, index)
|
||||
}
|
||||
|
||||
|
||||
if let draggedFeeds = draggedFeeds {
|
||||
let contentsType = draggedFeedContentsType(draggedFeeds)
|
||||
|
||||
@@ -124,7 +124,7 @@ import Account
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return localDragOperation(parentNode: parentNode, draggedFeeds)
|
||||
}
|
||||
|
||||
|
||||
func localDragOperation(parentNode: Node, _ draggedFeeds: Set<PasteboardFeed>)-> NSDragOperation {
|
||||
guard let firstDraggedFeed = draggedFeeds.first else { return .move }
|
||||
if sameAccount(firstDraggedFeed, parentNode) {
|
||||
@@ -282,7 +282,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func validateLocalFolderDrop(_ outlineView: NSOutlineView, _ draggedFolder: PasteboardFolder, _ parentNode: Node, _ index: Int) -> NSDragOperation {
|
||||
guard let dropAccount = parentNode.representedObject as? Account, dropAccount.accountID != draggedFolder.accountID else {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
@@ -296,7 +296,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return .copy // different AccountIDs means can only copy
|
||||
}
|
||||
|
||||
|
||||
func validateLocalFoldersDrop(_ outlineView: NSOutlineView, _ draggedFolders: Set<PasteboardFolder>, _ parentNode: Node, _ index: Int) -> NSDragOperation {
|
||||
guard let dropAccount = parentNode.representedObject as? Account else {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
@@ -314,7 +314,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return .copy // different AccountIDs means can only copy
|
||||
}
|
||||
|
||||
|
||||
func copyFeedInAccount(_ feed: Feed, _ destination: Container ) {
|
||||
destination.account?.addFeed(feed, to: destination) { result in
|
||||
switch result {
|
||||
@@ -325,7 +325,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func moveFeedInAccount(_ feed: Feed, _ source: Container, _ destination: Container) {
|
||||
BatchUpdate.shared.start()
|
||||
source.account?.moveFeed(feed, from: source, to: destination) { result in
|
||||
@@ -338,12 +338,12 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func copyFeedBetweenAccounts(_ feed: Feed, _ destinationContainer: Container) {
|
||||
guard let destinationAccount = destinationContainer.account else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let existingFeed = destinationAccount.existingFeed(withURL: feed.url) {
|
||||
destinationAccount.addFeed(existingFeed, to: destinationContainer) { result in
|
||||
switch result {
|
||||
@@ -369,7 +369,7 @@ private extension SidebarOutlineDataSource {
|
||||
guard draggedFeeds.isEmpty == false else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
draggedFeeds.forEach { pasteboardFeed in
|
||||
guard let sourceAccountID = pasteboardFeed.accountID,
|
||||
let sourceAccount = AccountManager.shared.existingAccount(with: sourceAccountID),
|
||||
@@ -379,7 +379,7 @@ private extension SidebarOutlineDataSource {
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var sourceContainer: Container = sourceAccount // default to top level,
|
||||
if let containerName = pasteboardFeed.containerName { // then check if have folder info to use instead.
|
||||
if let folderContainer = sourceAccount.existingFolder(with: containerName ) {
|
||||
@@ -388,7 +388,7 @@ private extension SidebarOutlineDataSource {
|
||||
sourceContainer = folderContainer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if sameAccount(pasteboardFeed, parentNode) {
|
||||
if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false {
|
||||
copyFeedInAccount(feed, destinationContainer)
|
||||
@@ -399,7 +399,7 @@ private extension SidebarOutlineDataSource {
|
||||
copyFeedBetweenAccounts(feed, destinationContainer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -434,12 +434,12 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return ancestorThatCanAcceptNonLocalFeed(parentNode)
|
||||
}
|
||||
|
||||
|
||||
func copyFolderBetweenAccounts(folder: Folder, to parentNode: Node) {
|
||||
guard let destinationAccount = nodeAccount(parentNode) else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
destinationAccount.addFolder(folder.name ?? "") { result in
|
||||
switch result {
|
||||
case .success(let destinationFolder):
|
||||
@@ -488,7 +488,7 @@ private extension SidebarOutlineDataSource {
|
||||
copyFolderBetweenAccounts(folder: folder, to: parentNode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ private extension SidebarOutlineDataSource {
|
||||
let folder = parentNode.representedObject as? Folder
|
||||
appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder)
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -524,14 +524,14 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func sameAccount(_ pasteboardFeed: PasteboardFeed, _ parentNode: Node) -> Bool {
|
||||
if let accountID = pasteboardFeed.accountID {
|
||||
return sameAccount(accountID, parentNode)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func sameAccount(_ pasteboardFolder: PasteboardFolder, _ parentNode: Node) -> Bool {
|
||||
if let accountID = pasteboardFolder.accountID {
|
||||
return sameAccount(accountID, parentNode)
|
||||
@@ -547,7 +547,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func nodeAccount(_ node: Node) -> Account? {
|
||||
if let account = node.representedObject as? Account {
|
||||
return account
|
||||
@@ -560,11 +560,11 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func nodeAccountID(_ node: Node) -> String? {
|
||||
return nodeAccount(node)?.accountID
|
||||
}
|
||||
|
||||
|
||||
func nodeHasChildRepresentingAnyDraggedFeed(_ parentNode: Node, _ draggedFeeds: Set<PasteboardFeed>) -> Bool {
|
||||
for node in parentNode.childNodes {
|
||||
if nodeRepresentsAnyDraggedFeed(node, draggedFeeds) {
|
||||
@@ -577,7 +577,7 @@ private extension SidebarOutlineDataSource {
|
||||
func violatesAccountSpecificBehavior(_ dropTargetNode: Node, _ draggedFeed: PasteboardFeed) -> Bool {
|
||||
return violatesAccountSpecificBehavior(dropTargetNode, Set([draggedFeed]))
|
||||
}
|
||||
|
||||
|
||||
func violatesAccountSpecificBehavior(_ dropTargetNode: Node, _ draggedFeeds: Set<PasteboardFeed>) -> Bool {
|
||||
if violatesDisallowFeedInRootFolder(dropTargetNode) {
|
||||
return true
|
||||
@@ -586,23 +586,23 @@ private extension SidebarOutlineDataSource {
|
||||
if violatesDisallowFeedCopyInRootFolder(dropTargetNode, draggedFeeds) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
if violatesDisallowFeedInMultipleFolders(dropTargetNode, draggedFeeds) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func violatesDisallowFeedInRootFolder(_ dropTargetNode: Node) -> Bool {
|
||||
guard let parentAccount = nodeAccount(dropTargetNode), parentAccount.behaviors.contains(.disallowFeedInRootFolder) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
if dropTargetNode.representedObject is Account {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -610,17 +610,17 @@ private extension SidebarOutlineDataSource {
|
||||
guard let dropTargetAccount = nodeAccount(dropTargetNode), dropTargetAccount.behaviors.contains(.disallowFeedCopyInRootFolder) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
for draggedFeed in draggedFeeds {
|
||||
if dropTargetAccount.accountID != draggedFeed.accountID {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if dropTargetNode.representedObject is Account && (NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -628,7 +628,7 @@ private extension SidebarOutlineDataSource {
|
||||
guard let dropTargetAccount = nodeAccount(dropTargetNode), dropTargetAccount.behaviors.contains(.disallowFeedInMultipleFolders) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
for draggedFeed in draggedFeeds {
|
||||
if dropTargetAccount.accountID == draggedFeed.accountID {
|
||||
if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false {
|
||||
@@ -640,7 +640,7 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ private extension SidebarOutlineDataSource {
|
||||
let draggedFolderNode = Node(representedObject: draggedFolderWrapper, parent: nil)
|
||||
draggedFolderNode.canHaveChildNodes = true
|
||||
let nodes = parentNode.childNodes + [draggedFolderNode]
|
||||
|
||||
|
||||
// Revisit if the tree controller can ever be sorted in some other way.
|
||||
let sortedNodes = nodes.sortedAlphabeticallyWithFoldersAtEnd()
|
||||
let index = sortedNodes.firstIndex(of: draggedFolderNode)!
|
||||
@@ -681,12 +681,12 @@ final class PasteboardFeedObjectWrapper: DisplayNameProvider {
|
||||
}
|
||||
|
||||
final class PasteboardFolderObjectWrapper: DisplayNameProvider {
|
||||
|
||||
|
||||
var nameForDisplay: String {
|
||||
return pasteboardFolder.name
|
||||
}
|
||||
let pasteboardFolder: PasteboardFolder
|
||||
|
||||
|
||||
init(pasteboardFolder: PasteboardFolder) {
|
||||
self.pasteboardFolder = pasteboardFolder
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ final class SidebarOutlineView : NSOutlineView {
|
||||
// MARK: NSView
|
||||
|
||||
override func viewWillStartLiveResize() {
|
||||
|
||||
|
||||
if let scrollView = self.enclosingScrollView {
|
||||
scrollView.hasVerticalScroller = false
|
||||
}
|
||||
super.viewWillStartLiveResize()
|
||||
}
|
||||
|
||||
|
||||
override func viewDidEndLiveResize() {
|
||||
|
||||
|
||||
if let scrollView = self.enclosingScrollView {
|
||||
scrollView.hasVerticalScroller = true
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ final class SidebarStatusBarView: NSView {
|
||||
let progressLabelFontSize = progressLabel.font?.pointSize ?? 13.0
|
||||
progressLabel.font = NSFont.monospacedDigitSystemFont(ofSize: progressLabelFontSize, weight: NSFont.Weight.regular)
|
||||
progressLabel.stringValue = ""
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .combinedRefreshProgressDidChange, object: nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ extension SidebarViewController {
|
||||
guard let menuItem = sender as? NSMenuItem, let objects = menuItem.representedObject as? [Any] else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let articles = unreadArticles(for: objects)
|
||||
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: Array(articles), markingRead: true, undoManager: undoManager) else {
|
||||
return
|
||||
@@ -80,7 +80,7 @@ extension SidebarViewController {
|
||||
guard let menuItem = sender as? NSMenuItem, let objects = menuItem.representedObject as? [AnyObject] else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let nodes = objects.compactMap { treeController.nodeInTreeRepresentingObject($0) }
|
||||
|
||||
let alert = SidebarDeleteItemsAlert.build(nodes)
|
||||
@@ -103,7 +103,7 @@ extension SidebarViewController {
|
||||
}
|
||||
window.beginSheet(renameSheet)
|
||||
}
|
||||
|
||||
|
||||
@objc func toggleNotificationsFromContextMenu(_ sender: Any?) {
|
||||
guard let item = sender as? NSMenuItem,
|
||||
let feed = item.representedObject as? Feed else {
|
||||
@@ -134,7 +134,7 @@ extension SidebarViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func toggleArticleExtractorFromContextMenu(_ sender: Any?) {
|
||||
guard let item = sender as? NSMenuItem,
|
||||
let feed = item.representedObject as? Feed else {
|
||||
@@ -144,7 +144,7 @@ extension SidebarViewController {
|
||||
feed.isArticleExtractorAlwaysOn?.toggle()
|
||||
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
|
||||
}
|
||||
|
||||
|
||||
func showNotificationsNotEnabledAlert() {
|
||||
DispatchQueue.main.async {
|
||||
let alert = NSAlert()
|
||||
@@ -163,7 +163,7 @@ extension SidebarViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension SidebarViewController: RenameWindowControllerDelegate {
|
||||
@@ -229,9 +229,9 @@ private extension SidebarViewController {
|
||||
menu.addItem(item)
|
||||
}
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
|
||||
let notificationText = feed.notificationDisplayName.capitalized
|
||||
|
||||
|
||||
let notificationMenuItem = menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), feed, image: AppAssets.notificationImage)
|
||||
if feed.isNotifyAboutNewArticles == nil || feed.isNotifyAboutNewArticles! == false {
|
||||
notificationMenuItem.state = .off
|
||||
@@ -251,7 +251,7 @@ private extension SidebarViewController {
|
||||
menu.addItem(articleExtractorMenuItem)
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
|
||||
menu.addItem(renameMenuItem(feed))
|
||||
menu.addItem(deleteMenuItem([feed]))
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ protocol SidebarDelegate: AnyObject {
|
||||
}
|
||||
|
||||
@objc final class SidebarViewController: NSViewController, NSOutlineViewDelegate, NSMenuDelegate, UndoableCommandRunner {
|
||||
|
||||
|
||||
@IBOutlet weak var outlineView: NSOutlineView!
|
||||
|
||||
|
||||
weak var delegate: SidebarDelegate?
|
||||
|
||||
weak var splitViewItem: NSSplitViewItem?
|
||||
@@ -35,7 +35,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
let selectedFeeds = selectedFeeds.compactMap { $0.sidebarItemID?.userInfo as? [String: String] }
|
||||
return SidebarWindowState(isReadFiltered: isReadFiltered, expandedContainers: expandedContainers, selectedFeeds: selectedFeeds)
|
||||
}
|
||||
|
||||
|
||||
private let rebuildTreeAndRestoreSelectionQueue = CoalescingQueue(name: "Rebuild Tree Queue", interval: 1.0)
|
||||
let treeControllerDelegate = SidebarTreeControllerDelegate()
|
||||
lazy var treeController: TreeController = {
|
||||
@@ -44,7 +44,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
lazy var dataSource: SidebarOutlineDataSource = {
|
||||
return SidebarOutlineDataSource(treeController: treeController)
|
||||
}()
|
||||
|
||||
|
||||
var isReadFiltered: Bool {
|
||||
get {
|
||||
return treeControllerDelegate.isReadFiltered
|
||||
@@ -97,22 +97,22 @@ protocol SidebarDelegate: AnyObject {
|
||||
}
|
||||
}
|
||||
expandNodes()
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
|
||||
func restoreState(from state: SidebarWindowState?) {
|
||||
guard let state else { return }
|
||||
|
||||
|
||||
let containerIdentifers = state.expandedContainers.compactMap( { ContainerIdentifier(userInfo: $0) })
|
||||
expandedTable = Set(containerIdentifers)
|
||||
|
||||
let selectedFeedIdentifers = Set(state.selectedFeeds.compactMap( { SidebarItemIdentifier(userInfo: $0) }))
|
||||
selectedFeedIdentifers.forEach { treeControllerDelegate.addFilterException($0) }
|
||||
|
||||
|
||||
rebuildTreeAndReloadDataIfNeeded()
|
||||
|
||||
|
||||
var selectIndexes = IndexSet()
|
||||
|
||||
func selectFeedsVisitor(node: Node) {
|
||||
@@ -126,7 +126,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
treeController.visitNodes(selectFeedsVisitor(node:))
|
||||
outlineView.selectRowIndexes(selectIndexes, byExtendingSelection: false)
|
||||
focus()
|
||||
|
||||
|
||||
isReadFiltered = state.isReadFiltered
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
guard let representedObject = note.object else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let timelineViewController = representedObject as? TimelineViewController {
|
||||
configureUnreadCountForCellsForRepresentedObjects(timelineViewController.representedObjects)
|
||||
} else {
|
||||
@@ -206,7 +206,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
@objc func accountsDidChange(_ notification: Notification) {
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
|
||||
|
||||
@objc func accountStateDidChange(_ notification: Notification) {
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
@@ -214,7 +214,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
@objc func batchUpdateDidPerform(_ notification: Notification) {
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
|
||||
|
||||
@objc func userDidAddFeed(_ notification: Notification) {
|
||||
guard let feed = notification.userInfo?[UserInfoKey.feed] else {
|
||||
return
|
||||
@@ -230,7 +230,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else { return }
|
||||
configureCellsForRepresentedObject(feed)
|
||||
}
|
||||
|
||||
|
||||
@objc func feedSettingDidChange(_ note: Notification) {
|
||||
guard let feed = note.object as? Feed, let key = note.userInfo?[Feed.SettingUserInfoKey] as? String else {
|
||||
return
|
||||
@@ -259,18 +259,18 @@ protocol SidebarDelegate: AnyObject {
|
||||
self.restoreSelection(to: savedSelection, sendNotificationIfChanged: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func delete(_ sender: AnyObject?) {
|
||||
let availableSelectedNodes = selectedNodes.filter { !($0.representedObject is PseudoFeed) }
|
||||
|
||||
|
||||
if availableSelectedNodes.isEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let alert = SidebarDeleteItemsAlert.build(availableSelectedNodes)
|
||||
|
||||
|
||||
alert.beginSheetModal(for: view.window!) { [weak self] result in
|
||||
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
|
||||
guard let self = self else { return }
|
||||
@@ -283,7 +283,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func doubleClickedSidebar(_ sender: Any?) {
|
||||
guard outlineView.clickedRow == outlineView.selectedRow else {
|
||||
return
|
||||
@@ -331,20 +331,20 @@ protocol SidebarDelegate: AnyObject {
|
||||
}
|
||||
|
||||
// MARK: - Navigation
|
||||
|
||||
|
||||
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
||||
if let _ = nextSelectableRowWithUnreadArticle(wrappingToTop: wrapping) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func goToNextUnread(wrappingToTop wrapping: Bool = false) {
|
||||
guard let row = nextSelectableRowWithUnreadArticle(wrappingToTop: wrapping) else {
|
||||
assertionFailure("goToNextUnread called before checking if there is a next unread.")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
NSCursor.setHiddenUntilMouseMoves(true)
|
||||
outlineView.selectRowIndexes(IndexSet([row]), byExtendingSelection: false)
|
||||
outlineView.scrollTo(row: row)
|
||||
@@ -371,13 +371,13 @@ protocol SidebarDelegate: AnyObject {
|
||||
// If the clickedRow is part of the selected rows, then do a contextual menu for all the selected rows.
|
||||
return contextualMenuForSelectedObjects()
|
||||
}
|
||||
|
||||
|
||||
let object = node.representedObject
|
||||
return menu(for: [object])
|
||||
}
|
||||
|
||||
// MARK: - NSMenuDelegate
|
||||
|
||||
|
||||
public func menuNeedsUpdate(_ menu: NSMenu) {
|
||||
menu.removeAllItems()
|
||||
guard let contextualMenu = contextualMenuForClickedRows() else {
|
||||
@@ -388,7 +388,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
|
||||
|
||||
// MARK: - NSOutlineViewDelegate
|
||||
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
|
||||
let node = item as! Node
|
||||
|
||||
@@ -433,7 +433,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
func outlineViewSelectionDidChange(_ notification: Notification) {
|
||||
selectionDidChange(selectedObjects.isEmpty ? nil : selectedObjects)
|
||||
}
|
||||
|
||||
|
||||
func outlineViewItemDidExpand(_ notification: Notification) {
|
||||
guard let node = notification.userInfo?["NSObject"] as? Node,
|
||||
let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else {
|
||||
@@ -444,7 +444,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
delegate?.sidebarInvalidatedRestorationState(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func outlineViewItemDidCollapse(_ notification: Notification) {
|
||||
guard let node = notification.userInfo?["NSObject"] as? Node,
|
||||
let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else {
|
||||
@@ -455,32 +455,32 @@ protocol SidebarDelegate: AnyObject {
|
||||
delegate?.sidebarInvalidatedRestorationState(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//MARK: - Node Manipulation
|
||||
|
||||
|
||||
func deleteNodes(_ nodes: [Node]) {
|
||||
let nodesToDelete = treeController.normalizedSelectedNodes(nodes)
|
||||
|
||||
|
||||
guard let undoManager = undoManager, let deleteCommand = DeleteCommand(nodesToDelete: nodesToDelete, treeController: treeController, undoManager: undoManager, errorHandler: ErrorHandler.present) else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
animatingChanges = true
|
||||
outlineView.beginUpdates()
|
||||
|
||||
|
||||
let indexSetsGroupedByParent = Node.indexSetsGroupedByParent(nodesToDelete)
|
||||
for (parent, indexSet) in indexSetsGroupedByParent {
|
||||
outlineView.removeItems(at: indexSet, inParent: parent.isRoot ? nil : parent, withAnimation: [.slideDown])
|
||||
}
|
||||
|
||||
|
||||
outlineView.endUpdates()
|
||||
|
||||
|
||||
runCommand(deleteCommand)
|
||||
animatingChanges = false
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
|
||||
|
||||
func selectFeed(_ sidebarItem: SidebarItem) {
|
||||
if isReadFiltered, let sidebarItemID = sidebarItem.sidebarItemID {
|
||||
self.treeControllerDelegate.addFilterException(sidebarItemID)
|
||||
@@ -491,7 +491,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
self.treeControllerDelegate.addFilterException(parentFolderSidebarItemID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addTreeControllerToFilterExceptions()
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
@@ -517,7 +517,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
delegate?.sidebarInvalidatedRestorationState(self)
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - NSUserInterfaceValidations
|
||||
@@ -535,18 +535,18 @@ extension SidebarViewController: NSUserInterfaceValidations {
|
||||
//MARK: - Private
|
||||
|
||||
private extension SidebarViewController {
|
||||
|
||||
|
||||
var accountNodes: [Account] {
|
||||
return treeController.rootNode.childNodes.compactMap { $0.representedObject as? Account }
|
||||
}
|
||||
|
||||
|
||||
var selectedNodes: [Node] {
|
||||
if let nodes = outlineView.selectedItems as? [Node] {
|
||||
return nodes
|
||||
}
|
||||
return [Node]()
|
||||
}
|
||||
|
||||
|
||||
var selectedFeeds: [SidebarItem] {
|
||||
selectedNodes.compactMap { $0.representedObject as? SidebarItem }
|
||||
}
|
||||
@@ -564,11 +564,11 @@ private extension SidebarViewController {
|
||||
}
|
||||
return node.representedObject as? Feed
|
||||
}
|
||||
|
||||
|
||||
func addAllSelectedToFilterExceptions() {
|
||||
selectedFeeds.forEach { addToFilterExceptionsIfNecessary($0) }
|
||||
}
|
||||
|
||||
|
||||
func addToFilterExceptionsIfNecessary(_ sidebarItem: SidebarItem?) {
|
||||
if isReadFiltered, let sidebarItemID = sidebarItem?.sidebarItemID {
|
||||
if sidebarItem is PseudoFeed {
|
||||
@@ -585,29 +585,29 @@ private extension SidebarViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addParentFolderToFilterExceptions(_ sidebarItem: SidebarItem) {
|
||||
guard let node = treeController.rootNode.descendantNodeRepresentingObject(sidebarItem as AnyObject),
|
||||
let folder = node.parent?.representedObject as? Folder,
|
||||
let folderSidebarItemID = folder.sidebarItemID else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
treeControllerDelegate.addFilterException(folderSidebarItemID)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func queueRebuildTreeAndRestoreSelection() {
|
||||
rebuildTreeAndRestoreSelectionQueue.add(self, #selector(rebuildTreeAndRestoreSelection))
|
||||
}
|
||||
|
||||
|
||||
@objc func rebuildTreeAndRestoreSelection() {
|
||||
let savedAccounts = accountNodes
|
||||
let savedSelection = selectedNodes
|
||||
|
||||
|
||||
rebuildTreeAndReloadDataIfNeeded()
|
||||
restoreSelection(to: savedSelection, sendNotificationIfChanged: true)
|
||||
|
||||
|
||||
// Automatically expand any new or newly active accounts
|
||||
AccountManager.shared.activeAccounts.forEach { account in
|
||||
if !savedAccounts.contains(account) {
|
||||
@@ -615,9 +615,9 @@ private extension SidebarViewController {
|
||||
outlineView.expandItem(accountNode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func rebuildTreeAndReloadDataIfNeeded() {
|
||||
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
||||
addAllSelectedToFilterExceptions()
|
||||
@@ -627,11 +627,11 @@ private extension SidebarViewController {
|
||||
expandNodes()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func expandNodes() {
|
||||
treeController.visitNodes(expandNodesVisitor(node:))
|
||||
}
|
||||
|
||||
|
||||
func expandNodesVisitor(node: Node) {
|
||||
if let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID {
|
||||
if expandedTable.contains(containerID) {
|
||||
@@ -641,7 +641,7 @@ private extension SidebarViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addTreeControllerToFilterExceptions() {
|
||||
treeController.visitNodes(addTreeControllerToFilterExceptionsVisitor(node:))
|
||||
}
|
||||
@@ -688,13 +688,13 @@ private extension SidebarViewController {
|
||||
if row < 0 || row >= outlineView.numberOfRows {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
if let node = outlineView.item(atRow: row) as? Node {
|
||||
return node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func rowHasAtLeastOneUnreadArticle(_ row: Int) -> Bool {
|
||||
if let oneNode = nodeForRow(row) {
|
||||
if let unreadCountProvider = oneNode.representedObject as? UnreadCountProvider {
|
||||
@@ -750,7 +750,7 @@ private extension SidebarViewController {
|
||||
return row
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -758,7 +758,7 @@ private extension SidebarViewController {
|
||||
guard let accountID = userInfo?[ArticlePathKey.accountID] as? String else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
if let node = treeController.rootNode.descendantNode(where: { ($0.representedObject as? Account)?.accountID == accountID }) {
|
||||
return node
|
||||
}
|
||||
@@ -773,7 +773,7 @@ private extension SidebarViewController {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func findFeedNode(_ userInfo: [AnyHashable : Any]?, beginningAt startingNode: Node) -> Node? {
|
||||
guard let feedID = userInfo?[ArticlePathKey.feedID] as? String else {
|
||||
return nil
|
||||
@@ -783,7 +783,7 @@ private extension SidebarViewController {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func configure(_ cell: SidebarCell, _ node: Node) {
|
||||
cell.cellAppearance = SidebarCellAppearance(rowSizeStyle: outlineView.effectiveRowSizeStyle)
|
||||
cell.name = nameFor(node)
|
||||
@@ -886,7 +886,7 @@ private extension SidebarViewController {
|
||||
func revealAndSelectRepresentedObject(_ representedObject: AnyObject) -> Bool {
|
||||
return outlineView.revealAndSelectRepresentedObject(representedObject, treeController)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension Node {
|
||||
|
||||
@@ -15,7 +15,7 @@ final class SidebarWindowState: NSObject, NSSecureCoding {
|
||||
let isReadFiltered: Bool
|
||||
let expandedContainers: [[String: String]]
|
||||
let selectedFeeds: [[String: String]]
|
||||
|
||||
|
||||
init(isReadFiltered: Bool, expandedContainers: [[String : String]], selectedFeeds: [[String : String]]) {
|
||||
self.isReadFiltered = isReadFiltered
|
||||
self.expandedContainers = expandedContainers
|
||||
@@ -33,7 +33,7 @@ final class SidebarWindowState: NSObject, NSSecureCoding {
|
||||
expandedContainers = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: Key.expandedContainers) as? [[String: String]] ?? []
|
||||
selectedFeeds = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: Key.selectedFeeds) as? [[String: String]] ?? []
|
||||
}
|
||||
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(isReadFiltered, forKey: Key.isReadFiltered)
|
||||
coder.encode(expandedContainers, forKey: Key.expandedContainers)
|
||||
|
||||
@@ -33,11 +33,11 @@ final class UnreadCountView : NSView {
|
||||
needsDisplay = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var currentTextColor: NSColor {
|
||||
return isSelected ? NSColor.white : NSColor.secondaryLabelColor
|
||||
}
|
||||
|
||||
|
||||
private var textAttributes: [NSAttributedString.Key: AnyObject] {
|
||||
return [
|
||||
.foregroundColor: currentTextColor,
|
||||
@@ -48,7 +48,7 @@ final class UnreadCountView : NSView {
|
||||
|
||||
private var intrinsicContentSizeIsValid = false
|
||||
private var _intrinsicContentSize = NSZeroSize
|
||||
|
||||
|
||||
override var intrinsicContentSize: NSSize {
|
||||
if !intrinsicContentSizeIsValid {
|
||||
var size = NSZeroSize
|
||||
@@ -62,11 +62,11 @@ final class UnreadCountView : NSView {
|
||||
}
|
||||
return _intrinsicContentSize
|
||||
}
|
||||
|
||||
|
||||
override var isFlipped: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override func invalidateIntrinsicContentSize() {
|
||||
intrinsicContentSizeIsValid = false
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ final class MultilineTextFieldSizer {
|
||||
guard attributedString.length > 0 else {
|
||||
return TextFieldSizeInfo(size: NSSize.zero, numberOfLinesUsed: 0)
|
||||
}
|
||||
|
||||
|
||||
// Assumes the same font family/size for the whole string
|
||||
let font = attributedString.attribute(.font, at: 0, effectiveRange: nil) as! NSFont
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ final class SingleLineTextFieldSizer {
|
||||
var calculatedSize = textField.fittingSize
|
||||
calculatedSize.height = ceil(calculatedSize.height)
|
||||
calculatedSize.width = ceil(calculatedSize.width)
|
||||
|
||||
|
||||
cache[text] = calculatedSize
|
||||
return calculatedSize
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ struct TimelineCellAppearance: Equatable {
|
||||
let showIcon: Bool
|
||||
|
||||
let cellPadding: NSEdgeInsets
|
||||
|
||||
|
||||
let feedNameFont: NSFont
|
||||
|
||||
let dateFont: NSFont
|
||||
@@ -22,7 +22,7 @@ struct TimelineCellAppearance: Equatable {
|
||||
let titleFont: NSFont
|
||||
let titleBottomMargin: CGFloat = 1.0
|
||||
let titleNumberOfLines = 3
|
||||
|
||||
|
||||
let textFont: NSFont
|
||||
|
||||
let textOnlyFont: NSFont
|
||||
@@ -55,7 +55,7 @@ struct TimelineCellAppearance: Equatable {
|
||||
self.textOnlyFont = NSFont.systemFont(ofSize: largeItemFontSize)
|
||||
|
||||
self.showIcon = showIcon
|
||||
|
||||
|
||||
cellPadding = NSEdgeInsets(top: 8.0, left: 4.0, bottom: 10.0, right: 4.0)
|
||||
|
||||
let margin = self.cellPadding.left + self.unreadCircleDimension + self.unreadCircleMarginRight
|
||||
|
||||
@@ -10,9 +10,9 @@ import AppKit
|
||||
import Articles
|
||||
|
||||
struct TimelineCellData {
|
||||
|
||||
|
||||
private static let noText = NSLocalizedString("(No Text)", comment: "No Text")
|
||||
|
||||
|
||||
let title: String
|
||||
let attributedTitle: NSAttributedString
|
||||
let text: String
|
||||
@@ -36,7 +36,7 @@ struct TimelineCellData {
|
||||
} else {
|
||||
self.text = truncatedSummary
|
||||
}
|
||||
|
||||
|
||||
self.dateString = ArticleStringFormatter.dateString(article.logicalDatePublished)
|
||||
|
||||
if let feedName = feedName {
|
||||
@@ -44,7 +44,7 @@ struct TimelineCellData {
|
||||
} else {
|
||||
self.feedName = ""
|
||||
}
|
||||
|
||||
|
||||
if let byline = byline {
|
||||
self.byline = byline
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@ import AppKit
|
||||
import RSCore
|
||||
|
||||
struct TimelineCellLayout {
|
||||
|
||||
|
||||
let width: CGFloat
|
||||
let height: CGFloat
|
||||
let feedNameRect: NSRect
|
||||
@@ -24,9 +24,9 @@ struct TimelineCellLayout {
|
||||
let iconImageRect: NSRect
|
||||
let separatorRect: NSRect
|
||||
let paddingBottom: CGFloat
|
||||
|
||||
|
||||
init(width: CGFloat, height: CGFloat, feedNameRect: NSRect, dateRect: NSRect, titleRect: NSRect, numberOfLinesForTitle: Int, summaryRect: NSRect, textRect: NSRect, unreadIndicatorRect: NSRect, starRect: NSRect, iconImageRect: NSRect, separatorRect: NSRect, paddingBottom: CGFloat) {
|
||||
|
||||
|
||||
self.width = width
|
||||
self.feedNameRect = feedNameRect
|
||||
self.dateRect = dateRect
|
||||
@@ -114,7 +114,7 @@ private extension TimelineCellLayout {
|
||||
r.size.height = 0
|
||||
return (r, 0)
|
||||
}
|
||||
|
||||
|
||||
let attributedTitle = cellData.attributedTitle.adding(font: appearance.titleFont)
|
||||
let sizeInfo = MultilineTextFieldSizer.size(for: attributedTitle, numberOfLines: appearance.titleNumberOfLines, width: Int(textBoxRect.width))
|
||||
r.size.height = sizeInfo.size.height
|
||||
@@ -132,7 +132,7 @@ private extension TimelineCellLayout {
|
||||
var r = textBoxRect
|
||||
r.origin.y = NSMaxY(titleRect)
|
||||
let summaryNumberOfLines = appearance.titleNumberOfLines - titleNumberOfLines
|
||||
|
||||
|
||||
let sizeInfo = MultilineTextFieldSizer.size(for: cellData.text, font: appearance.textOnlyFont, numberOfLines: summaryNumberOfLines, width: Int(textBoxRect.width))
|
||||
r.size.height = sizeInfo.size.height
|
||||
if sizeInfo.numberOfLinesUsed < 1 {
|
||||
@@ -160,7 +160,7 @@ private extension TimelineCellLayout {
|
||||
|
||||
static func rectForDate(_ textBoxRect: NSRect, _ rectAbove: NSRect, _ appearance: TimelineCellAppearance, _ cellData: TimelineCellData) -> NSRect {
|
||||
let textFieldSize = SingleLineTextFieldSizer.size(for: cellData.dateString, font: appearance.dateFont)
|
||||
|
||||
|
||||
var r = NSZeroRect
|
||||
r.size = textFieldSize
|
||||
r.origin.y = NSMaxY(rectAbove) + appearance.titleBottomMargin
|
||||
@@ -182,7 +182,7 @@ private extension TimelineCellLayout {
|
||||
r.origin.y = dateRect.minY
|
||||
r.origin.x = textBoxRect.origin.x
|
||||
r.size.width = (textBoxRect.maxX - (dateRect.size.width + appearance.dateMarginLeft)) - textBoxRect.origin.x
|
||||
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ private extension TimelineCellLayout {
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
static func rectForSeparator(_ cellData: TimelineCellData, _ appearance: TimelineCellAppearance, _ alignmentRect: NSRect, _ width: CGFloat, _ height: CGFloat) -> NSRect {
|
||||
return NSRect(x: alignmentRect.minX, y: height - 1, width: width - alignmentRect.minX, height: 1)
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var cellData: TimelineCellData! {
|
||||
didSet {
|
||||
updateSubviews()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isEmphasized: Bool = false {
|
||||
didSet {
|
||||
unreadIndicatorView.isEmphasized = isEmphasized
|
||||
@@ -55,7 +55,7 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
updateStarView()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override var isFlipped: Bool {
|
||||
return true
|
||||
}
|
||||
@@ -64,7 +64,7 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
super.init(frame: frameRect)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
commonInit()
|
||||
@@ -73,29 +73,29 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
convenience init() {
|
||||
self.init(frame: NSRect.zero)
|
||||
}
|
||||
|
||||
|
||||
override func setFrameSize(_ newSize: NSSize) {
|
||||
|
||||
|
||||
if newSize == self.frame.size {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
super.setFrameSize(newSize)
|
||||
needsLayout = true
|
||||
}
|
||||
|
||||
override func viewDidMoveToSuperview() {
|
||||
|
||||
|
||||
updateSubviews()
|
||||
}
|
||||
|
||||
|
||||
override func layout() {
|
||||
|
||||
resizeSubviews(withOldSize: NSZeroSize)
|
||||
}
|
||||
|
||||
|
||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||
|
||||
|
||||
let layoutRects = updatedLayoutRects()
|
||||
|
||||
setFrame(for: titleView, rect: layoutRects.titleRect)
|
||||
@@ -144,7 +144,7 @@ private extension TimelineTableCellView {
|
||||
imageView.imageScaling = scaling
|
||||
return imageView
|
||||
}
|
||||
|
||||
|
||||
func setFrame(for textField: NSTextField, rect: NSRect) {
|
||||
|
||||
if Int(floor(rect.height)) == 0 || Int(floor(rect.width)) == 0 {
|
||||
|
||||
@@ -11,7 +11,7 @@ import AppKit
|
||||
final class UnreadIndicatorView: NSView {
|
||||
|
||||
static let unreadCircleDimension: CGFloat = 8.0
|
||||
|
||||
|
||||
var isEmphasized = false {
|
||||
didSet {
|
||||
if isEmphasized != oldValue {
|
||||
@@ -19,7 +19,7 @@ final class UnreadIndicatorView: NSView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isSelected = false {
|
||||
didSet {
|
||||
if isSelected != oldValue {
|
||||
@@ -41,5 +41,5 @@ final class UnreadIndicatorView: NSView {
|
||||
}
|
||||
UnreadIndicatorView.bezierPath.fill()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ final class TimelineContainerViewController: NSViewController {
|
||||
@IBOutlet weak var newestToOldestMenuItem: NSMenuItem!
|
||||
@IBOutlet weak var oldestToNewestMenuItem: NSMenuItem!
|
||||
@IBOutlet weak var groupByFeedMenuItem: NSMenuItem!
|
||||
|
||||
|
||||
@IBOutlet weak var readFilteredButton: NSButton!
|
||||
@IBOutlet var containerView: TimelineContainerView!
|
||||
|
||||
@@ -37,7 +37,7 @@ final class TimelineContainerViewController: NSViewController {
|
||||
view?.window?.recalculateKeyViewLoop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var windowState: TimelineWindowState? {
|
||||
return currentTimelineViewController?.windowState
|
||||
}
|
||||
@@ -53,7 +53,7 @@ final class TimelineContainerViewController: NSViewController {
|
||||
guard let currentTimelineViewController = currentTimelineViewController, mode(for: currentTimelineViewController) == .regular else { return false }
|
||||
return regularTimelineViewController.isCleanUpAvailable
|
||||
}
|
||||
|
||||
|
||||
lazy var regularTimelineViewController = {
|
||||
return TimelineViewController(delegate: self)
|
||||
}()
|
||||
@@ -67,23 +67,23 @@ final class TimelineContainerViewController: NSViewController {
|
||||
super.viewDidLoad()
|
||||
setRepresentedObjects(nil, mode: .regular)
|
||||
showTimeline(for: .regular)
|
||||
|
||||
|
||||
makeMenuItemTitleLarger(newestToOldestMenuItem)
|
||||
makeMenuItemTitleLarger(oldestToNewestMenuItem)
|
||||
makeMenuItemTitleLarger(groupByFeedMenuItem)
|
||||
updateViewOptionsPopUpButton()
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
|
||||
@objc func userDefaultsDidChange(_ note: Notification) {
|
||||
Task {
|
||||
updateViewOptionsPopUpButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - API
|
||||
|
||||
func setRepresentedObjects(_ objects: [AnyObject]?, mode: TimelineSourceMode) {
|
||||
@@ -119,21 +119,21 @@ final class TimelineContainerViewController: NSViewController {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
func cleanUp() {
|
||||
regularTimelineViewController.cleanUp()
|
||||
}
|
||||
|
||||
|
||||
func toggleReadFilter() {
|
||||
regularTimelineViewController.toggleReadFilter()
|
||||
updateReadFilterButton()
|
||||
}
|
||||
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
|
||||
func restoreState(from state: TimelineWindowState?) {
|
||||
guard let state else { return }
|
||||
|
||||
|
||||
regularTimelineViewController.restoreState(from: state)
|
||||
updateReadFilterButton()
|
||||
}
|
||||
@@ -156,11 +156,11 @@ extension TimelineContainerViewController: TimelineDelegate {
|
||||
func timelineRequestedFeedSelection(_: TimelineViewController, feed: Feed) {
|
||||
delegate?.timelineRequestedFeedSelection(self, feed: feed)
|
||||
}
|
||||
|
||||
|
||||
func timelineInvalidatedRestorationState(_: TimelineViewController) {
|
||||
delegate?.timelineInvalidatedRestorationState(self)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension TimelineContainerViewController {
|
||||
@@ -169,7 +169,7 @@ private extension TimelineContainerViewController {
|
||||
menuItem.attributedTitle = NSAttributedString(string: menuItem.title,
|
||||
attributes: [NSAttributedString.Key.font: NSFont.controlContentFont(ofSize: NSFont.systemFontSize)])
|
||||
}
|
||||
|
||||
|
||||
func timelineViewController(for mode: TimelineSourceMode) -> TimelineViewController {
|
||||
switch mode {
|
||||
case .regular:
|
||||
@@ -189,7 +189,7 @@ private extension TimelineContainerViewController {
|
||||
assertionFailure("Expected timelineViewController to match either regular or search timelineViewController, but it doesn’t.")
|
||||
return .regular // Should never get here.
|
||||
}
|
||||
|
||||
|
||||
@MainActor func updateViewOptionsPopUpButton() {
|
||||
if AppDefaults.shared.timelineSortDirection == .orderedAscending {
|
||||
newestToOldestMenuItem.state = .off
|
||||
@@ -200,32 +200,32 @@ private extension TimelineContainerViewController {
|
||||
oldestToNewestMenuItem.state = .off
|
||||
viewOptionsPopUpButton.setTitle(newestToOldestMenuItem.title)
|
||||
}
|
||||
|
||||
|
||||
if AppDefaults.shared.timelineGroupByFeed == true {
|
||||
groupByFeedMenuItem.state = .on
|
||||
} else {
|
||||
groupByFeedMenuItem.state = .off
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func updateReadFilterButton() {
|
||||
guard currentTimelineViewController == regularTimelineViewController else {
|
||||
readFilteredButton.isHidden = true
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard let isReadFiltered = regularTimelineViewController.isReadFiltered else {
|
||||
readFilteredButton.isHidden = true
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
readFilteredButton.isHidden = false
|
||||
|
||||
|
||||
if isReadFiltered {
|
||||
readFilteredButton.image = AppAssets.filterActive
|
||||
} else {
|
||||
readFilteredButton.image = AppAssets.filterInactive
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import AppKit
|
||||
final class TimelineTableRowView : NSTableRowView {
|
||||
|
||||
private var separator: NSView?
|
||||
|
||||
|
||||
override var isOpaque: Bool {
|
||||
return true
|
||||
}
|
||||
@@ -21,14 +21,14 @@ final class TimelineTableRowView : NSTableRowView {
|
||||
cellView?.isEmphasized = isEmphasized
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override var isSelected: Bool {
|
||||
didSet {
|
||||
cellView?.isSelected = isSelected
|
||||
separator?.isHidden = isSelected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
super.init(frame: NSRect.zero)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ final class TimelineTableRowView : NSTableRowView {
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
|
||||
private var cellView: TimelineTableCellView? {
|
||||
for oneSubview in subviews {
|
||||
if let foundView = oneSubview as? TimelineTableCellView {
|
||||
@@ -51,7 +51,7 @@ final class TimelineTableRowView : NSTableRowView {
|
||||
addSeparatorView()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func addSeparatorView() {
|
||||
guard let cellView = cellView, separator == nil else { return }
|
||||
separator = NSView()
|
||||
@@ -66,5 +66,5 @@ final class TimelineTableRowView : NSTableRowView {
|
||||
separator!.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0)
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,15 +10,15 @@ import AppKit
|
||||
import RSCore
|
||||
|
||||
final class TimelineTableView: NSTableView {
|
||||
|
||||
|
||||
weak var keyboardDelegate: KeyboardDelegate?
|
||||
|
||||
|
||||
override func accessibilityLabel() -> String? {
|
||||
return NSLocalizedString("Timeline", comment: "Timeline")
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSResponder
|
||||
|
||||
|
||||
override func keyDown(with event: NSEvent) {
|
||||
if keyboardDelegate?.keydown(event, in: self) ?? false {
|
||||
return
|
||||
@@ -31,14 +31,14 @@ final class TimelineTableView: NSTableView {
|
||||
override var isOpaque: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override func viewWillStartLiveResize() {
|
||||
if let scrollView = self.enclosingScrollView {
|
||||
scrollView.hasVerticalScroller = false
|
||||
}
|
||||
super.viewWillStartLiveResize()
|
||||
}
|
||||
|
||||
|
||||
override func viewDidEndLiveResize() {
|
||||
if let scrollView = self.enclosingScrollView {
|
||||
scrollView.hasVerticalScroller = true
|
||||
|
||||
@@ -70,7 +70,7 @@ extension TimelineViewController {
|
||||
}
|
||||
delegate?.timelineRequestedFeedSelection(self, feed: feed)
|
||||
}
|
||||
|
||||
|
||||
@objc func markAllInFeedAsRead(_ sender: Any?) {
|
||||
guard let menuItem = sender as? NSMenuItem,
|
||||
let feed = menuItem.representedObject as? Feed else {
|
||||
@@ -90,7 +90,7 @@ extension TimelineViewController {
|
||||
|
||||
runCommand(markReadCommand)
|
||||
}
|
||||
|
||||
|
||||
@objc func openInBrowserFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else {
|
||||
@@ -98,7 +98,7 @@ extension TimelineViewController {
|
||||
}
|
||||
Browser.open(urlString, inBackground: false)
|
||||
}
|
||||
|
||||
|
||||
@objc func copyURLFromContextualMenu(_ sender: Any?) {
|
||||
guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else {
|
||||
return
|
||||
@@ -170,7 +170,7 @@ private extension TimelineViewController {
|
||||
}
|
||||
|
||||
menu.addSeparatorIfNeeded()
|
||||
|
||||
|
||||
if articles.count == 1, let feed = articles.first!.feed {
|
||||
if !(representedObjects?.contains(where: { $0 as? Feed == feed }) ?? false) {
|
||||
menu.addItem(selectFeedInSidebarMenuItem(feed))
|
||||
@@ -179,13 +179,13 @@ private extension TimelineViewController {
|
||||
menu.addItem(markAllMenuItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if articles.count == 1, let link = articles.first!.preferredLink {
|
||||
menu.addSeparatorIfNeeded()
|
||||
menu.addItem(openInBrowserMenuItem(link))
|
||||
menu.addSeparatorIfNeeded()
|
||||
menu.addItem(copyArticleURLMenuItem(link))
|
||||
|
||||
|
||||
if let externalLink = articles.first?.externalLink, externalLink != link {
|
||||
menu.addItem(copyExternalURLMenuItem(externalLink))
|
||||
}
|
||||
@@ -251,7 +251,7 @@ private extension TimelineViewController {
|
||||
func markAboveReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Mark Above as Read", comment: "Command"), #selector(markAboveArticlesReadFromContextualMenu(_:)), articles, image: AppAssets.markAboveAsReadImage)
|
||||
}
|
||||
|
||||
|
||||
func markBelowReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles, image: AppAssets.markBelowAsReadImage)
|
||||
}
|
||||
@@ -269,19 +269,19 @@ private extension TimelineViewController {
|
||||
|
||||
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
|
||||
let menuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
|
||||
|
||||
|
||||
return menuItem(menuText, #selector(markAllInFeedAsRead(_:)), feed, image: AppAssets.markAllAsReadImage)
|
||||
}
|
||||
|
||||
|
||||
func openInBrowserMenuItem(_ urlString: String) -> NSMenuItem {
|
||||
|
||||
return menuItem(NSLocalizedString("Open in Browser", comment: "Command"), #selector(openInBrowserFromContextualMenu(_:)), urlString, image: AppAssets.openInBrowserImage)
|
||||
}
|
||||
|
||||
|
||||
func copyArticleURLMenuItem(_ urlString: String) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Copy Article URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString, image: AppAssets.copyImage)
|
||||
}
|
||||
|
||||
|
||||
func copyExternalURLMenuItem(_ urlString: String) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Copy External URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString, image: AppAssets.copyImage)
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
return timelineFeed.defaultReadFilterType == .read
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isCleanUpAvailable: Bool {
|
||||
let isEligibleForCleanUp: Bool?
|
||||
|
||||
|
||||
if representedObjects?.count == 1, let timelineFeed = representedObjects?.first as? SidebarItem, timelineFeed.defaultReadFilterType == .alwaysRead {
|
||||
isEligibleForCleanUp = true
|
||||
} else {
|
||||
@@ -53,14 +53,14 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
guard isEligibleForCleanUp ?? false else { return false }
|
||||
|
||||
|
||||
let readSelectedCount = selectedArticles.filter({ $0.status.read }).count
|
||||
let readArticleCount = articles.count - unreadCount
|
||||
let availableToCleanCount = readArticleCount - readSelectedCount
|
||||
|
||||
|
||||
return availableToCleanCount > 0
|
||||
}
|
||||
|
||||
|
||||
var representedObjects: [AnyObject]? {
|
||||
didSet {
|
||||
if !representedObjectArraysAreEqual(oldValue, representedObjects) {
|
||||
@@ -83,7 +83,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
var windowState: TimelineWindowState {
|
||||
let readArticlesFilterStateKeys = readFilterEnabledTable.keys.compactMap { $0.userInfo as? [String: String] }
|
||||
let readArticlesFilterStateValues = readFilterEnabledTable.values.compactMap( { $0 })
|
||||
|
||||
|
||||
if selectedArticles.count == 1 {
|
||||
let path = selectedArticles.first!.pathUserInfo
|
||||
return TimelineWindowState(readArticlesFilterStateKeys: readArticlesFilterStateKeys,
|
||||
@@ -216,7 +216,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
self.init(nibName: "TimelineTableView", bundle: nil)
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
cellAppearance = TimelineCellAppearance(showIcon: false, fontSize: fontSize)
|
||||
cellAppearanceWithIcon = TimelineCellAppearance(showIcon: true, fontSize: fontSize)
|
||||
@@ -227,9 +227,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
tableView.doubleAction = #selector(openArticleInBrowser(_:))
|
||||
tableView.setDraggingSourceOperationMask(.copy, forLocal: false)
|
||||
tableView.keyboardDelegate = keyboardDelegate
|
||||
|
||||
|
||||
tableView.style = .inset
|
||||
|
||||
|
||||
if !didRegisterForNotifications {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil)
|
||||
@@ -244,13 +244,13 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
didRegisterForNotifications = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override func viewDidAppear() {
|
||||
sharingServiceDelegate = SharingServiceDelegate(self.view.window)
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
|
||||
|
||||
func markAllAsRead(completion: (() -> Void)? = nil) {
|
||||
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager, completion: completion) else {
|
||||
return
|
||||
@@ -275,7 +275,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
return representedObjects.first! === object
|
||||
}
|
||||
|
||||
|
||||
func cleanUp() {
|
||||
fetchAndReplacePreservingSelection()
|
||||
}
|
||||
@@ -286,23 +286,23 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
delegate?.timelineInvalidatedRestorationState(self)
|
||||
fetchAndReplacePreservingSelection()
|
||||
}
|
||||
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
|
||||
func restoreState(from state: TimelineWindowState) {
|
||||
for i in 0..<state.readArticlesFilterStateKeys.count {
|
||||
if let feedIdentifier = SidebarItemIdentifier(userInfo: state.readArticlesFilterStateKeys[i]) {
|
||||
readFilterEnabledTable[feedIdentifier] = state.readArticlesFilterStateValues[i]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let selectedAccountID = state.selectedAccountID,
|
||||
let account = AccountManager.shared.existingAccount(with: selectedAccountID),
|
||||
let selectedArticleID = state.selectedArticleID {
|
||||
|
||||
|
||||
exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: selectedArticleID)
|
||||
fetchAndReplaceArticlesSync()
|
||||
|
||||
|
||||
if let selectedIndex = articles.firstIndex(where: { $0.articleID == selectedArticleID }) {
|
||||
tableView.selectRow(selectedIndex)
|
||||
DispatchQueue.main.async {
|
||||
@@ -358,7 +358,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func toggleStatusOfSelectedArticles(_ sender: Any?) {
|
||||
guard !selectedArticles.isEmpty else {
|
||||
return
|
||||
@@ -381,7 +381,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
runCommand(markReadCommand)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func markSelectedArticlesAsUnread(_ sender: Any?) {
|
||||
guard let undoManager = undoManager, let markUnreadCommand = MarkStatusCommand(initialArticles: selectedArticles, markingRead: false, undoManager: undoManager) else {
|
||||
return
|
||||
@@ -397,36 +397,36 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
guard let lastSelectedRow = tableView.selectedRowIndexes.last else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let nextRowIndex = lastSelectedRow - 1
|
||||
if nextRowIndex <= 0 {
|
||||
tableView.scrollTo(row: 0, extraHeight: 0)
|
||||
}
|
||||
|
||||
|
||||
tableView.selectRow(nextRowIndex)
|
||||
|
||||
|
||||
let followingRowIndex = nextRowIndex - 1
|
||||
if followingRowIndex < 0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
tableView.scrollToRowIfNotVisible(followingRowIndex)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@IBAction func selectNextDown(_ sender: Any?) {
|
||||
guard let firstSelectedRow = tableView.selectedRowIndexes.first else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let tableMaxIndex = tableView.numberOfRows - 1
|
||||
let nextRowIndex = firstSelectedRow + 1
|
||||
if nextRowIndex >= tableMaxIndex {
|
||||
tableView.scrollTo(row: tableMaxIndex, extraHeight: 0)
|
||||
}
|
||||
|
||||
|
||||
tableView.selectRow(nextRowIndex)
|
||||
|
||||
|
||||
let followingRowIndex = nextRowIndex + 1
|
||||
if followingRowIndex > tableMaxIndex {
|
||||
return
|
||||
@@ -435,11 +435,11 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
tableView.scrollToRowIfNotVisible(followingRowIndex)
|
||||
|
||||
}
|
||||
|
||||
|
||||
func toggleReadStatusForSelectedArticles() {
|
||||
// If any one of the selected articles is unread, then mark them as read.
|
||||
// If all articles are read, then mark them as unread them.
|
||||
|
||||
|
||||
let commandStatus = markReadCommandStatus()
|
||||
let markingRead: Bool
|
||||
switch commandStatus {
|
||||
@@ -450,14 +450,14 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
case .canDoNothing:
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard let undoManager = undoManager, let markStarredCommand = MarkStatusCommand(initialArticles: selectedArticles, markingRead: markingRead, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
runCommand(markStarredCommand)
|
||||
}
|
||||
|
||||
|
||||
func toggleStarredStatusForSelectedArticles() {
|
||||
|
||||
// If any one of the selected articles is not starred, then star them.
|
||||
@@ -486,11 +486,11 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
|
||||
func markReadCommandStatus() -> MarkCommandValidationStatus {
|
||||
let articles = selectedArticles
|
||||
|
||||
|
||||
if articles.anyArticleIsUnread() {
|
||||
return .canMark
|
||||
}
|
||||
|
||||
|
||||
if articles.anyArticleIsReadAndCanMarkUnread() {
|
||||
return .canUnmark
|
||||
}
|
||||
@@ -568,7 +568,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
// MARK: - Navigation
|
||||
|
||||
|
||||
func goToDeepLink(for userInfo: [AnyHashable : Any]) {
|
||||
guard let articleID = userInfo[ArticlePathKey.articleID] as? String else { return }
|
||||
|
||||
@@ -581,12 +581,12 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
guard let ix = articles.firstIndex(where: { $0.articleID == articleID }) else { return }
|
||||
|
||||
|
||||
NSCursor.setHiddenUntilMouseMoves(true)
|
||||
tableView.selectRow(ix)
|
||||
tableView.scrollTo(row: ix)
|
||||
}
|
||||
|
||||
|
||||
func goToNextUnread(wrappingToTop wrapping: Bool = false) {
|
||||
guard let ix = indexOfNextUnreadArticle() else {
|
||||
return
|
||||
@@ -595,14 +595,14 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
tableView.selectRow(ix)
|
||||
tableView.scrollTo(row: ix)
|
||||
}
|
||||
|
||||
|
||||
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
||||
guard let _ = indexOfNextUnreadArticle(wrappingToTop: wrapping) else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
func indexOfNextUnreadArticle(wrappingToTop wrapping: Bool = false) -> Int? {
|
||||
return articles.rowOfNextUnreadArticle(tableView.selectedRow, wrappingToTop: wrapping)
|
||||
}
|
||||
@@ -611,7 +611,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
guard let window = tableView.window else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
window.makeFirstResponderUnlessDescendantIsFirstResponder(tableView)
|
||||
if !hasAtLeastOneSelectedArticle && articles.count > 0 {
|
||||
tableView.selectRowAndScrollToVisible(0)
|
||||
@@ -686,7 +686,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
fetchAndReplaceArticlesAsync()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func accountsDidChange(_ note: Notification) {
|
||||
if representedObjectsContainsAnyPseudoFeed() {
|
||||
fetchAndReplaceArticlesAsync()
|
||||
@@ -706,7 +706,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
self.groupByFeed = AppDefaults.shared.timelineGroupByFeed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Reloading Data
|
||||
|
||||
private func cellForRowView(_ rowView: NSView) -> NSView? {
|
||||
@@ -722,7 +722,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
reloadVisibleCells(for: indexes)
|
||||
}
|
||||
|
||||
|
||||
private func reloadVisibleCells(for articles: [Article]) {
|
||||
reloadVisibleCells(for: Set(articles.articleIDs()))
|
||||
}
|
||||
@@ -730,7 +730,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
private func reloadVisibleCells(for articles: Set<Article>) {
|
||||
reloadVisibleCells(for: articles.articleIDs())
|
||||
}
|
||||
|
||||
|
||||
private func reloadVisibleCells(for articleIDs: Set<String>) {
|
||||
if articleIDs.isEmpty {
|
||||
return
|
||||
@@ -754,7 +754,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
tableView.reloadData(forRowIndexes: indexes, columnIndexes: NSIndexSet(index: 0) as IndexSet)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Cell Configuring
|
||||
|
||||
private func calculateRowHeight() -> CGFloat {
|
||||
@@ -990,7 +990,7 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
// MARK: - Private
|
||||
|
||||
private extension TimelineViewController {
|
||||
|
||||
|
||||
func fetchAndReplacePreservingSelection() {
|
||||
if let article = oneSelectedArticle, let account = article.account {
|
||||
exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: article.articleID)
|
||||
@@ -999,7 +999,7 @@ private extension TimelineViewController {
|
||||
fetchAndReplaceArticlesSync()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func reloadAvailableCells() {
|
||||
if let indexesToReload = tableView.indexesOfAvailableRows() {
|
||||
reloadCells(for: indexesToReload)
|
||||
@@ -1034,7 +1034,7 @@ private extension TimelineViewController {
|
||||
self.showIcons = false
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
for article in articles {
|
||||
if let authors = article.authors {
|
||||
for author in authors {
|
||||
@@ -1061,7 +1061,7 @@ private extension TimelineViewController {
|
||||
replaceArticles(with: unsortedArticles)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func selectedArticleIDs() -> [String] {
|
||||
return selectedArticles.articleIDs()
|
||||
}
|
||||
@@ -1136,7 +1136,7 @@ private extension TimelineViewController {
|
||||
}
|
||||
|
||||
// MARK: - Fetching Articles
|
||||
|
||||
|
||||
func fetchAndReplaceArticlesSync() {
|
||||
// To be called when the user has made a change of selection in the sidebar.
|
||||
// It blocks the main thread, so that there’s no async delay,
|
||||
@@ -1147,12 +1147,12 @@ private extension TimelineViewController {
|
||||
emptyTheTimeline()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if exceptionArticleFetcher != nil {
|
||||
representedObjects.append(exceptionArticleFetcher as AnyObject)
|
||||
exceptionArticleFetcher = nil
|
||||
}
|
||||
|
||||
|
||||
let fetchedArticles = fetchUnsortedArticlesSync(for: representedObjects)
|
||||
replaceArticles(with: fetchedArticles)
|
||||
}
|
||||
@@ -1165,12 +1165,12 @@ private extension TimelineViewController {
|
||||
emptyTheTimeline()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if exceptionArticleFetcher != nil {
|
||||
representedObjects.append(exceptionArticleFetcher as AnyObject)
|
||||
exceptionArticleFetcher = nil
|
||||
}
|
||||
|
||||
|
||||
fetchUnsortedArticlesAsync(for: representedObjects) { [weak self] (articles) in
|
||||
self?.replaceArticles(with: articles)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ final class TimelineWindowState: NSObject, NSSecureCoding {
|
||||
selectedAccountID = coder.decodeObject(of: NSString.self, forKey: Key.selectedAccountID) as? String
|
||||
selectedArticleID = coder.decodeObject(of: NSString.self, forKey: Key.selectedArticleID) as? String
|
||||
}
|
||||
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(readArticlesFilterStateKeys, forKey: Key.readArticlesFilterStateKeys)
|
||||
coder.encode(readArticlesFilterStateValues, forKey: Key.readArticlesFilterStateValues)
|
||||
|
||||
@@ -9,33 +9,33 @@
|
||||
import AppKit
|
||||
|
||||
final class AccountCell: NSTableCellView {
|
||||
|
||||
|
||||
private var originalImage: NSImage?
|
||||
|
||||
|
||||
var isImageTemplateCapable = true
|
||||
|
||||
|
||||
override func prepareForReuse() {
|
||||
originalImage = nil
|
||||
}
|
||||
|
||||
|
||||
override var backgroundStyle: NSView.BackgroundStyle {
|
||||
didSet {
|
||||
updateImage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension AccountCell {
|
||||
|
||||
|
||||
func updateImage() {
|
||||
guard isImageTemplateCapable else { return }
|
||||
|
||||
|
||||
if backgroundStyle != .normal {
|
||||
guard !(imageView?.image?.isTemplate ?? false) else { return }
|
||||
|
||||
|
||||
originalImage = imageView?.image
|
||||
|
||||
|
||||
let templateImage = imageView?.image?.copy() as? NSImage
|
||||
templateImage?.isTemplate = true
|
||||
imageView?.image = templateImage
|
||||
@@ -44,5 +44,5 @@ private extension AccountCell {
|
||||
imageView?.image = originalImage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -36,13 +36,13 @@ final class AccountsAddCloudKitWindowController: NSWindowController {
|
||||
guard let hostWindow, let window else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
hostWindow.endSheet(window, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func create(_ sender: Any) {
|
||||
assert(!AccountManager.shared.hasiCloudAccount)
|
||||
|
||||
|
||||
guard AddCloudKitAccountUtilities.isiCloudDriveEnabled else {
|
||||
presentError(AddCloudKitAccountError.iCloudDriveMissing)
|
||||
return
|
||||
|
||||
@@ -13,21 +13,21 @@ final class AccountsAddLocalWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet private weak var nameTextField: NSTextField!
|
||||
@IBOutlet private weak var localAccountNameTextField: NSTextField!
|
||||
|
||||
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("AccountsAddLocal"))
|
||||
}
|
||||
|
||||
|
||||
override func windowDidLoad() {
|
||||
super.windowDidLoad()
|
||||
|
||||
|
||||
localAccountNameTextField.stringValue = NSLocalizedString("Create a local account on your Mac.", comment: "Account Local")
|
||||
}
|
||||
|
||||
|
||||
// MARK: API
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
guard let window else {
|
||||
return
|
||||
@@ -38,11 +38,11 @@ final class AccountsAddLocalWindowController: NSWindowController {
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
|
||||
@IBAction func cancel(_ sender: Any) {
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func create(_ sender: Any) {
|
||||
let account = AccountManager.shared.createAccount(type: .onMyMac)
|
||||
if !nameTextField.stringValue.isEmpty {
|
||||
@@ -50,5 +50,5 @@ final class AccountsAddLocalWindowController: NSWindowController {
|
||||
}
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
||||
@IBOutlet weak var nameTextField: NSTextField!
|
||||
@IBOutlet weak var activeButton: NSButtonCell!
|
||||
@IBOutlet weak var credentialsButton: NSButton!
|
||||
|
||||
|
||||
private var accountsWindowController: NSWindowController?
|
||||
private var account: Account?
|
||||
|
||||
@@ -27,7 +27,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
|
||||
private var hidesCredentialsButton: Bool {
|
||||
guard let account = account else {
|
||||
return true
|
||||
@@ -39,17 +39,17 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
||||
nameTextField.delegate = self
|
||||
typeLabel.stringValue = account?.defaultName ?? ""
|
||||
nameTextField.stringValue = account?.name ?? ""
|
||||
activeButton.state = account?.isActive ?? false ? .on : .off
|
||||
credentialsButton.isHidden = hidesCredentialsButton
|
||||
}
|
||||
|
||||
|
||||
func controlTextDidEndEditing(_ obj: Notification) {
|
||||
if !nameTextField.stringValue.isEmpty {
|
||||
account?.name = nameTextField.stringValue
|
||||
@@ -57,15 +57,15 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
||||
account?.name = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func active(_ sender: NSButtonCell) {
|
||||
account?.isActive = sender.state == .on ? true : false
|
||||
}
|
||||
|
||||
|
||||
@IBAction func credentials(_ sender: Any) {
|
||||
|
||||
|
||||
guard let account = account else { return }
|
||||
|
||||
|
||||
switch account.type {
|
||||
case .feedbin:
|
||||
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
|
||||
@@ -87,7 +87,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -21,15 +21,15 @@ final class AccountsFeedbinWindowController: NSWindowController {
|
||||
@IBOutlet weak var passwordTextField: NSSecureTextField!
|
||||
@IBOutlet weak var errorMessageLabel: NSTextField!
|
||||
@IBOutlet weak var actionButton: NSButton!
|
||||
|
||||
|
||||
var account: Account?
|
||||
|
||||
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("AccountsFeedbin"))
|
||||
}
|
||||
|
||||
|
||||
override func windowDidLoad() {
|
||||
if let account = account, let credentials = try? account.retrieveCredentials(type: .basic) {
|
||||
usernameTextField.stringValue = credentials.username
|
||||
@@ -41,14 +41,14 @@ final class AccountsFeedbinWindowController: NSWindowController {
|
||||
actionButton.title = NSLocalizedString("Create", comment: "Add Account")
|
||||
signInTextField.stringValue = NSLocalizedString("Sign in to your Feedbin account.", comment: "SignIn")
|
||||
}
|
||||
|
||||
|
||||
enableAutofill()
|
||||
|
||||
|
||||
usernameTextField.becomeFirstResponder()
|
||||
}
|
||||
|
||||
|
||||
// MARK: API
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
|
||||
guard let window else {
|
||||
return
|
||||
@@ -63,15 +63,15 @@ final class AccountsFeedbinWindowController: NSWindowController {
|
||||
@IBAction func cancel(_ sender: Any) {
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func action(_ sender: Any) {
|
||||
errorMessageLabel.stringValue = ""
|
||||
|
||||
|
||||
guard !usernameTextField.stringValue.isEmpty && !passwordTextField.stringValue.isEmpty else {
|
||||
errorMessageLabel.stringValue = NSLocalizedString("Username & password required.", comment: "Credentials Error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: .feedbin, username: usernameTextField.stringValue) else {
|
||||
errorMessageLabel.stringValue = NSLocalizedString("There is already a Feedbin account with that username created.", comment: "Duplicate Error")
|
||||
return
|
||||
@@ -123,11 +123,11 @@ final class AccountsFeedbinWindowController: NSWindowController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func createAccountWithProvider(_ sender: Any) {
|
||||
NSWorkspace.shared.open(URL(string: "https://feedbin.com/signup")!)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Autofill
|
||||
func enableAutofill() {
|
||||
usernameTextField.contentType = .username
|
||||
|
||||
@@ -12,7 +12,7 @@ import RSWeb
|
||||
import Secrets
|
||||
|
||||
final class AccountsNewsBlurWindowController: NSWindowController {
|
||||
|
||||
|
||||
@IBOutlet weak var signInTextField: NSTextField!
|
||||
@IBOutlet weak var noAccountTextField: NSTextField!
|
||||
@IBOutlet weak var createNewAccountButton: NSButton!
|
||||
@@ -69,7 +69,7 @@ final class AccountsNewsBlurWindowController: NSWindowController {
|
||||
errorMessageLabel.stringValue = NSLocalizedString("Username required.", comment: "Credentials Error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: .newsBlur, username: usernameTextField.stringValue) else {
|
||||
errorMessageLabel.stringValue = NSLocalizedString("There is already a NewsBlur account with that username created.", comment: "Duplicate Error")
|
||||
return
|
||||
@@ -79,27 +79,27 @@ final class AccountsNewsBlurWindowController: NSWindowController {
|
||||
actionButton.isEnabled = false
|
||||
progressIndicator.isHidden = false
|
||||
progressIndicator.startAnimation(self)
|
||||
|
||||
|
||||
@MainActor func stopAnimation() {
|
||||
actionButton.isEnabled = true
|
||||
progressIndicator.isHidden = true
|
||||
progressIndicator.stopAnimation(self)
|
||||
}
|
||||
|
||||
|
||||
let credentials = Credentials(type: .newsBlurBasic, username: usernameTextField.stringValue, secret: passwordTextField.stringValue)
|
||||
do {
|
||||
let validatedCredentials = try await Account.validateCredentials(type: .newsBlur, credentials: credentials)
|
||||
stopAnimation()
|
||||
|
||||
|
||||
guard let validatedCredentials else {
|
||||
errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if account == nil {
|
||||
account = AccountManager.shared.createAccount(type: .newsBlur)
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
try account?.removeCredentials(type: .newsBlurBasic)
|
||||
try account?.removeCredentials(type: .newsBlurSessionId)
|
||||
@@ -111,7 +111,7 @@ final class AccountsNewsBlurWindowController: NSWindowController {
|
||||
} catch {
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
|
||||
|
||||
hostWindow?.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
} catch {
|
||||
self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error")
|
||||
@@ -122,15 +122,15 @@ final class AccountsNewsBlurWindowController: NSWindowController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func createAccountWithProvider(_ sender: Any) {
|
||||
NSWorkspace.shared.open(URL(string: "https://newsblur.com")!)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Autofill
|
||||
func enableAutofill() {
|
||||
usernameTextField.contentType = .username
|
||||
passwordTextField.contentType = .password
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ final class AccountsPreferencesViewController: NSViewController {
|
||||
tableView.delegate = self
|
||||
tableView.dataSource = self
|
||||
addAccountDelegate = self
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .UserDidAddAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .UserDidDeleteAccount, object: nil)
|
||||
@@ -45,34 +45,34 @@ final class AccountsPreferencesViewController: NSViewController {
|
||||
var rTable = tableView.frame
|
||||
rTable.size.width = tableView.superview!.frame.size.width
|
||||
tableView.frame = rTable
|
||||
|
||||
|
||||
hideController()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func addAccount(_ sender: Any) {
|
||||
let controller = NSHostingController(rootView: AddAccountsView(delegate: self))
|
||||
controller.rootView.parent = controller
|
||||
addAccountsViewController = controller
|
||||
presentAsSheet(controller)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func removeAccount(_ sender: Any) {
|
||||
|
||||
|
||||
guard tableView.selectedRow != -1 else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let acctName = sortedAccounts[tableView.selectedRow].nameForDisplay
|
||||
|
||||
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
let deletePrompt = NSLocalizedString("Delete", comment: "Delete")
|
||||
alert.messageText = "\(deletePrompt) “\(acctName)”?"
|
||||
alert.informativeText = NSLocalizedString("Are you sure you want to delete the account “\(acctName)”? This cannot be undone.", comment: "Delete text")
|
||||
|
||||
|
||||
alert.addButton(withTitle: NSLocalizedString("Delete", comment: "Delete Account"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel Delete Account"))
|
||||
|
||||
|
||||
alert.beginSheetModal(for: view.window!) { [weak self] result in
|
||||
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
|
||||
guard let self = self else { return }
|
||||
@@ -80,19 +80,19 @@ final class AccountsPreferencesViewController: NSViewController {
|
||||
self.hideController()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@objc func displayNameDidChange(_ note: Notification) {
|
||||
updateSortedAccounts()
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
|
||||
@objc func accountsDidChange(_ note: Notification) {
|
||||
updateSortedAccounts()
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - NSTableViewDataSource
|
||||
@@ -118,18 +118,18 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
|
||||
let account = sortedAccounts[row]
|
||||
cell.textField?.stringValue = account.nameForDisplay
|
||||
cell.imageView?.image = account.smallIcon?.image
|
||||
|
||||
|
||||
if account.type == .feedbin {
|
||||
cell.isImageTemplateCapable = false
|
||||
}
|
||||
|
||||
|
||||
return cell
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func tableViewSelectionDidChange(_ notification: Notification) {
|
||||
|
||||
|
||||
let selectedRow = tableView.selectedRow
|
||||
if tableView.selectedRow == -1 {
|
||||
deleteButton.isEnabled = false
|
||||
@@ -143,12 +143,12 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
|
||||
if AccountManager.shared.defaultAccount == account {
|
||||
deleteButton.isEnabled = false
|
||||
}
|
||||
|
||||
|
||||
let controller = AccountsDetailViewController(account: account)
|
||||
showController(controller)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension AccountsPreferencesViewController: AccountsPreferencesAddAccountDelegate {
|
||||
@@ -187,26 +187,26 @@ extension AccountsPreferencesViewController: AccountsPreferencesAddAccountDelega
|
||||
addAccountWindowController = accountsNewsBlurWindowController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func runAwaitingFeedlyLoginAlertModal(forLifetimeOf operation: OAuthAccountAuthorizationOperation) {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .informational
|
||||
alert.messageText = NSLocalizedString("Waiting for access to Feedly",
|
||||
comment: "Alert title when adding a Feedly account and waiting for authorization from the user.")
|
||||
|
||||
|
||||
alert.informativeText = NSLocalizedString("A web browser will open the Feedly login for you to authorize access.",
|
||||
comment: "Alert informative text when adding a Feedly account and waiting for authorization from the user.")
|
||||
|
||||
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel"))
|
||||
|
||||
|
||||
let attachedWindow = self.view.window!
|
||||
|
||||
|
||||
alert.beginSheetModal(for: attachedWindow) { response in
|
||||
if response == .alertFirstButtonReturn {
|
||||
operation.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
operation.completionBlock = { _ in
|
||||
guard alert.window.isVisible else {
|
||||
return
|
||||
@@ -223,22 +223,22 @@ private extension AccountsPreferencesViewController {
|
||||
func updateSortedAccounts() {
|
||||
sortedAccounts = AccountManager.shared.sortedAccounts
|
||||
}
|
||||
|
||||
|
||||
func showController(_ controller: NSViewController) {
|
||||
hideController()
|
||||
|
||||
|
||||
addChild(controller)
|
||||
controller.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
detailView.addSubview(controller.view)
|
||||
detailView.addFullSizeConstraints(forSubview: controller.view)
|
||||
}
|
||||
|
||||
|
||||
func hideController() {
|
||||
if let controller = children.first {
|
||||
children.removeAll()
|
||||
controller.view.removeFromSuperview()
|
||||
}
|
||||
|
||||
|
||||
if tableView.selectedRow == -1 {
|
||||
var helpText = ""
|
||||
if sortedAccounts.count == 0 {
|
||||
@@ -246,7 +246,7 @@ private extension AccountsPreferencesViewController {
|
||||
} else {
|
||||
helpText = NSLocalizedString("To add an account to NetNewsWire,\nclick its icon above.\n\nOr click the + button in the lower left.", comment: "Add Account Explainer")
|
||||
}
|
||||
|
||||
|
||||
let textHostingController = NSHostingController(rootView:
|
||||
AddAccountHelpView(delegate: addAccountDelegate, helpText: helpText))
|
||||
addChild(textHostingController)
|
||||
@@ -257,14 +257,14 @@ private extension AccountsPreferencesViewController {
|
||||
NSLayoutConstraint(item: textHostingController.view, attribute: .bottom, relatedBy: .equal, toItem: detailView, attribute: .bottom, multiplier: 1, constant: -deleteButton.frame.height),
|
||||
NSLayoutConstraint(item: textHostingController.view, attribute: .width, relatedBy: .equal, toItem: detailView, attribute: .width, multiplier: 1, constant: 1)
|
||||
])
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension AccountsPreferencesViewController: OAuthAccountAuthorizationOperationDelegate {
|
||||
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didCreate account: Account) {
|
||||
// `OAuthAccountAuthorizationOperation` is using `ASWebAuthenticationSession` which bounces the user
|
||||
// to their browser on macOS for authorizing NetNewsWire to access the user's Feedly account.
|
||||
@@ -280,12 +280,12 @@ extension AccountsPreferencesViewController: OAuthAccountAuthorizationOperationD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error) {
|
||||
// `OAuthAccountAuthorizationOperation` is using `ASWebAuthenticationSession` which bounces the user
|
||||
// to their browser on macOS for authorizing NetNewsWire to access the user's Feedly account.
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
|
||||
|
||||
view.window?.presentError(error)
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet weak var titleImageView: NSImageView!
|
||||
@IBOutlet weak var titleLabel: NSTextField!
|
||||
|
||||
|
||||
@IBOutlet weak var gridView: NSGridView!
|
||||
@IBOutlet weak var progressIndicator: NSProgressIndicator!
|
||||
@IBOutlet weak var usernameTextField: NSTextField!
|
||||
@@ -25,16 +25,16 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
@IBOutlet weak var errorMessageLabel: NSTextField!
|
||||
@IBOutlet weak var actionButton: NSButton!
|
||||
@IBOutlet weak var noAccountTextField: NSTextField!
|
||||
|
||||
|
||||
var account: Account?
|
||||
var accountType: AccountType?
|
||||
|
||||
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("AccountsReaderAPI"))
|
||||
}
|
||||
|
||||
|
||||
override func windowDidLoad() {
|
||||
if let accountType = accountType {
|
||||
switch accountType {
|
||||
@@ -63,7 +63,7 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let account = account, let credentials = try? account.retrieveCredentials(type: .readerBasic) {
|
||||
usernameTextField.stringValue = credentials.username
|
||||
apiURLTextField.stringValue = account.endpointURL?.absoluteString ?? ""
|
||||
@@ -71,13 +71,13 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
} else {
|
||||
actionButton.title = NSLocalizedString("Create", comment: "Create")
|
||||
}
|
||||
|
||||
|
||||
enableAutofill()
|
||||
usernameTextField.becomeFirstResponder()
|
||||
}
|
||||
|
||||
|
||||
// MARK: API
|
||||
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
|
||||
guard let window else {
|
||||
return
|
||||
@@ -88,29 +88,29 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
|
||||
@IBAction func cancel(_ sender: Any) {
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func action(_ sender: Any) {
|
||||
self.errorMessageLabel.stringValue = ""
|
||||
|
||||
|
||||
guard !usernameTextField.stringValue.isEmpty && !passwordTextField.stringValue.isEmpty else {
|
||||
self.errorMessageLabel.stringValue = NSLocalizedString("Username, password & API URL are required.", comment: "Credentials Error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard let accountType = accountType, !(accountType == .freshRSS && apiURLTextField.stringValue.isEmpty) else {
|
||||
self.errorMessageLabel.stringValue = NSLocalizedString("Username, password & API URL are required.", comment: "Credentials Error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: accountType, username: usernameTextField.stringValue) else {
|
||||
self.errorMessageLabel.stringValue = NSLocalizedString("There is already an account of this type with that username created.", comment: "Duplicate Error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let apiURL: URL
|
||||
switch accountType {
|
||||
case .freshRSS:
|
||||
@@ -181,7 +181,7 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBAction func createAccountWithProvider(_ sender: Any) {
|
||||
switch accountType {
|
||||
case .freshRSS:
|
||||
@@ -196,11 +196,11 @@ final class AccountsReaderAPIWindowController: NSWindowController {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Autofill
|
||||
func enableAutofill() {
|
||||
usernameTextField.contentType = .username
|
||||
passwordTextField.contentType = .password
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
import Account
|
||||
|
||||
struct AddAccountHelpView: View {
|
||||
|
||||
|
||||
let accountTypes: [AccountType] = AddAccountSections.allOrdered.sectionContent
|
||||
var delegate: AccountsPreferencesAddAccountDelegate?
|
||||
var helpText: String
|
||||
@@ -38,7 +38,7 @@ struct AddAccountHelpView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Text(helpText)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.top, 8)
|
||||
|
||||
@@ -16,7 +16,7 @@ enum AddAccountSections: Int, CaseIterable {
|
||||
case web
|
||||
case selfhosted
|
||||
case allOrdered
|
||||
|
||||
|
||||
var sectionHeader: String {
|
||||
switch self {
|
||||
case .local:
|
||||
@@ -31,7 +31,7 @@ enum AddAccountSections: Int, CaseIterable {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var sectionFooter: String {
|
||||
switch self {
|
||||
case .local:
|
||||
@@ -46,7 +46,7 @@ enum AddAccountSections: Int, CaseIterable {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var sectionContent: [AccountType] {
|
||||
switch self {
|
||||
case .local:
|
||||
@@ -68,38 +68,38 @@ enum AddAccountSections: Int, CaseIterable {
|
||||
AddAccountSections.selfhosted.sectionContent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct AddAccountsView: View {
|
||||
|
||||
|
||||
weak var parent: NSHostingController<AddAccountsView>? // required because presentationMode.dismiss() doesn't work
|
||||
var addAccountDelegate: AccountsPreferencesAddAccountDelegate?
|
||||
private let chunkLimit = 4 // use this to control number of accounts in each web account column
|
||||
@State private var selectedAccount: AccountType = .onMyMac
|
||||
|
||||
|
||||
init(delegate: AccountsPreferencesAddAccountDelegate?) {
|
||||
self.addAccountDelegate = delegate
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Choose an account type to add...")
|
||||
.font(.headline)
|
||||
.padding()
|
||||
|
||||
|
||||
localAccount
|
||||
|
||||
|
||||
if !AppDefaults.shared.isDeveloperBuild {
|
||||
icloudAccount
|
||||
}
|
||||
|
||||
|
||||
webAccounts
|
||||
selfhostedAccounts
|
||||
|
||||
|
||||
HStack(spacing: 12) {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
@@ -128,13 +128,13 @@ struct AddAccountsView: View {
|
||||
.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) {
|
||||
@@ -150,23 +150,23 @@ struct AddAccountsView: View {
|
||||
})
|
||||
.pickerStyle(RadioGroupPickerStyle())
|
||||
.offset(x: 7.5, y: 0)
|
||||
|
||||
|
||||
Text(AddAccountSections.local.sectionFooter).foregroundColor(.gray)
|
||||
.padding(.horizontal)
|
||||
.lineLimit(3)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
@@ -175,7 +175,7 @@ struct AddAccountsView: View {
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 20, height: 20, alignment: .center)
|
||||
.padding(.leading, 4)
|
||||
|
||||
|
||||
Text(account.localizedAccountName())
|
||||
}
|
||||
.tag(account)
|
||||
@@ -190,7 +190,7 @@ struct AddAccountsView: View {
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ViewBuilder
|
||||
var webAccounts: some View {
|
||||
VStack(alignment: .leading) {
|
||||
@@ -198,13 +198,13 @@ struct AddAccountsView: View {
|
||||
.font(.headline)
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 8)
|
||||
|
||||
|
||||
HStack {
|
||||
ForEach(0..<chunkedWebAccounts().count, id: \.self, content: { chunk in
|
||||
VStack {
|
||||
Picker(selection: $selectedAccount, label: Text(""), content: {
|
||||
ForEach(chunkedWebAccounts()[chunk], id: \.self, content: { account in
|
||||
|
||||
|
||||
HStack(alignment: .center) {
|
||||
account.image()
|
||||
.resizable()
|
||||
@@ -214,7 +214,7 @@ struct AddAccountsView: View {
|
||||
Text(account.localizedAccountName())
|
||||
}
|
||||
.tag(account)
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
Spacer()
|
||||
@@ -222,21 +222,21 @@ struct AddAccountsView: View {
|
||||
})
|
||||
}
|
||||
.offset(x: 7.5, y: 0)
|
||||
|
||||
|
||||
Text(AddAccountSections.web.sectionFooter).foregroundColor(.gray)
|
||||
.padding(.horizontal)
|
||||
.lineLimit(3)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
@@ -245,13 +245,13 @@ struct AddAccountsView: View {
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 20, height: 20, alignment: .center)
|
||||
.padding(.leading, 4)
|
||||
|
||||
|
||||
Text(account.localizedAccountName())
|
||||
}.tag(account)
|
||||
})
|
||||
})
|
||||
.offset(x: 7.5, y: 0)
|
||||
|
||||
|
||||
Text(AddAccountSections.selfhosted.sectionFooter).foregroundColor(.gray)
|
||||
.padding(.horizontal)
|
||||
.lineLimit(3)
|
||||
|
||||
@@ -58,7 +58,7 @@ private extension AdvancedPreferencesViewController {
|
||||
releaseBuildsButton.state = .on
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func currentAppcastURL() -> String {
|
||||
return UserDefaults.standard.string(forKey: appcastDefaultsKey) ?? ""
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ final class GeneralPreferencesViewController: NSViewController {
|
||||
let url = URL(fileURLWithPath: ArticleThemesManager.shared.folderPath)
|
||||
NSWorkspace.shared.open(url)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func articleThemePopUpDidChange(_ sender: Any) {
|
||||
guard let menuItem = articleThemePopup.selectedItem else {
|
||||
return
|
||||
@@ -59,7 +59,7 @@ final class GeneralPreferencesViewController: NSViewController {
|
||||
ArticleThemesManager.shared.currentThemeName = menuItem.title
|
||||
updateArticleThemePopup()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func browserPopUpDidChangeValue(_ sender: Any?) {
|
||||
guard let menuItem = defaultBrowserPopup.selectedItem else {
|
||||
return
|
||||
@@ -84,18 +84,18 @@ private extension GeneralPreferencesViewController {
|
||||
updateArticleThemePopup()
|
||||
updateBrowserPopup()
|
||||
}
|
||||
|
||||
|
||||
func updateArticleThemePopup() {
|
||||
let menu = articleThemePopup.menu!
|
||||
menu.removeAllItems()
|
||||
|
||||
|
||||
menu.addItem(NSMenuItem(title: ArticleTheme.defaultTheme.name, action: nil, keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
for themeName in ArticleThemesManager.shared.themeNames {
|
||||
menu.addItem(NSMenuItem(title: themeName, action: nil, keyEquivalent: ""))
|
||||
}
|
||||
|
||||
|
||||
articleThemePopup.selectItem(withTitle: ArticleThemesManager.shared.currentThemeName)
|
||||
if articleThemePopup.indexOfSelectedItem == -1 {
|
||||
articleThemePopup.selectItem(withTitle: ArticleTheme.defaultTheme.name)
|
||||
|
||||
@@ -13,7 +13,7 @@ private struct PreferencesToolbarItemSpec {
|
||||
let identifier: NSToolbarItem.Identifier
|
||||
let name: String
|
||||
let image: NSImage?
|
||||
|
||||
|
||||
init(identifierRawValue: String, name: String, image: NSImage?) {
|
||||
self.identifier = NSToolbarItem.Identifier(identifierRawValue)
|
||||
self.name = name
|
||||
@@ -28,7 +28,7 @@ private struct ToolbarItemIdentifier {
|
||||
}
|
||||
|
||||
final class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
|
||||
|
||||
|
||||
private let windowWidth = CGFloat(512.0) // Width is constant for all views; only the height changes
|
||||
private var viewControllers = [String: NSViewController]()
|
||||
private let toolbarItemSpecs: [PreferencesToolbarItemSpec] = {
|
||||
@@ -126,7 +126,7 @@ private extension PreferencesWindowController {
|
||||
assertionFailure("Preferences window: no view controller matching \(identifier).")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if newViewController.view == currentView {
|
||||
return
|
||||
}
|
||||
@@ -167,23 +167,23 @@ private extension PreferencesWindowController {
|
||||
let viewFrame = view.frame
|
||||
let windowFrame = window!.frame
|
||||
let contentViewFrame = window!.contentView!.frame
|
||||
|
||||
|
||||
let deltaHeight = NSHeight(contentViewFrame) - NSHeight(viewFrame)
|
||||
let heightForWindow = NSHeight(windowFrame) - deltaHeight
|
||||
let windowOriginY = NSMinY(windowFrame) + deltaHeight
|
||||
|
||||
|
||||
var updatedWindowFrame = windowFrame
|
||||
updatedWindowFrame.size.height = heightForWindow
|
||||
updatedWindowFrame.origin.y = windowOriginY
|
||||
updatedWindowFrame.size.width = windowWidth //NSWidth(viewFrame)
|
||||
|
||||
|
||||
var updatedViewFrame = viewFrame
|
||||
updatedViewFrame.origin = NSZeroPoint
|
||||
updatedViewFrame.size.width = windowWidth
|
||||
if viewFrame != updatedViewFrame {
|
||||
view.frame = updatedViewFrame
|
||||
}
|
||||
|
||||
|
||||
if windowFrame != updatedWindowFrame {
|
||||
window!.contentView?.alphaValue = 0.0
|
||||
window!.setFrame(updatedWindowFrame, display: true, animate: true)
|
||||
|
||||
@@ -70,7 +70,7 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override func toolbarItemClicked(in window: SFSafariWindow) {
|
||||
window.getActiveTab { (activeTab) in
|
||||
activeTab?.getActivePage(completionHandler: { (activePage) in
|
||||
|
||||
@@ -13,12 +13,12 @@ import RSCore
|
||||
|
||||
@objc(ScriptableAccount)
|
||||
final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer {
|
||||
|
||||
|
||||
let account:Account
|
||||
init (_ account:Account) {
|
||||
self.account = account
|
||||
}
|
||||
|
||||
|
||||
@objc(objectSpecifier)
|
||||
override var objectSpecifier: NSScriptObjectSpecifier? {
|
||||
let myContainer = NSApplication.shared
|
||||
@@ -47,13 +47,13 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
}
|
||||
|
||||
// MARK: --- ScriptingObject protocol ---
|
||||
|
||||
|
||||
var scriptingKey: String {
|
||||
return "accounts"
|
||||
}
|
||||
|
||||
// MARK: --- UniqueIdScriptingObject protocol ---
|
||||
|
||||
|
||||
// I am not sure if account should prefer to be specified by name or by ID
|
||||
// but in either case it seems like the accountID would be used as the keydata, so I chose ID
|
||||
@objc(uniqueId)
|
||||
@@ -62,11 +62,11 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
}
|
||||
|
||||
// MARK: --- ScriptingObjectContainer protocol ---
|
||||
|
||||
|
||||
var scriptingClassDescription: NSScriptClassDescription {
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
if let scriptableFolder = element as? ScriptableFolder {
|
||||
BatchUpdate.shared.perform {
|
||||
@@ -93,30 +93,30 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable elements ---
|
||||
|
||||
|
||||
@objc(feeds)
|
||||
var feeds:NSArray {
|
||||
return account.topLevelFeeds.map { ScriptableFeed($0, container:self) } as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(countOfFeeds)
|
||||
func countOfFeeds() -> Int {
|
||||
return account.topLevelFeeds.count
|
||||
}
|
||||
|
||||
|
||||
@objc(objectInFeedsAtIndex:)
|
||||
func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
|
||||
let feeds = Array(account.topLevelFeeds)
|
||||
guard index >= 0 && index < feeds.count else { return nil }
|
||||
return ScriptableFeed(feeds[index], container: self)
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInFeedsWithUniqueID:)
|
||||
func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? {
|
||||
guard let feed = account.existingFeed(withFeedID: id) else { return nil }
|
||||
return ScriptableFeed(feed, container:self)
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInFeedsWithName:)
|
||||
func valueInFeeds(withName name:String) -> ScriptableFeed? {
|
||||
let feeds = Array(account.flattenedFeeds())
|
||||
@@ -130,12 +130,12 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
let folders = Array(foldersSet)
|
||||
return folders.map { ScriptableFolder($0, container:self) } as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(countOfFolders)
|
||||
func countOfFolders() -> Int {
|
||||
return account.folders?.count ?? 0
|
||||
}
|
||||
|
||||
|
||||
@objc(objectInFoldersAtIndex:)
|
||||
func objectInFoldersAtIndex(_ index: Int) -> ScriptableFolder? {
|
||||
let foldersSet = account.folders ?? Set<Folder>()
|
||||
@@ -143,7 +143,7 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
guard index >= 0 && index < folders.count else { return nil }
|
||||
return ScriptableFolder(folders[index], container: self)
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInFoldersWithUniqueID:)
|
||||
func valueInFolders(withUniqueID id:NSNumber) -> ScriptableFolder? {
|
||||
let folderId = id.intValue
|
||||
@@ -163,25 +163,25 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
}
|
||||
return scriptableFeeds as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(countOfAllFeeds)
|
||||
func countOfAllFeeds() -> Int {
|
||||
return account.flattenedFeeds().count
|
||||
}
|
||||
|
||||
|
||||
@objc(objectInAllFeedsAtIndex:)
|
||||
func objectInAllFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
|
||||
let allFeeds = Array(account.flattenedFeeds())
|
||||
guard index >= 0 && index < allFeeds.count else { return nil }
|
||||
return ScriptableFeed(allFeeds[index], container: self)
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInAllFeedsWithUniqueID:)
|
||||
func valueInAllFeeds(withUniqueID id:String) -> ScriptableFeed? {
|
||||
guard let feed = account.existingFeed(withFeedID: id) else { return nil }
|
||||
return ScriptableFeed(feed, container:self)
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInAllFeedsWithName:)
|
||||
func valueInAllFeeds(withName name:String) -> ScriptableFeed? {
|
||||
let feeds = Array(account.flattenedFeeds())
|
||||
|
||||
@@ -31,13 +31,13 @@ protocol ScriptingAppDelegate {
|
||||
}
|
||||
|
||||
extension AppDelegate : AppDelegateAppleEvents {
|
||||
|
||||
|
||||
// MARK: GetURL Apple Event
|
||||
|
||||
func installAppleEventHandlers() {
|
||||
NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(AppDelegate.getURL(_:_:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
|
||||
}
|
||||
|
||||
|
||||
@objc func getURL(_ event: NSAppleEventDescriptor, _ withReplyEvent: NSAppleEventDescriptor) {
|
||||
|
||||
guard var urlString = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue else {
|
||||
@@ -51,14 +51,14 @@ extension AppDelegate : AppDelegateAppleEvents {
|
||||
let themeURLString = queryItems.first(where: { $0.name == "url" })?.value else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let themeURL = URL(string: themeURLString) {
|
||||
let request = URLRequest(url: themeURL)
|
||||
let task = URLSession.shared.downloadTask(with: request) { location, response, error in
|
||||
guard let location = location else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
try ArticleThemeDownloader.shared.handleFile(at: location)
|
||||
} catch {
|
||||
@@ -68,10 +68,10 @@ extension AppDelegate : AppDelegateAppleEvents {
|
||||
task.resume()
|
||||
}
|
||||
return
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Special case URL with specific scheme handler x-netnewswire-feed: intended to ensure we open
|
||||
// it regardless of which news reader may be set as the default
|
||||
let nnwScheme = "x-netnewswire-feed:"
|
||||
@@ -128,7 +128,7 @@ final class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
container.deleteElement(element)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
delete(specifier:, from container:)
|
||||
At this point in handling the command, the container could be a list or a single object,
|
||||
@@ -177,7 +177,7 @@ final class NetNewsWireExistsCommand : NSExistsCommand {
|
||||
// must not exist. Otherwise, we return the result of the defaultImplementation
|
||||
// The wrinkle is that it is possible that the direct object is a list, so we need to
|
||||
// handle that case as well
|
||||
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let result = super.performDefaultImplementation() else { return NSNumber(booleanLiteral:false) }
|
||||
return result
|
||||
|
||||
@@ -15,7 +15,7 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
|
||||
let article:Article
|
||||
let container:ScriptingObjectContainer
|
||||
|
||||
|
||||
init (_ article:Article, container:ScriptingObjectContainer) {
|
||||
self.article = article
|
||||
self.container = container
|
||||
@@ -44,17 +44,17 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
}
|
||||
|
||||
// MARK: --- ScriptingObjectContainer protocol ---
|
||||
|
||||
|
||||
var scriptingClassDescription: NSScriptClassDescription {
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
print ("delete event not handled")
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
|
||||
@objc(url)
|
||||
var url:String? {
|
||||
return article.preferredLink
|
||||
@@ -69,7 +69,7 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
var externalUrl:String? {
|
||||
return article.externalLink
|
||||
}
|
||||
|
||||
|
||||
@objc(title)
|
||||
var title:String {
|
||||
return article.title ?? ""
|
||||
@@ -134,7 +134,7 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
|
||||
var imageURL:String {
|
||||
return article.imageLink ?? ""
|
||||
}
|
||||
|
||||
|
||||
@objc(authors)
|
||||
var authors:NSArray {
|
||||
let articleAuthors = article.authors ?? []
|
||||
|
||||
@@ -15,7 +15,7 @@ final class ScriptableAuthor: NSObject, UniqueIdScriptingObject {
|
||||
|
||||
let author:Author
|
||||
let container:ScriptingObjectContainer
|
||||
|
||||
|
||||
init (_ author:Author, container:ScriptingObjectContainer) {
|
||||
self.author = author
|
||||
self.container = container
|
||||
@@ -44,14 +44,14 @@ final class ScriptableAuthor: NSObject, UniqueIdScriptingObject {
|
||||
var scriptingUniqueId:Any {
|
||||
return author.authorID
|
||||
}
|
||||
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
|
||||
@objc(url)
|
||||
var url:String {
|
||||
return self.author.url ?? ""
|
||||
}
|
||||
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
return self.author.name ?? ""
|
||||
|
||||
@@ -16,7 +16,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
|
||||
let feed:Feed
|
||||
let container:ScriptingObjectContainer
|
||||
|
||||
|
||||
init (_ feed:Feed, container:ScriptingObjectContainer) {
|
||||
self.feed = feed
|
||||
self.container = container
|
||||
@@ -49,11 +49,11 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
}
|
||||
|
||||
// MARK: --- ScriptingObjectContainer protocol ---
|
||||
|
||||
|
||||
var scriptingClassDescription: NSScriptClassDescription {
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
|
||||
class func scriptableFeed(_ feed:Feed, account:Account, folder:Folder?) -> ScriptableFeed {
|
||||
let scriptableAccount = ScriptableAccount(account)
|
||||
if let folder = folder {
|
||||
@@ -80,14 +80,14 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
return ScriptableFeed(feed, container:scriptableAccount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class func scriptableFeed(for feed: Feed) -> ScriptableFeed? {
|
||||
guard let account = feed.account else { return nil }
|
||||
|
||||
|
||||
// Find the proper container hierarchy
|
||||
let containers = account.existingContainers(withFeed: feed)
|
||||
var folder: Folder? = nil
|
||||
|
||||
|
||||
// Check if feed is in a folder
|
||||
for container in containers {
|
||||
if let foundFolder = container as? Folder {
|
||||
@@ -95,23 +95,23 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return scriptableFeed(feed, account: account, folder: folder)
|
||||
}
|
||||
|
||||
|
||||
class func handleCreateElement(command:NSCreateCommand) -> Any? {
|
||||
guard command.isCreateCommand(forClass:"Feed") else { return nil }
|
||||
guard let arguments = command.arguments else {return nil}
|
||||
let titleFromArgs = command.property(forKey:"name") as? String
|
||||
let (account, folder) = command.accountAndFolderForNewChild()
|
||||
guard let url = self.urlForNewFeed(arguments:arguments) else {return nil}
|
||||
|
||||
|
||||
if let existingFeed = account.existingFeed(withURL:url) {
|
||||
return scriptableFeed(existingFeed, account:account, folder:folder).objectSpecifier
|
||||
}
|
||||
|
||||
|
||||
let container: Container = folder != nil ? folder! : account
|
||||
|
||||
|
||||
// We need to download the feed and parse it.
|
||||
// RSParser does the callback for the download on the main thread.
|
||||
// Because we can't wait here (on the main thread) for the callback, we have to return from this function.
|
||||
@@ -119,7 +119,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
// but we don’t yet have the result of the event yet, so we prevent the Apple event from returning by calling
|
||||
// suspendExecution(). When we get the callback, we supply the event result and call resumeExecution().
|
||||
command.suspendExecution()
|
||||
|
||||
|
||||
account.createFeed(url: url, name: titleFromArgs, container: container, validateFeed: true) { result in
|
||||
switch result {
|
||||
case .success(let feed):
|
||||
@@ -131,7 +131,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
var url:String {
|
||||
return self.feed.url
|
||||
}
|
||||
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
return self.feed.name ?? ""
|
||||
@@ -166,7 +166,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
var opmlRepresentation:String {
|
||||
return self.feed.OPMLString(indentLevel:0)
|
||||
}
|
||||
|
||||
|
||||
// MARK: --- scriptable elements ---
|
||||
|
||||
@objc(authors)
|
||||
@@ -174,13 +174,13 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
let feedAuthors = feed.authors ?? []
|
||||
return feedAuthors.map { ScriptableAuthor($0, container:self) } as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInAuthorsWithUniqueID:)
|
||||
func valueInAuthors(withUniqueID id:String) -> ScriptableAuthor? {
|
||||
guard let author = feed.authors?.first(where:{$0.authorID == id}) else { return nil }
|
||||
return ScriptableAuthor(author, container:self)
|
||||
}
|
||||
|
||||
|
||||
@objc(articles)
|
||||
var articles:NSArray {
|
||||
let feedArticles = (try? feed.fetchArticles()) ?? Set<Article>()
|
||||
@@ -190,7 +190,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
|
||||
})
|
||||
return sortedArticles.map { ScriptableArticle($0, container:self) } as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInArticlesWithUniqueID:)
|
||||
func valueInArticles(withUniqueID id:String) -> ScriptableArticle? {
|
||||
let articles = (try? feed.fetchArticles()) ?? Set<Article>()
|
||||
|
||||
@@ -43,13 +43,13 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
|
||||
var scriptingUniqueId:Any {
|
||||
return folder.folderID
|
||||
}
|
||||
|
||||
|
||||
// MARK: --- ScriptingObjectContainer protocol ---
|
||||
|
||||
|
||||
var scriptingClassDescription: NSScriptClassDescription {
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
if let scriptableFeed = element as? ScriptableFeed {
|
||||
BatchUpdate.shared.perform {
|
||||
@@ -76,9 +76,9 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
|
||||
print("support for folders within folders is NYI");
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
command.suspendExecution()
|
||||
|
||||
|
||||
account.addFolder(name) { result in
|
||||
switch result {
|
||||
case .success(let folder):
|
||||
@@ -89,12 +89,12 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
|
||||
command.resumeExecution(withResult:nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// MARK: --- Scriptable elements ---
|
||||
|
||||
|
||||
@objc(feeds)
|
||||
var feeds:NSArray {
|
||||
let feeds = Array(folder.topLevelFeeds)
|
||||
@@ -137,7 +137,7 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
return self.folder.name ?? ""
|
||||
|
||||
@@ -25,7 +25,7 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
var scriptingKey: String {
|
||||
return "application"
|
||||
}
|
||||
|
||||
|
||||
@objc(currentArticle)
|
||||
func currentArticle() -> ScriptableArticle? {
|
||||
var scriptableArticle: ScriptableArticle?
|
||||
@@ -51,18 +51,18 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
}
|
||||
return scriptableArticles as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(countOfSelectedArticles)
|
||||
func countOfSelectedArticles() -> Int {
|
||||
return appDelegate.scriptingSelectedArticles.count
|
||||
}
|
||||
|
||||
|
||||
@objc(objectInSelectedArticlesAtIndex:)
|
||||
func objectInSelectedArticlesAtIndex(_ index: Int) -> ScriptableArticle? {
|
||||
let articles = appDelegate.scriptingSelectedArticles
|
||||
guard index >= 0 && index < articles.count else { return nil }
|
||||
let article = articles[index]
|
||||
|
||||
|
||||
if let feed = article.feed,
|
||||
let scriptableFeed = ScriptableFeed.scriptableFeed(for: feed) {
|
||||
return ScriptableArticle(article, container: scriptableFeed)
|
||||
@@ -78,19 +78,19 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
let accounts = AccountManager.shared.accounts
|
||||
return accounts.map { ScriptableAccount($0) } as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(countOfAccounts)
|
||||
func countOfAccounts() -> Int {
|
||||
return AccountManager.shared.accounts.count
|
||||
}
|
||||
|
||||
|
||||
@objc(objectInAccountsAtIndex:)
|
||||
func objectInAccountsAtIndex(_ index: Int) -> ScriptableAccount? {
|
||||
let accounts = Array(AccountManager.shared.accounts)
|
||||
guard index >= 0 && index < accounts.count else { return nil }
|
||||
return ScriptableAccount(accounts[index])
|
||||
}
|
||||
|
||||
|
||||
@objc(valueInAccountsWithUniqueID:)
|
||||
func valueInAccounts(withUniqueID id:String) -> ScriptableAccount? {
|
||||
let accounts = AccountManager.shared.accounts
|
||||
@@ -103,7 +103,7 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
this allows a script like 'articles of feed "The Shape of Everything"' as a shorthand
|
||||
for 'articles of feed "The Shape of Everything" of account "On My Mac"'
|
||||
*/
|
||||
|
||||
|
||||
func allFeeds() -> [Feed] {
|
||||
let accounts = AccountManager.shared.activeAccounts
|
||||
let emptyFeeds:[Feed] = []
|
||||
@@ -117,12 +117,12 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
func feeds() -> NSArray {
|
||||
allFeeds().map { ScriptableFeed($0, container:self) } as NSArray
|
||||
}
|
||||
|
||||
|
||||
@objc(countOfFeeds)
|
||||
func countOfFeeds() -> Int {
|
||||
allFeeds().count
|
||||
}
|
||||
|
||||
|
||||
@objc(objectInFeedsAtIndex:)
|
||||
func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
|
||||
let feeds = allFeeds()
|
||||
|
||||
@@ -18,7 +18,7 @@ extension NSScriptCommand {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func isCreateCommand(forClass whatClass:String) -> Bool {
|
||||
guard let arguments = self.arguments else {return false}
|
||||
guard let newObjectClass = arguments["ObjectClass"] as? Int else {return false}
|
||||
@@ -44,7 +44,7 @@ extension NSScriptCommand {
|
||||
} else if let subjectDescriptor = appleEvent.attributeDescriptor(forKeyword:"subj".fourCharCode) {
|
||||
descriptorToConsider = subjectDescriptor
|
||||
}
|
||||
|
||||
|
||||
if let descriptorToConsider = descriptorToConsider {
|
||||
guard let newContainerSpecifier = NSScriptObjectSpecifier(descriptor:descriptorToConsider) else {return (account, folder)}
|
||||
let newContainer = newContainerSpecifier.objectsByEvaluatingSpecifier
|
||||
|
||||
@@ -25,7 +25,7 @@ extension ScriptingObjectContainer {
|
||||
containerSpecifier:containerScriptObjectSpecifier, key:scriptingKey, name:name)
|
||||
return specifier
|
||||
}
|
||||
|
||||
|
||||
func makeFormUniqueIDScriptObjectSpecifier(forObject object:UniqueIdScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
let containerClassDescription = self.scriptingClassDescription
|
||||
let containerScriptObjectSpecifier = self.objectSpecifier
|
||||
|
||||
@@ -13,7 +13,7 @@ final class ShareViewController: NSViewController {
|
||||
|
||||
@IBOutlet weak var nameTextField: NSTextField!
|
||||
@IBOutlet weak var folderPopUpButton: NSPopUpButton!
|
||||
|
||||
|
||||
private var url: URL?
|
||||
private var extensionContainers: ExtensionContainers?
|
||||
|
||||
@@ -23,10 +23,10 @@ final class ShareViewController: NSViewController {
|
||||
|
||||
override func loadView() {
|
||||
super.loadView()
|
||||
|
||||
|
||||
extensionContainers = ExtensionContainersFile.read()
|
||||
buildFolderPopupMenu()
|
||||
|
||||
|
||||
var provider: NSItemProvider? = nil
|
||||
|
||||
// Try to get any HTML that is maybe passed in
|
||||
@@ -91,7 +91,7 @@ final class ShareViewController: NSViewController {
|
||||
let name = nameTextField.stringValue.isEmpty ? nil : nameTextField.stringValue
|
||||
let request = ExtensionFeedAddRequest(name: name, feedURL: url, destinationContainerID: containerID)
|
||||
ExtensionFeedAddRequestFile.save(request)
|
||||
|
||||
|
||||
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ final class ShareViewController: NSViewController {
|
||||
}
|
||||
|
||||
private extension ShareViewController {
|
||||
|
||||
|
||||
func buildFolderPopupMenu() {
|
||||
|
||||
|
||||
let menu = NSMenu(title: "Folders")
|
||||
menu.autoenablesItems = false
|
||||
|
||||
|
||||
guard let extensionContainers = extensionContainers else {
|
||||
folderPopUpButton.menu = nil
|
||||
return
|
||||
@@ -116,18 +116,18 @@ private extension ShareViewController {
|
||||
|
||||
let defaultContainer = ShareDefaultContainer.defaultContainer(containers: extensionContainers)
|
||||
var defaultMenuItem: NSMenuItem? = nil
|
||||
|
||||
|
||||
for account in extensionContainers.accounts {
|
||||
|
||||
|
||||
let menuItem = NSMenuItem(title: account.name, action: nil, keyEquivalent: "")
|
||||
menuItem.representedObject = account
|
||||
|
||||
|
||||
if account.disallowFeedInRootFolder {
|
||||
menuItem.isEnabled = false
|
||||
}
|
||||
|
||||
|
||||
menu.addItem(menuItem)
|
||||
|
||||
|
||||
if defaultContainer?.containerID == account.containerID {
|
||||
defaultMenuItem = menuItem
|
||||
}
|
||||
@@ -141,15 +141,15 @@ private extension ShareViewController {
|
||||
defaultMenuItem = menuItem
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
folderPopUpButton.menu = menu
|
||||
folderPopUpButton.select(defaultMenuItem)
|
||||
}
|
||||
|
||||
|
||||
func selectedContainer() -> ExtensionContainer? {
|
||||
return folderPopUpButton.selectedItem?.representedObject as? ExtensionContainer
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -43,11 +43,11 @@ public enum AccountType: Int, Codable {
|
||||
case inoreader = 21
|
||||
case bazQux = 22
|
||||
case theOldReader = 23
|
||||
|
||||
|
||||
public var isDeveloperRestricted: Bool {
|
||||
return self == .cloudKit || self == .feedbin || self == .feedly || self == .inoreader
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum FetchType {
|
||||
@@ -79,11 +79,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
public static let defaultLocalAccountName = NSLocalizedString("account.name.on-my-device", tableName: "DefaultAccountNames", comment: "Device specific default account name, e.g: On My iPhone")
|
||||
|
||||
public var isDeleted = false
|
||||
|
||||
|
||||
public var containerID: ContainerIdentifier? {
|
||||
return ContainerIdentifier.account(accountID)
|
||||
}
|
||||
|
||||
|
||||
public var account: Account? {
|
||||
return self
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
public let defaultName: String
|
||||
|
||||
|
||||
public var isActive: Bool {
|
||||
get {
|
||||
return metadata.isActive
|
||||
@@ -128,7 +128,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
|
||||
public var topLevelFeeds = Set<Feed>()
|
||||
public var folders: Set<Folder>? = Set<Folder>()
|
||||
|
||||
|
||||
public var externalID: String? {
|
||||
get {
|
||||
return metadata.externalID
|
||||
@@ -137,14 +137,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
metadata.externalID = newValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var sortedFolders: [Folder]? {
|
||||
if let folders = folders {
|
||||
return Array(folders).sorted(by: { $0.nameForDisplay.caseInsensitiveCompare($1.nameForDisplay) == .orderedAscending })
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
private var feedDictionariesNeedUpdate = true
|
||||
private var _idToFeedDictionary = [String: Feed]()
|
||||
var idToFeedDictionary: [String: Feed] {
|
||||
@@ -160,7 +160,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
return _externalIDToFeedDictionary
|
||||
}
|
||||
|
||||
|
||||
var flattenedFeedURLs: Set<String> {
|
||||
return Set(flattenedFeeds().map({ $0.url }))
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var endpointURL: URL? {
|
||||
get {
|
||||
return metadata.endpointURL
|
||||
@@ -186,7 +186,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var fetchingAllUnreadCounts = false
|
||||
var isUnreadCountsInitialized = false
|
||||
|
||||
@@ -219,11 +219,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var behaviors: AccountBehaviors {
|
||||
return delegate.behaviors
|
||||
}
|
||||
|
||||
|
||||
var refreshInProgress = false {
|
||||
didSet {
|
||||
if refreshInProgress != oldValue {
|
||||
@@ -265,7 +265,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
|
||||
self.delegate.accountMetadata = metadata
|
||||
|
||||
|
||||
self.accountID = accountID
|
||||
self.type = type
|
||||
self.dataFolder = dataFolder
|
||||
@@ -312,9 +312,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
|
||||
self.delegate.accountDidInitialize(self)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - API
|
||||
|
||||
|
||||
public func storeCredentials(_ credentials: Credentials) throws {
|
||||
username = credentials.username
|
||||
guard let server = delegate.server else {
|
||||
@@ -324,14 +324,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
try CredentialsManager.storeCredentials(credentials, server: server)
|
||||
delegate.credentials = credentials
|
||||
}
|
||||
|
||||
|
||||
public func retrieveCredentials(type: CredentialsType) throws -> Credentials? {
|
||||
guard let username = self.username, let server = delegate.server else {
|
||||
return nil
|
||||
}
|
||||
return try CredentialsManager.retrieveCredentials(type: type, server: server, username: username)
|
||||
}
|
||||
|
||||
|
||||
public func removeCredentials(type: CredentialsType) throws {
|
||||
guard let username = self.username, let server = delegate.server else {
|
||||
return
|
||||
@@ -351,7 +351,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static func oauthAuthorizationClient(for type: AccountType) -> OAuthAuthorizationClient {
|
||||
switch type {
|
||||
case .feedly:
|
||||
@@ -360,7 +360,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
fatalError("\(type) is not a client for OAuth authorization code granting.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static func oauthAuthorizationCodeGrantRequest(for type: AccountType) -> URLRequest {
|
||||
let grantingType: OAuthAuthorizationGranting.Type
|
||||
switch type {
|
||||
@@ -369,24 +369,24 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
default:
|
||||
fatalError("\(type) does not support OAuth authorization code granting.")
|
||||
}
|
||||
|
||||
|
||||
return grantingType.oauthAuthorizationCodeGrantRequest()
|
||||
}
|
||||
|
||||
|
||||
public static func requestOAuthAccessToken(with response: OAuthAuthorizationResponse,
|
||||
client: OAuthAuthorizationClient,
|
||||
accountType: AccountType,
|
||||
transport: Transport = URLSession.webserviceTransport(),
|
||||
completion: @escaping (Result<OAuthAuthorizationGrant, Error>) -> ()) {
|
||||
let grantingType: OAuthAuthorizationGranting.Type
|
||||
|
||||
|
||||
switch accountType {
|
||||
case .feedly:
|
||||
grantingType = FeedlyAccountDelegate.self
|
||||
default:
|
||||
fatalError("\(accountType) does not support OAuth authorization code granting.")
|
||||
}
|
||||
|
||||
|
||||
grantingType.requestOAuthAccessToken(with: response, transport: transport, completion: completion)
|
||||
}
|
||||
|
||||
@@ -416,17 +416,17 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func syncArticleStatus(completion: ((Result<Void, Error>) -> Void)? = nil) {
|
||||
delegate.syncArticleStatus(for: self, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func importOPML(_ opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard !delegate.isOPMLImportInProgress else {
|
||||
completion(.failure(AccountError.opmlImportInProgress))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
delegate.importOPML(for: self, opmlFile: opmlFile) { [weak self] result in
|
||||
switch result {
|
||||
case .success:
|
||||
@@ -438,13 +438,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public func suspendNetwork() {
|
||||
delegate.suspendNetwork()
|
||||
}
|
||||
|
||||
|
||||
public func suspendDatabase() {
|
||||
#if os(iOS)
|
||||
database.cancelAndSuspend()
|
||||
@@ -471,7 +471,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
feedMetadataFile.save()
|
||||
opmlFile.save()
|
||||
}
|
||||
|
||||
|
||||
public func prepareForDeletion() {
|
||||
delegate.accountWillBeDeleted(self)
|
||||
}
|
||||
@@ -492,11 +492,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func loadOPMLItems(_ items: [RSOPMLItem]) {
|
||||
addOPMLItems(OPMLNormalizer.normalize(items))
|
||||
}
|
||||
|
||||
|
||||
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag, completion: completion)
|
||||
}
|
||||
@@ -507,7 +507,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
return existingFolder(withExternalID: externalID)
|
||||
}
|
||||
|
||||
|
||||
public func existingContainers(withFeed feed: Feed) -> [Container] {
|
||||
var containers = [Container]()
|
||||
if topLevelFeeds.contains(feed) {
|
||||
@@ -520,7 +520,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
return containers
|
||||
}
|
||||
|
||||
|
||||
@discardableResult
|
||||
func ensureFolder(with name: String) -> Folder? {
|
||||
// TODO: support subfolders, maybe, some day
|
||||
@@ -554,11 +554,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
public func existingFolder(withDisplayName displayName: String) -> Folder? {
|
||||
return folders?.first(where: { $0.nameForDisplay == displayName })
|
||||
}
|
||||
|
||||
|
||||
public func existingFolder(withExternalID externalID: String) -> Folder? {
|
||||
return folders?.first(where: { $0.externalID == externalID })
|
||||
}
|
||||
|
||||
|
||||
func newFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
|
||||
let feedURL = opmlFeedSpecifier.feedURL
|
||||
let metadata = feedMetadata(feedURL: feedURL, feedID: feedURL)
|
||||
@@ -578,7 +578,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
public func createFeed(url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result<Feed, Error>) -> Void) {
|
||||
delegate.createFeed(for: self, url: url, name: name, container: container, validateFeed: validateFeed, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
func createFeed(with name: String?, url: String, feedID: String, homePageURL: String?) -> Feed {
|
||||
let metadata = feedMetadata(feedURL: url, feedID: feedID)
|
||||
let feed = Feed(account: self, url: url, metadata: metadata)
|
||||
@@ -586,31 +586,31 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
feed.homePageURL = homePageURL
|
||||
return feed
|
||||
}
|
||||
|
||||
|
||||
public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.removeFeed(for: self, with: feed, from: container, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.moveFeed(for: self, with: feed, from: from, to: to, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.renameFeed(for: self, with: feed, to: name, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func restoreFeed(_ feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.restoreFeed(for: self, feed: feed, container: container, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func addFolder(_ name: String, completion: @escaping (Result<Folder, Error>) -> Void) {
|
||||
delegate.createFolder(for: self, name: name, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func removeFolder(_ folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.removeFolder(for: self, with: folder, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
public func renameFolder(_ folder: Folder, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.renameFolder(for: self, with: folder, to: name, completion: completion)
|
||||
}
|
||||
@@ -618,17 +618,17 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
public func restoreFolder(_ folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delegate.restoreFolder(for: self, folder: folder, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
func clearFeedMetadata(_ feed: Feed) {
|
||||
feedMetadata[feed.url] = nil
|
||||
}
|
||||
|
||||
|
||||
func addFolder(_ folder: Folder) {
|
||||
folders!.insert(folder)
|
||||
postChildrenDidChangeNotification()
|
||||
structureDidChange()
|
||||
}
|
||||
|
||||
|
||||
public func updateUnreadCounts(for feeds: Set<Feed>, completion: VoidCompletionBlock? = nil) {
|
||||
fetchUnreadCounts(for: feeds, completion: completion)
|
||||
}
|
||||
@@ -707,7 +707,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
public func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(_ completion: @escaping ArticleIDsCompletionBlock) {
|
||||
database.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(completion)
|
||||
}
|
||||
|
||||
|
||||
public func unreadCount(for feed: Feed) -> Int {
|
||||
return unreadCounts[feed.feedID] ?? 0
|
||||
}
|
||||
@@ -748,15 +748,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
completion(.success(ArticleChanges()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
update(feed.feedID, with: parsedItems, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
func update(_ feedID: String, with parsedItems: Set<ParsedItem>, deleteOlder: Bool = true, completion: @escaping UpdateArticlesCompletionBlock) {
|
||||
// Used only by an On My Mac or iCloud account.
|
||||
precondition(Thread.isMainThread)
|
||||
precondition(type == .onMyMac || type == .cloudKit)
|
||||
|
||||
|
||||
database.update(with: parsedItems, feedID: feedID, deleteOlder: deleteOlder) { updateArticlesResult in
|
||||
switch updateArticlesResult {
|
||||
case .success(let articleChanges):
|
||||
@@ -794,7 +794,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
completion(.success(Set<Article>()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
database.mark(articles, statusKey: statusKey, flag: flag) { result in
|
||||
switch result {
|
||||
case .success(let updatedStatuses):
|
||||
@@ -877,7 +877,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
database.delete(articleIDs: articleIDs, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
/// Empty caches that can reasonably be emptied. Call when the app goes in the background, for instance.
|
||||
func emptyCaches() {
|
||||
database.emptyCaches()
|
||||
@@ -898,7 +898,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
structureDidChange()
|
||||
postChildrenDidChangeNotification()
|
||||
}
|
||||
|
||||
|
||||
public func removeFeeds(_ feeds: Set<Feed>) {
|
||||
guard !feeds.isEmpty else {
|
||||
return
|
||||
@@ -907,7 +907,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
structureDidChange()
|
||||
postChildrenDidChangeNotification()
|
||||
}
|
||||
|
||||
|
||||
public func addFeed(_ feed: Feed) {
|
||||
topLevelFeeds.insert(feed)
|
||||
structureDidChange()
|
||||
@@ -919,13 +919,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
addFeed(feed)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func removeFolder(_ folder: Folder) {
|
||||
folders?.remove(folder)
|
||||
structureDidChange()
|
||||
postChildrenDidChangeNotification()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Debug
|
||||
|
||||
public func debugDropConditionalGetInfo() {
|
||||
@@ -956,13 +956,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
refreshInProgress = refreshProgress.numberRemaining > 0
|
||||
NotificationCenter.default.post(name: .AccountRefreshProgressDidChange, object: self)
|
||||
}
|
||||
|
||||
|
||||
@objc func unreadCountDidChange(_ note: Notification) {
|
||||
if let feed = note.object as? Feed, feed.account === self {
|
||||
updateUnreadCount()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func batchUpdateDidPerform(_ note: Notification) {
|
||||
flattenedFeedsNeedUpdate = true
|
||||
rebuildFeedDictionaries()
|
||||
@@ -1091,7 +1091,7 @@ private extension Account {
|
||||
func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set<String>) throws -> Set<Article> {
|
||||
return try database.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs)
|
||||
}
|
||||
|
||||
|
||||
func fetchArticlesMatchingAsync(_ searchString: String, _ completion: @escaping ArticleSetResultBlock) {
|
||||
database.fetchArticlesMatchingAsync(searchString, flattenedFeeds().feedIDs(), completion)
|
||||
}
|
||||
@@ -1137,13 +1137,13 @@ private extension Account {
|
||||
func fetchUnreadArticles(forContainer container: Container, limit: Int?) throws -> Set<Article> {
|
||||
let feeds = container.flattenedFeeds()
|
||||
let articles = try database.fetchUnreadArticles(feeds.feedIDs(), limit)
|
||||
|
||||
|
||||
// We don't validate limit queries because they, by definition, won't correctly match the
|
||||
// complete unread state for the given container.
|
||||
if limit == nil {
|
||||
validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
}
|
||||
|
||||
|
||||
return articles
|
||||
}
|
||||
|
||||
@@ -1152,13 +1152,13 @@ private extension Account {
|
||||
database.fetchUnreadArticlesAsync(feeds.feedIDs(), limit) { [weak self] (articleSetResult) in
|
||||
switch articleSetResult {
|
||||
case .success(let articles):
|
||||
|
||||
|
||||
// We don't validate limit queries because they, by definition, won't correctly match the
|
||||
// complete unread state for the given container.
|
||||
if limit == nil {
|
||||
self?.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles)
|
||||
}
|
||||
|
||||
|
||||
completion(.success(articles))
|
||||
case .failure(let databaseError):
|
||||
completion(.failure(databaseError))
|
||||
@@ -1226,7 +1226,7 @@ private extension Account {
|
||||
func rebuildFeedDictionaries() {
|
||||
var idDictionary = [String: Feed]()
|
||||
var externalIDDictionary = [String: Feed]()
|
||||
|
||||
|
||||
flattenedFeeds().forEach { (feed) in
|
||||
idDictionary[feed.feedID] = feed
|
||||
if let externalID = feed.externalID {
|
||||
@@ -1238,7 +1238,7 @@ private extension Account {
|
||||
_externalIDToFeedDictionary = externalIDDictionary
|
||||
feedDictionariesNeedUpdate = false
|
||||
}
|
||||
|
||||
|
||||
func updateUnreadCount() {
|
||||
if fetchingAllUnreadCounts {
|
||||
return
|
||||
@@ -1249,7 +1249,7 @@ private extension Account {
|
||||
}
|
||||
unreadCount = updatedUnreadCount
|
||||
}
|
||||
|
||||
|
||||
func noteStatusesForArticlesDidChange(_ articles: Set<Article>) {
|
||||
let feeds = Set(articles.compactMap { $0.feed })
|
||||
let statuses = Set(articles.map { $0.status })
|
||||
@@ -1258,7 +1258,7 @@ private extension Account {
|
||||
// .UnreadCountDidChange notification will get sent to Folder and Account objects,
|
||||
// which will update their own unread counts.
|
||||
updateUnreadCounts(for: feeds)
|
||||
|
||||
|
||||
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: statuses, UserInfoKey.articles: articles, UserInfoKey.articleIDs: articleIDs, UserInfoKey.feeds: feeds])
|
||||
}
|
||||
|
||||
@@ -1389,7 +1389,7 @@ extension Account {
|
||||
public func existingFeed(withExternalID externalID: String) -> Feed? {
|
||||
return externalIDToFeedDictionary[externalID]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - OPMLRepresentable
|
||||
|
||||
@@ -17,32 +17,32 @@ import Foundation
|
||||
public typealias AccountBehaviors = [AccountBehavior]
|
||||
|
||||
public enum AccountBehavior: Equatable {
|
||||
|
||||
|
||||
/**
|
||||
Account doesn't support copies of a feed that are in a folder to be made to the root folder.
|
||||
*/
|
||||
case disallowFeedCopyInRootFolder
|
||||
|
||||
|
||||
/**
|
||||
Account doesn't support feeds in the root folder.
|
||||
*/
|
||||
case disallowFeedInRootFolder
|
||||
|
||||
|
||||
/**
|
||||
Account doesn't support a feed being in more than one folder.
|
||||
*/
|
||||
case disallowFeedInMultipleFolders
|
||||
|
||||
|
||||
/**
|
||||
Account doesn't support folders
|
||||
*/
|
||||
case disallowFolderManagement
|
||||
|
||||
|
||||
/**
|
||||
Account doesn't support OPML imports
|
||||
*/
|
||||
case disallowOPMLImports
|
||||
|
||||
|
||||
/**
|
||||
Account doesn't allow mark as read after a period of days
|
||||
*/
|
||||
|
||||
@@ -16,11 +16,11 @@ protocol AccountDelegate {
|
||||
var behaviors: AccountBehaviors { get }
|
||||
|
||||
var isOPMLImportInProgress: Bool { get }
|
||||
|
||||
|
||||
var server: String? { get }
|
||||
var credentials: Credentials? { get set }
|
||||
var accountMetadata: AccountMetadata? { get set }
|
||||
|
||||
|
||||
var refreshProgress: DownloadProgress { get }
|
||||
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void)
|
||||
@@ -29,9 +29,9 @@ protocol AccountDelegate {
|
||||
func syncArticleStatus(for account: Account, completion: ((Result<Void, Error>) -> Void)?)
|
||||
func sendArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void))
|
||||
func refreshArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void))
|
||||
|
||||
|
||||
func importOPML(for account:Account, opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
|
||||
|
||||
func createFolder(for account: Account, name: String, completion: @escaping (Result<Folder, Error>) -> Void)
|
||||
func renameFolder(for account: Account, with folder: Folder, to name: String, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
@@ -49,17 +49,17 @@ protocol AccountDelegate {
|
||||
|
||||
// Called at the end of account’s init method.
|
||||
func accountDidInitialize(_ account: Account)
|
||||
|
||||
|
||||
func accountWillBeDeleted(_ account: Account)
|
||||
|
||||
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?) async throws -> Credentials?
|
||||
|
||||
/// Suspend all network activity
|
||||
func suspendNetwork()
|
||||
|
||||
|
||||
/// Suspend the SQLite databases
|
||||
func suspendDatabase()
|
||||
|
||||
|
||||
/// Make sure no SQLite databases are open and we are ready to issue network requests.
|
||||
func resume()
|
||||
}
|
||||
@@ -10,12 +10,12 @@ import Foundation
|
||||
import RSWeb
|
||||
|
||||
public enum AccountError: LocalizedError {
|
||||
|
||||
|
||||
case createErrorNotFound
|
||||
case createErrorAlreadySubscribed
|
||||
case opmlImportInProgress
|
||||
case wrappedError(error: Error, account: Account)
|
||||
|
||||
|
||||
public var account: Account? {
|
||||
if case .wrappedError(_, let account) = self {
|
||||
return account
|
||||
@@ -23,7 +23,7 @@ public enum AccountError: LocalizedError {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var isCredentialsError: Bool {
|
||||
if case .wrappedError(let error, _) = self {
|
||||
if case TransportError.httpError(let status) = error {
|
||||
@@ -32,7 +32,7 @@ public enum AccountError: LocalizedError {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .createErrorNotFound:
|
||||
@@ -55,7 +55,7 @@ public enum AccountError: LocalizedError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var recoverySuggestion: String? {
|
||||
switch self {
|
||||
case .createErrorNotFound:
|
||||
@@ -77,20 +77,20 @@ public enum AccountError: LocalizedError {
|
||||
return NSLocalizedString("Please try again later.", comment: "Try later")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private extension AccountError {
|
||||
|
||||
|
||||
func unknownError(_ error: Error, _ account: Account) -> String {
|
||||
let localizedText = NSLocalizedString("An error occurred while processing the “%@” account: %@", comment: "Unknown error")
|
||||
return NSString.localizedStringWithFormat(localizedText as NSString, account.nameForDisplay, error.localizedDescription) as String
|
||||
}
|
||||
|
||||
|
||||
func isCredentialsError(status: Int) -> Bool {
|
||||
return status == 401 || status == 403
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
public var unreadCount = 0 {
|
||||
didSet {
|
||||
if unreadCount != oldValue {
|
||||
@@ -73,7 +73,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
public var sortedActiveAccounts: [Account] {
|
||||
return sortByName(activeAccounts)
|
||||
}
|
||||
|
||||
|
||||
public var lastArticleFetchEndTime: Date? {
|
||||
var lastArticleFetchEndTime: Date? = nil
|
||||
for account in activeAccounts {
|
||||
@@ -89,7 +89,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
public func existingActiveAccount(forDisplayName displayName: String) -> Account? {
|
||||
return AccountManager.shared.activeAccounts.first(where: { $0.nameForDisplay == displayName })
|
||||
}
|
||||
|
||||
|
||||
public var refreshInProgress: Bool {
|
||||
for account in activeAccounts {
|
||||
if account.refreshInProgress {
|
||||
@@ -103,7 +103,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public init(accountsFolder: String) {
|
||||
self.accountsFolder = accountsFolder
|
||||
|
||||
|
||||
// The local "On My Mac" account must always exist, even if it's empty.
|
||||
let localAccountFolder = (accountsFolder as NSString).appendingPathComponent("OnMyMac")
|
||||
do {
|
||||
@@ -129,14 +129,14 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
|
||||
|
||||
public func createAccount(type: AccountType) -> Account {
|
||||
if type == .cloudKit {
|
||||
if let existingiCloudAccount = accounts.first(where: { $0.type == .cloudKit }) {
|
||||
return existingiCloudAccount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let accountID = type == .cloudKit ? "iCloud" : UUID().uuidString
|
||||
let accountFolder = (accountsFolder as NSString).appendingPathComponent("\(type.rawValue)_\(accountID)")
|
||||
|
||||
@@ -146,14 +146,14 @@ public final class AccountManager: UnreadCountProvider {
|
||||
assertionFailure("Could not create folder for \(accountID) account.")
|
||||
abort()
|
||||
}
|
||||
|
||||
|
||||
let account = Account(dataFolder: accountFolder, type: type, accountID: accountID)
|
||||
accountsDictionary[accountID] = account
|
||||
|
||||
|
||||
var userInfo = [String: Any]()
|
||||
userInfo[Account.UserInfoKey.account] = account
|
||||
NotificationCenter.default.post(name: .UserDidAddAccount, object: self, userInfo: userInfo)
|
||||
|
||||
|
||||
return account
|
||||
}
|
||||
|
||||
@@ -161,12 +161,12 @@ public final class AccountManager: UnreadCountProvider {
|
||||
guard !account.refreshInProgress else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
account.prepareForDeletion()
|
||||
|
||||
|
||||
accountsDictionary.removeValue(forKey: account.accountID)
|
||||
account.isDeleted = true
|
||||
|
||||
|
||||
do {
|
||||
try FileManager.default.removeItem(atPath: account.dataFolder)
|
||||
}
|
||||
@@ -174,14 +174,14 @@ public final class AccountManager: UnreadCountProvider {
|
||||
assertionFailure("Could not create folder for OnMyMac account.")
|
||||
abort()
|
||||
}
|
||||
|
||||
|
||||
updateUnreadCount()
|
||||
|
||||
var userInfo = [String: Any]()
|
||||
userInfo[Account.UserInfoKey.account] = account
|
||||
NotificationCenter.default.post(name: .UserDidDeleteAccount, object: self, userInfo: userInfo)
|
||||
}
|
||||
|
||||
|
||||
public func duplicateServiceAccount(type: AccountType, username: String?) -> Bool {
|
||||
guard type != .onMyMac else {
|
||||
return false
|
||||
@@ -193,11 +193,11 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
public func existingAccount(with accountID: String) -> Account? {
|
||||
return accountsDictionary[accountID]
|
||||
}
|
||||
|
||||
|
||||
public func existingContainer(with containerID: ContainerIdentifier) -> Container? {
|
||||
switch containerID {
|
||||
case .account(let accountID):
|
||||
@@ -209,7 +209,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
public func existingFeed(with sidebarItemID: SidebarItemIdentifier) -> SidebarItem? {
|
||||
switch sidebarItemID {
|
||||
case .folder(let accountID, let folderName):
|
||||
@@ -225,7 +225,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
public func suspendNetworkAll() {
|
||||
isSuspended = true
|
||||
accounts.forEach { $0.suspendNetwork() }
|
||||
@@ -243,14 +243,14 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: (() -> Void)? = nil) {
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
||||
activeAccounts.forEach { account in
|
||||
group.enter()
|
||||
account.receiveRemoteNotification(userInfo: userInfo) {
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
completion?()
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
combinedRefreshProgress.start()
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
||||
for account in activeAccounts {
|
||||
group.enter()
|
||||
account.refreshAll() { result in
|
||||
@@ -278,7 +278,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
self.combinedRefreshProgress.stop()
|
||||
completion?()
|
||||
@@ -287,7 +287,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public func sendArticleStatusAll(completion: (() -> Void)? = nil) {
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
||||
activeAccounts.forEach {
|
||||
group.enter()
|
||||
$0.sendArticleStatus() { _ in
|
||||
@@ -302,7 +302,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public func syncArticleStatusAll(completion: (() -> Void)? = nil) {
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
||||
activeAccounts.forEach {
|
||||
group.enter()
|
||||
$0.syncArticleStatus() { _ in
|
||||
@@ -314,11 +314,11 @@ public final class AccountManager: UnreadCountProvider {
|
||||
completion?()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func saveAll() {
|
||||
accounts.forEach { $0.save() }
|
||||
}
|
||||
|
||||
|
||||
public func anyAccountHasAtLeastOneFeed() -> Bool {
|
||||
for account in activeAccounts {
|
||||
if account.hasAtLeastOneFeed() {
|
||||
@@ -328,7 +328,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
public func anyAccountHasNetNewsWireNewsSubscription() -> Bool {
|
||||
return anyAccountHasFeedWithURL(Self.netNewsWireNewsURL) || anyAccountHasFeedWithURL(Self.jsonNetNewsWireNewsURL)
|
||||
}
|
||||
@@ -358,34 +358,34 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetResultBlock) {
|
||||
precondition(Thread.isMainThread)
|
||||
|
||||
|
||||
guard activeAccounts.count > 0 else {
|
||||
completion(.success(Set<Article>()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var allFetchedArticles = Set<Article>()
|
||||
var databaseError: DatabaseError?
|
||||
let dispatchGroup = DispatchGroup()
|
||||
|
||||
|
||||
for account in activeAccounts {
|
||||
|
||||
|
||||
dispatchGroup.enter()
|
||||
|
||||
|
||||
account.fetchArticlesAsync(fetchType) { (articleSetResult) in
|
||||
precondition(Thread.isMainThread)
|
||||
|
||||
|
||||
switch articleSetResult {
|
||||
case .success(let articles):
|
||||
allFetchedArticles.formUnion(articles)
|
||||
case .failure(let error):
|
||||
databaseError = error
|
||||
}
|
||||
|
||||
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dispatchGroup.notify(queue: .main) {
|
||||
if let databaseError {
|
||||
completion(.failure(databaseError))
|
||||
@@ -417,7 +417,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
|
||||
@objc func unreadCountDidInitialize(_ notification: Notification) {
|
||||
guard let _ = notification.object as? Account else {
|
||||
return
|
||||
@@ -426,14 +426,14 @@ public final class AccountManager: UnreadCountProvider {
|
||||
postUnreadCountDidInitializeNotification()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc dynamic func unreadCountDidChange(_ notification: Notification) {
|
||||
guard let _ = notification.object as? Account else {
|
||||
return
|
||||
}
|
||||
updateUnreadCount()
|
||||
}
|
||||
|
||||
|
||||
@objc func accountStateDidChange(_ notification: Notification) {
|
||||
updateUnreadCount()
|
||||
}
|
||||
@@ -469,7 +469,7 @@ private extension AccountManager {
|
||||
print("Error reading Accounts folder: \(error)")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
filenames = filenames?.sorted()
|
||||
|
||||
filenames?.forEach { (oneFilename) in
|
||||
@@ -483,14 +483,14 @@ private extension AccountManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func duplicateServiceAccount(_ account: Account) -> Bool {
|
||||
return duplicateServiceAccount(type: account.type, username: account.username)
|
||||
}
|
||||
|
||||
func sortByName(_ accounts: [Account]) -> [Account] {
|
||||
// LocalAccount is first.
|
||||
|
||||
|
||||
return accounts.sorted { (account1, account2) -> Bool in
|
||||
if account1 === defaultAccount {
|
||||
return true
|
||||
@@ -516,14 +516,14 @@ private struct AccountSpecifier {
|
||||
if !FileManager.default.isFolder(atPath: folderPath) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let name = NSString(string: folderPath).lastPathComponent
|
||||
if name.hasPrefix(".") {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let nameComponents = name.components(separatedBy: "_")
|
||||
|
||||
|
||||
guard nameComponents.count == 2, let rawType = Int(nameComponents[0]), let accountType = AccountType(rawValue: rawType) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isActive: Bool = true {
|
||||
didSet {
|
||||
if isActive != oldValue {
|
||||
@@ -42,7 +42,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var username: String? {
|
||||
didSet {
|
||||
if username != oldValue {
|
||||
@@ -50,7 +50,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var conditionalGetInfo = [String: HTTPConditionalGetInfo]() {
|
||||
didSet {
|
||||
if conditionalGetInfo != oldValue {
|
||||
@@ -58,7 +58,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var lastArticleFetchStartTime: Date? {
|
||||
didSet {
|
||||
if lastArticleFetchStartTime != oldValue {
|
||||
@@ -66,7 +66,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var lastArticleFetchEndTime: Date? {
|
||||
didSet {
|
||||
if lastArticleFetchEndTime != oldValue {
|
||||
@@ -74,7 +74,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var endpointURL: URL? {
|
||||
didSet {
|
||||
if endpointURL != oldValue {
|
||||
@@ -94,7 +94,7 @@ final class AccountMetadata: Codable {
|
||||
}
|
||||
|
||||
weak var delegate: AccountMetadataDelegate?
|
||||
|
||||
|
||||
func valueDidChange(_ key: CodingKeys) {
|
||||
delegate?.valueDidChange(self, key: key)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import RSCore
|
||||
final class AccountMetadataFile {
|
||||
private let fileURL: URL
|
||||
private let account: Account
|
||||
|
||||
|
||||
private var isDirty = false {
|
||||
didSet {
|
||||
queueSaveToDiskIfNeeded()
|
||||
@@ -26,11 +26,11 @@ final class AccountMetadataFile {
|
||||
self.fileURL = URL(fileURLWithPath: filename)
|
||||
self.account = account
|
||||
}
|
||||
|
||||
|
||||
func markAsDirty() {
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
|
||||
func load() {
|
||||
if let fileData = try? Data(contentsOf: fileURL) {
|
||||
let decoder = PropertyListDecoder()
|
||||
@@ -38,10 +38,10 @@ final class AccountMetadataFile {
|
||||
}
|
||||
account.metadata.delegate = account
|
||||
}
|
||||
|
||||
|
||||
func save() {
|
||||
guard !account.isDeleted else { return }
|
||||
|
||||
|
||||
let encoder = PropertyListEncoder()
|
||||
encoder.outputFormat = .binary
|
||||
|
||||
@@ -52,7 +52,7 @@ final class AccountMetadataFile {
|
||||
Self.logger.error("AccountMetadataFile accountID: \(self.account.accountID) save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension AccountMetadataFile {
|
||||
|
||||
@@ -19,7 +19,7 @@ public protocol ArticleFetcher {
|
||||
}
|
||||
|
||||
extension Feed: ArticleFetcher {
|
||||
|
||||
|
||||
public func fetchArticles() throws -> Set<Article> {
|
||||
return try account?.fetchArticles(.feed(self)) ?? Set<Article>()
|
||||
}
|
||||
@@ -55,7 +55,7 @@ extension Feed: ArticleFetcher {
|
||||
}
|
||||
|
||||
extension Folder: ArticleFetcher {
|
||||
|
||||
|
||||
public func fetchArticles() throws -> Set<Article> {
|
||||
guard let account = account else {
|
||||
assertionFailure("Expected folder.account, but got nil.")
|
||||
|
||||
@@ -10,17 +10,17 @@ import Foundation
|
||||
import CloudKit
|
||||
|
||||
extension CKRecord {
|
||||
|
||||
|
||||
var externalID: String {
|
||||
return recordID.externalID
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension CKRecord.ID {
|
||||
|
||||
|
||||
var externalID: String {
|
||||
return recordName
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -88,7 +88,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
syncProgress.reset()
|
||||
|
||||
|
||||
guard NetworkMonitor.shared.isConnected else {
|
||||
completion(.success(()))
|
||||
return
|
||||
@@ -172,7 +172,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
let normalizedItems = OPMLNormalizer.normalize(opmlItems)
|
||||
|
||||
|
||||
syncProgress.addToNumberOfTasksAndRemaining(1)
|
||||
self.accountZone.importOPML(rootExternalID: rootExternalID, items: normalizedItems) { _ in
|
||||
self.syncProgress.completeTask()
|
||||
@@ -304,7 +304,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
|
||||
syncProgress.addToNumberOfTasksAndRemaining(2)
|
||||
accountZone.findFeedExternalIDs(for: folder) { result in
|
||||
self.syncProgress.completeTask()
|
||||
@@ -544,7 +544,7 @@ private extension CloudKitAccountDelegate {
|
||||
}
|
||||
|
||||
func standardRefreshAll(for account: Account, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
|
||||
syncProgress.addToNumberOfTasksAndRemaining(3)
|
||||
|
||||
func fail(_ error: Error) {
|
||||
@@ -556,7 +556,7 @@ private extension CloudKitAccountDelegate {
|
||||
accountZone.fetchChangesInZone() { result in
|
||||
switch result {
|
||||
case .success:
|
||||
|
||||
|
||||
self.syncProgress.completeTask()
|
||||
let feeds = account.flattenedFeeds()
|
||||
|
||||
@@ -613,7 +613,7 @@ private extension CloudKitAccountDelegate {
|
||||
|
||||
syncProgress.addToNumberOfTasksAndRemaining(5)
|
||||
FeedFinder.find(url: url) { result in
|
||||
|
||||
|
||||
self.syncProgress.completeTask()
|
||||
switch result {
|
||||
case .success(let feedSpecifiers):
|
||||
@@ -641,7 +641,7 @@ private extension CloudKitAccountDelegate {
|
||||
InitialFeedDownloader.download(url) { parsedFeed, _, response, _ in
|
||||
self.syncProgress.completeTask()
|
||||
feed.lastCheckDate = Date()
|
||||
|
||||
|
||||
if let parsedFeed {
|
||||
// Save conditional GET info so that first refresh uses conditional GET.
|
||||
if let httpResponse = response as? HTTPURLResponse,
|
||||
|
||||
@@ -26,7 +26,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
weak var container: CKContainer?
|
||||
weak var database: CKDatabase?
|
||||
var delegate: CloudKitZoneDelegate?
|
||||
|
||||
|
||||
struct CloudKitFeed {
|
||||
static let recordType = "AccountWebFeed"
|
||||
struct Fields {
|
||||
@@ -37,7 +37,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
static let containerExternalIDs = "containerExternalIDs"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct CloudKitContainer {
|
||||
static let recordType = "AccountContainer"
|
||||
struct Fields {
|
||||
@@ -45,18 +45,18 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
static let name = "name"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init(container: CKContainer) {
|
||||
self.container = container
|
||||
self.database = container.privateCloudDatabase
|
||||
self.zoneID = CKRecordZone.ID(zoneName: "Account", ownerName: CKCurrentUserDefaultName)
|
||||
migrateChangeToken()
|
||||
}
|
||||
|
||||
|
||||
func importOPML(rootExternalID: String, items: [RSOPMLItem], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
var records = [CKRecord]()
|
||||
var feedRecords = [String: CKRecord]()
|
||||
|
||||
|
||||
func processFeed(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) {
|
||||
if let feedRecord = feedRecords[feedSpecifier.feedURL], var containerExternalIDs = feedRecord[CloudKitFeed.Fields.containerExternalIDs] as? [String] {
|
||||
containerExternalIDs.append(containerExternalID)
|
||||
@@ -67,7 +67,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
feedRecords[feedSpecifier.feedURL] = feedRecord
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for item in items {
|
||||
if let feedSpecifier = item.feedSpecifier {
|
||||
processFeed(feedSpecifier: feedSpecifier, containerExternalID: rootExternalID)
|
||||
@@ -86,7 +86,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
|
||||
save(records, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
/// Persist a web feed record to iCloud and return the external key
|
||||
func createFeed(url: String, name: String?, editedName: String?, homePageURL: String?, container: Container, completion: @escaping (Result<String, Error>) -> Void) {
|
||||
let recordID = CKRecord.ID(recordName: url.md5String, zoneID: zoneID)
|
||||
@@ -115,7 +115,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Rename the given web feed
|
||||
func renameFeed(_ feed: Feed, editedName: String?, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let externalID = feed.externalID else {
|
||||
@@ -126,7 +126,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
let recordID = CKRecord.ID(recordName: externalID, zoneID: zoneID)
|
||||
let record = CKRecord(recordType: CloudKitFeed.recordType, recordID: recordID)
|
||||
record[CloudKitFeed.Fields.editedName] = editedName
|
||||
|
||||
|
||||
save(record) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
@@ -136,22 +136,22 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Removes a web feed from a container and optionally deletes it, calling the completion with true if deleted
|
||||
func removeFeed(_ feed: Feed, from: Container, completion: @escaping (Result<Bool, Error>) -> Void) {
|
||||
guard let fromContainerExternalID = from.externalID else {
|
||||
completion(.failure(CloudKitZoneError.corruptAccount))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fetch(externalID: feed.externalID) { result in
|
||||
switch result {
|
||||
case .success(let record):
|
||||
|
||||
|
||||
if let containerExternalIDs = record[CloudKitFeed.Fields.containerExternalIDs] as? [String] {
|
||||
var containerExternalIDSet = Set(containerExternalIDs)
|
||||
containerExternalIDSet.remove(fromContainerExternalID)
|
||||
|
||||
|
||||
if containerExternalIDSet.isEmpty {
|
||||
self.delete(externalID: feed.externalID) { result in
|
||||
switch result {
|
||||
@@ -161,9 +161,9 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
record[CloudKitFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet)
|
||||
self.save(record) { result in
|
||||
switch result {
|
||||
@@ -173,10 +173,10 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case .failure(let error):
|
||||
if let ckError = ((error as? CloudKitError)?.error as? CKError), ckError.code == .unknownItem {
|
||||
completion(.success(true))
|
||||
@@ -186,13 +186,13 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let fromContainerExternalID = from.externalID, let toContainerExternalID = to.externalID else {
|
||||
completion(.failure(CloudKitZoneError.corruptAccount))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fetch(externalID: feed.externalID) { result in
|
||||
switch result {
|
||||
case .success(let record):
|
||||
@@ -208,13 +208,13 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addFeed(_ feed: Feed, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let toContainerExternalID = to.externalID else {
|
||||
completion(.failure(CloudKitZoneError.corruptAccount))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fetch(externalID: feed.externalID) { result in
|
||||
switch result {
|
||||
case .success(let record):
|
||||
@@ -229,16 +229,16 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func findFeedExternalIDs(for folder: Folder, completion: @escaping (Result<[String], Error>) -> Void) {
|
||||
guard let folderExternalID = folder.externalID else {
|
||||
completion(.failure(CloudKitAccountZoneError.unknown))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let predicate = NSPredicate(format: "containerExternalIDs CONTAINS %@", folderExternalID)
|
||||
let ckQuery = CKQuery(recordType: CloudKitFeed.recordType, predicate: predicate)
|
||||
|
||||
|
||||
query(ckQuery) { result in
|
||||
switch result {
|
||||
case .success(let records):
|
||||
@@ -249,11 +249,11 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func findOrCreateAccount(completion: @escaping (Result<String, Error>) -> Void) {
|
||||
let predicate = NSPredicate(format: "isAccount = \"1\"")
|
||||
let ckQuery = CKQuery(recordType: CloudKitContainer.recordType, predicate: predicate)
|
||||
|
||||
|
||||
database?.fetch(withQuery: ckQuery, inZoneWith: zoneID, desiredKeys: nil, resultsLimit: CKQueryOperation.maximumResults) { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
@@ -293,13 +293,13 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func createFolder(name: String, completion: @escaping (Result<String, Error>) -> Void) {
|
||||
createContainer(name: name, isAccount: false, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
func renameFolder(_ folder: Folder, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let externalID = folder.externalID else {
|
||||
completion(.failure(CloudKitZoneError.corruptAccount))
|
||||
@@ -309,7 +309,7 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
let recordID = CKRecord.ID(recordName: externalID, zoneID: zoneID)
|
||||
let record = CKRecord(recordType: CloudKitContainer.recordType, recordID: recordID)
|
||||
record[CloudKitContainer.Fields.name] = name
|
||||
|
||||
|
||||
save(record) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
@@ -319,15 +319,15 @@ final class CloudKitAccountZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func removeFolder(_ folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
delete(externalID: folder.externalID, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension CloudKitAccountZone {
|
||||
|
||||
|
||||
func newFeedCKRecord(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) -> CKRecord {
|
||||
let record = CKRecord(recordType: CloudKitFeed.recordType, recordID: generateRecordID())
|
||||
record[CloudKitFeed.Fields.url] = feedSpecifier.feedURL
|
||||
@@ -340,14 +340,14 @@ private extension CloudKitAccountZone {
|
||||
record[CloudKitFeed.Fields.containerExternalIDs] = [containerExternalID]
|
||||
return record
|
||||
}
|
||||
|
||||
|
||||
func newContainerCKRecord(name: String) -> CKRecord {
|
||||
let record = CKRecord(recordType: CloudKitContainer.recordType, recordID: generateRecordID())
|
||||
record[CloudKitContainer.Fields.name] = name
|
||||
record[CloudKitContainer.Fields.isAccount] = "0"
|
||||
return record
|
||||
}
|
||||
|
||||
|
||||
func createContainer(name: String, isAccount: Bool, completion: @escaping (Result<String, Error>) -> Void) {
|
||||
let record = CKRecord(recordType: CloudKitContainer.recordType, recordID: generateRecordID())
|
||||
record[CloudKitContainer.Fields.name] = name
|
||||
@@ -362,5 +362,5 @@ private extension CloudKitAccountZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import RSCore
|
||||
import Articles
|
||||
|
||||
final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
|
||||
|
||||
private typealias UnclaimedFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, feedExternalID: String)
|
||||
private var newUnclaimedFeeds = [String: [UnclaimedFeed]]()
|
||||
private var existingUnclaimedFeeds = [String: [Feed]]()
|
||||
@@ -26,7 +26,7 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
self.account = account
|
||||
self.articlesZone = articlesZone
|
||||
}
|
||||
|
||||
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
for deletedRecordKey in deleted {
|
||||
switch deletedRecordKey.recordType {
|
||||
@@ -38,7 +38,7 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
assertionFailure("Unknown record type: \(deletedRecordKey.recordType)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for changedRecord in changed {
|
||||
switch changedRecord.recordType {
|
||||
case CloudKitAccountZone.CloudKitFeed.recordType:
|
||||
@@ -49,10 +49,10 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
assertionFailure("Unknown record type: \(changedRecord.recordType)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
|
||||
func addOrUpdateFeed(_ record: CKRecord) {
|
||||
guard let account = account,
|
||||
let urlString = record[CloudKitAccountZone.CloudKitFeed.Fields.url] as? String,
|
||||
@@ -60,7 +60,7 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
let url = URL(string: urlString) else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let name = record[CloudKitAccountZone.CloudKitFeed.Fields.name] as? String
|
||||
let editedName = record[CloudKitAccountZone.CloudKitFeed.Fields.editedName] as? String
|
||||
let homePageURL = record[CloudKitAccountZone.CloudKitFeed.Fields.homePageURL] as? String
|
||||
@@ -77,7 +77,7 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func removeFeed(_ externalID: String) {
|
||||
if let feed = account?.existingFeed(withExternalID: externalID), let containers = account?.existingContainers(withFeed: feed) {
|
||||
for container in containers {
|
||||
@@ -86,7 +86,7 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addOrUpdateContainer(_ record: CKRecord) {
|
||||
guard let account = account,
|
||||
let name = record[CloudKitAccountZone.CloudKitContainer.Fields.name] as? String,
|
||||
@@ -94,17 +94,17 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
isAccount != "1" else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var folder = account.existingFolder(withExternalID: record.externalID)
|
||||
folder?.name = name
|
||||
|
||||
|
||||
if folder == nil {
|
||||
folder = account.ensureFolder(with: name)
|
||||
folder?.externalID = record.externalID
|
||||
}
|
||||
|
||||
|
||||
guard let container = folder, let containerExternalID = container.externalID else { return }
|
||||
|
||||
|
||||
if let newUnclaimedFeeds = newUnclaimedFeeds[containerExternalID] {
|
||||
for newUnclaimedFeed in newUnclaimedFeeds {
|
||||
createFeedIfNecessary(url: newUnclaimedFeed.url,
|
||||
@@ -117,7 +117,7 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
|
||||
self.newUnclaimedFeeds.removeValue(forKey: containerExternalID)
|
||||
}
|
||||
|
||||
|
||||
if let existingUnclaimedFeeds = existingUnclaimedFeeds[containerExternalID] {
|
||||
for existingUnclaimedFeed in existingUnclaimedFeeds {
|
||||
container.addFeed(existingUnclaimedFeed)
|
||||
@@ -125,29 +125,29 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
self.existingUnclaimedFeeds.removeValue(forKey: containerExternalID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func removeContainer(_ externalID: String) {
|
||||
if let folder = account?.existingFolder(withExternalID: externalID) {
|
||||
account?.removeFolder(folder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension CloudKitAcountZoneDelegate {
|
||||
|
||||
|
||||
func updateFeed(_ feed: Feed, name: String?, editedName: String?, homePageURL: String?, containerExternalIDs: [String]) {
|
||||
guard let account = account else { return }
|
||||
|
||||
|
||||
feed.name = name
|
||||
feed.editedName = editedName
|
||||
feed.homePageURL = homePageURL
|
||||
|
||||
|
||||
let existingContainers = account.existingContainers(withFeed: feed)
|
||||
let existingContainerExternalIds = existingContainers.compactMap { $0.externalID }
|
||||
|
||||
let diff = containerExternalIDs.difference(from: existingContainerExternalIds)
|
||||
|
||||
|
||||
for change in diff {
|
||||
switch change {
|
||||
case .remove(_, let externalID, _):
|
||||
@@ -163,20 +163,20 @@ private extension CloudKitAcountZoneDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func createFeedIfNecessary(url: URL, name: String?, editedName: String?, homePageURL: String?, feedExternalID: String, container: Container) {
|
||||
guard let account = account else { return }
|
||||
|
||||
|
||||
if account.existingFeed(withExternalID: feedExternalID) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let feed = account.createFeed(with: name, url: url.absoluteString, feedID: url.absoluteString, homePageURL: homePageURL)
|
||||
feed.editedName = editedName
|
||||
feed.externalID = feedExternalID
|
||||
container.addFeed(feed)
|
||||
}
|
||||
|
||||
|
||||
func addNewUnclaimedFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, feedExternalID: String, containerExternalID: String) {
|
||||
if var unclaimedFeeds = self.newUnclaimedFeeds[containerExternalID] {
|
||||
unclaimedFeeds.append(UnclaimedFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, feedExternalID: feedExternalID))
|
||||
@@ -187,7 +187,7 @@ private extension CloudKitAcountZoneDelegate {
|
||||
self.newUnclaimedFeeds[containerExternalID] = unclaimedFeeds
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func addExistingUnclaimedFeed(_ feed: Feed, containerExternalID: String) {
|
||||
if var unclaimedFeeds = self.existingUnclaimedFeeds[containerExternalID] {
|
||||
unclaimedFeeds.append(feed)
|
||||
@@ -198,5 +198,5 @@ private extension CloudKitAcountZoneDelegate {
|
||||
self.existingUnclaimedFeeds[containerExternalID] = unclaimedFeeds
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,18 +11,18 @@ import SyncDatabase
|
||||
import Articles
|
||||
|
||||
struct CloudKitArticleStatusUpdate {
|
||||
|
||||
|
||||
enum Record {
|
||||
case all
|
||||
case new
|
||||
case statusOnly
|
||||
case delete
|
||||
}
|
||||
|
||||
|
||||
var articleID: String
|
||||
var statuses: [SyncStatus]
|
||||
var article: Article?
|
||||
|
||||
|
||||
init?(articleID: String, statuses: [SyncStatus], article: Article?) {
|
||||
self.articleID = articleID
|
||||
self.statuses = statuses
|
||||
@@ -34,16 +34,16 @@ struct CloudKitArticleStatusUpdate {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var record: Record {
|
||||
if statuses.contains(where: { $0.key == .deleted }) {
|
||||
return .delete
|
||||
}
|
||||
|
||||
|
||||
if statuses.count == 1, statuses.first!.key == .new {
|
||||
return .new
|
||||
}
|
||||
|
||||
|
||||
if let article = article {
|
||||
if article.status.read == false || article.status.starred == true {
|
||||
return .all
|
||||
@@ -52,19 +52,19 @@ struct CloudKitArticleStatusUpdate {
|
||||
|
||||
return .statusOnly
|
||||
}
|
||||
|
||||
|
||||
var isRead: Bool {
|
||||
if let article = article {
|
||||
return article.status.read
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
var isStarred: Bool {
|
||||
if let article = article {
|
||||
return article.status.starred
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -16,15 +16,15 @@ import Articles
|
||||
import SyncDatabase
|
||||
|
||||
final class CloudKitArticlesZone: CloudKitZone {
|
||||
|
||||
|
||||
var zoneID: CKRecordZone.ID
|
||||
|
||||
|
||||
weak var container: CKContainer?
|
||||
weak var database: CKDatabase?
|
||||
var delegate: CloudKitZoneDelegate? = nil
|
||||
|
||||
|
||||
var compressionQueue = DispatchQueue(label: "Articles Zone Compression Queue")
|
||||
|
||||
|
||||
struct CloudKitArticle {
|
||||
static let recordType = "Article"
|
||||
struct Fields {
|
||||
@@ -61,7 +61,7 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||
self.zoneID = CKRecordZone.ID(zoneName: "Articles", ownerName: CKCurrentUserDefaultName)
|
||||
migrateChangeToken()
|
||||
}
|
||||
|
||||
|
||||
func refreshArticles(completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
fetchChangesInZone() { result in
|
||||
switch result {
|
||||
@@ -83,15 +83,15 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func saveNewArticles(_ articles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
guard !articles.isEmpty else {
|
||||
completion(.success(()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var records = [CKRecord]()
|
||||
|
||||
|
||||
let saveArticles = articles.filter { $0.status.read == false || $0.status.starred == true }
|
||||
for saveArticle in saveArticles {
|
||||
records.append(makeStatusRecord(saveArticle))
|
||||
@@ -103,23 +103,23 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||
self.save(compressedRecords, completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func deleteArticles(_ feedExternalID: String, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
let predicate = NSPredicate(format: "webFeedExternalID = %@", feedExternalID)
|
||||
let ckQuery = CKQuery(recordType: CloudKitArticleStatus.recordType, predicate: predicate)
|
||||
delete(ckQuery: ckQuery, completion: completion)
|
||||
}
|
||||
|
||||
|
||||
func modifyArticles(_ statusUpdates: [CloudKitArticleStatusUpdate], completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
guard !statusUpdates.isEmpty else {
|
||||
completion(.success(()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var modifyRecords = [CKRecord]()
|
||||
var newRecords = [CKRecord]()
|
||||
var deleteRecordIDs = [CKRecord.ID]()
|
||||
|
||||
|
||||
for statusUpdate in statusUpdates {
|
||||
switch statusUpdate.record {
|
||||
case .all:
|
||||
@@ -155,9 +155,9 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension CloudKitArticlesZone {
|
||||
@@ -176,15 +176,15 @@ private extension CloudKitArticlesZone {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func statusID(_ id: String) -> String {
|
||||
return "s|\(id)"
|
||||
}
|
||||
|
||||
|
||||
func articleID(_ id: String) -> String {
|
||||
return "a|\(id)"
|
||||
}
|
||||
|
||||
|
||||
func makeStatusRecord(_ article: Article) -> CKRecord {
|
||||
let recordID = CKRecord.ID(recordName: statusID(article.articleID), zoneID: zoneID)
|
||||
let record = CKRecord(recordType: CloudKitArticleStatus.recordType, recordID: recordID)
|
||||
@@ -195,21 +195,21 @@ private extension CloudKitArticlesZone {
|
||||
record[CloudKitArticleStatus.Fields.starred] = article.status.starred ? "1" : "0"
|
||||
return record
|
||||
}
|
||||
|
||||
|
||||
func makeStatusRecord(_ statusUpdate: CloudKitArticleStatusUpdate) -> CKRecord {
|
||||
let recordID = CKRecord.ID(recordName: statusID(statusUpdate.articleID), zoneID: zoneID)
|
||||
let record = CKRecord(recordType: CloudKitArticleStatus.recordType, recordID: recordID)
|
||||
|
||||
|
||||
if let feedExternalID = statusUpdate.article?.feed?.externalID {
|
||||
record[CloudKitArticleStatus.Fields.feedExternalID] = feedExternalID
|
||||
}
|
||||
|
||||
|
||||
record[CloudKitArticleStatus.Fields.read] = statusUpdate.isRead ? "1" : "0"
|
||||
record[CloudKitArticleStatus.Fields.starred] = statusUpdate.isStarred ? "1" : "0"
|
||||
|
||||
|
||||
return record
|
||||
}
|
||||
|
||||
|
||||
func makeArticleRecord(_ article: Article) -> CKRecord {
|
||||
let recordID = CKRecord.ID(recordName: articleID(article.articleID), zoneID: zoneID)
|
||||
let record = CKRecord(recordType: CloudKitArticle.recordType, recordID: recordID)
|
||||
@@ -227,10 +227,10 @@ private extension CloudKitArticlesZone {
|
||||
record[CloudKitArticle.Fields.imageURL] = article.rawImageLink
|
||||
record[CloudKitArticle.Fields.datePublished] = article.datePublished
|
||||
record[CloudKitArticle.Fields.dateModified] = article.dateModified
|
||||
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
var parsedAuthors = [String]()
|
||||
|
||||
|
||||
if let authors = article.authors, !authors.isEmpty {
|
||||
for author in authors {
|
||||
let parsedAuthor = ParsedAuthor(name: author.name,
|
||||
@@ -243,17 +243,17 @@ private extension CloudKitArticlesZone {
|
||||
}
|
||||
record[CloudKitArticle.Fields.parsedAuthors] = parsedAuthors
|
||||
}
|
||||
|
||||
|
||||
return record
|
||||
}
|
||||
|
||||
func compressArticleRecords(_ records: [CKRecord]) -> [CKRecord] {
|
||||
var result = [CKRecord]()
|
||||
|
||||
|
||||
for record in records {
|
||||
|
||||
|
||||
if record.recordType == CloudKitArticle.recordType {
|
||||
|
||||
|
||||
if let contentHTML = record[CloudKitArticle.Fields.contentHTML] as? String {
|
||||
let data = Data(contentHTML.utf8) as NSData
|
||||
if let compressedData = try? data.compressed(using: .lzfse) {
|
||||
@@ -261,7 +261,7 @@ private extension CloudKitArticlesZone {
|
||||
record[CloudKitArticle.Fields.contentHTML] = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let contentText = record[CloudKitArticle.Fields.contentText] as? String {
|
||||
let data = Data(contentText.utf8) as NSData
|
||||
if let compressedData = try? data.compressed(using: .lzfse) {
|
||||
@@ -269,12 +269,12 @@ private extension CloudKitArticlesZone {
|
||||
record[CloudKitArticle.Fields.contentText] = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
result.append(record)
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -24,15 +24,15 @@ final class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
|
||||
var database: SyncDatabase
|
||||
weak var articlesZone: CloudKitArticlesZone?
|
||||
var compressionQueue = DispatchQueue(label: "Articles Zone Delegate Compression Queue")
|
||||
|
||||
|
||||
init(account: Account, database: SyncDatabase, articlesZone: CloudKitArticlesZone) {
|
||||
self.account = account
|
||||
self.database = database
|
||||
self.articlesZone = articlesZone
|
||||
}
|
||||
|
||||
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
|
||||
database.selectPendingReadStatusArticleIDs() { result in
|
||||
switch result {
|
||||
case .success(let pendingReadStatusArticleIDs):
|
||||
@@ -47,7 +47,7 @@ final class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
|
||||
pendingStarredStatusArticleIDs: pendingStarredStatusArticleIDs,
|
||||
completion: completion)
|
||||
}
|
||||
|
||||
|
||||
case .failure(let error):
|
||||
Self.logger.error("CloudKit: Error getting pending starred records: \(error.localizedDescription)")
|
||||
completion(.failure(CloudKitZoneError.unknown))
|
||||
@@ -67,12 +67,12 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
let receivedRecordIDs = recordKeys.filter({ $0.recordType == CloudKitArticlesZone.CloudKitArticleStatus.recordType }).map({ $0.recordID })
|
||||
let receivedArticleIDs = Set(receivedRecordIDs.map({ stripPrefix($0.externalID) }))
|
||||
let deletableArticleIDs = receivedArticleIDs.subtracting(pendingStarredStatusArticleIDs)
|
||||
|
||||
|
||||
guard !deletableArticleIDs.isEmpty else {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
database.deleteSelectedForProcessing(Array(deletableArticleIDs)) { _ in
|
||||
self.account?.delete(articleIDs: deletableArticleIDs) { _ in
|
||||
completion()
|
||||
@@ -94,7 +94,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
|
||||
var errorOccurred = false
|
||||
let group = DispatchGroup()
|
||||
|
||||
|
||||
group.enter()
|
||||
account?.markAsUnread(updateableUnreadArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
@@ -103,7 +103,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
|
||||
|
||||
group.enter()
|
||||
account?.markAsRead(updateableReadArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
@@ -112,7 +112,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
|
||||
|
||||
group.enter()
|
||||
account?.markAsUnstarred(updateableUnstarredArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
@@ -121,7 +121,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
|
||||
|
||||
group.enter()
|
||||
account?.markAsStarred(updateableStarredArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
@@ -130,7 +130,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
|
||||
|
||||
group.enter()
|
||||
compressionQueue.async {
|
||||
let parsedItems = records.compactMap { self.makeParsedItem($0) }
|
||||
@@ -159,9 +159,9 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
if errorOccurred {
|
||||
completion(.failure(CloudKitZoneError.unknown))
|
||||
@@ -170,7 +170,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func stripPrefix(_ externalID: String) -> String {
|
||||
return String(externalID[externalID.index(externalID.startIndex, offsetBy: 2)..<externalID.endIndex])
|
||||
}
|
||||
@@ -179,11 +179,11 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
guard articleRecord.recordType == CloudKitArticlesZone.CloudKitArticle.recordType else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
var parsedAuthors = Set<ParsedAuthor>()
|
||||
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
|
||||
if let encodedParsedAuthors = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.parsedAuthors] as? [String] {
|
||||
for encodedParsedAuthor in encodedParsedAuthors {
|
||||
if let data = encodedParsedAuthor.data(using: .utf8), let parsedAuthor = try? decoder.decode(ParsedAuthor.self, from: data) {
|
||||
@@ -191,26 +191,26 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
guard let uniqueID = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.uniqueID] as? String,
|
||||
let feedURL = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.feedURL] as? String else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
var contentHTML = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.contentHTML] as? String
|
||||
if let contentHTMLData = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.contentHTMLData] as? NSData {
|
||||
if let decompressedContentHTMLData = try? contentHTMLData.decompressed(using: .lzfse) {
|
||||
contentHTML = String(data: decompressedContentHTMLData as Data, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var contentText = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.contentText] as? String
|
||||
if let contentTextData = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.contentTextData] as? NSData {
|
||||
if let decompressedContentTextData = try? contentTextData.decompressed(using: .lzfse) {
|
||||
contentText = String(data: decompressedContentTextData as Data, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let parsedItem = ParsedItem(syncServiceID: nil,
|
||||
uniqueID: uniqueID,
|
||||
feedURL: feedURL,
|
||||
@@ -229,8 +229,8 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
authors: parsedAuthors,
|
||||
tags: nil,
|
||||
attachments: nil)
|
||||
|
||||
|
||||
return parsedItem
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public final class CombinedRefreshProgress {
|
||||
guard isStarted else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var updatedNumberOfTasks = 0
|
||||
var updatedNumberRemaining = 0
|
||||
var updatedNumberCompleted = 0
|
||||
|
||||
@@ -12,7 +12,7 @@ import RSCore
|
||||
import Articles
|
||||
|
||||
extension Notification.Name {
|
||||
|
||||
|
||||
public static let ChildrenDidChange = Notification.Name("ChildrenDidChange")
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public protocol Container: AnyObject, ContainerIdentifiable {
|
||||
var topLevelFeeds: Set<Feed> { get set }
|
||||
var folders: Set<Folder>? { get set }
|
||||
var externalID: String? { get set }
|
||||
|
||||
|
||||
func hasAtLeastOneFeed() -> Bool
|
||||
func objectIsChild(_ object: AnyObject) -> Bool
|
||||
|
||||
@@ -100,7 +100,7 @@ public extension Container {
|
||||
func has(_ feed: Feed) -> Bool {
|
||||
return flattenedFeeds().contains(feed)
|
||||
}
|
||||
|
||||
|
||||
func existingFeed(withFeedID feedID: String) -> Feed? {
|
||||
for feed in flattenedFeeds() {
|
||||
if feed.feedID == feedID {
|
||||
@@ -118,7 +118,7 @@ public extension Container {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func existingFeed(withExternalID externalID: String) -> Feed? {
|
||||
for feed in flattenedFeeds() {
|
||||
if feed.externalID == externalID {
|
||||
|
||||
Loaded 100 of 452 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user