mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 10:47:21 +00:00
Merge branch 'main' into 4659-widget-updates
This commit is contained in:
200 files changed
+1160
-1095
No files matched your search
@@ -68,7 +68,8 @@
|
||||
"Bash(echo:*)",
|
||||
"Bash(done)",
|
||||
"Bash(# Show files touched by state restoration related commits echo \"\"=== Files changed in state restoration commits ===\"\" for commit in 04e98a47d 89b31858c d788af388 1d49b9328 236943f82 38d6b11c5 3be027699 16c66513c 1ef2aa162 6ce3bdadc 1954f5b65 55b7da75d 20b3bda94 4bf57afc1 e0074d70b 616b9deeb f6bca9ee8 ea6eedb86 380617920 d68106ac0 d30c62757 813f0706b 2ea00619c; do git diff-tree --no-commit-id --name-only -r \"\"$commit\"\" done)",
|
||||
"Bash(swiftlint version:*)"
|
||||
"Bash(swiftlint version:*)",
|
||||
"Bash(swiftlint:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
+6
-2
@@ -3,6 +3,9 @@ identifier_name:
|
||||
max_length: 50
|
||||
allowed_symbols: "_"
|
||||
|
||||
type_name:
|
||||
max_length: 50
|
||||
|
||||
# line_length:
|
||||
# warning: 200
|
||||
# error: 300
|
||||
@@ -10,8 +13,8 @@ identifier_name:
|
||||
# ignores_urls: true
|
||||
|
||||
large_tuple:
|
||||
warning: 4
|
||||
error: 5
|
||||
warning: 5
|
||||
error: 6
|
||||
|
||||
disabled_rules:
|
||||
- todo
|
||||
@@ -27,6 +30,7 @@ disabled_rules:
|
||||
- line_length
|
||||
- operator_whitespace
|
||||
- nesting
|
||||
- class_delegate_protocol
|
||||
|
||||
excluded:
|
||||
- ".build"
|
||||
|
||||
@@ -37,7 +37,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
guard let extensionContainers = await ExtensionContainersFile.read() else {
|
||||
throw AddWebFeedIntentHandlerError.communicationFailure
|
||||
}
|
||||
|
||||
|
||||
let accountNames = extensionContainers.accounts.map { $0.name }
|
||||
return accountNames
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class AddWebFeedIntentHandler: NSObject, AddWebFeedIntentHandling {
|
||||
guard let accountName = intent.accountName else {
|
||||
return .notRequired()
|
||||
}
|
||||
|
||||
|
||||
guard let extensionContainers = await ExtensionContainersFile.read() else {
|
||||
return .unsupported(forReason: .communication)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ final class AppDefaults: Sendable {
|
||||
}()
|
||||
|
||||
let isFirstRun: Bool = {
|
||||
if let _ = UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date {
|
||||
if UserDefaults.standard.object(forKey: Key.firstRunDate) is Date {
|
||||
return false
|
||||
}
|
||||
firstRunDate = Date()
|
||||
@@ -117,8 +117,7 @@ final class AppDefaults: Sendable {
|
||||
if let appGroupID = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String,
|
||||
let appGroupDefaults = UserDefaults(suiteName: appGroupID) {
|
||||
return appGroupDefaults
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return UserDefaults.standard
|
||||
}
|
||||
}
|
||||
@@ -324,7 +323,7 @@ final class AppDefaults: Sendable {
|
||||
let showDebugMenu = false
|
||||
#endif
|
||||
|
||||
let defaults: [String : Any] = [
|
||||
let defaults: [String: Any] = [
|
||||
Key.sidebarFontSize: FontSize.medium.rawValue,
|
||||
Key.timelineFontSize: FontSize.medium.rawValue,
|
||||
Key.detailFontSize: FontSize.medium.rawValue,
|
||||
@@ -428,7 +427,7 @@ private extension AppDefaults {
|
||||
UserDefaults.standard.set(date, forKey: key)
|
||||
}
|
||||
|
||||
static func sortDirection(for key:String) -> ComparisonResult {
|
||||
static func sortDirection(for key: String) -> ComparisonResult {
|
||||
let rawInt = int(for: key)
|
||||
if rawInt == ComparisonResult.orderedAscending.rawValue {
|
||||
return .orderedAscending
|
||||
@@ -439,8 +438,7 @@ private extension AppDefaults {
|
||||
static func setSortDirection(for key: String, _ value: ComparisonResult) {
|
||||
if value == .orderedAscending {
|
||||
setInt(for: key, ComparisonResult.orderedAscending.rawValue)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
setInt(for: key, ComparisonResult.orderedDescending.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,3 @@ final class CrashReportWindowController: NSWindowController {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import CrashReporter
|
||||
let boundary = "0xKhTmLbOuNdArY"
|
||||
|
||||
let contentType = "multipart/form-data; boundary=\(boundary)"
|
||||
request.setValue(contentType, forHTTPHeaderField:HTTPRequestHeader.contentType)
|
||||
request.setValue(contentType, forHTTPHeaderField: HTTPRequestHeader.contentType)
|
||||
|
||||
let formString = "--\(boundary)\r\nContent-Disposition: form-data; name=\"crashlog\"\r\n\r\n\(crashLogText)\r\n--\(boundary)--\r\n"
|
||||
let formData = formString.data(using: .utf8, allowLossyConversion: true)
|
||||
|
||||
@@ -31,7 +31,7 @@ final class BuiltinSmartFeedInspectorViewController: NSViewController, Inspector
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool {
|
||||
|
||||
guard let _ = singleSmartFeed(from: objects) else {
|
||||
guard singleSmartFeed(from: objects) != nil else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -63,7 +63,7 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
// MARK: Actions
|
||||
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
|
||||
guard authorizationStatus != nil else {
|
||||
guard authorizationStatus != nil else {
|
||||
DispatchQueue.main.async {
|
||||
self.isNotifyAboutNewArticlesCheckBox.setNextState()
|
||||
}
|
||||
@@ -85,7 +85,7 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
|
||||
}
|
||||
} else {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { granted, _ in
|
||||
Task { @MainActor in
|
||||
self.updateNotificationSettings()
|
||||
if granted {
|
||||
|
||||
@@ -35,8 +35,7 @@ final class FolderInspectorViewController: NSViewController, Inspector {
|
||||
var windowTitle: String = NSLocalizedString("Folder Inspector", comment: "Folder Inspector window title")
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool {
|
||||
|
||||
guard let _ = singleFolder(from: objects) else {
|
||||
guard singleFolder(from: objects) != nil else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -25,7 +25,7 @@ final class InspectorWindowController: NSWindowController {
|
||||
|
||||
var objects: [Any]? {
|
||||
didSet {
|
||||
let _ = window
|
||||
_ = window
|
||||
currentInspector = inspector(for: objects)
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,7 @@ final class InspectorWindowController: NSWindowController {
|
||||
|
||||
if let savedOrigin = originFromDefaults() {
|
||||
window?.setFlippedOriginAdjustingForScreen(savedOrigin)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
window?.flippedOrigin = NSPoint(x: 256, y: 256)
|
||||
}
|
||||
}
|
||||
@@ -77,8 +76,7 @@ final class InspectorWindowController: NSWindowController {
|
||||
for inspector in inspectors {
|
||||
if inspector.isFallbackInspector {
|
||||
fallbackInspector = inspector
|
||||
}
|
||||
else if let objects = objects, inspector.canInspect(objects) {
|
||||
} else if let objects = objects, inspector.canInspect(objects) {
|
||||
return inspector
|
||||
}
|
||||
}
|
||||
@@ -110,7 +108,7 @@ private extension InspectorWindowController {
|
||||
|
||||
DispatchQueue.main.async {
|
||||
window.title = inspector.windowTitle
|
||||
}
|
||||
}
|
||||
|
||||
let flippedOrigin = window.flippedOrigin
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ private extension NothingInspectorViewController {
|
||||
if let objects = objects, objects.count > 1 {
|
||||
nothingTextField?.isHidden = true
|
||||
multipleTextField?.isHidden = false
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
nothingTextField?.isHidden = false
|
||||
multipleTextField?.isHidden = true
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ import Account
|
||||
func addFeedWindowControllerUserDidCancel(_: AddFeedWindowController)
|
||||
}
|
||||
|
||||
final class AddFeedWindowController : NSWindowController {
|
||||
|
||||
final class AddFeedWindowController: NSWindowController {
|
||||
@IBOutlet var urlTextField: NSTextField!
|
||||
@IBOutlet var nameTextField: NSTextField!
|
||||
@IBOutlet var addButton: NSButton!
|
||||
@@ -97,7 +96,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
|
||||
if normalizedURLString.isEmpty {
|
||||
cancelSheet()
|
||||
return;
|
||||
return
|
||||
}
|
||||
guard let url = URL(string: normalizedURLString) else {
|
||||
cancelSheet()
|
||||
|
||||
@@ -38,7 +38,7 @@ final class DetailContainerView: NSView {
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
NSColor.controlBackgroundColor.set()
|
||||
let r = NSIntersectionRect(dirtyRect, bounds)
|
||||
let r = dirtyRect.intersection(bounds)
|
||||
r.fill()
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,7 @@ final class DetailStatusBarView: NSView {
|
||||
if let link = linkForDisplay {
|
||||
urlLabel.stringValue = link
|
||||
self.isHidden = false
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
urlLabel.stringValue = ""
|
||||
self.isHidden = true
|
||||
}
|
||||
@@ -68,8 +67,7 @@ private extension DetailStatusBarView {
|
||||
func updateLinkForDisplay() {
|
||||
if let mouseoverLink = mouseoverLink, !mouseoverLink.isEmpty {
|
||||
linkForDisplay = mouseoverLink.strippingHTTPOrHTTPSScheme
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
linkForDisplay = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,4 +89,3 @@ private extension DetailWebView {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ final class DetailWebViewController: NSViewController {
|
||||
|
||||
private var isShowingExtractedArticle: Bool {
|
||||
switch state {
|
||||
case .extracted(_, _, _):
|
||||
case .extracted:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -208,7 +208,7 @@ extension DetailWebViewController: WKNavigationDelegate, WKUIDelegate {
|
||||
decisionHandler(.cancel)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
decisionHandler(.allow)
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ private extension DetailWebViewController {
|
||||
}
|
||||
|
||||
func reloadHTMLMaintainingScrollPosition() {
|
||||
fetchScrollInfo() { scrollInfo in
|
||||
fetchScrollInfo { scrollInfo in
|
||||
self.windowScrollY = scrollInfo?.offsetY
|
||||
self.reloadHTML()
|
||||
}
|
||||
@@ -319,7 +319,7 @@ private extension DetailWebViewController {
|
||||
private func fetchScrollInfo(_ completion: @escaping (ScrollInfo?) -> Void) {
|
||||
let javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: document.body.scrollTop}; x"
|
||||
|
||||
webView.evaluateJavaScript(javascriptString) { (info, error) in
|
||||
webView.evaluateJavaScript(javascriptString) { (info, _) in
|
||||
guard let info = info as? [String: Any] else {
|
||||
completion(nil)
|
||||
return
|
||||
|
||||
@@ -79,7 +79,7 @@ final class IconView: NSView {
|
||||
}
|
||||
|
||||
override func layout() {
|
||||
resizeSubviews(withOldSize: NSZeroSize)
|
||||
resizeSubviews(withOldSize: NSSize.zero)
|
||||
}
|
||||
|
||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||
@@ -106,7 +106,7 @@ private extension IconView {
|
||||
|
||||
func rectForImageView() -> NSRect {
|
||||
guard !(iconImage?.isSymbol ?? false) else {
|
||||
return NSMakeRect(0.0, 0.0, bounds.size.width, bounds.size.height)
|
||||
return NSRect(x: 0.0, y: 0.0, width: bounds.size.width, height: bounds.size.height)
|
||||
}
|
||||
|
||||
guard let image = iconImage?.image else {
|
||||
@@ -118,21 +118,21 @@ private extension IconView {
|
||||
if imageSize.height == imageSize.width {
|
||||
if imageSize.height >= viewSize.height * 0.75 {
|
||||
// Close enough to viewSize to scale up the image.
|
||||
return NSMakeRect(0.0, 0.0, viewSize.width, viewSize.height)
|
||||
return NSRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height)
|
||||
}
|
||||
let offset = floor((viewSize.height - imageSize.height) / 2.0)
|
||||
return NSMakeRect(offset, offset, imageSize.width, imageSize.height)
|
||||
return NSRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height)
|
||||
} else if imageSize.height > imageSize.width {
|
||||
let factor = viewSize.height / imageSize.height
|
||||
let width = imageSize.width * factor
|
||||
let originX = floor((viewSize.width - width) / 2.0)
|
||||
return NSMakeRect(originX, 0.0, width, viewSize.height)
|
||||
return NSRect(x: originX, y: 0.0, width: width, height: viewSize.height)
|
||||
}
|
||||
|
||||
// Wider than tall: imageSize.width > imageSize.height
|
||||
let factor = viewSize.width / imageSize.width
|
||||
let height = imageSize.height * factor
|
||||
let originY = floor((viewSize.height - height) / 2.0)
|
||||
return NSMakeRect(0.0, originY, viewSize.width, height)
|
||||
return NSRect(x: 0.0, y: originY, width: viewSize.width, height: height)
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,3 @@ import RSCore
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations
|
||||
@IBAction func openArticleInBrowser(_ sender: Any?) {
|
||||
if let link = currentLink {
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func openInBrowser(_ sender: Any?) {
|
||||
@@ -370,8 +370,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations
|
||||
// TODO: handle search mode
|
||||
if timelineViewController.canGoToNextUnread(wrappingToTop: false) {
|
||||
goToNextUnreadInTimeline(wrappingToTop: false)
|
||||
}
|
||||
else if sidebarViewController.canGoToNextUnread(wrappingToTop: true) {
|
||||
} else if sidebarViewController.canGoToNextUnread(wrappingToTop: true) {
|
||||
sidebarViewController.goToNextUnread(wrappingToTop: true)
|
||||
|
||||
// If we ended up on the same timelineViewController, we may need to wrap
|
||||
@@ -444,7 +443,7 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations
|
||||
}
|
||||
|
||||
@IBAction func markAllAsReadAndGoToNextUnread(_ sender: Any?) {
|
||||
currentTimelineViewController?.markAllAsRead() {
|
||||
currentTimelineViewController?.markAllAsRead {
|
||||
self.nextUnread(sender)
|
||||
}
|
||||
}
|
||||
@@ -981,7 +980,7 @@ private extension MainWindowController {
|
||||
|
||||
let splitViewWidths: [Int]
|
||||
if let splitView = splitViewController?.splitView {
|
||||
splitViewWidths = splitView.arrangedSubviews.map{ Int(floor($0.frame.width)) }
|
||||
splitViewWidths = splitView.arrangedSubviews.map { Int(floor($0.frame.width)) }
|
||||
} else {
|
||||
splitViewWidths = []
|
||||
}
|
||||
@@ -1422,6 +1421,4 @@ private extension MainWindowController {
|
||||
articleThemeMenuToolbarItem.menu = articleThemeMenu
|
||||
articleThemePopUpButton?.menu = articleThemeMenu
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -141,4 +141,3 @@ extension NNW3Feed: OPMLRepresentable {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,7 @@ final class ExportOPMLWindowController: NSWindowController {
|
||||
let opmlString = OPMLExporter.OPMLString(with: account, title: filename)
|
||||
do {
|
||||
try opmlString.write(to: url, atomically: true, encoding: String.Encoding.utf8)
|
||||
}
|
||||
catch let error as NSError {
|
||||
} catch let error as NSError {
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ final class SidebarCell: NSTableCellView {
|
||||
}()
|
||||
|
||||
private let faviconImageView = IconView()
|
||||
private let unreadCountView = UnreadCountView(frame: NSZeroRect)
|
||||
private let unreadCountView = UnreadCountView(frame: NSRect.zero)
|
||||
|
||||
override var backgroundStyle: NSView.BackgroundStyle {
|
||||
didSet {
|
||||
@@ -91,7 +91,7 @@ final class SidebarCell: NSTableCellView {
|
||||
commonInit()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
commonInit()
|
||||
}
|
||||
@@ -100,7 +100,7 @@ final class SidebarCell: NSTableCellView {
|
||||
if let cellAppearance = cellAppearance {
|
||||
titleView.font = cellAppearance.textFieldFont
|
||||
}
|
||||
resizeSubviews(withOldSize: NSZeroSize)
|
||||
resizeSubviews(withOldSize: NSSize.zero)
|
||||
}
|
||||
|
||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||
|
||||
@@ -32,4 +32,3 @@ struct SidebarCellAppearance: Equatable {
|
||||
self.textFieldFont = NSFont.systemFont(ofSize: textFieldFontSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import RSCore
|
||||
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))
|
||||
|
||||
var rFavicon = NSRect.zero
|
||||
@@ -31,7 +30,7 @@ import RSCore
|
||||
|
||||
var rTextField = NSRect(x: 0.0, y: 0.0, width: textFieldSize.width, height: textFieldSize.height)
|
||||
if shouldShowImage {
|
||||
rTextField.origin.x = NSMaxX(rFavicon) + appearance.imageMarginRight
|
||||
rTextField.origin.x = rFavicon.maxX + appearance.imageMarginRight
|
||||
}
|
||||
rTextField = rTextField.centeredVertically(in: bounds)
|
||||
|
||||
@@ -41,17 +40,17 @@ import RSCore
|
||||
var rUnread = NSRect.zero
|
||||
if !unreadCountIsHidden {
|
||||
rUnread.size = unreadCountSize
|
||||
rUnread.origin.x = NSMaxX(bounds) - unreadCountSize.width
|
||||
rUnread.origin.x = bounds.maxX - unreadCountSize.width
|
||||
rUnread = rUnread.centeredVertically(in: bounds)
|
||||
let textFieldMaxX = NSMinX(rUnread) - appearance.unreadCountMarginLeft
|
||||
if NSMaxX(rTextField) > textFieldMaxX {
|
||||
rTextField.size.width = textFieldMaxX - NSMinX(rTextField)
|
||||
let textFieldMaxX = rUnread.minX - appearance.unreadCountMarginLeft
|
||||
if rTextField.maxX > textFieldMaxX {
|
||||
rTextField.size.width = textFieldMaxX - rTextField.minX
|
||||
}
|
||||
}
|
||||
self.unreadCountRect = rUnread
|
||||
|
||||
if NSMaxX(rTextField) > NSMaxX(bounds) {
|
||||
rTextField.size.width = NSMaxX(bounds) - NSMinX(rTextField)
|
||||
if rTextField.maxX > bounds.maxX {
|
||||
rTextField.size.width = bounds.maxX - rTextField.minX
|
||||
}
|
||||
self.titleRect = rTextField
|
||||
}
|
||||
|
||||
@@ -39,4 +39,3 @@ import RSCore
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,7 @@ struct PasteboardFeed: Hashable {
|
||||
var pasteboardType: NSPasteboard.PasteboardType?
|
||||
if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIInternalType) {
|
||||
pasteboardType = FeedPasteboardWriter.feedUTIInternalType
|
||||
}
|
||||
else if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIType) {
|
||||
} else if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIType) {
|
||||
pasteboardType = FeedPasteboardWriter.feedUTIType
|
||||
}
|
||||
if let foundType = pasteboardType {
|
||||
@@ -91,8 +90,7 @@ struct PasteboardFeed: Hashable {
|
||||
// Check for URL or a string that may be a URL.
|
||||
if pasteboardItem.types.contains(.URL) {
|
||||
pasteboardType = .URL
|
||||
}
|
||||
else if pasteboardItem.types.contains(.string) {
|
||||
} else if pasteboardItem.types.contains(.string) {
|
||||
pasteboardType = .string
|
||||
}
|
||||
if let foundType = pasteboardType {
|
||||
|
||||
@@ -64,7 +64,7 @@ import Account
|
||||
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
|
||||
let draggedFolders = PasteboardFolder.pasteboardFolders(with: info.draggingPasteboard)
|
||||
let draggedFeeds = PasteboardFeed.pasteboardFeeds(with: info.draggingPasteboard)
|
||||
if (draggedFolders == nil && draggedFeeds == nil) || (draggedFolders != nil && draggedFeeds != nil) {
|
||||
if (draggedFolders == nil && draggedFeeds == nil) || (draggedFolders != nil && draggedFeeds != nil) {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
}
|
||||
let parentNode = nodeForItem(item)
|
||||
@@ -100,7 +100,7 @@ import Account
|
||||
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)
|
||||
if (draggedFolders == nil && draggedFeeds == nil) || (draggedFolders != nil && draggedFeeds != nil) {
|
||||
if (draggedFolders == nil && draggedFeeds == nil) || (draggedFolders != nil && draggedFeeds != nil) {
|
||||
return false
|
||||
}
|
||||
let parentNode = nodeForItem(item)
|
||||
@@ -167,8 +167,7 @@ private extension SidebarOutlineDataSource {
|
||||
for feed in draggedFeeds {
|
||||
if feed.isLocalFeed {
|
||||
hasLocalFeed = true
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
hasNonLocalFeed = true
|
||||
}
|
||||
if hasLocalFeed && hasNonLocalFeed {
|
||||
@@ -237,7 +236,7 @@ private extension SidebarOutlineDataSource {
|
||||
return localDragOperation(parentNode: parentNode, draggedFeeds)
|
||||
}
|
||||
|
||||
func localDragOperation(parentNode: Node, _ draggedFeeds: Set<PasteboardFeed>)-> NSDragOperation {
|
||||
func localDragOperation(parentNode: Node, _ draggedFeeds: Set<PasteboardFeed>) -> NSDragOperation {
|
||||
guard let firstDraggedFeed = draggedFeeds.first else { return .move }
|
||||
if sameAccount(firstDraggedFeed, parentNode) {
|
||||
if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false {
|
||||
@@ -443,7 +442,7 @@ private extension SidebarOutlineDataSource {
|
||||
Task { @MainActor in
|
||||
do {
|
||||
let destinationFolder = try await destinationAccount.addFolder(folder.name ?? "")
|
||||
|
||||
|
||||
for feed in folder.topLevelFeeds {
|
||||
if let existingFeed = destinationAccount.existingFeed(withURL: feed.url) {
|
||||
destinationAccount.addFeed(existingFeed, to: destinationFolder) { result in
|
||||
|
||||
@@ -119,7 +119,7 @@ extension SidebarViewController {
|
||||
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
|
||||
}
|
||||
} else {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { granted, _ in
|
||||
if granted {
|
||||
DispatchQueue.main.async {
|
||||
if feed.isNotifyAboutNewArticles == nil { feed.isNotifyAboutNewArticles = false }
|
||||
@@ -215,7 +215,7 @@ private extension SidebarViewController {
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
}
|
||||
|
||||
if let homePageURL = feed.homePageURL, let _ = URL(string: homePageURL) {
|
||||
if let homePageURL = feed.homePageURL, URL(string: homePageURL) != nil {
|
||||
let item = menuItem(NSLocalizedString("Open Home Page", comment: "Command"), #selector(openHomePageFromContextualMenu(_:)), homePageURL, image: Assets.Images.openInBrowser)
|
||||
menu.addItem(item)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
@@ -365,4 +365,3 @@ private extension SidebarViewController {
|
||||
return articles
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ extension Notification.Name {
|
||||
/// Restore state using legacy state restoration data.
|
||||
///
|
||||
/// TODO: Delete for NetNewsWire 7.
|
||||
func restoreLegacyState(from state: [AnyHashable : Any]) {
|
||||
func restoreLegacyState(from state: [AnyHashable: Any]) {
|
||||
|
||||
if let containerExpandedWindowState = state[UserInfoKey.containerExpandedWindowState] as? [[AnyHashable: AnyHashable]] {
|
||||
let containerIdentifiers = containerExpandedWindowState.compactMap( { ContainerIdentifier(userInfo: $0) })
|
||||
@@ -339,7 +339,7 @@ extension Notification.Name {
|
||||
// MARK: - Navigation
|
||||
|
||||
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
||||
if let _ = nextSelectableRowWithUnreadArticle(wrappingToTop: wrapping) {
|
||||
if nextSelectableRowWithUnreadArticle(wrappingToTop: wrapping) != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -461,7 +461,7 @@ extension Notification.Name {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Node Manipulation
|
||||
// MARK: - Node Manipulation
|
||||
|
||||
func deleteNodes(_ nodes: [Node]) {
|
||||
let nodesToDelete = treeController.normalizedSelectedNodes(nodes)
|
||||
@@ -504,7 +504,7 @@ extension Notification.Name {
|
||||
revealAndSelectRepresentedObject(sidebarItem as AnyObject)
|
||||
}
|
||||
|
||||
func deepLinkRevealAndSelect(for userInfo: [AnyHashable : Any]) {
|
||||
func deepLinkRevealAndSelect(for userInfo: [AnyHashable: Any]) {
|
||||
guard let accountNode = findAccountNode(userInfo),
|
||||
let feedNode = findFeedNode(userInfo, beginningAt: accountNode),
|
||||
let sidebarItem = feedNode.representedObject as? SidebarItem else {
|
||||
@@ -537,7 +537,7 @@ extension SidebarViewController: NSUserInterfaceValidations {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Private
|
||||
// MARK: - Private
|
||||
|
||||
private extension SidebarViewController {
|
||||
|
||||
@@ -758,7 +758,7 @@ private extension SidebarViewController {
|
||||
return nil
|
||||
}
|
||||
|
||||
func findAccountNode(_ userInfo: [AnyHashable : Any]?) -> Node? {
|
||||
func findAccountNode(_ userInfo: [AnyHashable: Any]?) -> Node? {
|
||||
guard let accountID = userInfo?[ArticlePathKey.accountID] as? String else {
|
||||
return nil
|
||||
}
|
||||
@@ -778,7 +778,7 @@ private extension SidebarViewController {
|
||||
return nil
|
||||
}
|
||||
|
||||
func findFeedNode(_ userInfo: [AnyHashable : Any]?, beginningAt startingNode: Node) -> Node? {
|
||||
func findFeedNode(_ userInfo: [AnyHashable: Any]?, beginningAt startingNode: Node) -> Node? {
|
||||
guard let feedID = userInfo?[ArticlePathKey.feedID] as? String else {
|
||||
return nil
|
||||
}
|
||||
@@ -857,7 +857,7 @@ private extension SidebarViewController {
|
||||
}
|
||||
|
||||
func applyToAvailableCells(_ completion: (SidebarCell, Node) -> Void) {
|
||||
outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, row: Int) -> Void in
|
||||
outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, row: Int) in
|
||||
guard let cell = cellForRowView(rowView), let node = nodeForRow(row) else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ final class UnreadCountView: NSView {
|
||||
}
|
||||
|
||||
private var intrinsicContentSizeIsValid = false
|
||||
private var _intrinsicContentSize = NSZeroSize
|
||||
private var _intrinsicContentSize = NSSize.zero
|
||||
|
||||
override var intrinsicContentSize: NSSize {
|
||||
if !intrinsicContentSizeIsValid {
|
||||
var size = NSZeroSize
|
||||
var size = NSSize.zero
|
||||
if unreadCount > 0 {
|
||||
size = textSize()
|
||||
size.width += (Appearance.padding.left + Appearance.padding.right)
|
||||
@@ -74,7 +74,7 @@ final class UnreadCountView: NSView {
|
||||
|
||||
private func textSize() -> NSSize {
|
||||
if unreadCount < 1 {
|
||||
return NSZeroSize
|
||||
return NSSize.zero
|
||||
}
|
||||
|
||||
if let cachedSize = UnreadCountView.textSizeCache[unreadCount] {
|
||||
@@ -91,9 +91,9 @@ final class UnreadCountView: NSView {
|
||||
|
||||
private func textRect() -> NSRect {
|
||||
let size = textSize()
|
||||
var r = NSZeroRect
|
||||
var r = NSRect.zero
|
||||
r.size = size
|
||||
r.origin.x = (NSMaxX(bounds) - Appearance.padding.right) - r.size.width
|
||||
r.origin.x = (bounds.maxX - Appearance.padding.right) - r.size.width
|
||||
r.origin.y = Appearance.padding.top
|
||||
return r
|
||||
}
|
||||
@@ -108,4 +108,3 @@ final class UnreadCountView: NSView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ extension Article: @retroactive PasteboardWriterOwner {
|
||||
func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
|
||||
var types = [ArticlePasteboardWriter.articleUTIType]
|
||||
|
||||
if let _ = article.preferredURL {
|
||||
if article.preferredURL != nil {
|
||||
types += [.URL]
|
||||
}
|
||||
types += [.string, .html, ArticlePasteboardWriter.articleUTIInternalType]
|
||||
@@ -78,11 +78,9 @@ private extension ArticlePasteboardWriter {
|
||||
}
|
||||
if let text = article.contentText {
|
||||
s += "\(text)\n\n"
|
||||
}
|
||||
else if let summary = article.summary {
|
||||
} else if let summary = article.summary {
|
||||
s += "\(summary)\n\n"
|
||||
}
|
||||
else if let html = article.contentHTML {
|
||||
} else if let html = article.contentHTML {
|
||||
let convertedHTML = html.convertingToPlainText()
|
||||
s += "\(convertedHTML)\n\n"
|
||||
}
|
||||
@@ -184,7 +182,6 @@ private extension ArticlePasteboardWriter {
|
||||
guard let authors = article.authors, !authors.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
return authors.map{ authorDictionary($0) }
|
||||
return authors.map { authorDictionary($0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ import Articles
|
||||
self.starred = article.status.starred
|
||||
}
|
||||
|
||||
init() { //Empty
|
||||
init() { // Empty
|
||||
self.title = ""
|
||||
self.text = ""
|
||||
self.dateString = ""
|
||||
|
||||
@@ -42,8 +42,7 @@ import RSCore
|
||||
|
||||
if height > 0.1 {
|
||||
self.height = height
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
self.height = [feedNameRect, dateRect, titleRect, summaryRect, textRect, unreadIndicatorRect, iconImageRect].maxY() + paddingBottom
|
||||
}
|
||||
}
|
||||
@@ -62,8 +61,7 @@ import RSCore
|
||||
var lastTextRect = titleRect
|
||||
if numberOfLinesForTitle == 0 {
|
||||
lastTextRect = textRect
|
||||
}
|
||||
else if numberOfLinesForTitle < appearance.titleNumberOfLines {
|
||||
} else if numberOfLinesForTitle < appearance.titleNumberOfLines {
|
||||
if summaryRect.height > 0.1 {
|
||||
lastTextRect = summaryRect
|
||||
}
|
||||
@@ -124,13 +122,13 @@ import RSCore
|
||||
return (r, sizeInfo.numberOfLinesUsed)
|
||||
}
|
||||
|
||||
static func rectForSummary(_ textBoxRect: NSRect, _ titleRect: NSRect, _ titleNumberOfLines: Int, _ appearance: TimelineCellAppearance, _ cellData: TimelineCellData) -> NSRect {
|
||||
static func rectForSummary(_ textBoxRect: NSRect, _ titleRect: NSRect, _ titleNumberOfLines: Int, _ appearance: TimelineCellAppearance, _ cellData: TimelineCellData) -> NSRect {
|
||||
if titleNumberOfLines >= appearance.titleNumberOfLines || cellData.text.isEmpty {
|
||||
return NSRect.zero
|
||||
}
|
||||
|
||||
var r = textBoxRect
|
||||
r.origin.y = NSMaxY(titleRect)
|
||||
r.origin.y = titleRect.maxY
|
||||
let summaryNumberOfLines = appearance.titleNumberOfLines - titleNumberOfLines
|
||||
|
||||
let sizeInfo = MultilineTextFieldSizer.size(for: cellData.text, font: appearance.textOnlyFont, numberOfLines: summaryNumberOfLines, width: Int(textBoxRect.width))
|
||||
@@ -161,9 +159,9 @@ import RSCore
|
||||
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
|
||||
var r = NSRect.zero
|
||||
r.size = textFieldSize
|
||||
r.origin.y = NSMaxY(rectAbove) + appearance.titleBottomMargin
|
||||
r.origin.y = rectAbove.maxY + appearance.titleBottomMargin
|
||||
r.size.width = textFieldSize.width
|
||||
|
||||
r.origin.x = textBoxRect.maxX - textFieldSize.width
|
||||
@@ -173,11 +171,11 @@ import RSCore
|
||||
|
||||
static func rectForFeedName(_ textBoxRect: NSRect, _ dateRect: NSRect, _ appearance: TimelineCellAppearance, _ cellData: TimelineCellData) -> NSRect {
|
||||
if cellData.showFeedName == .none {
|
||||
return NSZeroRect
|
||||
return NSRect.zero
|
||||
}
|
||||
|
||||
let textFieldSize = SingleLineTextFieldSizer.size(for: cellData.feedName, font: appearance.feedNameFont)
|
||||
var r = NSZeroRect
|
||||
var r = NSRect.zero
|
||||
r.size = textFieldSize
|
||||
r.origin.y = dateRect.minY
|
||||
r.origin.x = textBoxRect.origin.x
|
||||
@@ -188,7 +186,7 @@ import RSCore
|
||||
|
||||
static func rectForUnreadIndicator(_ appearance: TimelineCellAppearance, _ titleRect: NSRect) -> NSRect {
|
||||
|
||||
var r = NSZeroRect
|
||||
var r = NSRect.zero
|
||||
r.size = NSSize(width: appearance.unreadCircleDimension, height: appearance.unreadCircleDimension)
|
||||
r.origin.x = appearance.cellPadding.left
|
||||
r.origin.y = titleRect.minY + 6
|
||||
@@ -235,4 +233,3 @@ private extension Array where Element == NSRect {
|
||||
return y
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
private let titleView = TimelineTableCellView.multiLineTextField()
|
||||
private let summaryView = TimelineTableCellView.multiLineTextField()
|
||||
private let textView = TimelineTableCellView.multiLineTextField()
|
||||
private let unreadIndicatorView = UnreadIndicatorView(frame: NSZeroRect)
|
||||
private let unreadIndicatorView = UnreadIndicatorView(frame: NSRect.zero)
|
||||
private let dateView = TimelineTableCellView.singleLineTextField()
|
||||
private let feedNameView = TimelineTableCellView.singleLineTextField()
|
||||
|
||||
@@ -65,7 +65,7 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
commonInit()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
commonInit()
|
||||
}
|
||||
@@ -91,7 +91,7 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
|
||||
override func layout() {
|
||||
|
||||
resizeSubviews(withOldSize: NSZeroSize)
|
||||
resizeSubviews(withOldSize: NSSize.zero)
|
||||
}
|
||||
|
||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||
@@ -149,8 +149,7 @@ private extension TimelineTableCellView {
|
||||
|
||||
if Int(floor(rect.height)) == 0 || Int(floor(rect.width)) == 0 {
|
||||
hideView(textField)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
showView(textField)
|
||||
textField.setFrame(ifNotEqualTo: rect)
|
||||
}
|
||||
@@ -300,7 +299,11 @@ private extension TimelineTableCellView {
|
||||
}
|
||||
|
||||
func showOrHideView(_ view: NSView, _ shouldHide: Bool) {
|
||||
shouldHide ? hideView(view) : showView(view)
|
||||
if shouldHide {
|
||||
hideView(view)
|
||||
} else {
|
||||
showView(view)
|
||||
}
|
||||
}
|
||||
|
||||
func updateSubviews() {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
import AppKit
|
||||
|
||||
final class TimelineContainerView: NSView {
|
||||
|
||||
private var contentViewConstraints: [NSLayoutConstraint]?
|
||||
|
||||
var contentView: NSView? {
|
||||
@@ -34,4 +33,3 @@ final class TimelineContainerView: NSView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ final class TimelineContainerViewController: NSViewController {
|
||||
return false
|
||||
}
|
||||
for object in representedObjects {
|
||||
guard let _ = currentObjects.firstIndex(where: { $0 === object } ) else {
|
||||
if currentObjects.firstIndex(where: { $0 === object }) == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -183,8 +183,7 @@ private extension TimelineContainerViewController {
|
||||
func mode(for timelineViewController: TimelineViewController) -> TimelineSourceMode {
|
||||
if timelineViewController === regularTimelineViewController {
|
||||
return .regular
|
||||
}
|
||||
else if timelineViewController === searchTimelineViewController {
|
||||
} else if timelineViewController === searchTimelineViewController {
|
||||
return .search
|
||||
}
|
||||
assertionFailure("Expected timelineViewController to match either regular or search timelineViewController, but it doesn’t.")
|
||||
|
||||
@@ -248,11 +248,11 @@ private extension TimelineViewController {
|
||||
}
|
||||
|
||||
func markAboveReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Mark Above as Read", comment: "Command"), #selector(markAboveArticlesReadFromContextualMenu(_:)), articles, image: Assets.Images.markAboveAsRead)
|
||||
return menuItem(NSLocalizedString("Mark Above as Read", comment: "Command"), #selector(markAboveArticlesReadFromContextualMenu(_:)), articles, image: Assets.Images.markAboveAsRead)
|
||||
}
|
||||
|
||||
func markBelowReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles, image: Assets.Images.markBelowAsRead)
|
||||
return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles, image: Assets.Images.markBelowAsRead)
|
||||
}
|
||||
|
||||
func selectFeedInSidebarMenuItem(_ feed: Feed) -> NSMenuItem {
|
||||
|
||||
@@ -12,7 +12,7 @@ import Articles
|
||||
import Account
|
||||
import os.log
|
||||
|
||||
@MainActor protocol TimelineDelegate: AnyObject {
|
||||
@MainActor protocol TimelineDelegate: AnyObject {
|
||||
func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?)
|
||||
func timelineRequestedFeedSelection(_: TimelineViewController, feed: Feed)
|
||||
func timelineInvalidatedRestorationState(_: TimelineViewController)
|
||||
@@ -405,8 +405,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
|
||||
if markAsRead {
|
||||
markSelectedArticlesAsRead(sender)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
markSelectedArticlesAsUnread(sender)
|
||||
}
|
||||
}
|
||||
@@ -563,8 +562,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
for article in selectedArticles {
|
||||
if cutoffDate == nil {
|
||||
cutoffDate = article.logicalDatePublished
|
||||
}
|
||||
else if cutoffDate! > article.logicalDatePublished {
|
||||
} else if cutoffDate! > article.logicalDatePublished {
|
||||
cutoffDate = article.logicalDatePublished
|
||||
}
|
||||
}
|
||||
@@ -605,7 +603,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
|
||||
// MARK: - Navigation
|
||||
|
||||
func goToDeepLink(for userInfo: [AnyHashable : Any]) {
|
||||
func goToDeepLink(for userInfo: [AnyHashable: Any]) {
|
||||
guard let articleID = userInfo[ArticlePathKey.articleID] as? String else { return }
|
||||
|
||||
if isReadFiltered ?? false {
|
||||
@@ -633,10 +631,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
||||
guard let _ = indexOfNextUnreadArticle(wrappingToTop: wrapping) else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return indexOfNextUnreadArticle(wrappingToTop: wrapping) != nil
|
||||
}
|
||||
|
||||
func indexOfNextUnreadArticle(wrappingToTop wrapping: Bool = false) -> Int? {
|
||||
@@ -913,8 +908,7 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
cell.cellAppearance = showIcons ? cellAppearanceWithIcon : cellAppearance
|
||||
if let article = articles.articleAtRow(row) {
|
||||
configureTimelineCell(cell, article: article)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
makeTimelineCellEmpty(cell)
|
||||
}
|
||||
}
|
||||
@@ -996,25 +990,25 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
}
|
||||
|
||||
switch edge {
|
||||
case .leading:
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.read ? "Unread" : "Read") { (action, row) in
|
||||
self.toggleArticleRead(article);
|
||||
tableView.rowActionsVisible = false
|
||||
}
|
||||
action.image = article.status.read ? Assets.Images.swipeMarkUnread : Assets.Images.swipeMarkRead
|
||||
return [action]
|
||||
case .leading:
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.read ? "Unread" : "Read") { (_, _) in
|
||||
self.toggleArticleRead(article)
|
||||
tableView.rowActionsVisible = false
|
||||
}
|
||||
action.image = article.status.read ? Assets.Images.swipeMarkUnread : Assets.Images.swipeMarkRead
|
||||
return [action]
|
||||
|
||||
case .trailing:
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.starred ? "Unstar" : "Star") { (action, row) in
|
||||
self.toggleArticleStarred(article);
|
||||
tableView.rowActionsVisible = false
|
||||
}
|
||||
case .trailing:
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.starred ? "Unstar" : "Star") { (_, _) in
|
||||
self.toggleArticleStarred(article)
|
||||
tableView.rowActionsVisible = false
|
||||
}
|
||||
action.backgroundColor = Assets.Colors.star
|
||||
action.image = article.status.starred ? Assets.Images.swipeMarkUnstarred : Assets.Images.swipeMarkStarred
|
||||
return [action]
|
||||
action.image = article.status.starred ? Assets.Images.swipeMarkUnstarred : Assets.Images.swipeMarkStarred
|
||||
return [action]
|
||||
|
||||
@unknown default:
|
||||
Self.logger.error("TimelineViewController: unknown edge \(edge.rawValue, privacy: .public)")
|
||||
@unknown default:
|
||||
Self.logger.error("TimelineViewController: unknown edge \(edge.rawValue, privacy: .public)")
|
||||
}
|
||||
|
||||
return []
|
||||
@@ -1221,7 +1215,7 @@ private extension TimelineViewController {
|
||||
|
||||
func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set<Article> {
|
||||
cancelPendingAsyncFetches()
|
||||
let fetchers = representedObjects.compactMap{ $0 as? ArticleFetcher }
|
||||
let fetchers = representedObjects.compactMap { $0 as? ArticleFetcher }
|
||||
if fetchers.isEmpty {
|
||||
return Set<Article>()
|
||||
}
|
||||
@@ -1316,8 +1310,7 @@ private extension TimelineViewController {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
else if let folder = representedObject as? Folder {
|
||||
} else if let folder = representedObject as? Folder {
|
||||
for oneFeed in feeds {
|
||||
if folder.hasFeed(with: oneFeed.feedID) || folder.hasFeed(withURL: oneFeed.url) {
|
||||
return true
|
||||
|
||||
@@ -52,7 +52,7 @@ final class AccountsAddCloudKitWindowController: NSWindowController {
|
||||
return
|
||||
}
|
||||
|
||||
let _ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
_ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
hostWindow.endSheet(window, returnCode: NSApplication.ModalResponse.OK)
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,7 @@ struct AddAccountHelpView: View {
|
||||
ForEach(accountTypes, id: \.self) { accountType in
|
||||
if accountType == .cloudKit && hasiCloudAccount {
|
||||
EmptyView()
|
||||
}
|
||||
else if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) {
|
||||
} else if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) {
|
||||
Button(action: {
|
||||
delegate?.presentSheetForAccount(accountType)
|
||||
}, label: {
|
||||
|
||||
@@ -57,8 +57,7 @@ private extension AdvancedPreferencesViewController {
|
||||
func updateUI() {
|
||||
if wantsTestBuilds {
|
||||
testBuildsButton.state = .on
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
releaseBuildsButton.state = .on
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ final class PreferencesControlsBackgroundView: NSView {
|
||||
|
||||
let fillColor = self.effectiveAppearance.isDarkMode ? darkModeFillColor : lightModeFillColor
|
||||
fillColor.setFill()
|
||||
let r = NSIntersectionRect(dirtyRect, bounds)
|
||||
let r = dirtyRect.intersection(bounds)
|
||||
r.fill()
|
||||
|
||||
let borderColor = self.effectiveAppearance.isDarkMode ? darkModeBorderColor : lightModeBorderColor
|
||||
|
||||
@@ -17,7 +17,7 @@ final class PreferencesTableViewBackgroundView: NSView {
|
||||
let color = self.effectiveAppearance.isDarkMode ? darkBorderColor : lightBorderColor
|
||||
color.setFill()
|
||||
|
||||
let r = NSIntersectionRect(dirtyRect, bounds)
|
||||
let r = dirtyRect.intersection(bounds)
|
||||
r.fill()
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ private struct ToolbarItemIdentifier {
|
||||
static let Advanced = "Advanced"
|
||||
}
|
||||
|
||||
final class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
|
||||
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]()
|
||||
@@ -140,8 +140,7 @@ private extension PreferencesWindowController {
|
||||
|
||||
if let currentView = currentView {
|
||||
window!.contentView?.replaceSubview(currentView, with: newViewController.view)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
window!.contentView?.addSubview(newViewController.view)
|
||||
}
|
||||
|
||||
@@ -168,17 +167,17 @@ private extension PreferencesWindowController {
|
||||
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
|
||||
let deltaHeight = contentViewFrame.height - viewFrame.height
|
||||
let heightForWindow = windowFrame.height - deltaHeight
|
||||
let windowOriginY = windowFrame.minY + deltaHeight
|
||||
|
||||
var updatedWindowFrame = windowFrame
|
||||
updatedWindowFrame.size.height = heightForWindow
|
||||
updatedWindowFrame.origin.y = windowOriginY
|
||||
updatedWindowFrame.size.width = windowWidth //NSWidth(viewFrame)
|
||||
updatedWindowFrame.size.width = windowWidth // NSWidth(viewFrame)
|
||||
|
||||
var updatedViewFrame = viewFrame
|
||||
updatedViewFrame.origin = NSZeroPoint
|
||||
updatedViewFrame.origin = NSPoint.zero
|
||||
updatedViewFrame.size.width = windowWidth
|
||||
if viewFrame != updatedViewFrame {
|
||||
view.frame = updatedViewFrame
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 SFPro-Bold;\f1\fnil\fcharset0 SFPro-Regular;}
|
||||
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
|
||||
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0\cname textColor;}
|
||||
\margl1440\margr1440\vieww14060\viewh15660\viewkind0
|
||||
\paperw12240\paperh15840\margl1440\margr1440\vieww14060\viewh15660\viewkind0
|
||||
\deftab720
|
||||
\pard\pardeftab720\sa60\partightenfactor0
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
\cf2 Contributing Developers \
|
||||
\pard\pardeftab720\sl168\slmult1\sa60\partightenfactor0
|
||||
{\field{\*\fldinst{HYPERLINK "https://stuartbreckenridge.net/"}}{\fldrslt \cf2 Stuart Breckenridge}}, {\field{\*\fldinst{HYPERLINK "https://github.com/vincode-io"}}{\fldrslt Maurice Parker}}\
|
||||
\pard\pardeftab720\sl168\slmult1\sa60\partightenfactor0
|
||||
\cf2 \
|
||||
\
|
||||
App Icon\
|
||||
{\field{\*\fldinst{HYPERLINK "https://twitter.com/BradEllis"}}{\fldrslt Brad Ellis}}\
|
||||
\pard\pardeftab720\sl168\slmult1\sa60\partightenfactor0
|
||||
{\field{\*\fldinst{HYPERLINK "https://hachyderm.io/@bradellis"}}{\fldrslt \cf2 Brad Ellis}}\
|
||||
\
|
||||
Feedly Syncing\
|
||||
{\field{\*\fldinst{HYPERLINK "https://twitter.com/kielgillard"}}{\fldrslt Kiel Gillard}}\
|
||||
\
|
||||
NewsBlur Syncing\
|
||||
{\field{\*\fldinst{HYPERLINK "https://twitter.com/quanganhdo"}}{\fldrslt Anh Do}}\
|
||||
{\field{\*\fldinst{HYPERLINK "https://mastodon.social/@anhdo"}}{\fldrslt Anh Do}}\
|
||||
\
|
||||
Under-the-Hood Magic and CSS Stylin's\
|
||||
{\field{\*\fldinst{HYPERLINK "https://github.com/wevah"}}{\fldrslt Nate Weaver}}\
|
||||
@@ -31,8 +31,14 @@ Under-the-Hood Magic and CSS Stylin's\
|
||||
Newsfoot (JS footnote displayer)\
|
||||
{\field{\*\fldinst{HYPERLINK "https://github.com/brehaut/"}}{\fldrslt Andrew Brehaut}}\
|
||||
\
|
||||
\pard\pardeftab720\sl168\slmult1\sa60\partightenfactor0
|
||||
\cf2 Help Book\
|
||||
{\field{\*\fldinst{HYPERLINK "https://github.com/nostodnayr"}}{\fldrslt Ryan Dotson}}\
|
||||
\pard\pardeftab720\sl168\slmult1\sa60\partightenfactor0
|
||||
\cf2 \
|
||||
And featuring contributions from\
|
||||
{\field{\*\fldinst{HYPERLINK "https://github.com/danielpunkass"}}{\fldrslt Daniel Jalkut}}, {\field{\*\fldinst{HYPERLINK "https://rhonabwy.com/"}}{\fldrslt Joe Heck}}, {\field{\*\fldinst{HYPERLINK "https://github.com/olofhellman"}}{\fldrslt Olof Hellman}}, {\field{\*\fldinst{HYPERLINK "https://blog.rizwan.dev/"}}{\fldrslt Rizwan Mohamed Ibrahim}}, {\field{\*\fldinst{HYPERLINK "https://twitter.com/philviso"}}{\fldrslt Phil Viso}}, and {\field{\*\fldinst{HYPERLINK "https://github.com/Ranchero-Software/NetNewsWire/graphs/contributors"}}{\fldrslt many more}}!\
|
||||
\pard\pardeftab720\sl168\slmult1\sa60\partightenfactor0
|
||||
{\field{\*\fldinst{HYPERLINK "https://github.com/danielpunkass"}}{\fldrslt \cf2 Daniel Jalkut}}, {\field{\*\fldinst{HYPERLINK "https://rhonabwy.com/"}}{\fldrslt Joe Heck}}, {\field{\*\fldinst{HYPERLINK "https://github.com/olofhellman"}}{\fldrslt Olof Hellman}}, {\field{\*\fldinst{HYPERLINK "https://blog.rizwan.dev/"}}{\fldrslt Rizwan Mohamed Ibrahim}}, {\field{\*\fldinst{HYPERLINK "https://github.com/philviso"}}{\fldrslt Phil Viso}}, and {\field{\*\fldinst{HYPERLINK "https://github.com/Ranchero-Software/NetNewsWire/graphs/contributors"}}{\fldrslt many more}}!\
|
||||
\pard\pardeftab720\li360\sa60\partightenfactor0
|
||||
\cf2 \
|
||||
\pard\pardeftab720\sa60\partightenfactor0
|
||||
|
||||
@@ -29,7 +29,7 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
}
|
||||
|
||||
// Maps from UUID to a validation wrapper
|
||||
nonisolated(unsafe) static var gPingPongMap = Dictionary<String, ValidationWrapper>()
|
||||
nonisolated(unsafe) static var gPingPongMap = [String: ValidationWrapper]()
|
||||
static let validationQueue = DispatchQueue(label: "Toolbar Validation")
|
||||
|
||||
// Bottleneck for calling through to a validation handler we have saved, and removing it from the list.
|
||||
@@ -40,8 +40,8 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) {
|
||||
if (messageName == "subscribeToFeed") {
|
||||
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String: Any]?) {
|
||||
if messageName == "subscribeToFeed" {
|
||||
if var feedURLString = userInfo?["url"] as? String {
|
||||
var openInDefaultBrowser = false
|
||||
|
||||
@@ -61,12 +61,11 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
NSWorkspace.shared.open(feedURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (messageName == "pong") {
|
||||
} else if messageName == "pong" {
|
||||
if let validationIDString = userInfo?["validationID"] as? String {
|
||||
// Should we validate the button?
|
||||
let shouldValidate = userInfo?["shouldValidate"] as? Bool ?? false
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: validationIDString, withShouldValidate:shouldValidate)
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: validationIDString, withShouldValidate: shouldValidate)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +96,7 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
if thisValidationID != uniqueValidationID {
|
||||
// Default to valid ... we'll know soon enough whether the latest state
|
||||
// is actually still valid or not...
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: thisValidationID, withShouldValidate: true);
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: thisValidationID, withShouldValidate: true)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -108,17 +107,17 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
// a timeout period has elapsed
|
||||
window.getActiveTab { (activeTab) in
|
||||
guard let activeTab = activeTab else {
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: uniqueValidationID, withShouldValidate:false);
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: uniqueValidationID, withShouldValidate: false)
|
||||
return
|
||||
}
|
||||
|
||||
activeTab.getActivePage { (activePage) in
|
||||
guard let activePage = activePage else {
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: uniqueValidationID, withShouldValidate:false);
|
||||
return
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: uniqueValidationID, withShouldValidate: false)
|
||||
return
|
||||
}
|
||||
|
||||
activePage.getPropertiesWithCompletionHandler { (pageProperties) in
|
||||
activePage.getPropertiesWithCompletionHandler { pageProperties in
|
||||
if let isActive = pageProperties?.isActive {
|
||||
if isActive {
|
||||
// Capture the uniqueValidationID to ensure it doesn't change out from under us on a future call
|
||||
@@ -127,7 +126,7 @@ final class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
let pongTimeoutInNanoseconds = Int(Double(NSEC_PER_SEC) * 0.5)
|
||||
let timeoutDeadline = DispatchTime.now() + DispatchTimeInterval.nanoseconds(pongTimeoutInNanoseconds)
|
||||
DispatchQueue.main.asyncAfter(deadline: timeoutDeadline, execute: { [timedOutValidationID = uniqueValidationID] in
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: timedOutValidationID, withShouldValidate:false)
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: timedOutValidationID, withShouldValidate: false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ import RSCore
|
||||
self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
func deleteElement(_ element: ScriptingObject) {
|
||||
if let scriptableFolder = element as? ScriptableFolder {
|
||||
BatchUpdate.shared.perform {
|
||||
account.removeFolder(scriptableFolder.folder) { _ in
|
||||
@@ -93,8 +93,8 @@ import RSCore
|
||||
// MARK: --- Scriptable elements ---
|
||||
|
||||
@objc(feeds)
|
||||
var feeds: NSArray {
|
||||
account.topLevelFeeds.map { ScriptableFeed($0, container:self) } as NSArray
|
||||
var feeds: NSArray {
|
||||
account.topLevelFeeds.map { ScriptableFeed($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(countOfFeeds)
|
||||
@@ -116,23 +116,23 @@ import RSCore
|
||||
guard let feed = account.existingFeed(withFeedID: id) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFeed(feed, container:self)
|
||||
return ScriptableFeed(feed, container: self)
|
||||
}
|
||||
|
||||
@objc(valueInFeedsWithName:)
|
||||
func valueInFeeds(withName name: String) -> ScriptableFeed? {
|
||||
let feeds = Array(account.flattenedFeeds())
|
||||
guard let feed = feeds.first(where:{$0.name == name}) else {
|
||||
guard let feed = feeds.first(where: { $0.name == name }) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFeed(feed, container:self)
|
||||
return ScriptableFeed(feed, container: self)
|
||||
}
|
||||
|
||||
@objc(folders)
|
||||
var folders: NSArray {
|
||||
var folders: NSArray {
|
||||
let foldersSet = account.folders ?? Set<Folder>()
|
||||
let folders = Array(foldersSet)
|
||||
return folders.map { ScriptableFolder($0, container:self) } as NSArray
|
||||
return folders.map { ScriptableFolder($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(countOfFolders)
|
||||
@@ -151,20 +151,20 @@ import RSCore
|
||||
}
|
||||
|
||||
@objc(valueInFoldersWithUniqueID:)
|
||||
func valueInFolders(withUniqueID id:NSNumber) -> ScriptableFolder? {
|
||||
func valueInFolders(withUniqueID id: NSNumber) -> ScriptableFolder? {
|
||||
let folderId = id.intValue
|
||||
let foldersSet = account.folders ?? Set<Folder>()
|
||||
let folders = Array(foldersSet)
|
||||
guard let folder = folders.first(where:{$0.folderID == folderId}) else {
|
||||
guard let folder = folders.first(where: { $0.folderID == folderId }) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFolder(folder, container:self)
|
||||
return ScriptableFolder(folder, container: self)
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
@objc(allFeeds)
|
||||
var allFeeds: NSArray {
|
||||
var allFeeds: NSArray {
|
||||
let allFeeds = account.flattenedFeeds()
|
||||
let scriptableFeeds = allFeeds.map { feed in
|
||||
ScriptableFeed(feed, container: self)
|
||||
@@ -191,7 +191,7 @@ import RSCore
|
||||
guard let feed = account.existingFeed(withFeedID: id) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFeed(feed, container:self)
|
||||
return ScriptableFeed(feed, container: self)
|
||||
}
|
||||
|
||||
@objc(valueInAllFeedsWithName:)
|
||||
@@ -200,12 +200,12 @@ import RSCore
|
||||
guard let feed = feeds.first(where: {$0.name == name}) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFeed(feed, container:self)
|
||||
return ScriptableFeed(feed, container: self)
|
||||
}
|
||||
|
||||
@objc(opmlRepresentation)
|
||||
var opmlRepresentation: String {
|
||||
self.account.OPMLString(indentLevel:0)
|
||||
var opmlRepresentation: String {
|
||||
self.account.OPMLString(indentLevel: 0)
|
||||
}
|
||||
|
||||
@objc(accountType)
|
||||
|
||||
@@ -25,9 +25,9 @@ import Articles
|
||||
}
|
||||
|
||||
@MainActor protocol ScriptingAppDelegate {
|
||||
var scriptingCurrentArticle: Article? {get}
|
||||
var scriptingSelectedArticles: [Article] {get}
|
||||
var scriptingMainWindowController:ScriptingMainWindowController? {get}
|
||||
var scriptingCurrentArticle: Article? {get}
|
||||
var scriptingSelectedArticles: [Article] {get}
|
||||
var scriptingMainWindowController: ScriptingMainWindowController? {get}
|
||||
}
|
||||
|
||||
// Wrapper to safely transfer non-Sendable values across isolation boundaries
|
||||
@@ -60,7 +60,7 @@ extension AppDelegate: AppDelegateAppleEvents {
|
||||
|
||||
if let themeURL = URL(string: themeURLString) {
|
||||
let request = URLRequest(url: themeURL)
|
||||
let task = URLSession.shared.downloadTask(with: request) { location, response, error in
|
||||
let task = URLSession.shared.downloadTask(with: request) { location, _, error in
|
||||
guard let location = location else {
|
||||
return
|
||||
}
|
||||
@@ -96,7 +96,7 @@ extension AppDelegate: AppDelegateAppleEvents {
|
||||
}
|
||||
}
|
||||
|
||||
final class NetNewsWireCreateElementCommand : NSCreateCommand {
|
||||
final class NetNewsWireCreateElementCommand: NSCreateCommand {
|
||||
// AppleScript commands always execute on the main thread, so using assumeIsolated is safe
|
||||
// even though NSCreateCommand doesn't have concurrency annotations
|
||||
nonisolated override func performDefaultImplementation() -> Any? {
|
||||
@@ -105,10 +105,10 @@ final class NetNewsWireCreateElementCommand : NSCreateCommand {
|
||||
let instance = unsafeSelf.value
|
||||
let classDescription: NSScriptClassDescription = instance.createClassDescription
|
||||
let command: NSCreateCommand = instance
|
||||
if (classDescription.className == "feed") {
|
||||
return UnsafeSendable(value: ScriptableFeed.handleCreateElement(command:command))
|
||||
} else if (classDescription.className == "folder") {
|
||||
return UnsafeSendable(value: ScriptableFolder.handleCreateElement(command:command))
|
||||
if classDescription.className == "feed" {
|
||||
return UnsafeSendable(value: ScriptableFeed.handleCreateElement(command: command))
|
||||
} else if classDescription.className == "folder" {
|
||||
return UnsafeSendable(value: ScriptableFolder.handleCreateElement(command: command))
|
||||
}
|
||||
return UnsafeSendable(value: nil)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ final class NetNewsWireCreateElementCommand : NSCreateCommand {
|
||||
is ambiguity about whether specifiers are lists or single objects, the code switches
|
||||
based on which it is.
|
||||
*/
|
||||
final class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
final class NetNewsWireDeleteCommand: NSDeleteCommand {
|
||||
|
||||
/*
|
||||
delete(objectToDelete:, from container:)
|
||||
@@ -132,10 +132,10 @@ final class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
Here the code unravels the case of objectToDelete being a list or a single object,
|
||||
ultimately calling container.deleteElement(element) for each element to delete
|
||||
*/
|
||||
@MainActor func delete(objectToDelete:Any, from container:ScriptingObjectContainer) {
|
||||
@MainActor func delete(objectToDelete: Any, from container: ScriptingObjectContainer) {
|
||||
if let objectList = objectToDelete as? [Any] {
|
||||
for nthObject in objectList {
|
||||
self.delete(objectToDelete:nthObject, from:container)
|
||||
self.delete(objectToDelete: nthObject, from: container)
|
||||
}
|
||||
} else if let element = objectToDelete as? ScriptingObject {
|
||||
container.deleteElement(element)
|
||||
@@ -151,14 +151,14 @@ final class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
After resolving, we call delete(objectToDelete:, from container:) with the container and
|
||||
the resolved objects
|
||||
*/
|
||||
@MainActor func delete(specifier:NSScriptObjectSpecifier, from container:Any) {
|
||||
@MainActor func delete(specifier: NSScriptObjectSpecifier, from container: Any) {
|
||||
if let containerList = container as? [Any] {
|
||||
for nthObject in containerList {
|
||||
self.delete(specifier:specifier, from:nthObject)
|
||||
self.delete(specifier: specifier, from: nthObject)
|
||||
}
|
||||
} else if let container = container as? ScriptingObjectContainer {
|
||||
if let resolvedObjects = specifier.objectsByEvaluating(withContainers:container) {
|
||||
self.delete(objectToDelete:resolvedObjects, from:container)
|
||||
if let resolvedObjects = specifier.objectsByEvaluating(withContainers: container) {
|
||||
self.delete(objectToDelete: resolvedObjects, from: container)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,14 +176,14 @@ final class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
MainActor.assumeIsolated {
|
||||
let instance = unsafeSelf.value
|
||||
if let receiverObjects = instance.receiversSpecifier?.objectsByEvaluatingSpecifier {
|
||||
instance.delete(specifier:instance.keySpecifier, from:receiverObjects)
|
||||
instance.delete(specifier: instance.keySpecifier, from: receiverObjects)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
final class NetNewsWireExistsCommand : NSExistsCommand {
|
||||
final class NetNewsWireExistsCommand: NSExistsCommand {
|
||||
|
||||
// cocoa default behavior doesn't work here, because of cases where we define an object's property
|
||||
// to be another object type. e.g., 'permalink of the current article' parses as
|
||||
@@ -195,9 +195,10 @@ final class NetNewsWireExistsCommand : NSExistsCommand {
|
||||
// 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
|
||||
}
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let result = super.performDefaultImplementation() else {
|
||||
return false as NSNumber
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,64 +48,64 @@ import Articles
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
print ("delete event not handled")
|
||||
func deleteElement(_ element: ScriptingObject) {
|
||||
print("delete event not handled")
|
||||
}
|
||||
|
||||
// MARK: - Scriptable properties
|
||||
|
||||
@objc(url)
|
||||
var url: String? {
|
||||
var url: String? {
|
||||
article.preferredLink
|
||||
}
|
||||
|
||||
@objc(permalink)
|
||||
var permalink: String? {
|
||||
var permalink: String? {
|
||||
article.link
|
||||
}
|
||||
|
||||
@objc(externalUrl)
|
||||
var externalUrl: String? {
|
||||
var externalUrl: String? {
|
||||
article.externalLink
|
||||
}
|
||||
|
||||
@objc(title)
|
||||
var title: String {
|
||||
var title: String {
|
||||
article.title ?? ""
|
||||
}
|
||||
|
||||
@objc(contents)
|
||||
var contents: String {
|
||||
var contents: String {
|
||||
article.contentText ?? ""
|
||||
}
|
||||
|
||||
@objc(html)
|
||||
var html: String {
|
||||
var html: String {
|
||||
article.contentHTML ?? ""
|
||||
}
|
||||
|
||||
@objc(summary)
|
||||
var summary: String {
|
||||
var summary: String {
|
||||
article.summary ?? ""
|
||||
}
|
||||
|
||||
@objc(datePublished)
|
||||
var datePublished: Date? {
|
||||
var datePublished: Date? {
|
||||
article.datePublished
|
||||
}
|
||||
|
||||
@objc(dateModified)
|
||||
var dateModified: Date? {
|
||||
var dateModified: Date? {
|
||||
article.dateModified
|
||||
}
|
||||
|
||||
@objc(dateArrived)
|
||||
var dateArrived: Date {
|
||||
var dateArrived: Date {
|
||||
article.status.dateArrived
|
||||
}
|
||||
|
||||
@objc(read)
|
||||
var read: Bool {
|
||||
var read: Bool {
|
||||
get {
|
||||
article.status.boolStatus(forKey: .read)
|
||||
}
|
||||
@@ -115,9 +115,9 @@ import Articles
|
||||
}
|
||||
|
||||
@objc(starred)
|
||||
var starred: Bool {
|
||||
var starred: Bool {
|
||||
get {
|
||||
article.status.boolStatus(forKey:.starred)
|
||||
article.status.boolStatus(forKey: .starred)
|
||||
}
|
||||
set {
|
||||
markArticles([self.article], statusKey: .starred, flag: newValue)
|
||||
@@ -125,19 +125,19 @@ import Articles
|
||||
}
|
||||
|
||||
@objc(deleted)
|
||||
var deleted: Bool {
|
||||
var deleted: Bool {
|
||||
false
|
||||
}
|
||||
|
||||
@objc(imageURL)
|
||||
var imageURL: String {
|
||||
var imageURL: String {
|
||||
article.imageLink ?? ""
|
||||
}
|
||||
|
||||
@objc(authors)
|
||||
var authors: NSArray {
|
||||
let articleAuthors = article.authors ?? []
|
||||
return articleAuthors.map { ScriptableAuthor($0, container:self) } as NSArray
|
||||
return articleAuthors.map { ScriptableAuthor($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(feed)
|
||||
|
||||
@@ -15,7 +15,7 @@ import Articles
|
||||
let author: Author
|
||||
nonisolated(unsafe) let container: ScriptingObjectContainer
|
||||
|
||||
init (_ author: Author, container: ScriptingObjectContainer) {
|
||||
init(_ author: Author, container: ScriptingObjectContainer) {
|
||||
self.author = author
|
||||
self.container = container
|
||||
}
|
||||
@@ -28,41 +28,41 @@ import Articles
|
||||
|
||||
@objc(scriptingSpecifierDescriptor)
|
||||
func scriptingSpecifierDescriptor() -> NSScriptObjectSpecifier {
|
||||
return (self.objectSpecifier ?? NSScriptObjectSpecifier() )
|
||||
objectSpecifier ?? NSScriptObjectSpecifier()
|
||||
}
|
||||
|
||||
// MARK: --- ScriptingObject protocol ---
|
||||
// MARK: - ScriptingObject protocol
|
||||
|
||||
nonisolated var scriptingKey: String {
|
||||
return "authors"
|
||||
"authors"
|
||||
}
|
||||
|
||||
// MARK: --- UniqueIdScriptingObject protocol ---
|
||||
// MARK: - UniqueIdScriptingObject protocol
|
||||
|
||||
@objc(uniqueId)
|
||||
nonisolated var scriptingUniqueID:Any {
|
||||
return author.authorID
|
||||
nonisolated var scriptingUniqueID: Any {
|
||||
author.authorID
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
// MARK: - Scriptable properties
|
||||
|
||||
@objc(url)
|
||||
var url:String {
|
||||
return self.author.url ?? ""
|
||||
var url: String {
|
||||
author.url ?? ""
|
||||
}
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
return self.author.name ?? ""
|
||||
var name: String {
|
||||
author.name ?? ""
|
||||
}
|
||||
|
||||
@objc(avatarURL)
|
||||
var avatarURL:String {
|
||||
return self.author.avatarURL ?? ""
|
||||
var avatarURL: String {
|
||||
author.avatarURL ?? ""
|
||||
}
|
||||
|
||||
@objc(emailAddress)
|
||||
var emailAddress:String {
|
||||
return self.author.emailAddress ?? ""
|
||||
var emailAddress: String {
|
||||
author.emailAddress ?? ""
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import RSCore
|
||||
let folder: Folder
|
||||
nonisolated(unsafe) let container: ScriptingObjectContainer
|
||||
|
||||
init (_ folder:Folder, container: ScriptingObjectContainer) {
|
||||
init (_ folder: Folder, container: ScriptingObjectContainer) {
|
||||
self.folder = folder
|
||||
self.container = container
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import RSCore
|
||||
// but in either case it seems like the accountID would be used as the keydata, so I chose ID
|
||||
|
||||
@objc(uniqueId)
|
||||
nonisolated var scriptingUniqueID:Any {
|
||||
nonisolated var scriptingUniqueID: Any {
|
||||
folder.folderID
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ import RSCore
|
||||
or
|
||||
tell account X to make new folder at end with properties {name:"new folder name"}
|
||||
*/
|
||||
class func handleCreateElement(command: NSCreateCommand) -> Any? {
|
||||
static func handleCreateElement(command: NSCreateCommand) -> Any? {
|
||||
guard command.isCreateCommand(forClass: "fold") else {
|
||||
return nil
|
||||
}
|
||||
@@ -74,7 +74,7 @@ import RSCore
|
||||
// identifies where the new folder should be created
|
||||
let (account, folder) = command.accountAndFolderForNewChild()
|
||||
guard folder == nil else {
|
||||
print("support for folders within folders is NYI");
|
||||
print("support for folders within folders is NYI")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ import RSCore
|
||||
return nil
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable elements ---
|
||||
// MARK: - Scriptable elements
|
||||
|
||||
@objc(feeds)
|
||||
var feeds: NSArray {
|
||||
var feeds: NSArray {
|
||||
let feeds = Array(folder.topLevelFeeds)
|
||||
return feeds.map { ScriptableFeed($0, container: self) } as NSArray
|
||||
}
|
||||
@@ -112,7 +112,7 @@ import RSCore
|
||||
let sortedArticles = allArticles.sorted(by: {
|
||||
$0.logicalDatePublished > $1.logicalDatePublished
|
||||
})
|
||||
return sortedArticles.map { ScriptableArticle($0, container:self) } as NSArray
|
||||
return sortedArticles.map { ScriptableArticle($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(countOfArticles)
|
||||
@@ -142,12 +142,12 @@ import RSCore
|
||||
// MARK: - Scriptable properties
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
var name: String {
|
||||
folder.name ?? ""
|
||||
}
|
||||
|
||||
@objc(opmlRepresentation)
|
||||
var opmlRepresentation:String {
|
||||
folder.OPMLString(indentLevel:0)
|
||||
var opmlRepresentation: String {
|
||||
folder.OPMLString(indentLevel: 0)
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,15 @@ import AppKit
|
||||
import Account
|
||||
import Articles
|
||||
|
||||
extension NSApplication : @preconcurrency ScriptingObjectContainer {
|
||||
extension NSApplication: @preconcurrency ScriptingObjectContainer {
|
||||
// MARK: - ScriptingObjectContainer protocol
|
||||
|
||||
nonisolated var scriptingClassDescription: NSScriptClassDescription {
|
||||
|
||||
nonisolated var scriptingClassDescription: NSScriptClassDescription {
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
print ("delete event not handled")
|
||||
func deleteElement(_ element: ScriptingObject) {
|
||||
print("delete event not handled")
|
||||
}
|
||||
|
||||
nonisolated var scriptingKey: String {
|
||||
@@ -40,10 +40,10 @@ extension NSApplication : @preconcurrency ScriptingObjectContainer {
|
||||
@objc(selectedArticles)
|
||||
func selectedArticles() -> NSArray {
|
||||
let articles = appDelegate.scriptingSelectedArticles
|
||||
let scriptableArticles:[ScriptableArticle] = articles.compactMap { article in
|
||||
let scriptableArticles: [ScriptableArticle] = articles.compactMap { article in
|
||||
if let feed = article.feed,
|
||||
let scriptableFeed = ScriptableFeed.scriptableFeed(for: feed) {
|
||||
return ScriptableArticle(article, container:scriptableFeed)
|
||||
return ScriptableArticle(article, container: scriptableFeed)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
@@ -91,9 +91,11 @@ extension NSApplication : @preconcurrency ScriptingObjectContainer {
|
||||
}
|
||||
|
||||
@objc(valueInAccountsWithUniqueID:)
|
||||
func valueInAccounts(withUniqueID id:String) -> ScriptableAccount? {
|
||||
func valueInAccounts(withUniqueID id: String) -> ScriptableAccount? {
|
||||
let accounts = AccountManager.shared.accounts
|
||||
guard let account = accounts.first(where:{$0.accountID == id}) else { return nil }
|
||||
guard let account = accounts.first(where: { $0.accountID == id }) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableAccount(account)
|
||||
}
|
||||
|
||||
@@ -105,7 +107,7 @@ extension NSApplication : @preconcurrency ScriptingObjectContainer {
|
||||
|
||||
func allFeeds() -> [Feed] {
|
||||
let accounts = AccountManager.shared.activeAccounts
|
||||
let emptyFeeds:[Feed] = []
|
||||
let emptyFeeds: [Feed] = []
|
||||
return accounts.reduce(emptyFeeds) { (result, nthAccount) -> [Feed] in
|
||||
let accountFeeds = Array(nthAccount.topLevelFeeds)
|
||||
return result + accountFeeds
|
||||
@@ -114,7 +116,7 @@ extension NSApplication : @preconcurrency ScriptingObjectContainer {
|
||||
|
||||
@objc(feeds)
|
||||
func feeds() -> NSArray {
|
||||
allFeeds().map { ScriptableFeed($0, container:self) } as NSArray
|
||||
allFeeds().map { ScriptableFeed($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(countOfFeeds)
|
||||
@@ -125,14 +127,18 @@ extension NSApplication : @preconcurrency ScriptingObjectContainer {
|
||||
@objc(objectInFeedsAtIndex:)
|
||||
func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
|
||||
let feeds = allFeeds()
|
||||
guard index >= 0 && index < feeds.count else { return nil }
|
||||
guard index >= 0 && index < feeds.count else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFeed(feeds[index], container: self)
|
||||
}
|
||||
|
||||
@objc(valueInFeedsWithUniqueID:)
|
||||
func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? {
|
||||
func valueInFeeds(withUniqueID id: String) -> ScriptableFeed? {
|
||||
let feeds = allFeeds()
|
||||
guard let feed = feeds.first(where:{$0.feedID == id}) else { return nil }
|
||||
return ScriptableFeed(feed, container:self)
|
||||
guard let feed = feeds.first(where: { $0.feedID == id}) else {
|
||||
return nil
|
||||
}
|
||||
return ScriptableFeed(feed, container: self)
|
||||
}
|
||||
}
|
||||
@@ -10,43 +10,51 @@ import Foundation
|
||||
import Account
|
||||
|
||||
@MainActor extension NSScriptCommand {
|
||||
func property(forKey key:String) -> Any? {
|
||||
if let evaluatedArguments = self.evaluatedArguments {
|
||||
func property(forKey key: String) -> Any? {
|
||||
if let evaluatedArguments = self.evaluatedArguments {
|
||||
if let props = evaluatedArguments["KeyDictionary"] as? [String: Any] {
|
||||
return props[key]
|
||||
return props[key]
|
||||
}
|
||||
}
|
||||
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}
|
||||
guard (newObjectClass.fourCharCode == whatClass.fourCharCode) else {return false}
|
||||
func isCreateCommand(forClass whatClass: String) -> Bool {
|
||||
guard let arguments = self.arguments else {
|
||||
return false
|
||||
}
|
||||
guard let newObjectClass = arguments["ObjectClass"] as? Int else {
|
||||
return false
|
||||
}
|
||||
guard newObjectClass.fourCharCode == whatClass.fourCharCode else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func accountAndFolderForNewChild() -> (Account, Folder?) {
|
||||
let appleEvent = self.appleEvent
|
||||
var account = AccountManager.shared.defaultAccount
|
||||
var folder:Folder?
|
||||
var folder: Folder?
|
||||
if let appleEvent = appleEvent {
|
||||
var descriptorToConsider:NSAppleEventDescriptor?
|
||||
if let insertionLocationDescriptor = appleEvent.paramDescriptor(forKeyword:keyAEInsertHere) {
|
||||
var descriptorToConsider: NSAppleEventDescriptor?
|
||||
if let insertionLocationDescriptor = appleEvent.paramDescriptor(forKeyword: keyAEInsertHere) {
|
||||
print("insertionLocation : \(insertionLocationDescriptor)")
|
||||
// insertion location can be a typeObjectSpecifier, e.g. 'in account "Acct"'
|
||||
// or a typeInsertionLocation, e.g. 'at end of folder "
|
||||
if (insertionLocationDescriptor.descriptorType == "insl".fourCharCode) {
|
||||
if insertionLocationDescriptor.descriptorType == "insl".fourCharCode {
|
||||
descriptorToConsider = insertionLocationDescriptor.forKeyword("kobj".fourCharCode)
|
||||
} else if ( insertionLocationDescriptor.descriptorType == "obj ".fourCharCode) {
|
||||
} else if insertionLocationDescriptor.descriptorType == "obj ".fourCharCode {
|
||||
descriptorToConsider = insertionLocationDescriptor
|
||||
}
|
||||
} else if let subjectDescriptor = appleEvent.attributeDescriptor(forKeyword:"subj".fourCharCode) {
|
||||
} 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)}
|
||||
if let descriptorToConsider {
|
||||
guard let newContainerSpecifier = NSScriptObjectSpecifier(descriptor: descriptorToConsider) else {
|
||||
return (account, folder)
|
||||
}
|
||||
let newContainer = newContainerSpecifier.objectsByEvaluatingSpecifier
|
||||
if let scriptableAccount = newContainer as? ScriptableAccount {
|
||||
account = scriptableAccount.account
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
import Foundation
|
||||
|
||||
protocol ScriptingObject {
|
||||
var objectSpecifier: NSScriptObjectSpecifier? { get }
|
||||
var objectSpecifier: NSScriptObjectSpecifier? { get }
|
||||
var scriptingKey: String { get }
|
||||
}
|
||||
|
||||
protocol NamedScriptingObject: ScriptingObject {
|
||||
var name:String { get }
|
||||
var name: String { get }
|
||||
}
|
||||
|
||||
protocol UniqueIDScriptingObject: ScriptingObject {
|
||||
|
||||
@@ -10,30 +10,29 @@ import AppKit
|
||||
import Account
|
||||
|
||||
protocol ScriptingObjectContainer: ScriptingObject {
|
||||
var scriptingClassDescription:NSScriptClassDescription { get }
|
||||
func deleteElement(_ element:ScriptingObject)
|
||||
var scriptingClassDescription: NSScriptClassDescription { get }
|
||||
func deleteElement(_ element: ScriptingObject)
|
||||
}
|
||||
|
||||
extension ScriptingObjectContainer {
|
||||
|
||||
nonisolated func makeFormNameScriptObjectSpecifier(forObject object:NamedScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
nonisolated func makeFormNameScriptObjectSpecifier(forObject object: NamedScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
let containerClassDescription = self.scriptingClassDescription
|
||||
let containerScriptObjectSpecifier = self.objectSpecifier
|
||||
let scriptingKey = object.scriptingKey
|
||||
let name = object.name
|
||||
let specifier = NSNameSpecifier(containerClassDescription:containerClassDescription,
|
||||
containerSpecifier:containerScriptObjectSpecifier, key:scriptingKey, name:name)
|
||||
let specifier = NSNameSpecifier(containerClassDescription: containerClassDescription,
|
||||
containerSpecifier: containerScriptObjectSpecifier, key: scriptingKey, name: name)
|
||||
return specifier
|
||||
}
|
||||
|
||||
nonisolated func makeFormUniqueIDScriptObjectSpecifier(forObject object:UniqueIDScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
nonisolated func makeFormUniqueIDScriptObjectSpecifier(forObject object: UniqueIDScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
let containerClassDescription = self.scriptingClassDescription
|
||||
let containerScriptObjectSpecifier = self.objectSpecifier
|
||||
let scriptingKey = object.scriptingKey
|
||||
let uniqueId = object.scriptingUniqueID
|
||||
let specifier = NSUniqueIDSpecifier(containerClassDescription:containerClassDescription,
|
||||
containerSpecifier:containerScriptObjectSpecifier, key:scriptingKey, uniqueID: uniqueId)
|
||||
let specifier = NSUniqueIDSpecifier(containerClassDescription: containerClassDescription,
|
||||
containerSpecifier: containerScriptObjectSpecifier, key: scriptingKey, uniqueID: uniqueId)
|
||||
return specifier
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ final class ShareViewController: NSViewController {
|
||||
extensionContainers = ExtensionContainersFile.read()
|
||||
buildFolderPopupMenu()
|
||||
|
||||
var provider: NSItemProvider? = nil
|
||||
var provider: NSItemProvider?
|
||||
|
||||
// Try to get any HTML that is maybe passed in
|
||||
for item in self.extensionContext!.inputItems as! [NSExtensionItem] {
|
||||
@@ -50,7 +50,7 @@ final class ShareViewController: NSViewController {
|
||||
}
|
||||
}
|
||||
|
||||
if provider != nil {
|
||||
if provider != nil {
|
||||
provider!.loadItem(forTypeIdentifier: UTType.propertyList.identifier, options: nil, completionHandler: { [weak self] (pList, error) in
|
||||
if error != nil {
|
||||
return
|
||||
@@ -77,7 +77,7 @@ final class ShareViewController: NSViewController {
|
||||
}
|
||||
}
|
||||
|
||||
if provider != nil {
|
||||
if provider != nil {
|
||||
provider!.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil, completionHandler: { [weak self] (urlCoded, error) in
|
||||
if error != nil {
|
||||
return
|
||||
@@ -126,7 +126,7 @@ private extension ShareViewController {
|
||||
}
|
||||
|
||||
let defaultContainer = ShareDefaultContainer.defaultContainer(containers: extensionContainers)
|
||||
var defaultMenuItem: NSMenuItem? = nil
|
||||
var defaultMenuItem: NSMenuItem?
|
||||
|
||||
for account in extensionContainers.accounts {
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ let package = Package(
|
||||
.library(
|
||||
name: "Account",
|
||||
type: .dynamic,
|
||||
targets: ["Account"]),
|
||||
targets: ["Account"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../Articles"),
|
||||
@@ -41,16 +41,16 @@ let package = Package(
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
name: "AccountTests",
|
||||
dependencies: ["Account"],
|
||||
resources: [
|
||||
.copy("JSON"),
|
||||
.copy("JSON")
|
||||
],
|
||||
swiftSettings: [.swiftLanguageMode(.v6)]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -378,10 +378,10 @@ public enum FetchType {
|
||||
}
|
||||
|
||||
public static func requestOAuthAccessToken(with response: OAuthAuthorizationResponse,
|
||||
client: OAuthAuthorizationClient,
|
||||
accountType: AccountType,
|
||||
transport: Transport = URLSession.webserviceTransport(),
|
||||
completion: @escaping @MainActor (Result<OAuthAuthorizationGrant, Error>) -> Void) {
|
||||
client: OAuthAuthorizationClient,
|
||||
accountType: AccountType,
|
||||
transport: Transport = URLSession.webserviceTransport(),
|
||||
completion: @escaping @MainActor (Result<OAuthAuthorizationGrant, Error>) -> Void) {
|
||||
let grantingType: OAuthAuthorizationGranting.Type
|
||||
|
||||
switch accountType {
|
||||
|
||||
@@ -23,7 +23,7 @@ import Secrets
|
||||
|
||||
var refreshProgress: DownloadProgress { get }
|
||||
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable: Any]) async
|
||||
|
||||
func refreshAll(for account: Account) async throws
|
||||
func syncArticleStatus(for account: Account) async throws
|
||||
|
||||
@@ -77,7 +77,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
// Parse items on background thread
|
||||
let feedIDsAndItems = await Task.detached(priority: .userInitiated) {
|
||||
let parsedItems = records.compactMap { makeParsedItem($0) }
|
||||
return Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
||||
return Dictionary(grouping: parsedItems, by: { item in item.feedURL }).mapValues { Set($0) }
|
||||
}.value
|
||||
|
||||
nonisolated(unsafe) var updateError: Error?
|
||||
|
||||
@@ -322,7 +322,7 @@ extension Feed: OPMLRepresentable {
|
||||
return Set<String>(map { $0.feedID })
|
||||
}
|
||||
|
||||
func sorted() -> Array<Feed> {
|
||||
func sorted() -> [Feed] {
|
||||
return sorted(by: { (feed1, feed2) -> Bool in
|
||||
if feed1.nameForDisplay.localizedStandardCompare(feed2.nameForDisplay) == .orderedSame {
|
||||
return feed1.url < feed2.url
|
||||
|
||||
@@ -254,7 +254,7 @@ enum CreateSubscriptionResult {
|
||||
|
||||
let payload = try JSONEncoder().encode(FeedbinCreateTagging(feedID: feedID, name: name))
|
||||
|
||||
let (response, _) = try await transport.send(request: request, method: HTTPMethod.post, payload:payload)
|
||||
let (response, _) = try await transport.send(request: request, method: HTTPMethod.post, payload: payload)
|
||||
|
||||
if let taggingLocation = response.valueForHTTPHeaderField(HTTPResponseHeader.location),
|
||||
let lowerBound = taggingLocation.range(of: "v2/taggings/")?.upperBound,
|
||||
@@ -463,7 +463,7 @@ enum CreateSubscriptionResult {
|
||||
|
||||
extension FeedbinAPICaller {
|
||||
|
||||
func storeConditionalGet(key: String, headers: [AnyHashable : Any]) {
|
||||
func storeConditionalGet(key: String, headers: [AnyHashable: Any]) {
|
||||
if var conditionalGet = accountMetadata?.conditionalGetInfo {
|
||||
conditionalGet[key] = HTTPConditionalGetInfo(headers: headers)
|
||||
accountMetadata?.conditionalGetInfo = conditionalGet
|
||||
|
||||
@@ -644,11 +644,11 @@ private extension FeedbinAccountDelegate {
|
||||
for articleIDGroup in articleIDGroups {
|
||||
do {
|
||||
try await apiCall(articleIDGroup)
|
||||
try? await self.syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup.map { String($0) } ))
|
||||
try? await self.syncDatabase.deleteSelectedForProcessing(Set(articleIDGroup.map { String($0) }))
|
||||
} catch {
|
||||
savedError = error
|
||||
Self.logger.error("Feedbin: Article status sync call failed: \(error.localizedDescription)")
|
||||
try? await self.syncDatabase.resetSelectedForProcessing(Set(articleIDGroup.map { String($0) } ))
|
||||
try? await self.syncDatabase.resetSelectedForProcessing(Set(articleIDGroup.map { String($0) }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,7 +799,7 @@ private extension FeedbinAccountDelegate {
|
||||
|
||||
func processEntries(account: Account, entries: [FeedbinEntry]?) async throws {
|
||||
let parsedItems = mapEntriesToParsedItems(entries: entries)
|
||||
let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
||||
let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL }).mapValues { Set($0) }
|
||||
try await account.updateAsync(feedIDsAndItems: feedIDsAndItems, defaultRead: true)
|
||||
}
|
||||
|
||||
@@ -827,7 +827,7 @@ private extension FeedbinAccountDelegate {
|
||||
return
|
||||
}
|
||||
|
||||
let feedbinUnreadArticleIDs = Set(articleIDs.map { String($0) } )
|
||||
let feedbinUnreadArticleIDs = Set(articleIDs.map { String($0) })
|
||||
let updatableFeedbinUnreadArticleIDs = feedbinUnreadArticleIDs.subtracting(pendingArticleIDs)
|
||||
|
||||
let currentUnreadArticleIDs = try await account.fetchUnreadArticleIDsAsync()
|
||||
@@ -854,7 +854,7 @@ private extension FeedbinAccountDelegate {
|
||||
return
|
||||
}
|
||||
|
||||
let feedbinStarredArticleIDs = Set(articleIDs.map { String($0) } )
|
||||
let feedbinStarredArticleIDs = Set(articleIDs.map { String($0) })
|
||||
let updatableFeedbinStarredArticleIDs = feedbinStarredArticleIDs.subtracting(pendingArticleIDs)
|
||||
|
||||
let currentStarredArticleIDs = try await account.fetchStarredArticleIDsAsync()
|
||||
|
||||
@@ -104,7 +104,7 @@ import Secrets
|
||||
|
||||
// MARK: Account API
|
||||
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async {
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable: Any]) async {
|
||||
}
|
||||
|
||||
func refreshAll(for account: Account) async throws {
|
||||
|
||||
@@ -213,7 +213,7 @@ extension Folder: OPMLRepresentable {
|
||||
|
||||
@MainActor extension Set where Element == Folder {
|
||||
|
||||
func sorted() -> Array<Folder> {
|
||||
func sorted() -> [Folder] {
|
||||
return sorted(by: { (folder1, folder2) -> Bool in
|
||||
return folder1.nameForDisplay.localizedStandardCompare(folder2.nameForDisplay) == .orderedAscending
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ import Secrets
|
||||
refresher.downloadProgress
|
||||
}()
|
||||
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any]) async {
|
||||
func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable: Any]) async {
|
||||
}
|
||||
|
||||
@MainActor func refreshAll(for account: Account) async throws {
|
||||
|
||||
@@ -19,7 +19,6 @@ import os
|
||||
}
|
||||
|
||||
@MainActor final class LocalAccountRefresher {
|
||||
|
||||
var delegate: LocalAccountRefresherDelegate?
|
||||
var downloadProgress: DownloadProgress {
|
||||
downloadSession.downloadProgress
|
||||
@@ -292,4 +291,3 @@ private extension Data {
|
||||
return self.isImage
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -293,7 +293,7 @@ import os.log
|
||||
return
|
||||
}
|
||||
|
||||
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash } )
|
||||
let newsBlurUnreadStoryHashes = Set(hashes.map { $0.hash })
|
||||
let updatableNewsBlurUnreadStoryHashes = newsBlurUnreadStoryHashes.subtracting(pendingStoryHashes)
|
||||
|
||||
let currentUnreadArticleIDs = try await account.fetchUnreadArticleIDsAsync()
|
||||
@@ -320,7 +320,7 @@ import os.log
|
||||
return
|
||||
}
|
||||
|
||||
let newsBlurStarredStoryHashes = Set(hashes.map { $0.hash } )
|
||||
let newsBlurStarredStoryHashes = Set(hashes.map { $0.hash })
|
||||
let updatableNewsBlurUnreadStoryHashes = newsBlurStarredStoryHashes.subtracting(pendingStoryHashes)
|
||||
|
||||
let currentStarredArticleIDs = try await account.fetchStarredArticleIDsAsync()
|
||||
|
||||
@@ -774,7 +774,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
func processEntries(account: Account, entries: [ReaderAPIEntry]?) async {
|
||||
|
||||
let parsedItems = mapEntriesToParsedItems(account: account, entries: entries)
|
||||
let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
||||
let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL }).mapValues { Set($0) }
|
||||
|
||||
try? await account.updateAsync(feedIDsAndItems: feedIDsAndItems, defaultRead: true)
|
||||
}
|
||||
|
||||
@@ -201,9 +201,9 @@ enum CreateReaderAPISubscriptionResult {
|
||||
|
||||
let oldTagName = "user/-/label/\(encodedOldName)"
|
||||
let newTagName = "user/-/label/\(encodedNewName)"
|
||||
let postData = "T=\(token)&s=\(oldTagName)&dest=\(newTagName)".data(using: String.Encoding.utf8)
|
||||
let postData = Data("T=\(token)&s=\(oldTagName)&dest=\(newTagName)".utf8)
|
||||
|
||||
_ = try await transport.send(request: request, method: HTTPMethod.post, payload: postData!)
|
||||
_ = try await transport.send(request: request, method: HTTPMethod.post, payload: postData)
|
||||
}
|
||||
|
||||
@MainActor public func deleteTag(folderExternalID: String) async throws {
|
||||
@@ -219,9 +219,9 @@ enum CreateReaderAPISubscriptionResult {
|
||||
request.setValue(MimeType.formURLEncoded, forHTTPHeaderField: "Content-Type")
|
||||
request.httpMethod = "POST"
|
||||
|
||||
let postData = "T=\(token)&s=\(folderExternalID)".data(using: String.Encoding.utf8)
|
||||
let postData = Data("T=\(token)&s=\(folderExternalID)".utf8)
|
||||
|
||||
_ = try await self.transport.send(request: request, method: HTTPMethod.post, payload: postData!)
|
||||
_ = try await self.transport.send(request: request, method: HTTPMethod.post, payload: postData)
|
||||
}
|
||||
|
||||
@MainActor public func retrieveSubscriptions() async throws -> [ReaderAPISubscription]? {
|
||||
@@ -265,9 +265,9 @@ enum CreateReaderAPISubscriptionResult {
|
||||
throw AccountError.invalidParameter
|
||||
}
|
||||
|
||||
let postData = "T=\(token)&quickadd=\(encodedFeedURL)".data(using: String.Encoding.utf8)
|
||||
let postData = Data("T=\(token)&quickadd=\(encodedFeedURL)".utf8)
|
||||
|
||||
let (_, subResult) = try await self.transport.send(request: request, method: HTTPMethod.post, data: postData!, resultType: ReaderAPIQuickAddResult.self)
|
||||
let (_, subResult) = try await self.transport.send(request: request, method: HTTPMethod.post, data: postData, resultType: ReaderAPIQuickAddResult.self)
|
||||
|
||||
guard let subResult else {
|
||||
return .notFound
|
||||
@@ -306,9 +306,9 @@ enum CreateReaderAPISubscriptionResult {
|
||||
request.setValue(MimeType.formURLEncoded, forHTTPHeaderField: "Content-Type")
|
||||
request.httpMethod = "POST"
|
||||
|
||||
let postData = "T=\(token)&s=\(subscriptionID)&ac=unsubscribe".data(using: String.Encoding.utf8)
|
||||
let postData = Data("T=\(token)&s=\(subscriptionID)&ac=unsubscribe".utf8)
|
||||
|
||||
_ = try await self.transport.send(request: request, method: HTTPMethod.post, payload: postData!)
|
||||
_ = try await self.transport.send(request: request, method: HTTPMethod.post, payload: postData)
|
||||
}
|
||||
|
||||
public func createTagging(subscriptionID: String, tagName: String) async throws {
|
||||
@@ -354,7 +354,7 @@ enum CreateReaderAPISubscriptionResult {
|
||||
}
|
||||
let postData = postString.data(using: String.Encoding.utf8)
|
||||
|
||||
_ = try await transport.send(request: request, method: HTTPMethod.post, payload: postData!)
|
||||
_ = try await transport.send(request: request, method: HTTPMethod.post, payload: postData)
|
||||
}
|
||||
|
||||
@MainActor public func retrieveEntries(articleIDs: [String]) async throws -> [ReaderAPIEntry]? {
|
||||
@@ -384,9 +384,9 @@ enum CreateReaderAPISubscriptionResult {
|
||||
}
|
||||
}).joined(separator: "&")
|
||||
|
||||
let postData = "T=\(token)&output=json&\(idsToFetch)".data(using: String.Encoding.utf8)
|
||||
let postData = Data("T=\(token)&output=json&\(idsToFetch)".utf8)
|
||||
|
||||
let (_, entryWrapper) = try await transport.send(request: request, method: HTTPMethod.post, data: postData!, resultType: ReaderAPIEntryWrapper.self)
|
||||
let (_, entryWrapper) = try await transport.send(request: request, method: HTTPMethod.post, data: postData, resultType: ReaderAPIEntryWrapper.self)
|
||||
|
||||
guard let entryWrapper else {
|
||||
throw AccountError.invalidResponse
|
||||
@@ -557,8 +557,8 @@ private extension ReaderAPICaller {
|
||||
|
||||
let actionIndicator = add ? "a" : "r"
|
||||
|
||||
let postData = "T=\(token)&\(idsToFetch)&\(actionIndicator)=\(state.rawValue)".data(using: String.Encoding.utf8)
|
||||
let postData = Data("T=\(token)&\(idsToFetch)&\(actionIndicator)=\(state.rawValue)".utf8)
|
||||
|
||||
_ = try await transport.send(request: request, method: HTTPMethod.post, payload: postData!)
|
||||
_ = try await transport.send(request: request, method: HTTPMethod.post, payload: postData)
|
||||
}
|
||||
}
|
||||
@@ -14,18 +14,17 @@ import Secrets
|
||||
public extension URLRequest {
|
||||
|
||||
init(url: URL, credentials: Credentials?, conditionalGet: HTTPConditionalGetInfo? = nil) {
|
||||
|
||||
self.init(url: url)
|
||||
|
||||
guard let credentials = credentials else {
|
||||
guard let credentials else {
|
||||
return
|
||||
}
|
||||
|
||||
switch credentials.type {
|
||||
case .basic:
|
||||
let data = "\(credentials.username):\(credentials.secret)".data(using: .utf8)
|
||||
let base64 = data?.base64EncodedString()
|
||||
let auth = "Basic \(base64 ?? "")"
|
||||
let data = Data("\(credentials.username):\(credentials.secret)".utf8)
|
||||
let base64 = data.base64EncodedString()
|
||||
let auth = "Basic \(base64)"
|
||||
setValue(auth, forHTTPHeaderField: HTTPRequestHeader.authorization)
|
||||
case .newsBlurBasic:
|
||||
setValue("application/x-www-form-urlencoded", forHTTPHeaderField: HTTPRequestHeader.contentType)
|
||||
@@ -33,15 +32,15 @@ public extension URLRequest {
|
||||
var postData = URLComponents()
|
||||
postData.queryItems = [
|
||||
URLQueryItem(name: "username", value: credentials.username),
|
||||
URLQueryItem(name: "password", value: credentials.secret),
|
||||
URLQueryItem(name: "password", value: credentials.secret)
|
||||
]
|
||||
httpBody = postData.enhancedPercentEncodedQuery?.data(using: .utf8)
|
||||
case .newsBlurSessionID:
|
||||
setValue("\(NewsBlurAPICaller.sessionIDCookieKey)=\(credentials.secret)", forHTTPHeaderField: "Cookie")
|
||||
httpShouldHandleCookies = true
|
||||
case .readerBasic:
|
||||
setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||
httpMethod = "POST"
|
||||
setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||
httpMethod = "POST"
|
||||
var postData = URLComponents()
|
||||
postData.queryItems = [
|
||||
URLQueryItem(name: "Email", value: credentials.username),
|
||||
@@ -49,22 +48,20 @@ public extension URLRequest {
|
||||
]
|
||||
httpBody = postData.enhancedPercentEncodedQuery?.data(using: .utf8)
|
||||
case .readerAPIKey:
|
||||
let auth = "GoogleLogin auth=\(credentials.secret)"
|
||||
setValue(auth, forHTTPHeaderField: HTTPRequestHeader.authorization)
|
||||
let auth = "GoogleLogin auth=\(credentials.secret)"
|
||||
setValue(auth, forHTTPHeaderField: HTTPRequestHeader.authorization)
|
||||
case .oauthAccessToken:
|
||||
let auth = "OAuth \(credentials.secret)"
|
||||
setValue(auth, forHTTPHeaderField: "Authorization")
|
||||
let auth = "OAuth \(credentials.secret)"
|
||||
setValue(auth, forHTTPHeaderField: "Authorization")
|
||||
case .oauthAccessTokenSecret:
|
||||
assertionFailure("Token secrets are used by OAuth1. Did you mean to use `OAuthSwift` instead of a URLRequest?")
|
||||
break
|
||||
case .oauthRefreshToken:
|
||||
// While both access and refresh tokens are credentials, it seems the `Credentials` cases
|
||||
// enumerates how the identity of the user can be proved rather than
|
||||
// credentials-in-general, such as in this refresh token case,
|
||||
// the authority to prove an identity.
|
||||
assertionFailure("Refresh tokens are used to replace expired access tokens. Did you mean to use `accessToken` instead?")
|
||||
break
|
||||
}
|
||||
assertionFailure("Token secrets are used by OAuth1. Did you mean to use `OAuthSwift` instead of a URLRequest?")
|
||||
case .oauthRefreshToken:
|
||||
// While both access and refresh tokens are credentials, it seems the `Credentials` cases
|
||||
// enumerates how the identity of the user can be proved rather than
|
||||
// credentials-in-general, such as in this refresh token case,
|
||||
// the authority to prove an identity.
|
||||
assertionFailure("Refresh tokens are used to replace expired access tokens. Did you mean to use `accessToken` instead?")
|
||||
}
|
||||
|
||||
guard let conditionalGet = conditionalGet else {
|
||||
return
|
||||
@@ -78,7 +75,5 @@ public extension URLRequest {
|
||||
if let etag = conditionalGet.etag {
|
||||
setValue(etag, forHTTPHeaderField: HTTPRequestHeader.ifNoneMatch)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,10 @@ let package = Package(
|
||||
.library(
|
||||
name: "Articles",
|
||||
type: .dynamic,
|
||||
targets: ["Articles"]),
|
||||
targets: ["Articles"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../RSCore"),
|
||||
.package(path: "../RSCore")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
@@ -21,7 +21,7 @@ let package = Package(
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
]),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
])
|
||||
]
|
||||
)
|
||||
@@ -47,8 +47,7 @@ public final class Article: Hashable, Sendable {
|
||||
|
||||
if let articleID = articleID {
|
||||
self.articleID = articleID
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
self.articleID = Article.calculatedArticleID(feedID: feedID, uniqueID: uniqueID)
|
||||
}
|
||||
}
|
||||
@@ -111,16 +110,24 @@ public extension Article {
|
||||
result.append(text)
|
||||
}
|
||||
|
||||
if let _ = scanner.scanString("<") {
|
||||
if scanner.scanString("<") != nil {
|
||||
// All the allowed tags currently don't allow attributes
|
||||
if let tag = scanner.scanUpToString(">") {
|
||||
if Self.allowedTags.contains(tag.replacingOccurrences(of: "/", with: "")) {
|
||||
forHTML ? result.append("<\(tag)>") : result.append("")
|
||||
if forHTML {
|
||||
result.append("<\(tag)>")
|
||||
} else {
|
||||
result.append("")
|
||||
}
|
||||
} else {
|
||||
forHTML ? result.append("<\(tag)>") : result.append("<\(tag)>")
|
||||
if forHTML {
|
||||
result.append("<\(tag)>")
|
||||
} else {
|
||||
result.append("<\(tag)>")
|
||||
}
|
||||
}
|
||||
|
||||
let _ = scanner.scanString(">")
|
||||
_ = scanner.scanString(">")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public extension Set where Element == ArticleStatus {
|
||||
|
||||
public extension Array where Element == ArticleStatus {
|
||||
|
||||
func articleIDs() -> [String] {
|
||||
func articleIDs() -> [String] {
|
||||
return map { $0.articleID }
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,7 @@ public struct Author: Codable, Hashable, Sendable {
|
||||
|
||||
if let authorID = authorID {
|
||||
self.authorID = authorID
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var s = name ?? ""
|
||||
s += url ?? ""
|
||||
s += avatarURL ?? ""
|
||||
@@ -46,8 +45,7 @@ public struct Author: Codable, Hashable, Sendable {
|
||||
do {
|
||||
let authors = try decoder.decode([Author].self, from: data)
|
||||
return Set(authors)
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
assertionFailure("JSON representation of Author array could not be decoded: \(jsonString) error: \(error)")
|
||||
}
|
||||
return nil
|
||||
@@ -75,8 +73,7 @@ extension Set where Element == Author {
|
||||
do {
|
||||
let jsonData = try encoder.encode(Array(self))
|
||||
return String(data: jsonData, encoding: .utf8)
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
assertionFailure("JSON representation of Author array could not be encoded: \(self) error: \(error)")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -8,13 +8,13 @@ let package = Package(
|
||||
.library(
|
||||
name: "ArticlesDatabase",
|
||||
type: .dynamic,
|
||||
targets: ["ArticlesDatabase"]),
|
||||
targets: ["ArticlesDatabase"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../Articles"),
|
||||
.package(path: "../RSCore"),
|
||||
.package(path: "../RSParser"),
|
||||
.package(path: "../RSDatabase"),
|
||||
.package(path: "../RSDatabase")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
@@ -23,12 +23,12 @@ let package = Package(
|
||||
"RSCore",
|
||||
"RSDatabase",
|
||||
"RSParser",
|
||||
"Articles",
|
||||
"Articles"
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -36,7 +36,7 @@ public struct ArticleChanges: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor public final class ArticlesDatabase: Sendable {
|
||||
@MainActor public final class ArticlesDatabase {
|
||||
public enum RetentionStyle: Sendable {
|
||||
case feedBased // Local and iCloud: article retention is defined by contents of feed
|
||||
case syncSystem // Feedbin, Feedly, etc.: article retention is defined by external system
|
||||
|
||||
@@ -48,7 +48,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
// MARK: - Fetching Articles for Feed
|
||||
|
||||
func fetchArticles(_ feedID: String) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchArticlesForFeedID(feedID, $0) }
|
||||
return try fetchArticles { self.fetchArticlesForFeedID(feedID, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(_ feedID: String, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@@ -56,7 +56,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
}
|
||||
|
||||
func fetchArticles(_ feedIDs: Set<String>) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchArticles(feedIDs, $0) }
|
||||
return try fetchArticles { self.fetchArticles(feedIDs, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(_ feedIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@@ -66,7 +66,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
// MARK: - Fetching Articles by articleID
|
||||
|
||||
func fetchArticles(articleIDs: Set<String>) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchArticles(articleIDs: articleIDs, $0) }
|
||||
return try fetchArticles { self.fetchArticles(articleIDs: articleIDs, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@@ -76,7 +76,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
// MARK: - Fetching Unread Articles
|
||||
|
||||
func fetchUnreadArticles(_ feedIDs: Set<String>, _ limit: Int?) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchUnreadArticles(feedIDs, limit, $0) }
|
||||
return try fetchArticles { self.fetchUnreadArticles(feedIDs, limit, $0) }
|
||||
}
|
||||
|
||||
func fetchUnreadArticlesAsync(_ feedIDs: Set<String>, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@@ -86,7 +86,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
// MARK: - Fetching Today Articles
|
||||
|
||||
func fetchArticlesSince(_ feedIDs: Set<String>, _ cutoffDate: Date, _ limit: Int?) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }
|
||||
return try fetchArticles { self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }
|
||||
}
|
||||
|
||||
func fetchArticlesSinceAsync(_ feedIDs: Set<String>, _ cutoffDate: Date, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@@ -96,7 +96,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
// MARK: - Fetching Starred Articles
|
||||
|
||||
func fetchStarredArticles(_ feedIDs: Set<String>, _ limit: Int?) throws -> Set<Article> {
|
||||
return try fetchArticles{ self.fetchStarredArticles(feedIDs, limit, $0) }
|
||||
return try fetchArticles { self.fetchStarredArticles(feedIDs, limit, $0) }
|
||||
}
|
||||
|
||||
func fetchStarredArticlesAsync(_ feedIDs: Set<String>, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) {
|
||||
@@ -104,7 +104,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
}
|
||||
|
||||
func fetchStarredArticlesCount(_ feedIDs: Set<String>) throws -> Int {
|
||||
return try fetchArticlesCount{ self.fetchStarredArticlesCount(feedIDs, $0) }
|
||||
return try fetchArticlesCount { self.fetchStarredArticlesCount(feedIDs, $0) }
|
||||
}
|
||||
|
||||
// MARK: - Fetching Search Articles
|
||||
@@ -130,13 +130,13 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
|
||||
func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set<String>) throws -> Set<Article> {
|
||||
var articles = try fetchArticlesMatching(searchString)
|
||||
articles = articles.filter{ feedIDs.contains($0.feedID) }
|
||||
articles = articles.filter { feedIDs.contains($0.feedID) }
|
||||
return articles
|
||||
}
|
||||
|
||||
func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set<String>) throws -> Set<Article> {
|
||||
var articles = try fetchArticlesMatching(searchString)
|
||||
articles = articles.filter{ articleIDs.contains($0.articleID) }
|
||||
articles = articles.filter { articleIDs.contains($0.articleID) }
|
||||
return articles
|
||||
}
|
||||
|
||||
@@ -216,20 +216,20 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
func makeDatabaseCalls(_ database: FMDatabase) {
|
||||
let articleIDs = parsedItems.articleIDs()
|
||||
|
||||
let (statusesDictionary, _) = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, false, database) //1
|
||||
let (statusesDictionary, _) = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, false, database) // 1
|
||||
assert(statusesDictionary.count == articleIDs.count)
|
||||
|
||||
let incomingArticles = Article.articlesWithParsedItems(parsedItems, feedID, self.accountID, statusesDictionary) //2
|
||||
let incomingArticles = Article.articlesWithParsedItems(parsedItems, feedID, self.accountID, statusesDictionary) // 2
|
||||
if incomingArticles.isEmpty {
|
||||
self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion)
|
||||
return
|
||||
}
|
||||
|
||||
let fetchedArticles = self.fetchArticlesForFeedID(feedID, database) //4
|
||||
let fetchedArticles = self.fetchArticlesForFeedID(feedID, database) // 4
|
||||
let fetchedArticlesDictionary = fetchedArticles.dictionary()
|
||||
|
||||
let newArticles = self.findAndSaveNewArticles(incomingArticles, fetchedArticlesDictionary, database) //5
|
||||
let updatedArticles = self.findAndSaveUpdatedArticles(incomingArticles, fetchedArticlesDictionary, database) //6
|
||||
let newArticles = self.findAndSaveNewArticles(incomingArticles, fetchedArticlesDictionary, database) // 5
|
||||
let updatedArticles = self.findAndSaveUpdatedArticles(incomingArticles, fetchedArticlesDictionary, database) // 6
|
||||
|
||||
// Articles to delete are 1) not starred and 2) older than 30 days and 3) no longer in feed.
|
||||
let articlesToDelete: Set<Article>
|
||||
@@ -242,7 +242,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
articlesToDelete = Set<Article>()
|
||||
}
|
||||
|
||||
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, articlesToDelete, completion) //7
|
||||
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, articlesToDelete, completion) // 7
|
||||
|
||||
self.addArticlesToCache(newArticles)
|
||||
self.addArticlesToCache(updatedArticles)
|
||||
@@ -298,29 +298,29 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
articleIDs.formUnion(parsedItems.articleIDs())
|
||||
}
|
||||
|
||||
let (statusesDictionary, _) = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, read, database) //1
|
||||
let (statusesDictionary, _) = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, read, database) // 1
|
||||
assert(statusesDictionary.count == articleIDs.count)
|
||||
|
||||
let allIncomingArticles = Article.articlesWithFeedIDsAndItems(feedIDsAndItems, self.accountID, statusesDictionary) //2
|
||||
let allIncomingArticles = Article.articlesWithFeedIDsAndItems(feedIDsAndItems, self.accountID, statusesDictionary) // 2
|
||||
if allIncomingArticles.isEmpty {
|
||||
self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion)
|
||||
return
|
||||
}
|
||||
|
||||
let incomingArticles = self.filterIncomingArticles(allIncomingArticles) //3
|
||||
let incomingArticles = self.filterIncomingArticles(allIncomingArticles) // 3
|
||||
if incomingArticles.isEmpty {
|
||||
self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion)
|
||||
return
|
||||
}
|
||||
|
||||
let incomingArticleIDs = incomingArticles.articleIDs()
|
||||
let fetchedArticles = self.fetchArticles(articleIDs: incomingArticleIDs, database) //4
|
||||
let fetchedArticles = self.fetchArticles(articleIDs: incomingArticleIDs, database) // 4
|
||||
let fetchedArticlesDictionary = fetchedArticles.dictionary()
|
||||
|
||||
let newArticles = self.findAndSaveNewArticles(incomingArticles, fetchedArticlesDictionary, database) //5
|
||||
let updatedArticles = self.findAndSaveUpdatedArticles(incomingArticles, fetchedArticlesDictionary, database) //6
|
||||
let newArticles = self.findAndSaveNewArticles(incomingArticles, fetchedArticlesDictionary, database) //
|
||||
let updatedArticles = self.findAndSaveUpdatedArticles(incomingArticles, fetchedArticlesDictionary, database) // 6
|
||||
|
||||
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, nil, completion) //7
|
||||
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, nil, completion) // 7
|
||||
|
||||
self.addArticlesToCache(newArticles)
|
||||
self.addArticlesToCache(updatedArticles)
|
||||
@@ -543,7 +543,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
queue.runInTransaction { databaseResult in
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
@@ -569,7 +569,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: nil) else {
|
||||
return
|
||||
}
|
||||
let articleIDs = resultSet.mapToSet{ $0.string(forColumn: DatabaseKey.articleID) }
|
||||
let articleIDs = resultSet.mapToSet { $0.string(forColumn: DatabaseKey.articleID) }
|
||||
if articleIDs.isEmpty {
|
||||
return
|
||||
}
|
||||
@@ -677,7 +677,7 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
|
||||
return
|
||||
}
|
||||
let articleIDs = resultSet.mapToSet{ $0.string(forColumn: DatabaseKey.articleID) }
|
||||
let articleIDs = resultSet.mapToSet { $0.string(forColumn: DatabaseKey.articleID) }
|
||||
if articleIDs.isEmpty {
|
||||
return
|
||||
}
|
||||
@@ -734,8 +734,8 @@ nonisolated private extension ArticlesTable {
|
||||
|
||||
private func fetchArticlesCount(_ fetchMethod: @escaping ArticlesCountFetchMethod) throws -> Int {
|
||||
nonisolated(unsafe) var articlesCount = 0
|
||||
nonisolated(unsafe) var error: DatabaseError? = nil
|
||||
|
||||
nonisolated(unsafe) var error: DatabaseError?
|
||||
|
||||
queue.runInDatabaseSync { databaseResult in
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
@@ -859,8 +859,8 @@ nonisolated private extension ArticlesTable {
|
||||
|
||||
func sqliteSearchString(with searchString: String) -> String {
|
||||
var s = ""
|
||||
searchString.enumerateSubstrings(in: searchString.startIndex..<searchString.endIndex, options: .byWords) { (word, range, enclosingRange, stop) in
|
||||
guard let word = word else {
|
||||
searchString.enumerateSubstrings(in: searchString.startIndex..<searchString.endIndex, options: .byWords) { (word, _, _, _) in
|
||||
guard let word else {
|
||||
return
|
||||
}
|
||||
s += word
|
||||
@@ -962,13 +962,13 @@ nonisolated private extension ArticlesTable {
|
||||
func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
|
||||
let articles = fetchArticlesMatching(searchString, database)
|
||||
// TODO: include the feedIDs in the SQL rather than filtering here.
|
||||
return articles.filter{ feedIDs.contains($0.feedID) }
|
||||
return articles.filter { feedIDs.contains($0.feedID) }
|
||||
}
|
||||
|
||||
func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
|
||||
let articles = fetchArticlesMatching(searchString, database)
|
||||
// TODO: include the articleIDs in the SQL rather than filtering here.
|
||||
return articles.filter{ articleIDs.contains($0.articleID) }
|
||||
return articles.filter { articleIDs.contains($0.articleID) }
|
||||
}
|
||||
|
||||
// MARK: - Saving Parsed Items
|
||||
@@ -987,7 +987,7 @@ nonisolated private extension ArticlesTable {
|
||||
return newArticles.isEmpty ? nil : newArticles
|
||||
}
|
||||
|
||||
func findAndSaveNewArticles(_ incomingArticles: Set<Article>, _ fetchedArticlesDictionary: [String: Article], _ database: FMDatabase) -> Set<Article>? { //5
|
||||
func findAndSaveNewArticles(_ incomingArticles: Set<Article>, _ fetchedArticlesDictionary: [String: Article], _ database: FMDatabase) -> Set<Article>? { // 5
|
||||
guard let newArticles = findNewArticles(incomingArticles, fetchedArticlesDictionary) else {
|
||||
return nil
|
||||
}
|
||||
@@ -1011,11 +1011,11 @@ nonisolated private extension ArticlesTable {
|
||||
// MARK: - Updating Existing Articles
|
||||
|
||||
func articlesWithRelatedObjectChanges<T>(_ comparisonKeyPath: KeyPath<Article, Set<T>?>, _ updatedArticles: Set<Article>, _ fetchedArticles: [String: Article]) -> Set<Article> {
|
||||
return updatedArticles.filter{ (updatedArticle) -> Bool in
|
||||
return updatedArticles.filter { (updatedArticle) -> Bool in
|
||||
if let fetchedArticle = fetchedArticles[updatedArticle.articleID] {
|
||||
return updatedArticle[keyPath: comparisonKeyPath] != fetchedArticle[keyPath: comparisonKeyPath]
|
||||
}
|
||||
assertionFailure("Expected to find matching fetched article.");
|
||||
assertionFailure("Expected to find matching fetched article.")
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -1032,7 +1032,7 @@ nonisolated private extension ArticlesTable {
|
||||
}
|
||||
|
||||
func findUpdatedArticles(_ incomingArticles: Set<Article>, _ fetchedArticlesDictionary: [String: Article]) -> Set<Article>? {
|
||||
let updatedArticles = incomingArticles.filter{ (incomingArticle) -> Bool in //6
|
||||
let updatedArticles = incomingArticles.filter { (incomingArticle) -> Bool in // 6
|
||||
if let existingArticle = fetchedArticlesDictionary[incomingArticle.articleID] {
|
||||
if existingArticle != incomingArticle {
|
||||
return true
|
||||
@@ -1044,7 +1044,7 @@ nonisolated private extension ArticlesTable {
|
||||
return updatedArticles.isEmpty ? nil : updatedArticles
|
||||
}
|
||||
|
||||
func findAndSaveUpdatedArticles(_ incomingArticles: Set<Article>, _ fetchedArticlesDictionary: [String: Article], _ database: FMDatabase) -> Set<Article>? { //6
|
||||
func findAndSaveUpdatedArticles(_ incomingArticles: Set<Article>, _ fetchedArticlesDictionary: [String: Article], _ database: FMDatabase) -> Set<Article>? { // 6
|
||||
guard let updatedArticles = findUpdatedArticles(incomingArticles, fetchedArticlesDictionary) else {
|
||||
return nil
|
||||
}
|
||||
@@ -1065,7 +1065,7 @@ nonisolated private extension ArticlesTable {
|
||||
// Untested theory: this gets us better performance and less database fragmentation.
|
||||
|
||||
guard let fetchedArticle = fetchedArticles[updatedArticle.articleID] else {
|
||||
assertionFailure("Expected to find matching fetched article.");
|
||||
assertionFailure("Expected to find matching fetched article.")
|
||||
saveNewArticles(Set([updatedArticle]), database)
|
||||
return
|
||||
}
|
||||
@@ -1106,7 +1106,7 @@ nonisolated private extension ArticlesTable {
|
||||
func filterIncomingArticles(_ articles: Set<Article>) -> Set<Article> {
|
||||
// Drop Articles that we can ignore.
|
||||
precondition(retentionStyle == .syncSystem)
|
||||
return Set(articles.filter{ !articleIsIgnorable($0) })
|
||||
return Set(articles.filter { !articleIsIgnorable($0) })
|
||||
}
|
||||
|
||||
func removeArticles(_ articleIDs: Set<String>, _ database: FMDatabase) {
|
||||
|
||||
@@ -62,7 +62,7 @@ extension Article {
|
||||
self.init(accountID: accountID, articleID: parsedItem.syncServiceID, feedID: feedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, markdown: parsedItem.markdown, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, datePublished: datePublished, dateModified: dateModified, authors: authors, status: status)
|
||||
}
|
||||
|
||||
private func addPossibleStringChangeWithKeyPath(_ comparisonKeyPath: KeyPath<Article,String?>, _ otherArticle: Article, _ key: String, _ dictionary: inout DatabaseDictionary) {
|
||||
private func addPossibleStringChangeWithKeyPath(_ comparisonKeyPath: KeyPath<Article, String?>, _ otherArticle: Article, _ key: String, _ dictionary: inout DatabaseDictionary) {
|
||||
if self[keyPath: comparisonKeyPath] != otherArticle[keyPath: comparisonKeyPath] {
|
||||
dictionary[key] = self[keyPath: comparisonKeyPath] ?? ""
|
||||
}
|
||||
@@ -133,7 +133,7 @@ extension Article {
|
||||
|
||||
static func articlesWithParsedItems(_ parsedItems: Set<ParsedItem>, _ feedID: String, _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set<Article> {
|
||||
let maximumDateAllowed = _maximumDateAllowed()
|
||||
return Set(parsedItems.map{ Article(parsedItem: $0, maximumDateAllowed: maximumDateAllowed, accountID: accountID, feedID: feedID, status: statusesDictionary[$0.articleID]!) })
|
||||
return Set(parsedItems.map { Article(parsedItem: $0, maximumDateAllowed: maximumDateAllowed, accountID: accountID, feedID: feedID, status: statusesDictionary[$0.articleID]!) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ extension Set where Element == Article {
|
||||
}
|
||||
|
||||
func databaseObjects() -> [DatabaseObject] {
|
||||
return self.map{ $0 as DatabaseObject }
|
||||
return self.map { $0 as DatabaseObject }
|
||||
}
|
||||
|
||||
func databaseDictionaries() -> [DatabaseDictionary]? {
|
||||
|
||||
-3
@@ -19,11 +19,9 @@ extension ArticleStatus {
|
||||
|
||||
self.init(articleID: articleID, read: read, starred: starred, dateArrived: dateArrived)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ArticleStatus: @retroactive DatabaseObject {
|
||||
|
||||
public var databaseID: String {
|
||||
return articleID
|
||||
}
|
||||
@@ -32,4 +30,3 @@ extension ArticleStatus: @retroactive DatabaseObject {
|
||||
return [DatabaseKey.articleID: articleID, DatabaseKey.read: read, DatabaseKey.starred: starred, DatabaseKey.dateArrived: dateArrived]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ final class SearchTable: DatabaseTable, @unchecked Sendable {
|
||||
|
||||
/// Index new articles.
|
||||
func indexNewArticles(_ articles: Set<Article>, _ database: FMDatabase) {
|
||||
let articleSearchInfos = Set(articles.map{ ArticleSearchInfo(article: $0) })
|
||||
let articleSearchInfos = Set(articles.map { ArticleSearchInfo(article: $0) })
|
||||
performInitialIndexForArticles(articleSearchInfos, database)
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ final class StatusesTable: DatabaseTable, Sendable {
|
||||
return statusWithRow(row, articleID: articleID)
|
||||
}
|
||||
|
||||
func statusWithRow(_ row: FMResultSet, articleID: String) ->ArticleStatus? {
|
||||
func statusWithRow(_ row: FMResultSet, articleID: String) -> ArticleStatus? {
|
||||
if let cachedStatus = cache[articleID] {
|
||||
return cachedStatus
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ let package = Package(
|
||||
.library(
|
||||
name: "CloudKitSync",
|
||||
targets: ["CloudKitSync"]
|
||||
),
|
||||
)
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../RSCore")
|
||||
@@ -21,12 +21,12 @@ let package = Package(
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
name: "CloudKitSyncTests",
|
||||
dependencies: ["CloudKitSync"]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -29,7 +29,7 @@ public enum CloudKitZoneError: LocalizedError, Sendable {
|
||||
|
||||
// Wrapper to safely transfer non-Sendable values in @Sendable closures
|
||||
// Generic over the Success type of the Result
|
||||
fileprivate struct CloudKitZoneCaptures<Success>: @unchecked Sendable {
|
||||
private struct CloudKitZoneCaptures<Success>: @unchecked Sendable {
|
||||
weak var zone: (any CloudKitZone)?
|
||||
let completion: (Result<Success, Error>) -> Void
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public typealias CloudKitRecordKey = (recordType: CKRecord.RecordType, recordID:
|
||||
func subscribeToZoneChanges()
|
||||
|
||||
/// Process a remove notification
|
||||
func receiveRemoteNotification(userInfo: [AnyHashable : Any]) async
|
||||
func receiveRemoteNotification(userInfo: [AnyHashable: Any]) async
|
||||
|
||||
}
|
||||
|
||||
@@ -119,14 +119,14 @@ public extension CloudKitZone {
|
||||
return CKRecord.ID(recordName: UUID().uuidString, zoneID: zoneID)
|
||||
}
|
||||
|
||||
func retryIfPossible(after: Double, block: @escaping @MainActor () -> ()) {
|
||||
func retryIfPossible(after: Double, block: @escaping @MainActor () -> Void) {
|
||||
let delayTime = DispatchTime.now() + after
|
||||
DispatchQueue.main.asyncAfter(deadline: delayTime, execute: {
|
||||
block()
|
||||
})
|
||||
}
|
||||
|
||||
func receiveRemoteNotification(userInfo: [AnyHashable : Any]) async {
|
||||
func receiveRemoteNotification(userInfo: [AnyHashable: Any]) async {
|
||||
let note = CKRecordZoneNotification(fromRemoteNotificationDictionary: userInfo)
|
||||
guard note?.recordZoneID?.zoneName == zoneID.zoneName else {
|
||||
return
|
||||
@@ -148,7 +148,7 @@ public extension CloudKitZone {
|
||||
return
|
||||
}
|
||||
|
||||
database.save(CKRecordZone(zoneID: zoneID)) { (recordZone, error) in
|
||||
database.save(CKRecordZone(zoneID: zoneID)) { (_, error) in
|
||||
Task { @MainActor in
|
||||
if let error {
|
||||
completion(.failure(CloudKitError(error)))
|
||||
@@ -185,7 +185,7 @@ public extension CloudKitZone {
|
||||
op.desiredKeys = desiredKeys
|
||||
}
|
||||
|
||||
op.recordMatchedBlock = { recordID, result in
|
||||
op.recordMatchedBlock = { _, result in
|
||||
if let record = try? result.get() {
|
||||
records.append(record)
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public extension CloudKitZone {
|
||||
completion(.success(records))
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.query(ckQuery, desiredKeys: desiredKeys, completion: completion)
|
||||
@@ -254,7 +254,7 @@ public extension CloudKitZone {
|
||||
op.desiredKeys = desiredKeys
|
||||
}
|
||||
|
||||
op.recordMatchedBlock = { recordID, result in
|
||||
op.recordMatchedBlock = { _, result in
|
||||
if let record = try? result.get() {
|
||||
records.append(record)
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public extension CloudKitZone {
|
||||
completion(.success(records))
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.query(cursor: cursor, desiredKeys: desiredKeys, carriedRecords: records, completion: completion)
|
||||
@@ -341,7 +341,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.fetch(externalID: externalID, completion: captures.completion)
|
||||
@@ -403,7 +403,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.saveIfNew(records, completion: completion)
|
||||
@@ -475,7 +475,7 @@ public extension CloudKitZone {
|
||||
captures.completion(.success((savedSubscription!)))
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.save(subscription, completion: captures.completion)
|
||||
@@ -506,7 +506,7 @@ public extension CloudKitZone {
|
||||
|
||||
let op = CKQueryOperation(query: ckQuery)
|
||||
op.qualityOfService = Self.qualityOfService
|
||||
op.recordMatchedBlock = { recordID, result in
|
||||
op.recordMatchedBlock = { _, result in
|
||||
if let record = try? result.get() {
|
||||
records.append(record)
|
||||
}
|
||||
@@ -550,7 +550,7 @@ public extension CloudKitZone {
|
||||
|
||||
let op = CKQueryOperation(cursor: cursor)
|
||||
op.qualityOfService = Self.qualityOfService
|
||||
op.recordMatchedBlock = { recordID, result in
|
||||
op.recordMatchedBlock = { _, result in
|
||||
if let record = try? result.get() {
|
||||
records.append(record)
|
||||
}
|
||||
@@ -667,7 +667,7 @@ public extension CloudKitZone {
|
||||
completion(.success(()))
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.modify(recordsToSave: recordsToSave, recordIDsToDelete: recordIDsToDelete, completion: completion)
|
||||
@@ -728,7 +728,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
|
||||
saveChunks() { result in
|
||||
saveChunks { result in
|
||||
switch result {
|
||||
case .success:
|
||||
deleteChunks()
|
||||
@@ -764,11 +764,11 @@ public extension CloudKitZone {
|
||||
op.fetchAllChanges = true
|
||||
op.qualityOfService = Self.qualityOfService
|
||||
|
||||
op.recordZoneChangeTokensUpdatedBlock = { zoneID, token, _ in
|
||||
op.recordZoneChangeTokensUpdatedBlock = { _, token, _ in
|
||||
savedChangeToken = token
|
||||
}
|
||||
|
||||
op.recordWasChangedBlock = { recordID, result in
|
||||
op.recordWasChangedBlock = { _, result in
|
||||
if let record = try? result.get() {
|
||||
changedRecords.append(record)
|
||||
}
|
||||
@@ -779,7 +779,7 @@ public extension CloudKitZone {
|
||||
deletedRecordKeys.append(recordKey)
|
||||
}
|
||||
|
||||
op.recordZoneFetchResultBlock = { zoneID, result in
|
||||
op.recordZoneFetchResultBlock = { _, result in
|
||||
if case .success(let (serverChangeToken, _, _)) = result {
|
||||
savedChangeToken = serverChangeToken
|
||||
}
|
||||
@@ -815,7 +815,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
self.createZoneRecord { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.fetchChangesInZone(completion: completion)
|
||||
|
||||
@@ -63,13 +63,13 @@ public enum CloudKitZoneResult {
|
||||
private extension CloudKitZoneResult {
|
||||
|
||||
static func anyRequestErrors(_ errors: [AnyHashable: CKError]) -> CloudKitZoneResult? {
|
||||
if errors.values.contains(where: { $0.code == .changeTokenExpired } ) {
|
||||
if errors.values.contains(where: { $0.code == .changeTokenExpired }) {
|
||||
return .changeTokenExpired
|
||||
}
|
||||
if errors.values.contains(where: { $0.code == .zoneNotFound } ) {
|
||||
if errors.values.contains(where: { $0.code == .zoneNotFound }) {
|
||||
return .zoneNotFound
|
||||
}
|
||||
if errors.values.contains(where: { $0.code == .userDeletedZone } ) {
|
||||
if errors.values.contains(where: { $0.code == .userDeletedZone }) {
|
||||
return .userDeletedZone
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -32,7 +32,7 @@ public struct FeedSpecifier: Hashable, Sendable {
|
||||
self.source = source
|
||||
self.orderFound = orderFound
|
||||
}
|
||||
|
||||
|
||||
/// Some feed URLs are known in advance. Save time/bandwidth by special-casing those.
|
||||
static func knownFeedSpecifier(url: URL) -> FeedSpecifier? {
|
||||
if url.isRachelByTheBayURL {
|
||||
@@ -87,7 +87,7 @@ private extension FeedSpecifier {
|
||||
score += 50
|
||||
}
|
||||
|
||||
score = score - ((orderFound - 1) * 5)
|
||||
score -= (orderFound - 1) * 5
|
||||
|
||||
if urlString.caseInsensitiveContains("comments") {
|
||||
score -= 10
|
||||
|
||||
@@ -25,7 +25,7 @@ final class HTMLFeedFinder {
|
||||
|
||||
for oneFeedLink in metadata.feedLinks {
|
||||
if let oneURLString = oneFeedLink.urlString?.normalizedURL {
|
||||
orderFound = orderFound + 1
|
||||
orderFound += 1
|
||||
let oneFeedSpecifier = FeedSpecifier(title: oneFeedLink.title, urlString: oneURLString, source: .HTMLHead, orderFound: orderFound)
|
||||
addFeedSpecifier(oneFeedSpecifier)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ final class HTMLFeedFinder {
|
||||
let bodyLinks = RSHTMLLinkParser.htmlLinks(with: parserData)
|
||||
for oneBodyLink in bodyLinks {
|
||||
if linkMightBeFeed(oneBodyLink), let normalizedURL = oneBodyLink.urlString?.normalizedURL {
|
||||
orderFound = orderFound + 1
|
||||
orderFound += 1
|
||||
let oneFeedSpecifier = FeedSpecifier(title: oneBodyLink.text, urlString: normalizedURL, source: .HTMLLink, orderFound: orderFound)
|
||||
addFeedSpecifier(oneFeedSpecifier)
|
||||
}
|
||||
@@ -50,8 +50,7 @@ private extension HTMLFeedFinder {
|
||||
if let existingFeedSpecifier = feedSpecifiersDictionary[feedSpecifier.urlString] {
|
||||
let mergedFeedSpecifier = existingFeedSpecifier.feedSpecifierByMerging(feedSpecifier)
|
||||
feedSpecifiersDictionary[feedSpecifier.urlString] = mergedFeedSpecifier
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
feedSpecifiersDictionary[feedSpecifier.urlString] = feedSpecifier
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ let package = Package(
|
||||
dependencies: ["RSCoreObjC"],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
.target(
|
||||
@@ -33,7 +33,7 @@ let package = Package(
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances")
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
@@ -41,6 +41,6 @@ let package = Package(
|
||||
dependencies: ["RSCore"],
|
||||
resources: [.copy("Resources")],
|
||||
swiftSettings: [.swiftLanguageMode(.v5)]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -102,7 +102,7 @@ public struct KeyboardKey: Hashable, Sendable {
|
||||
|
||||
var integerValue = 0
|
||||
|
||||
switch(s) {
|
||||
switch s {
|
||||
case "[space]":
|
||||
integerValue = " ".keyboardIntegerValue!
|
||||
case "[uparrow]":
|
||||
@@ -121,8 +121,8 @@ public struct KeyboardKey: Hashable, Sendable {
|
||||
integerValue = KeyboardKey.deleteKeyCode
|
||||
case "[deletefunction]":
|
||||
integerValue = NSDeleteFunctionKey
|
||||
case "[tab]":
|
||||
integerValue = NSTabCharacter
|
||||
case "[tab]":
|
||||
integerValue = NSTabCharacter
|
||||
default:
|
||||
guard let unwrappedIntegerValue = s.keyboardIntegerValue else {
|
||||
return nil
|
||||
|
||||
@@ -30,7 +30,7 @@ public struct TextFieldSizeInfo: Sendable {
|
||||
|
||||
private let numberOfLines: Int
|
||||
private let font: NSFont
|
||||
private let textField:NSTextField
|
||||
private let textField: NSTextField
|
||||
private let singleLineHeightEstimate: Int
|
||||
private let doubleLineHeightEstimate: Int
|
||||
private var cache = [String: WidthHeightCache]() // Each string has a cache.
|
||||
@@ -227,8 +227,7 @@ private extension MultilineTextFieldSizer {
|
||||
|
||||
if oneWidth < width && (oneWidth > smallNeighbor.width || smallNeighbor.width == 0) {
|
||||
smallNeighbor = (oneWidth, oneHeight)
|
||||
}
|
||||
else if oneWidth > width && (oneWidth < largeNeighbor.width || largeNeighbor.width == 0) {
|
||||
} else if oneWidth > width && (oneWidth < largeNeighbor.width || largeNeighbor.width == 0) {
|
||||
largeNeighbor = (oneWidth, oneHeight)
|
||||
}
|
||||
|
||||
@@ -242,4 +241,3 @@ private extension MultilineTextFieldSizer {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -64,13 +64,12 @@ public extension NSOutlineView {
|
||||
|
||||
while true {
|
||||
row += 1
|
||||
if let _ = item(atRow: row) {
|
||||
if item(atRow: row) != nil {
|
||||
if canSelect(row) {
|
||||
selectRowAndScrollToVisible(row)
|
||||
return
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return // if there are no more items, we’re out of rows
|
||||
}
|
||||
}
|
||||
@@ -180,4 +179,3 @@ public extension NSOutlineView {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,14 +13,13 @@ public extension NSResponder {
|
||||
|
||||
func hasAncestor(_ ancestor: NSResponder) -> Bool {
|
||||
var nomad: NSResponder = self
|
||||
while(true) {
|
||||
while true {
|
||||
if nomad === ancestor {
|
||||
return true
|
||||
}
|
||||
if let _ = nomad.nextResponder {
|
||||
nomad = nomad.nextResponder!
|
||||
}
|
||||
else {
|
||||
if let next = nomad.nextResponder {
|
||||
nomad = next
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ public extension NSTableView {
|
||||
let documentVisibleRect = scrollView.documentVisibleRect
|
||||
|
||||
let r = rect(ofRow: row)
|
||||
if NSContainsRect(documentVisibleRect, r) {
|
||||
if documentVisibleRect.contains(r) {
|
||||
return
|
||||
}
|
||||
|
||||
let rMidY = NSMidY(r)
|
||||
var scrollPoint = NSZeroPoint;
|
||||
let rMidY = r.midY
|
||||
var scrollPoint = NSPoint.zero
|
||||
scrollPoint.y = floor(rMidY - (documentVisibleRect.size.height / 2.0)) + CGFloat(extraHeight)
|
||||
scrollPoint.y = max(scrollPoint.y, 0)
|
||||
|
||||
@@ -54,7 +54,7 @@ public extension NSTableView {
|
||||
|
||||
let clipView = scrollView.contentView
|
||||
|
||||
let rClipView = NSMakeRect(scrollPoint.x, scrollPoint.y, NSWidth(clipView.bounds), NSHeight(clipView.bounds))
|
||||
let rClipView = NSRect(x: scrollPoint.x, y: scrollPoint.y, width: clipView.bounds.width, height: clipView.bounds.height)
|
||||
|
||||
clipView.animator().bounds = rClipView
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ import Cocoa
|
||||
// every time the app becomes active. This catches a good number of edge-case
|
||||
// changes to the app bundle's path, such as when a containing folder or the
|
||||
// volume name changes.
|
||||
NotificationCenter.default.addObserver(forName: NSApplication.didBecomeActiveNotification, object: nil, queue: nil) { notification in
|
||||
NotificationCenter.default.addObserver(forName: NSApplication.didBecomeActiveNotification, object: nil, queue: nil) { _ in
|
||||
Task { @MainActor in
|
||||
// Removing observer in invalidate doesn't seem to prevent this getting called? Maybe
|
||||
// because it's on the same invocation of the runloop?
|
||||
|
||||
@@ -12,7 +12,7 @@ import AppKit
|
||||
public class RSToolbarItem: NSToolbarItem {
|
||||
|
||||
override public func validate() {
|
||||
guard let view = view, let _ = view.window else {
|
||||
guard let view = view, view.window != nil else {
|
||||
isEnabled = false
|
||||
return
|
||||
}
|
||||
@@ -34,7 +34,7 @@ private extension RSToolbarItem {
|
||||
return false
|
||||
}
|
||||
|
||||
while(true) {
|
||||
while true {
|
||||
if let validated = validateWithResponder(responder!) {
|
||||
return validated
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ import AppKit
|
||||
self.urlString = urlString
|
||||
}
|
||||
|
||||
public class func write(urlString: String, to pasteboard: NSPasteboard) {
|
||||
public static func write(urlString: String, to pasteboard: NSPasteboard) {
|
||||
write(urlStrings: [urlString], to: pasteboard)
|
||||
}
|
||||
|
||||
public class func write(urlStrings: [String], to pasteboard: NSPasteboard) {
|
||||
public static func write(urlStrings: [String], to pasteboard: NSPasteboard) {
|
||||
assert(!urlStrings.isEmpty)
|
||||
guard !urlStrings.isEmpty else {
|
||||
return
|
||||
@@ -36,7 +36,7 @@ import AppKit
|
||||
// MARK: - NSPasteboardWriting
|
||||
|
||||
public func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
|
||||
if let _ = URL(string: urlString) {
|
||||
if URL(string: urlString) != nil {
|
||||
return [.URL, .string]
|
||||
}
|
||||
return [.string]
|
||||
|
||||
@@ -44,8 +44,7 @@ public final class UserApp {
|
||||
if app == runningApplication {
|
||||
break
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if !app.isTerminated {
|
||||
runningApplication = app
|
||||
break
|
||||
@@ -58,8 +57,7 @@ public final class UserApp {
|
||||
icon = runningApplication.icon
|
||||
if let bundleURL = runningApplication.bundleURL {
|
||||
path = bundleURL.path
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
path = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)?.path
|
||||
}
|
||||
if icon == nil, let path = path {
|
||||
@@ -74,8 +72,7 @@ public final class UserApp {
|
||||
icon = NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
existsOnDisk = true
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
existsOnDisk = false
|
||||
icon = nil
|
||||
}
|
||||
@@ -140,4 +137,3 @@ public final class UserApp {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -49,17 +49,17 @@ public extension Notification.Name {
|
||||
public func end() {
|
||||
precondition(Thread.isMainThread)
|
||||
decrementCount()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension BatchUpdate {
|
||||
|
||||
func incrementCount() {
|
||||
count = count + 1
|
||||
count += 1
|
||||
}
|
||||
|
||||
func decrementCount() {
|
||||
count = count - 1
|
||||
count -= 1
|
||||
if count < 1 {
|
||||
assert(count > -1, "Expected batch updates count to be 0 or greater.")
|
||||
count = 0
|
||||
|
||||
@@ -53,8 +53,7 @@ nonisolated public final class BinaryDiskCache: Sendable {
|
||||
do {
|
||||
try _setData(data, forKey: key)
|
||||
} catch {}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
do {
|
||||
try _deleteData(forKey: key)
|
||||
} catch {}
|
||||
|
||||
@@ -71,7 +71,7 @@ private extension CoalescingQueue {
|
||||
|
||||
func add(_ call: QueueCall) {
|
||||
restartTimer()
|
||||
|
||||
|
||||
if !calls.contains(call) {
|
||||
calls.append(call)
|
||||
}
|
||||
|
||||
Loaded 100 of 200 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user