Fix lint issues.
This commit is contained in:
parent
8f1379360c
commit
40ada2ba5a
@ -72,9 +72,9 @@ final class AppDefaults {
|
||||
return true
|
||||
}()
|
||||
|
||||
var windowState: [AnyHashable : Any]? {
|
||||
var windowState: [AnyHashable: Any]? {
|
||||
get {
|
||||
return UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable : Any]
|
||||
return UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable: Any]
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Key.windowState)
|
||||
@ -105,8 +105,7 @@ final class AppDefaults {
|
||||
if let appGroupID = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String,
|
||||
let appGroupDefaults = UserDefaults(suiteName: appGroupID) {
|
||||
return appGroupDefaults
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return UserDefaults.standard
|
||||
}
|
||||
}
|
||||
@ -312,7 +311,7 @@ final class AppDefaults {
|
||||
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,
|
||||
@ -416,7 +415,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
|
||||
@ -427,8 +426,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)
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,7 @@ import Sparkle
|
||||
var appDelegate: AppDelegate!
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate
|
||||
{
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate {
|
||||
|
||||
private struct WindowRestorationIdentifiers {
|
||||
static let mainWindow = "mainWindow"
|
||||
@ -139,8 +138,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
let cacheFolder: String
|
||||
if let userCacheFolder = try? FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: false).path {
|
||||
cacheFolder = userCacheFolder
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let bundleIdentifier = (Bundle.main.infoDictionary!["CFBundleIdentifier"]! as! String)
|
||||
cacheFolder = (NSTemporaryDirectory() as NSString).appendingPathComponent(bundleIdentifier)
|
||||
}
|
||||
@ -166,8 +164,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
|
||||
do {
|
||||
try self.softwareUpdater.start()
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
NSLog("Failed to start software updater with error: \(error)")
|
||||
}
|
||||
|
||||
@ -214,7 +211,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
refreshTimer = AccountRefreshTimer()
|
||||
syncTimer = ArticleStatusSyncTimer()
|
||||
|
||||
UNUserNotificationCenter.current().requestAuthorization(options:[.badge]) { (granted, error) in }
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.badge]) { (_, _) in }
|
||||
|
||||
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
|
||||
if settings.authorizationStatus == .authorized {
|
||||
@ -282,7 +279,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
saveState()
|
||||
}
|
||||
|
||||
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
|
||||
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String: Any]) {
|
||||
AccountManager.shared.receiveRemoteNotification(userInfo: userInfo)
|
||||
}
|
||||
|
||||
@ -298,7 +295,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
|
||||
ArticleThemeDownloader.shared.cleanUp()
|
||||
|
||||
AccountManager.shared.sendArticleStatusAll() {
|
||||
AccountManager.shared.sendArticleStatusAll {
|
||||
self.isShutDownSyncDone = true
|
||||
}
|
||||
|
||||
@ -318,7 +315,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
return
|
||||
}
|
||||
if key == Feed.FeedSettingKey.homePageURL || key == Feed.FeedSettingKey.faviconURL {
|
||||
let _ = faviconDownloader.favicon(for: feed)
|
||||
_ = faviconDownloader.favicon(for: feed)
|
||||
}
|
||||
}
|
||||
|
||||
@ -530,8 +527,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
|
||||
if inspectorWindowController!.isOpen {
|
||||
inspectorWindowController!.window!.performClose(self)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
inspectorWindowController!.objects = objectsForInspector()
|
||||
inspectorWindowController!.showWindow(self)
|
||||
}
|
||||
@ -581,7 +577,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
Browser.open(URL.releaseNotes.absoluteString, inBackground: false)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func openHowToSupport(_ sender: Any?) {
|
||||
|
||||
Browser.open("https://github.com/brentsimmons/NetNewsWire/blob/main/Technotes/HowToSupportNetNewsWire.markdown", inBackground: false)
|
||||
@ -751,7 +746,7 @@ internal extension AppDelegate {
|
||||
let localizedMessageText = NSLocalizedString("Install theme “%@” by %@?", comment: "Theme message text")
|
||||
alert.messageText = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.name, theme.creatorName) as String
|
||||
|
||||
var attrs = [NSAttributedString.Key : Any]()
|
||||
var attrs = [NSAttributedString.Key: Any]()
|
||||
attrs[.font] = NSFont.systemFont(ofSize: NSFont.smallSystemFontSize)
|
||||
attrs[.foregroundColor] = NSColor.textColor
|
||||
|
||||
@ -811,7 +806,7 @@ internal extension AppDelegate {
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error" : error, "path": filename])
|
||||
NotificationCenter.default.post(name: .didFailToImportThemeWithError, object: nil, userInfo: ["error": error, "path": filename])
|
||||
}
|
||||
}
|
||||
|
||||
@ -900,7 +895,7 @@ internal extension AppDelegate {
|
||||
These would be unnecessary if the similar accessors were marked internal rather than private,
|
||||
but for now, we'll keep the stratification of visibility
|
||||
*/
|
||||
extension AppDelegate : ScriptingAppDelegate {
|
||||
extension AppDelegate: ScriptingAppDelegate {
|
||||
|
||||
internal var scriptingMainWindowController: ScriptingMainWindowController? {
|
||||
return mainWindowController
|
||||
@ -918,7 +913,7 @@ extension AppDelegate : ScriptingAppDelegate {
|
||||
extension AppDelegate: NSWindowRestoration {
|
||||
|
||||
@objc static func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: @escaping (NSWindow?, Error?) -> Void) {
|
||||
var mainWindow: NSWindow? = nil
|
||||
var mainWindow: NSWindow?
|
||||
if identifier.rawValue == WindowRestorationIdentifiers.mainWindow {
|
||||
mainWindow = appDelegate.createAndShowMainWindow().window
|
||||
}
|
||||
@ -932,7 +927,7 @@ extension AppDelegate: NSWindowRestoration {
|
||||
private extension AppDelegate {
|
||||
|
||||
func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable: Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
return
|
||||
@ -952,7 +947,7 @@ private extension AppDelegate {
|
||||
}
|
||||
|
||||
func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable: Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
return
|
||||
|
@ -23,7 +23,6 @@ struct Browser {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
/// Opens a URL in the default browser.
|
||||
///
|
||||
/// - Parameters:
|
||||
@ -34,7 +33,6 @@ struct Browser {
|
||||
open(urlString, inBackground: invert ? !AppDefaults.shared.openInBrowserInBackground : AppDefaults.shared.openInBrowserInBackground)
|
||||
}
|
||||
|
||||
|
||||
/// Opens a URL in the default browser.
|
||||
///
|
||||
/// - Parameters:
|
||||
@ -52,7 +50,7 @@ struct Browser {
|
||||
configuration.activates = false
|
||||
}
|
||||
|
||||
NSWorkspace.shared.open(preparedURL, configuration: configuration) { (runningApplication, error) in
|
||||
NSWorkspace.shared.open(preparedURL, configuration: configuration) { (_, error) in
|
||||
guard error != nil else { return }
|
||||
if let defaultBrowser = defaultBrowser {
|
||||
defaultBrowser.openURL(url, inBackground: inBackground)
|
||||
|
@ -59,4 +59,3 @@ final class CrashReportWindowController: NSWindowController {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ struct 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)
|
||||
|
@ -63,7 +63,7 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
// MARK: Actions
|
||||
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
|
||||
guard userNotificationSettings != nil else {
|
||||
guard userNotificationSettings != nil else {
|
||||
DispatchQueue.main.async {
|
||||
self.isNotifyAboutNewArticlesCheckBox.setNextState()
|
||||
}
|
||||
@ -83,7 +83,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
|
||||
self.updateNotificationSettings()
|
||||
if granted {
|
||||
DispatchQueue.main.async {
|
||||
@ -130,7 +130,6 @@ private extension FeedInspectorViewController {
|
||||
feed = singleFeed
|
||||
}
|
||||
|
||||
|
||||
@objc func updateUI() {
|
||||
updateImage()
|
||||
updateName()
|
||||
|
@ -19,7 +19,6 @@ protocol Inspector: AnyObject {
|
||||
|
||||
typealias InspectorViewController = Inspector & NSViewController
|
||||
|
||||
|
||||
final class InspectorWindowController: NSWindowController {
|
||||
|
||||
class var shouldOpenAtStartup: Bool {
|
||||
@ -28,7 +27,7 @@ final class InspectorWindowController: NSWindowController {
|
||||
|
||||
var objects: [Any]? {
|
||||
didSet {
|
||||
let _ = window
|
||||
_ = window
|
||||
currentInspector = inspector(for: objects)
|
||||
}
|
||||
}
|
||||
@ -67,21 +66,19 @@ final class InspectorWindowController: NSWindowController {
|
||||
|
||||
if let savedOrigin = originFromDefaults() {
|
||||
window?.setFlippedOriginAdjustingForScreen(savedOrigin)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
window?.flippedOrigin = NSPoint(x: 256, y: 256)
|
||||
}
|
||||
}
|
||||
|
||||
func inspector(for objects: [Any]?) -> InspectorViewController {
|
||||
|
||||
var fallbackInspector: InspectorViewController? = nil
|
||||
var fallbackInspector: InspectorViewController?
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ private extension AddFeedController {
|
||||
// MARK: Progress
|
||||
|
||||
func beginShowingProgress() {
|
||||
runIndeterminateProgressWithMessage(NSLocalizedString("Finding feed…", comment:"Feed finder"))
|
||||
runIndeterminateProgressWithMessage(NSLocalizedString("Finding feed…", comment: "Feed finder"))
|
||||
}
|
||||
|
||||
func endShowingProgress() {
|
||||
@ -165,4 +165,3 @@ private extension AddFeedController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ protocol AddFeedWindowControllerDelegate: AnyObject {
|
||||
func addFeedWindowControllerUserDidCancel(_: AddFeedWindowController)
|
||||
}
|
||||
|
||||
//protocol AddFeedWindowController {
|
||||
// protocol AddFeedWindowController {
|
||||
//
|
||||
// var window: NSWindow? { get }
|
||||
// func runSheetOnWindow(_ hostWindow: NSWindow)
|
||||
//}
|
||||
// }
|
||||
|
@ -12,7 +12,7 @@ import RSTree
|
||||
import Articles
|
||||
import Account
|
||||
|
||||
final class AddFeedWindowController : NSWindowController {
|
||||
final class AddFeedWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet var urlTextField: NSTextField!
|
||||
@IBOutlet var nameTextField: NSTextField!
|
||||
@ -48,7 +48,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
}
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
hostWindow.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in
|
||||
hostWindow.beginSheet(window!) { (_: NSApplication.ModalResponse) in
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ final class AddFeedWindowController : NSWindowController {
|
||||
|
||||
if normalizedURLString.isEmpty {
|
||||
cancelSheet()
|
||||
return;
|
||||
return
|
||||
}
|
||||
guard let url = URL(string: normalizedURLString) else {
|
||||
cancelSheet()
|
||||
|
@ -10,7 +10,7 @@ import AppKit
|
||||
import Articles
|
||||
import Account
|
||||
|
||||
class AddFolderWindowController : NSWindowController {
|
||||
class AddFolderWindowController: NSWindowController {
|
||||
|
||||
@IBOutlet var folderNameTextField: NSTextField!
|
||||
@IBOutlet var accountPopupButton: NSPopUpButton!
|
||||
@ -25,7 +25,7 @@ class AddFolderWindowController : NSWindowController {
|
||||
|
||||
func runSheetOnWindow(_ w: NSWindow) {
|
||||
hostWindow = w
|
||||
hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in
|
||||
hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) in
|
||||
|
||||
if returnCode == NSApplication.ModalResponse.OK {
|
||||
self.addFolderIfNeeded()
|
||||
|
@ -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,11 +67,8 @@ private extension DetailStatusBarView {
|
||||
func updateLinkForDisplay() {
|
||||
if let mouseoverLink = mouseoverLink, !mouseoverLink.isEmpty {
|
||||
linkForDisplay = mouseoverLink.strippingHTTPOrHTTPSScheme
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
linkForDisplay = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,7 +110,7 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func saveState(to state: inout [AnyHashable : Any]) {
|
||||
func saveState(to state: inout [AnyHashable: Any]) {
|
||||
currentWebViewController.saveState(to: &state)
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ private extension DetailViewController {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func userDefaultsDidChange(_ : Notification) {
|
||||
@objc func userDefaultsDidChange(_: Notification) {
|
||||
if AppDefaults.shared.isArticleContentJavascriptEnabled != isArticleContentJavascriptEnabled {
|
||||
isArticleContentJavascriptEnabled = AppDefaults.shared.isArticleContentJavascriptEnabled
|
||||
createNewWebViewsAndRestoreState()
|
||||
|
@ -58,7 +58,7 @@ final class DetailWebView: WKWebView {
|
||||
|
||||
override func setFrameSize(_ newSize: NSSize) {
|
||||
super.setFrameSize(newSize)
|
||||
if (!inLiveResize) {
|
||||
if !inLiveResize {
|
||||
bigSurOffsetFix()
|
||||
}
|
||||
}
|
||||
@ -128,4 +128,3 @@ private extension DetailWebView {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ final class DetailWebViewController: NSViewController {
|
||||
|
||||
private var isShowingExtractedArticle: Bool {
|
||||
switch state {
|
||||
case .extracted(_, _, _):
|
||||
case .extracted:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@ -164,7 +164,7 @@ final class DetailWebViewController: NSViewController {
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func saveState(to state: inout [AnyHashable : Any]) {
|
||||
func saveState(to state: inout [AnyHashable: Any]) {
|
||||
state[UserInfoKey.isShowingExtractedArticle] = isShowingExtractedArticle
|
||||
state[UserInfoKey.articleWindowScrollY] = windowScrollY
|
||||
}
|
||||
@ -281,7 +281,7 @@ private extension DetailWebViewController {
|
||||
}
|
||||
|
||||
func reloadHTMLMaintainingScrollPosition() {
|
||||
fetchScrollInfo() { scrollInfo in
|
||||
fetchScrollInfo { scrollInfo in
|
||||
self.windowScrollY = scrollInfo?.offsetY
|
||||
self.reloadHTML()
|
||||
}
|
||||
@ -320,7 +320,7 @@ private extension DetailWebViewController {
|
||||
func fetchScrollInfo(_ completion: @escaping (ScrollInfo?) -> Void) {
|
||||
let javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: window.pageYOffset}; x"
|
||||
|
||||
webView.evaluateJavaScript(javascriptString) { (info, error) in
|
||||
webView.evaluateJavaScript(javascriptString) { (info, _) in
|
||||
guard let info = info as? [String: Any] else {
|
||||
completion(nil)
|
||||
return
|
||||
|
@ -10,7 +10,7 @@ import AppKit
|
||||
|
||||
final class IconView: NSView {
|
||||
|
||||
var iconImage: IconImage? = nil {
|
||||
var iconImage: IconImage? {
|
||||
didSet {
|
||||
if iconImage !== oldValue {
|
||||
imageView.image = iconImage?.image
|
||||
@ -76,7 +76,7 @@ final class IconView: NSView {
|
||||
}
|
||||
|
||||
override func layout() {
|
||||
resizeSubviews(withOldSize: NSZeroSize)
|
||||
resizeSubviews(withOldSize: NSSize.zero)
|
||||
}
|
||||
|
||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||
@ -89,7 +89,7 @@ final class IconView: NSView {
|
||||
|
||||
let color = NSApplication.shared.effectiveAppearance.isDarkMode ? IconView.darkBackgroundColor : IconView.lightBackgroundColor
|
||||
color.set()
|
||||
let r = NSIntersectionRect(dirtyRect, bounds)
|
||||
let r = dirtyRect.intersection(bounds)
|
||||
r.fill()
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,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 {
|
||||
@ -116,22 +116,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)
|
||||
}
|
||||
else if imageSize.height > imageSize.width {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,3 @@ final class MainWindowKeyboardHandler: KeyboardDelegate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,14 +16,14 @@ enum TimelineSourceMode {
|
||||
case regular, search
|
||||
}
|
||||
|
||||
class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
class MainWindowController: NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
@IBOutlet weak var articleThemePopUpButton: NSPopUpButton?
|
||||
|
||||
private var activityManager = ActivityManager()
|
||||
|
||||
private var isShowingExtractedArticle = false
|
||||
private var articleExtractor: ArticleExtractor? = nil
|
||||
private var articleExtractor: ArticleExtractor?
|
||||
private var sharingServicePickerDelegate: NSSharingServicePickerDelegate?
|
||||
|
||||
private let windowAutosaveName = NSWindow.FrameAutosaveName("MainWindow")
|
||||
@ -45,17 +45,17 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
private var sidebarViewController: SidebarViewController?
|
||||
private var timelineContainerViewController: TimelineContainerViewController?
|
||||
private var detailViewController: DetailViewController?
|
||||
private var currentSearchField: NSSearchField? = nil
|
||||
private var currentSearchField: NSSearchField?
|
||||
private let articleThemeMenuToolbarItem = NSMenuToolbarItem(itemIdentifier: .articleThemeMenu)
|
||||
private var searchString: String? = nil
|
||||
private var lastSentSearchString: String? = nil
|
||||
private var searchString: String?
|
||||
private var lastSentSearchString: String?
|
||||
private var timelineSourceMode: TimelineSourceMode = .regular {
|
||||
didSet {
|
||||
timelineContainerViewController?.showTimeline(for: timelineSourceMode)
|
||||
detailViewController?.showDetail(for: timelineSourceMode)
|
||||
}
|
||||
}
|
||||
private var searchSmartFeed: SmartFeed? = nil
|
||||
private var searchSmartFeed: SmartFeed?
|
||||
private var restoreArticleWindowScrollY: CGFloat?
|
||||
|
||||
// MARK: - NSWindowController
|
||||
@ -115,14 +115,14 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
func handle(_ response: UNNotificationResponse) {
|
||||
let userInfo = response.notification.request.content.userInfo
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any] else { return }
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable: Any] else { return }
|
||||
sidebarViewController?.deepLinkRevealAndSelect(for: articlePathUserInfo)
|
||||
currentTimelineViewController?.goToDeepLink(for: articlePathUserInfo)
|
||||
}
|
||||
|
||||
func handle(_ activity: NSUserActivity) {
|
||||
guard let userInfo = activity.userInfo else { return }
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any] else { return }
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable: Any] else { return }
|
||||
sidebarViewController?.deepLinkRevealAndSelect(for: articlePathUserInfo)
|
||||
currentTimelineViewController?.goToDeepLink(for: articlePathUserInfo)
|
||||
}
|
||||
@ -283,7 +283,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
return
|
||||
}
|
||||
detailViewController.canScrollUp { (canScroll) in
|
||||
if (canScroll) {
|
||||
if canScroll {
|
||||
NSCursor.setHiddenUntilMouseMoves(true)
|
||||
detailViewController.scrollPageUp(sender)
|
||||
}
|
||||
@ -340,8 +340,7 @@ 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
|
||||
@ -414,7 +413,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
}
|
||||
|
||||
@IBAction func markAllAsReadAndGoToNextUnread(_ sender: Any?) {
|
||||
currentTimelineViewController?.markAllAsRead() {
|
||||
currentTimelineViewController?.markAllAsRead {
|
||||
self.nextUnread(sender)
|
||||
}
|
||||
}
|
||||
@ -528,7 +527,7 @@ extension MainWindowController: NSWindowDelegate {
|
||||
}
|
||||
|
||||
func window(_ window: NSWindow, didDecodeRestorableState coder: NSCoder) {
|
||||
guard let state = try? coder.decodeTopLevelObject(forKey: UserInfoKey.windowState) as? [AnyHashable : Any] else { return }
|
||||
guard let state = try? coder.decodeTopLevelObject(forKey: UserInfoKey.windowState) as? [AnyHashable: Any] else { return }
|
||||
restoreState(from: state)
|
||||
}
|
||||
|
||||
@ -710,7 +709,7 @@ extension MainWindowController: ArticleExtractorDelegate {
|
||||
but for now, we'll keep the stratification of visibility
|
||||
*/
|
||||
|
||||
extension MainWindowController : ScriptingMainWindowController {
|
||||
extension MainWindowController: ScriptingMainWindowController {
|
||||
|
||||
internal var scriptingCurrentArticle: Article? {
|
||||
return self.oneSelectedArticle
|
||||
@ -947,8 +946,8 @@ private extension MainWindowController {
|
||||
|
||||
// MARK: - State Restoration
|
||||
|
||||
func savableState() -> [AnyHashable : Any] {
|
||||
var state = [AnyHashable : Any]()
|
||||
func savableState() -> [AnyHashable: Any] {
|
||||
var state = [AnyHashable: Any]()
|
||||
state[UserInfoKey.windowFullScreenState] = window?.styleMask.contains(.fullScreen) ?? false
|
||||
saveSplitViewState(to: &state)
|
||||
sidebarViewController?.saveState(to: &state)
|
||||
@ -957,7 +956,7 @@ private extension MainWindowController {
|
||||
return state
|
||||
}
|
||||
|
||||
func restoreState(from state: [AnyHashable : Any]) {
|
||||
func restoreState(from state: [AnyHashable: Any]) {
|
||||
if let fullScreen = state[UserInfoKey.windowFullScreenState] as? Bool, fullScreen {
|
||||
window?.toggleFullScreen(self)
|
||||
}
|
||||
@ -1235,16 +1234,16 @@ private extension MainWindowController {
|
||||
}
|
||||
}
|
||||
|
||||
func saveSplitViewState(to state: inout [AnyHashable : Any]) {
|
||||
func saveSplitViewState(to state: inout [AnyHashable: Any]) {
|
||||
guard let splitView = splitViewController?.splitView else {
|
||||
return
|
||||
}
|
||||
|
||||
let widths = splitView.arrangedSubviews.map{ Int(floor($0.frame.width)) }
|
||||
let widths = splitView.arrangedSubviews.map { Int(floor($0.frame.width)) }
|
||||
state[MainWindowController.mainWindowWidthsStateKey] = widths
|
||||
}
|
||||
|
||||
func restoreSplitViewState(from state: [AnyHashable : Any]) {
|
||||
func restoreSplitViewState(from state: [AnyHashable: Any]) {
|
||||
guard let splitView = splitViewController?.splitView,
|
||||
let widths = state[MainWindowController.mainWindowWidthsStateKey] as? [Int],
|
||||
widths.count == 3,
|
||||
@ -1322,4 +1321,3 @@ private extension MainWindowController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -141,4 +141,3 @@ extension NNW3Feed: OPMLRepresentable {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,7 @@ 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)
|
||||
}
|
||||
}
|
||||
|
@ -105,4 +105,3 @@ class ImportOPMLWindowController: NSWindowController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import RSCore
|
||||
import Account
|
||||
import RSTree
|
||||
|
||||
class SidebarCell : NSTableCellView {
|
||||
class SidebarCell: NSTableCellView {
|
||||
|
||||
var iconImage: IconImage? {
|
||||
didSet {
|
||||
@ -73,7 +73,7 @@ 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 {
|
||||
@ -99,7 +99,7 @@ class SidebarCell : NSTableCellView {
|
||||
if let cellAppearance = cellAppearance {
|
||||
titleView.font = cellAppearance.textFieldFont
|
||||
}
|
||||
resizeSubviews(withOldSize: NSZeroSize)
|
||||
resizeSubviews(withOldSize: NSSize.zero)
|
||||
}
|
||||
|
||||
override func resizeSubviews(withOldSize oldSize: NSSize) {
|
||||
@ -165,4 +165,3 @@ private extension SidebarCell {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,4 +32,3 @@ struct SidebarCellAppearance: Equatable {
|
||||
self.textFieldFont = NSFont.systemFont(ofSize: textFieldFontSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ struct SidebarCellLayout {
|
||||
|
||||
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)
|
||||
|
||||
@ -42,17 +42,17 @@ struct SidebarCellLayout {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ struct PasteboardFeed: Hashable {
|
||||
let feedID = dictionary[Key.feedID]
|
||||
let editedName = dictionary[Key.editedName]
|
||||
|
||||
var accountType: AccountType? = nil
|
||||
var accountType: AccountType?
|
||||
if let accountTypeString = dictionary[Key.accountType], let accountTypeInt = Int(accountTypeString) {
|
||||
accountType = AccountType(rawValue: accountTypeInt)
|
||||
}
|
||||
@ -72,8 +72,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 {
|
||||
@ -87,8 +86,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 {
|
||||
@ -161,7 +159,6 @@ extension Feed: @retroactive PasteboardWriterOwner {
|
||||
static let feedUTIInternal = "com.ranchero.NetNewsWire-Evergreen.internal.feed"
|
||||
static let feedUTIInternalType = NSPasteboard.PasteboardType(rawValue: feedUTIInternal)
|
||||
|
||||
|
||||
init(feed: Feed) {
|
||||
self.feed = feed
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ struct PasteboardFolder: Hashable {
|
||||
static let accountID = "accountID"
|
||||
}
|
||||
|
||||
|
||||
let name: String
|
||||
let folderID: String?
|
||||
let accountID: String?
|
||||
|
@ -16,7 +16,7 @@ import Account
|
||||
|
||||
let treeController: TreeController
|
||||
static let dragOperationNone = NSDragOperation(rawValue: 0)
|
||||
private var draggedNodes: Set<Node>? = nil
|
||||
private var draggedNodes: Set<Node>?
|
||||
|
||||
init(treeController: TreeController) {
|
||||
self.treeController = treeController
|
||||
@ -56,7 +56,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)
|
||||
@ -92,7 +92,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)
|
||||
@ -159,8 +159,7 @@ private extension SidebarOutlineDataSource {
|
||||
for feed in draggedFeeds {
|
||||
if feed.isLocalFeed {
|
||||
hasLocalFeed = true
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
hasNonLocalFeed = true
|
||||
}
|
||||
if hasLocalFeed && hasNonLocalFeed {
|
||||
|
@ -10,7 +10,7 @@ import AppKit
|
||||
import RSCore
|
||||
import RSTree
|
||||
|
||||
class SidebarOutlineView : NSOutlineView {
|
||||
class SidebarOutlineView: NSOutlineView {
|
||||
|
||||
@IBOutlet var keyboardDelegate: KeyboardDelegate!
|
||||
|
||||
|
@ -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 }
|
||||
@ -362,4 +362,3 @@ private extension SidebarViewController {
|
||||
return articles
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,13 +94,13 @@ protocol SidebarDelegate: AnyObject {
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func saveState(to state: inout [AnyHashable : Any]) {
|
||||
func saveState(to state: inout [AnyHashable: Any]) {
|
||||
state[UserInfoKey.readFeedsFilterState] = isReadFiltered
|
||||
state[UserInfoKey.containerExpandedWindowState] = expandedTable.map { $0.userInfo }
|
||||
state[UserInfoKey.selectedFeedsState] = selectedFeeds.compactMap { $0.sidebarItemID?.userInfo }
|
||||
}
|
||||
|
||||
func restoreState(from state: [AnyHashable : Any]) {
|
||||
func restoreState(from state: [AnyHashable: Any]) {
|
||||
|
||||
if let containerExpandedWindowState = state[UserInfoKey.containerExpandedWindowState] as? [[AnyHashable: AnyHashable]] {
|
||||
let containerIdentifiers = containerExpandedWindowState.compactMap( { ContainerIdentifier(userInfo: $0) })
|
||||
@ -354,7 +354,6 @@ protocol SidebarDelegate: AnyObject {
|
||||
menu.takeItems(from: contextualMenu)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSOutlineViewDelegate
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
|
||||
@ -421,7 +420,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Node Manipulation
|
||||
// MARK: - Node Manipulation
|
||||
|
||||
func deleteNodes(_ nodes: [Node]) {
|
||||
let nodesToDelete = treeController.normalizedSelectedNodes(nodes)
|
||||
@ -464,7 +463,7 @@ protocol SidebarDelegate: AnyObject {
|
||||
revealAndSelectRepresentedObject(feed 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 feed = feedNode.representedObject as? SidebarItem else {
|
||||
@ -497,7 +496,7 @@ extension SidebarViewController: NSUserInterfaceValidations {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Private
|
||||
// MARK: - Private
|
||||
|
||||
private extension SidebarViewController {
|
||||
|
||||
@ -563,7 +562,6 @@ private extension SidebarViewController {
|
||||
treeControllerDelegate.addFilterException(folderFeedID)
|
||||
}
|
||||
|
||||
|
||||
func queueRebuildTreeAndRestoreSelection() {
|
||||
rebuildTreeAndRestoreSelectionQueue.add(self, #selector(rebuildTreeAndRestoreSelection))
|
||||
}
|
||||
@ -720,7 +718,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
|
||||
}
|
||||
@ -740,7 +738,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
|
||||
}
|
||||
@ -819,7 +817,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
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import AppKit
|
||||
|
||||
class UnreadCountView : NSView {
|
||||
class UnreadCountView: NSView {
|
||||
|
||||
struct Appearance {
|
||||
static let padding = NSEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0)
|
||||
@ -31,11 +31,11 @@ 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)
|
||||
@ -59,7 +59,7 @@ class UnreadCountView : NSView {
|
||||
|
||||
private func textSize() -> NSSize {
|
||||
if unreadCount < 1 {
|
||||
return NSZeroSize
|
||||
return NSSize.zero
|
||||
}
|
||||
|
||||
if let cachedSize = UnreadCountView.textSizeCache[unreadCount] {
|
||||
@ -76,9 +76,9 @@ 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
|
||||
}
|
||||
@ -93,4 +93,3 @@ class UnreadCountView : NSView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ final class MultilineTextFieldSizer {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ struct TimelineCellData {
|
||||
self.starred = article.status.starred
|
||||
}
|
||||
|
||||
init() { //Empty
|
||||
init() { // Empty
|
||||
self.title = ""
|
||||
self.text = ""
|
||||
self.dateString = ""
|
||||
|
@ -42,8 +42,7 @@ struct TimelineCellLayout {
|
||||
|
||||
if height > 0.1 {
|
||||
self.height = height
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
self.height = [feedNameRect, dateRect, titleRect, summaryRect, textRect, unreadIndicatorRect, iconImageRect].maxY() + paddingBottom
|
||||
}
|
||||
}
|
||||
@ -62,8 +61,7 @@ struct TimelineCellLayout {
|
||||
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 @@ private extension TimelineCellLayout {
|
||||
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 @@ private extension TimelineCellLayout {
|
||||
static func rectForDate(_ textBoxRect: NSRect, _ rectAbove: NSRect, _ appearance: TimelineCellAppearance, _ cellData: TimelineCellData) -> NSRect {
|
||||
let textFieldSize = SingleLineTextFieldSizer.size(for: cellData.dateString, font: appearance.dateFont)
|
||||
|
||||
var r = NSZeroRect
|
||||
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 @@ private extension TimelineCellLayout {
|
||||
|
||||
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 @@ private extension TimelineCellLayout {
|
||||
|
||||
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
|
||||
@ -237,4 +235,3 @@ private extension Array where Element == NSRect {
|
||||
return y
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ 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()
|
||||
|
||||
@ -91,7 +91,7 @@ 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)
|
||||
}
|
||||
|
@ -34,4 +34,3 @@ final class TimelineContainerView: NSView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ final class TimelineContainerViewController: NSViewController {
|
||||
return false
|
||||
}
|
||||
for object in representedObjects {
|
||||
guard let _ = currentObjects.firstIndex(where: { $0 === object } ) else {
|
||||
guard let _ = currentObjects.firstIndex(where: { $0 === object }) else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -125,11 +125,11 @@ final class TimelineContainerViewController: NSViewController {
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func saveState(to state: inout [AnyHashable : Any]) {
|
||||
func saveState(to state: inout [AnyHashable: Any]) {
|
||||
regularTimelineViewController.saveState(to: &state)
|
||||
}
|
||||
|
||||
func restoreState(from state: [AnyHashable : Any]) {
|
||||
func restoreState(from state: [AnyHashable: Any]) {
|
||||
regularTimelineViewController.restoreState(from: state)
|
||||
updateReadFilterButton()
|
||||
}
|
||||
@ -170,8 +170,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.")
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import AppKit
|
||||
|
||||
class TimelineTableRowView : NSTableRowView {
|
||||
class TimelineTableRowView: NSTableRowView {
|
||||
|
||||
private var separator: NSView?
|
||||
|
||||
|
@ -106,7 +106,6 @@ extension TimelineViewController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private extension TimelineViewController {
|
||||
|
||||
func markArticles(_ articles: [Article], read: Bool) {
|
||||
@ -241,11 +240,11 @@ private extension TimelineViewController {
|
||||
}
|
||||
|
||||
func markAboveReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Mark Above as Read", comment: "Command"), #selector(markAboveArticlesReadFromContextualMenu(_:)), articles)
|
||||
return menuItem(NSLocalizedString("Mark Above as Read", comment: "Command"), #selector(markAboveArticlesReadFromContextualMenu(_:)), articles)
|
||||
}
|
||||
|
||||
func markBelowReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
||||
return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles)
|
||||
return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles)
|
||||
}
|
||||
|
||||
func selectFeedInSidebarMenuItem(_ feed: Feed) -> NSMenuItem {
|
||||
@ -282,7 +281,6 @@ private extension TimelineViewController {
|
||||
return menuItem(NSLocalizedString("Copy External URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString)
|
||||
}
|
||||
|
||||
|
||||
func menuItem(_ title: String, _ action: Selector, _ representedObject: Any) -> NSMenuItem {
|
||||
|
||||
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
|
||||
|
@ -12,7 +12,7 @@ import Articles
|
||||
import Account
|
||||
import os.log
|
||||
|
||||
protocol TimelineDelegate: AnyObject {
|
||||
protocol TimelineDelegate: AnyObject {
|
||||
func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?)
|
||||
func timelineRequestedFeedSelection(_: TimelineViewController, feed: Feed)
|
||||
func timelineInvalidatedRestorationState(_: TimelineViewController)
|
||||
@ -268,7 +268,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func saveState(to state: inout [AnyHashable : Any]) {
|
||||
func saveState(to state: inout [AnyHashable: Any]) {
|
||||
state[UserInfoKey.readArticlesFilterStateKeys] = readFilterEnabledTable.keys.compactMap { $0.userInfo }
|
||||
state[UserInfoKey.readArticlesFilterStateValues] = readFilterEnabledTable.values.compactMap( { $0 })
|
||||
|
||||
@ -277,7 +277,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
}
|
||||
|
||||
func restoreState(from state: [AnyHashable : Any]) {
|
||||
func restoreState(from state: [AnyHashable: Any]) {
|
||||
guard let readArticlesFilterStateKeys = state[UserInfoKey.readArticlesFilterStateKeys] as? [[AnyHashable: AnyHashable]],
|
||||
let readArticlesFilterStateValues = state[UserInfoKey.readArticlesFilterStateValues] as? [Bool] else {
|
||||
return
|
||||
@ -289,7 +289,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
}
|
||||
|
||||
if let articlePathUserInfo = state[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
if let articlePathUserInfo = state[UserInfoKey.articlePath] as? [AnyHashable: Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let account = AccountManager.shared.existingAccount(with: accountID),
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String {
|
||||
@ -331,8 +331,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
|
||||
if markAsRead {
|
||||
markSelectedArticlesAsRead(sender)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
markSelectedArticlesAsUnread(sender)
|
||||
}
|
||||
}
|
||||
@ -485,12 +484,11 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
func markOlderArticlesRead(_ selectedArticles: [Article]) {
|
||||
// Mark articles older than the selectedArticles(s) as read.
|
||||
|
||||
var cutoffDate: Date? = nil
|
||||
var cutoffDate: Date?
|
||||
for article in selectedArticles {
|
||||
if cutoffDate == nil {
|
||||
cutoffDate = article.logicalDatePublished
|
||||
}
|
||||
else if cutoffDate! > article.logicalDatePublished {
|
||||
} else if cutoffDate! > article.logicalDatePublished {
|
||||
cutoffDate = article.logicalDatePublished
|
||||
}
|
||||
}
|
||||
@ -531,7 +529,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 {
|
||||
@ -833,8 +831,7 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
cell.cellAppearance = showIcons ? cellAppearanceWithIcon : cellAppearance
|
||||
if let article = articles.articleAtRow(row) {
|
||||
configureTimelineCell(cell, article: article)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
makeTimelineCellEmpty(cell)
|
||||
}
|
||||
}
|
||||
@ -917,16 +914,16 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
|
||||
switch edge {
|
||||
case .leading:
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.read ? "Unread" : "Read") { (action, row) in
|
||||
self.toggleArticleRead(article);
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.read ? "Unread" : "Read") { (_, _) in
|
||||
self.toggleArticleRead(article)
|
||||
tableView.rowActionsVisible = false
|
||||
}
|
||||
action.image = article.status.read ? AppAssets.swipeMarkUnreadImage : AppAssets.swipeMarkReadImage
|
||||
return [action]
|
||||
|
||||
case .trailing:
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.starred ? "Unstar" : "Star") { (action, row) in
|
||||
self.toggleArticleStarred(article);
|
||||
let action = NSTableViewRowAction(style: .regular, title: article.status.starred ? "Unstar" : "Star") { (_, _) in
|
||||
self.toggleArticleStarred(article)
|
||||
tableView.rowActionsVisible = false
|
||||
}
|
||||
action.backgroundColor = AppAssets.starColor
|
||||
@ -1141,7 +1138,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>()
|
||||
}
|
||||
@ -1236,8 +1233,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
|
||||
|
@ -53,7 +53,7 @@ class AccountsAddCloudKitWindowController: NSWindowController {
|
||||
return
|
||||
}
|
||||
|
||||
let _ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
_ = AccountManager.shared.createAccount(type: .cloudKit)
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
}
|
||||
|
||||
|
@ -82,13 +82,12 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
|
||||
accountsFeedbinWindowController.account = account
|
||||
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
|
||||
accountsWindowController = accountsFeedbinWindowController
|
||||
case .inoreader, .bazQux, .theOldReader, .freshRSS:
|
||||
case .inoreader, .bazQux, .theOldReader, .freshRSS:
|
||||
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
|
||||
accountsReaderAPIWindowController.accountType = account.type
|
||||
accountsReaderAPIWindowController.account = account
|
||||
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
|
||||
accountsWindowController = accountsReaderAPIWindowController
|
||||
break
|
||||
case .newsBlur:
|
||||
let accountsNewsBlurWindowController = AccountsNewsBlurWindowController()
|
||||
accountsNewsBlurWindowController.account = account
|
||||
|
@ -103,7 +103,7 @@ class AccountsFeedbinWindowController: NSWindowController {
|
||||
try self.account?.removeCredentials(type: .basic)
|
||||
try self.account?.storeCredentials(validatedCredentials)
|
||||
|
||||
self.account?.refreshAll() { result in
|
||||
self.account?.refreshAll { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
|
@ -101,7 +101,7 @@ class AccountsNewsBlurWindowController: NSWindowController {
|
||||
try self.account?.storeCredentials(credentials)
|
||||
try self.account?.storeCredentials(validatedCredentials)
|
||||
|
||||
self.account?.refreshAll() { result in
|
||||
self.account?.refreshAll { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
|
@ -40,7 +40,6 @@ final class AccountsPreferencesViewController: NSViewController {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .UserDidAddAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .UserDidDeleteAccount, object: nil)
|
||||
|
||||
|
||||
// Fix tableView frame — for some reason IB wants it 1pt wider than the clip view. This leads to unwanted horizontal scrolling.
|
||||
var rTable = tableView.frame
|
||||
rTable.size.width = tableView.superview!.frame.size.width
|
||||
|
@ -158,7 +158,7 @@ class AccountsReaderAPIWindowController: NSWindowController {
|
||||
try self.account?.storeCredentials(credentials)
|
||||
try self.account?.storeCredentials(validatedCredentials)
|
||||
|
||||
self.account?.refreshAll() { result in
|
||||
self.account?.refreshAll { result in
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
|
@ -69,9 +69,6 @@ enum AddAccountSections: Int, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct AddAccountsView: View {
|
||||
@ -270,10 +267,8 @@ struct AddAccountsView: View {
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct AddAccountsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddAccountsView(delegate: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,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"
|
||||
}
|
||||
|
||||
class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
|
||||
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
|
||||
|
@ -29,7 +29,7 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||
}
|
||||
|
||||
// Maps from UUID to a validation wrapper
|
||||
static var gPingPongMap = Dictionary<String, ValidationWrapper>()
|
||||
static var gPingPongMap = [String: ValidationWrapper]()
|
||||
static var 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 @@ 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 @@ 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 @@ 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,13 +107,13 @@ 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);
|
||||
SafariExtensionHandler.callValidationHandler(forHandlerID: uniqueValidationID, withShouldValidate: false)
|
||||
return
|
||||
}
|
||||
|
||||
@ -127,7 +126,7 @@ 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController {
|
||||
// This would be the place to handle a popover that could, for example, list the possibly multiple feeds offered by a site.
|
||||
static let shared: SafariExtensionViewController = {
|
||||
let shared = SafariExtensionViewController()
|
||||
shared.preferredContentSize = NSSize(width:320, height:240)
|
||||
shared.preferredContentSize = NSSize(width: 320, height: 240)
|
||||
return shared
|
||||
}()
|
||||
|
||||
|
@ -14,15 +14,15 @@ import RSCore
|
||||
@objc(ScriptableAccount)
|
||||
class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer {
|
||||
|
||||
let account:Account
|
||||
init (_ account:Account) {
|
||||
let account: Account
|
||||
init (_ account: Account) {
|
||||
self.account = account
|
||||
}
|
||||
|
||||
@objc(objectSpecifier)
|
||||
override var objectSpecifier: NSScriptObjectSpecifier? {
|
||||
let myContainer = NSApplication.shared
|
||||
let scriptObjectSpecifier = myContainer.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
|
||||
let scriptObjectSpecifier = myContainer.makeFormUniqueIDScriptObjectSpecifier(forObject: self)
|
||||
return (scriptObjectSpecifier)
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
// I am not sure if account should prefer to be specified by name or by ID
|
||||
// but in either case it seems like the accountID would be used as the keydata, so I chose ID
|
||||
@objc(uniqueId)
|
||||
var scriptingUniqueId:Any {
|
||||
var scriptingUniqueId: Any {
|
||||
return account.accountID
|
||||
}
|
||||
|
||||
@ -67,71 +67,71 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
return 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) { result in
|
||||
account.removeFolder(scriptableFolder.folder) { _ in
|
||||
}
|
||||
}
|
||||
} else if let scriptableFeed = element as? ScriptableFeed {
|
||||
BatchUpdate.shared.perform {
|
||||
var container: Container? = nil
|
||||
var container: Container?
|
||||
if let scriptableFolder = scriptableFeed.container as? ScriptableFolder {
|
||||
container = scriptableFolder.folder
|
||||
} else {
|
||||
container = account
|
||||
}
|
||||
account.removeFeed(scriptableFeed.feed, from: container!) { result in
|
||||
account.removeFeed(scriptableFeed.feed, from: container!) { _ in
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc(isLocationRequiredToCreateForKey:)
|
||||
func isLocationRequiredToCreate(forKey key:String) -> Bool {
|
||||
return false;
|
||||
func isLocationRequiredToCreate(forKey key: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable elements ---
|
||||
|
||||
@objc(feeds)
|
||||
var feeds:NSArray {
|
||||
return account.topLevelFeeds.map { ScriptableFeed($0, container:self) } as NSArray
|
||||
var feeds: NSArray {
|
||||
return account.topLevelFeeds.map { ScriptableFeed($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(valueInFeedsWithUniqueID:)
|
||||
func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? {
|
||||
func valueInFeeds(withUniqueID id: String) -> ScriptableFeed? {
|
||||
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? {
|
||||
func valueInFeeds(withName name: String) -> ScriptableFeed? {
|
||||
let feeds = Array(account.flattenedFeeds())
|
||||
guard let feed = feeds.first(where:{$0.name == name}) else { return nil }
|
||||
return ScriptableFeed(feed, container:self)
|
||||
guard let feed = feeds.first(where: {$0.name == name}) else { return nil }
|
||||
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(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 { return nil }
|
||||
return ScriptableFolder(folder, container:self)
|
||||
guard let folder = folders.first(where: {$0.folderID == folderId}) else { return nil }
|
||||
return ScriptableFolder(folder, container: self)
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
@objc(allFeeds)
|
||||
var allFeeds: NSArray {
|
||||
var allFeeds: NSArray {
|
||||
var feeds = [ScriptableFeed]()
|
||||
for feed in account.topLevelFeeds {
|
||||
feeds.append(ScriptableFeed(feed, container: self))
|
||||
@ -148,13 +148,13 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
}
|
||||
|
||||
@objc(opmlRepresentation)
|
||||
var opmlRepresentation:String {
|
||||
return self.account.OPMLString(indentLevel:0)
|
||||
var opmlRepresentation: String {
|
||||
return self.account.OPMLString(indentLevel: 0)
|
||||
}
|
||||
|
||||
@objc(accountType)
|
||||
var accountType:OSType {
|
||||
var osType:String = ""
|
||||
var accountType: OSType {
|
||||
var osType: String = ""
|
||||
switch self.account.type {
|
||||
case .onMyMac:
|
||||
osType = "Locl"
|
||||
|
@ -25,12 +25,12 @@ protocol AppDelegateAppleEvents {
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
extension AppDelegate : AppDelegateAppleEvents {
|
||||
extension AppDelegate: AppDelegateAppleEvents {
|
||||
|
||||
// MARK: GetURL Apple Event
|
||||
|
||||
@ -54,7 +54,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
|
||||
}
|
||||
@ -71,7 +71,6 @@ extension AppDelegate : AppDelegateAppleEvents {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Special case URL with specific scheme handler x-netnewswire-feed: intended to ensure we open
|
||||
// it regardless of which news reader may be set as the default
|
||||
let nnwScheme = "x-netnewswire-feed:"
|
||||
@ -91,13 +90,13 @@ extension AppDelegate : AppDelegateAppleEvents {
|
||||
}
|
||||
}
|
||||
|
||||
class NetNewsWireCreateElementCommand : NSCreateCommand {
|
||||
class NetNewsWireCreateElementCommand: NSCreateCommand {
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
let classDescription = self.createClassDescription
|
||||
if (classDescription.className == "feed") {
|
||||
return ScriptableFeed.handleCreateElement(command:self)
|
||||
} else if (classDescription.className == "folder") {
|
||||
return ScriptableFolder.handleCreateElement(command:self)
|
||||
if classDescription.className == "feed" {
|
||||
return ScriptableFeed.handleCreateElement(command: self)
|
||||
} else if classDescription.className == "folder" {
|
||||
return ScriptableFolder.handleCreateElement(command: self)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -111,7 +110,7 @@ class NetNewsWireCreateElementCommand : NSCreateCommand {
|
||||
is ambiguity about whether specifiers are lists or single objects, the code switches
|
||||
based on which it is.
|
||||
*/
|
||||
class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
class NetNewsWireDeleteCommand: NSDeleteCommand {
|
||||
|
||||
/*
|
||||
delete(objectToDelete:, from container:)
|
||||
@ -119,10 +118,10 @@ 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
|
||||
*/
|
||||
func delete(objectToDelete:Any, from container:ScriptingObjectContainer) {
|
||||
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)
|
||||
@ -138,14 +137,14 @@ class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
After resolving, we call delete(objectToDelete:, from container:) with the container and
|
||||
the resolved objects
|
||||
*/
|
||||
func delete(specifier:NSScriptObjectSpecifier, from container:Any) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,14 +158,14 @@ class NetNewsWireDeleteCommand : NSDeleteCommand {
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
if let receiversSpecifier = self.receiversSpecifier {
|
||||
if let receiverObjects = receiversSpecifier.objectsByEvaluatingSpecifier {
|
||||
self.delete(specifier:self.keySpecifier, from:receiverObjects)
|
||||
self.delete(specifier: self.keySpecifier, from: receiverObjects)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
class NetNewsWireExistsCommand : NSExistsCommand {
|
||||
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
|
||||
@ -179,8 +178,7 @@ class NetNewsWireExistsCommand : NSExistsCommand {
|
||||
// handle that case as well
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let result = super.performDefaultImplementation() else { return NSNumber(booleanLiteral:false) }
|
||||
guard let result = super.performDefaultImplementation() else { return NSNumber(booleanLiteral: false) }
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,17 +13,17 @@ import Articles
|
||||
@objc(ScriptableArticle)
|
||||
class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer {
|
||||
|
||||
let article:Article
|
||||
let container:ScriptingObjectContainer
|
||||
let article: Article
|
||||
let container: ScriptingObjectContainer
|
||||
|
||||
init (_ article:Article, container:ScriptingObjectContainer) {
|
||||
init (_ article: Article, container: ScriptingObjectContainer) {
|
||||
self.article = article
|
||||
self.container = container
|
||||
}
|
||||
|
||||
@objc(objectSpecifier)
|
||||
override var objectSpecifier: NSScriptObjectSpecifier? {
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject: self)
|
||||
return (scriptObjectSpecifier)
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
// article.uniqueID here is the feed unique id
|
||||
|
||||
@objc(uniqueId)
|
||||
var scriptingUniqueId:Any {
|
||||
var scriptingUniqueId: Any {
|
||||
return article.uniqueID
|
||||
}
|
||||
|
||||
@ -49,66 +49,66 @@ class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
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? {
|
||||
return article.preferredLink
|
||||
}
|
||||
|
||||
@objc(permalink)
|
||||
var permalink:String? {
|
||||
var permalink: String? {
|
||||
return article.link
|
||||
}
|
||||
|
||||
@objc(externalUrl)
|
||||
var externalUrl:String? {
|
||||
var externalUrl: String? {
|
||||
return article.externalLink
|
||||
}
|
||||
|
||||
@objc(title)
|
||||
var title:String {
|
||||
var title: String {
|
||||
return article.title ?? ""
|
||||
}
|
||||
|
||||
@objc(contents)
|
||||
var contents:String {
|
||||
var contents: String {
|
||||
return article.contentText ?? ""
|
||||
}
|
||||
|
||||
@objc(html)
|
||||
var html:String {
|
||||
var html: String {
|
||||
return article.contentHTML ?? ""
|
||||
}
|
||||
|
||||
@objc(summary)
|
||||
var summary:String {
|
||||
var summary: String {
|
||||
return article.summary ?? ""
|
||||
}
|
||||
|
||||
@objc(datePublished)
|
||||
var datePublished:Date? {
|
||||
var datePublished: Date? {
|
||||
return article.datePublished
|
||||
}
|
||||
|
||||
@objc(dateModified)
|
||||
var dateModified:Date? {
|
||||
var dateModified: Date? {
|
||||
return article.dateModified
|
||||
}
|
||||
|
||||
@objc(dateArrived)
|
||||
var dateArrived:Date {
|
||||
var dateArrived: Date {
|
||||
return article.status.dateArrived
|
||||
}
|
||||
|
||||
@objc(read)
|
||||
var read:Bool {
|
||||
var read: Bool {
|
||||
get {
|
||||
return article.status.boolStatus(forKey:.read)
|
||||
return article.status.boolStatus(forKey: .read)
|
||||
}
|
||||
set {
|
||||
markArticles([self.article], statusKey: .read, flag: newValue)
|
||||
@ -116,9 +116,9 @@ class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
}
|
||||
|
||||
@objc(starred)
|
||||
var starred:Bool {
|
||||
var starred: Bool {
|
||||
get {
|
||||
return article.status.boolStatus(forKey:.starred)
|
||||
return article.status.boolStatus(forKey: .starred)
|
||||
}
|
||||
set {
|
||||
markArticles([self.article], statusKey: .starred, flag: newValue)
|
||||
@ -126,19 +126,19 @@ class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
|
||||
}
|
||||
|
||||
@objc(deleted)
|
||||
var deleted:Bool {
|
||||
var deleted: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@objc(imageURL)
|
||||
var imageURL:String {
|
||||
var imageURL: String {
|
||||
return article.imageLink ?? ""
|
||||
}
|
||||
|
||||
@objc(authors)
|
||||
var authors:NSArray {
|
||||
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)
|
||||
|
@ -13,17 +13,17 @@ import Articles
|
||||
@objc(ScriptableAuthor)
|
||||
class ScriptableAuthor: NSObject, UniqueIdScriptingObject {
|
||||
|
||||
let author:Author
|
||||
let container:ScriptingObjectContainer
|
||||
let author: Author
|
||||
let container: ScriptingObjectContainer
|
||||
|
||||
init (_ author:Author, container:ScriptingObjectContainer) {
|
||||
init (_ author: Author, container: ScriptingObjectContainer) {
|
||||
self.author = author
|
||||
self.container = container
|
||||
}
|
||||
|
||||
@objc(objectSpecifier)
|
||||
override var objectSpecifier: NSScriptObjectSpecifier? {
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject: self)
|
||||
return (scriptObjectSpecifier)
|
||||
}
|
||||
|
||||
@ -41,29 +41,29 @@ class ScriptableAuthor: NSObject, UniqueIdScriptingObject {
|
||||
// MARK: --- UniqueIdScriptingObject protocol ---
|
||||
|
||||
@objc(uniqueId)
|
||||
var scriptingUniqueId:Any {
|
||||
var scriptingUniqueId: Any {
|
||||
return author.authorID
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
@objc(url)
|
||||
var url:String {
|
||||
var url: String {
|
||||
return self.author.url ?? ""
|
||||
}
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
var name: String {
|
||||
return self.author.name ?? ""
|
||||
}
|
||||
|
||||
@objc(avatarURL)
|
||||
var avatarURL:String {
|
||||
var avatarURL: String {
|
||||
return self.author.avatarURL ?? ""
|
||||
}
|
||||
|
||||
@objc(emailAddress)
|
||||
var emailAddress:String {
|
||||
var emailAddress: String {
|
||||
return self.author.emailAddress ?? ""
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ import RSCore
|
||||
@objc(ScriptableFolder)
|
||||
class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer {
|
||||
|
||||
let folder:Folder
|
||||
let container:ScriptingObjectContainer
|
||||
let folder: Folder
|
||||
let container: ScriptingObjectContainer
|
||||
|
||||
init (_ folder:Folder, container:ScriptingObjectContainer) {
|
||||
init (_ folder: Folder, container: ScriptingObjectContainer) {
|
||||
self.folder = folder
|
||||
self.container = container
|
||||
}
|
||||
|
||||
@objc(objectSpecifier)
|
||||
override var objectSpecifier: NSScriptObjectSpecifier? {
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject: self)
|
||||
return (scriptObjectSpecifier)
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContai
|
||||
// but in either case it seems like the accountID would be used as the keydata, so I chose ID
|
||||
|
||||
@objc(uniqueId)
|
||||
var scriptingUniqueId:Any {
|
||||
var scriptingUniqueId: Any {
|
||||
return folder.folderID
|
||||
}
|
||||
|
||||
@ -50,10 +50,10 @@ class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContai
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
func deleteElement(_ element: ScriptingObject) {
|
||||
if let scriptableFeed = element as? ScriptableFeed {
|
||||
BatchUpdate.shared.perform {
|
||||
folder.account?.removeFeed(scriptableFeed.feed, from: folder) { result in }
|
||||
folder.account?.removeFeed(scriptableFeed.feed, from: folder) { _ in }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,15 +65,15 @@ class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContai
|
||||
or
|
||||
tell account X to make new folder at end with properties {name:"new folder name"}
|
||||
*/
|
||||
class func handleCreateElement(command:NSCreateCommand) -> Any? {
|
||||
guard command.isCreateCommand(forClass:"fold") else { return nil }
|
||||
let name = command.property(forKey:"name") as? String ?? ""
|
||||
class func handleCreateElement(command: NSCreateCommand) -> Any? {
|
||||
guard command.isCreateCommand(forClass: "fold") else { return nil }
|
||||
let name = command.property(forKey: "name") as? String ?? ""
|
||||
|
||||
// some combination of the tell target and the location specifier ("in" or "at")
|
||||
// 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
|
||||
}
|
||||
|
||||
@ -83,10 +83,10 @@ class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContai
|
||||
switch result {
|
||||
case .success(let folder):
|
||||
let scriptableAccount = ScriptableAccount(account)
|
||||
let scriptableFolder = ScriptableFolder(folder, container:scriptableAccount)
|
||||
command.resumeExecution(withResult:scriptableFolder.objectSpecifier)
|
||||
let scriptableFolder = ScriptableFolder(folder, container: scriptableAccount)
|
||||
command.resumeExecution(withResult: scriptableFolder.objectSpecifier)
|
||||
case .failure:
|
||||
command.resumeExecution(withResult:nil)
|
||||
command.resumeExecution(withResult: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,21 +96,21 @@ class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContai
|
||||
// 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
|
||||
return feeds.map { ScriptableFeed($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
var name: String {
|
||||
return self.folder.name ?? ""
|
||||
}
|
||||
|
||||
@objc(opmlRepresentation)
|
||||
var opmlRepresentation:String {
|
||||
return self.folder.OPMLString(indentLevel:0)
|
||||
var opmlRepresentation: String {
|
||||
return self.folder.OPMLString(indentLevel: 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,4 +13,3 @@ protocol ScriptingMainWindowController {
|
||||
var scriptingCurrentArticle: Article? { get }
|
||||
var scriptingSelectedArticles: [Article] { get }
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import AppKit
|
||||
import Account
|
||||
import Articles
|
||||
|
||||
extension NSApplication : ScriptingObjectContainer {
|
||||
extension NSApplication: ScriptingObjectContainer {
|
||||
|
||||
// MARK: --- ScriptingObjectContainer protocol ---
|
||||
|
||||
@ -18,8 +18,8 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
return NSApplication.shared.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
print ("delete event not handled")
|
||||
func deleteElement(_ element: ScriptingObject) {
|
||||
print("delete event not handled")
|
||||
}
|
||||
|
||||
var scriptingKey: String {
|
||||
@ -31,8 +31,8 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
var scriptableArticle: ScriptableArticle?
|
||||
if let currentArticle = appDelegate.scriptingCurrentArticle {
|
||||
if let feed = currentArticle.feed {
|
||||
let scriptableFeed = ScriptableFeed(feed, container:self)
|
||||
scriptableArticle = ScriptableArticle(currentArticle, container:scriptableFeed)
|
||||
let scriptableFeed = ScriptableFeed(feed, container: self)
|
||||
scriptableArticle = ScriptableArticle(currentArticle, container: scriptableFeed)
|
||||
}
|
||||
}
|
||||
return scriptableArticle
|
||||
@ -41,8 +41,8 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
@objc(selectedArticles)
|
||||
func selectedArticles() -> NSArray {
|
||||
let articles = appDelegate.scriptingSelectedArticles
|
||||
let scriptableArticles:[ScriptableArticle] = articles.compactMap { article in
|
||||
if let feed = article.feed, let account = feed.account {
|
||||
let scriptableArticles: [ScriptableArticle] = articles.compactMap { article in
|
||||
if let feed = article.feed, let account = feed.account {
|
||||
let scriptableFeed = ScriptableFeed(feed, container: ScriptableAccount(account))
|
||||
return ScriptableArticle(article, container: scriptableFeed)
|
||||
} else {
|
||||
@ -61,9 +61,9 @@ extension NSApplication : 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)
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ extension NSApplication : 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
|
||||
@ -85,15 +85,13 @@ extension NSApplication : ScriptingObjectContainer {
|
||||
@objc(feeds)
|
||||
func feeds() -> NSArray {
|
||||
let feeds = self.allFeeds()
|
||||
return feeds.map { ScriptableFeed($0, container:self) } as NSArray
|
||||
return feeds.map { ScriptableFeed($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(valueInFeedsWithUniqueID:)
|
||||
func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? {
|
||||
func valueInFeeds(withUniqueID id: String) -> ScriptableFeed? {
|
||||
let feeds = self.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,8 +10,8 @@ import Foundation
|
||||
import Account
|
||||
|
||||
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]
|
||||
}
|
||||
@ -19,34 +19,34 @@ extension NSScriptCommand {
|
||||
return nil
|
||||
}
|
||||
|
||||
func isCreateCommand(forClass whatClass:String) -> Bool {
|
||||
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}
|
||||
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? = nil
|
||||
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)}
|
||||
guard let newContainerSpecifier = NSScriptObjectSpecifier(descriptor: descriptorToConsider) else {return (account, folder)}
|
||||
let newContainer = newContainerSpecifier.objectsByEvaluatingSpecifier
|
||||
if let scriptableAccount = newContainer as? ScriptableAccount {
|
||||
account = scriptableAccount.account
|
||||
|
@ -9,14 +9,14 @@
|
||||
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 {
|
||||
var scriptingUniqueId:Any { get }
|
||||
var scriptingUniqueId: Any { get }
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
func makeFormNameScriptObjectSpecifier(forObject object:NamedScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
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
|
||||
}
|
||||
|
||||
func makeFormUniqueIDScriptObjectSpecifier(forObject object:UniqueIdScriptingObject) -> NSScriptObjectSpecifier? {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,14 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
|
||||
let feed: Feed
|
||||
let container: ScriptingObjectContainer
|
||||
|
||||
init (_ feed:Feed, container:ScriptingObjectContainer) {
|
||||
init (_ feed: Feed, container: ScriptingObjectContainer) {
|
||||
self.feed = feed
|
||||
self.container = container
|
||||
}
|
||||
|
||||
@objc(objectSpecifier)
|
||||
override var objectSpecifier: NSScriptObjectSpecifier? {
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
|
||||
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject: self)
|
||||
return (scriptObjectSpecifier)
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
|
||||
// I am not sure if account should prefer to be specified by name or by ID
|
||||
// but in either case it seems like the accountID would be used as the keydata, so I chose ID
|
||||
@objc(uniqueId)
|
||||
var scriptingUniqueId:Any {
|
||||
var scriptingUniqueId: Any {
|
||||
return feed.feedID
|
||||
}
|
||||
|
||||
@ -54,42 +54,42 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
|
||||
return self.classDescription as! NSScriptClassDescription
|
||||
}
|
||||
|
||||
func deleteElement(_ element:ScriptingObject) {
|
||||
func deleteElement(_ element: ScriptingObject) {
|
||||
}
|
||||
|
||||
// MARK: --- handle NSCreateCommand ---
|
||||
|
||||
class func urlForNewFeed(arguments:[String:Any]) -> String? {
|
||||
var url:String?
|
||||
class func urlForNewFeed(arguments: [String: Any]) -> String? {
|
||||
var url: String?
|
||||
if let withDataParam = arguments["ObjectData"] {
|
||||
if let objectDataDescriptor = withDataParam as? NSAppleEventDescriptor {
|
||||
url = objectDataDescriptor.stringValue
|
||||
}
|
||||
} else if let withPropsParam = arguments["ObjectProperties"] as? [String:Any] {
|
||||
} else if let withPropsParam = arguments["ObjectProperties"] as? [String: Any] {
|
||||
url = withPropsParam["url"] as? String
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
class func scriptableFeed(_ feed:Feed, account:Account, folder:Folder?) -> ScriptableFeed {
|
||||
class func scriptableFeed(_ feed: Feed, account: Account, folder: Folder?) -> ScriptableFeed {
|
||||
let scriptableAccount = ScriptableAccount(account)
|
||||
if let folder = folder {
|
||||
let scriptableFolder = ScriptableFolder(folder, container:scriptableAccount)
|
||||
return ScriptableFeed(feed, container:scriptableFolder)
|
||||
} else {
|
||||
return ScriptableFeed(feed, container:scriptableAccount)
|
||||
let scriptableFolder = ScriptableFolder(folder, container: scriptableAccount)
|
||||
return ScriptableFeed(feed, container: scriptableFolder)
|
||||
} else {
|
||||
return ScriptableFeed(feed, container: scriptableAccount)
|
||||
}
|
||||
}
|
||||
|
||||
class func handleCreateElement(command:NSCreateCommand) -> Any? {
|
||||
guard command.isCreateCommand(forClass:"Feed") else { return nil }
|
||||
class func handleCreateElement(command: NSCreateCommand) -> Any? {
|
||||
guard command.isCreateCommand(forClass: "Feed") else { return nil }
|
||||
guard let arguments = command.arguments else {return nil}
|
||||
let titleFromArgs = command.property(forKey:"name") as? String
|
||||
let titleFromArgs = command.property(forKey: "name") as? String
|
||||
let (account, folder) = command.accountAndFolderForNewChild()
|
||||
guard let url = self.urlForNewFeed(arguments:arguments) else {return nil}
|
||||
guard let url = self.urlForNewFeed(arguments: arguments) else {return nil}
|
||||
|
||||
if let existingFeed = account.existingFeed(withURL:url) {
|
||||
return scriptableFeed(existingFeed, account:account, folder:folder).objectSpecifier
|
||||
if let existingFeed = account.existingFeed(withURL: url) {
|
||||
return scriptableFeed(existingFeed, account: account, folder: folder).objectSpecifier
|
||||
}
|
||||
|
||||
let container: Container = folder != nil ? folder! : account
|
||||
@ -106,10 +106,10 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
|
||||
switch result {
|
||||
case .success(let feed):
|
||||
NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed])
|
||||
let scriptableFeed = self.scriptableFeed(feed, account:account, folder:folder)
|
||||
command.resumeExecution(withResult:scriptableFeed.objectSpecifier)
|
||||
let scriptableFeed = self.scriptableFeed(feed, account: account, folder: folder)
|
||||
command.resumeExecution(withResult: scriptableFeed.objectSpecifier)
|
||||
case .failure:
|
||||
command.resumeExecution(withResult:nil)
|
||||
command.resumeExecution(withResult: nil)
|
||||
}
|
||||
|
||||
}
|
||||
@ -120,64 +120,64 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContaine
|
||||
// MARK: --- Scriptable properties ---
|
||||
|
||||
@objc(url)
|
||||
var url:String {
|
||||
var url: String {
|
||||
return self.feed.url
|
||||
}
|
||||
|
||||
@objc(name)
|
||||
var name:String {
|
||||
var name: String {
|
||||
return self.feed.name ?? ""
|
||||
}
|
||||
|
||||
@objc(homePageURL)
|
||||
var homePageURL:String {
|
||||
var homePageURL: String {
|
||||
return self.feed.homePageURL ?? ""
|
||||
}
|
||||
|
||||
@objc(iconURL)
|
||||
var iconURL:String {
|
||||
var iconURL: String {
|
||||
return self.feed.iconURL ?? ""
|
||||
}
|
||||
|
||||
@objc(faviconURL)
|
||||
var faviconURL:String {
|
||||
var faviconURL: String {
|
||||
return self.feed.faviconURL ?? ""
|
||||
}
|
||||
|
||||
@objc(opmlRepresentation)
|
||||
var opmlRepresentation:String {
|
||||
return self.feed.OPMLString(indentLevel:0)
|
||||
var opmlRepresentation: String {
|
||||
return self.feed.OPMLString(indentLevel: 0)
|
||||
}
|
||||
|
||||
// MARK: --- scriptable elements ---
|
||||
|
||||
@objc(authors)
|
||||
var authors:NSArray {
|
||||
var authors: NSArray {
|
||||
let feedAuthors = feed.authors ?? []
|
||||
return feedAuthors.map { ScriptableAuthor($0, container:self) } as NSArray
|
||||
return feedAuthors.map { ScriptableAuthor($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(valueInAuthorsWithUniqueID:)
|
||||
func valueInAuthors(withUniqueID id:String) -> ScriptableAuthor? {
|
||||
guard let author = feed.authors?.first(where:{$0.authorID == id}) else { return nil }
|
||||
return ScriptableAuthor(author, container:self)
|
||||
func valueInAuthors(withUniqueID id: String) -> ScriptableAuthor? {
|
||||
guard let author = feed.authors?.first(where: {$0.authorID == id}) else { return nil }
|
||||
return ScriptableAuthor(author, container: self)
|
||||
}
|
||||
|
||||
@objc(articles)
|
||||
var articles:NSArray {
|
||||
var articles: NSArray {
|
||||
let feedArticles = (try? feed.fetchArticles()) ?? Set<Article>()
|
||||
// the articles are a set, use the sorting algorithm from the viewer
|
||||
let sortedArticles = feedArticles.sorted(by:{
|
||||
let sortedArticles = feedArticles.sorted(by: {
|
||||
return $0.logicalDatePublished > $1.logicalDatePublished
|
||||
})
|
||||
return sortedArticles.map { ScriptableArticle($0, container:self) } as NSArray
|
||||
return sortedArticles.map { ScriptableArticle($0, container: self) } as NSArray
|
||||
}
|
||||
|
||||
@objc(valueInArticlesWithUniqueID:)
|
||||
func valueInArticles(withUniqueID id:String) -> ScriptableArticle? {
|
||||
func valueInArticles(withUniqueID id: String) -> ScriptableArticle? {
|
||||
let articles = (try? feed.fetchArticles()) ?? Set<Article>()
|
||||
guard let article = articles.first(where:{$0.uniqueID == id}) else { return nil }
|
||||
return ScriptableArticle(article, container:self)
|
||||
guard let article = articles.first(where: {$0.uniqueID == id}) else { return nil }
|
||||
return ScriptableArticle(article, container: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ 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] {
|
||||
@ -40,7 +40,7 @@ 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
|
||||
@ -67,7 +67,7 @@ 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
|
||||
@ -117,7 +117,7 @@ private extension ShareViewController {
|
||||
}
|
||||
|
||||
let defaultContainer = ShareDefaultContainer.defaultContainer(containers: extensionContainers)
|
||||
var defaultMenuItem: NSMenuItem? = nil
|
||||
var defaultMenuItem: NSMenuItem?
|
||||
|
||||
for account in extensionContainers.accounts {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user