Delete global appDelegate variable.
This commit is contained in:
parent
9e3b659710
commit
2fed6d3cb3
@ -19,8 +19,6 @@ import OSLog
|
||||
import CrashReporter
|
||||
import Sparkle
|
||||
|
||||
//var appDelegate: AppDelegate!
|
||||
|
||||
@NSApplicationMain
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate {
|
||||
|
||||
@ -32,8 +30,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
var extensionContainersFile: ExtensionContainersFile!
|
||||
var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile!
|
||||
|
||||
var appName: String!
|
||||
|
||||
var refreshTimer: AccountRefreshTimer?
|
||||
var syncTimer: ArticleStatusSyncTimer?
|
||||
var lastRefreshInterval = AppDefaults.refreshInterval
|
||||
@ -113,6 +109,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(importDownloadedTheme(_:)), name: .didEndDownloadingTheme, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themeImportError(_:)), name: .didFailToImportThemeWithError, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(mainWindowWillClose(_:)), name: .mainWindowControllerWillClose, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDidDragFeedToSidebar(_:)), name: .userDidDragFeedToSidebar, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(didWakeNotification(_:)), name: NSWorkspace.didWakeNotification, object: nil)
|
||||
|
||||
Self.shared = self
|
||||
@ -148,8 +145,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
let imagesFolder = (cacheFolder as NSString).appendingPathComponent("Images")
|
||||
let imagesFolderURL = URL(fileURLWithPath: imagesFolder)
|
||||
try! FileManager.default.createDirectory(at: imagesFolderURL, withIntermediateDirectories: true, attributes: nil)
|
||||
|
||||
appName = (Bundle.main.infoDictionary!["CFBundleExecutable"]! as! String)
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ note: Notification) {
|
||||
@ -358,6 +353,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
removeMainWindowController(mainWindowController)
|
||||
}
|
||||
|
||||
@objc func userDidDragFeedToSidebar(_ note: Notification) {
|
||||
guard let draggedFeed = note.userInfo?[UserInfoKey.draggedFeed] as? DraggedFeed else {
|
||||
assertionFailure("Expected userInfo to contain a DraggedFeed.")
|
||||
return
|
||||
}
|
||||
|
||||
addFeed(draggedFeed.url, name: draggedFeed.name, account: draggedFeed.account, folder: draggedFeed.folder)
|
||||
}
|
||||
|
||||
// MARK: Main Window
|
||||
|
||||
func createMainWindowController() -> MainWindowController {
|
||||
|
@ -1207,8 +1207,8 @@ private extension MainWindowController {
|
||||
}
|
||||
|
||||
guard let selectedObjects = selectedObjectsInSidebar(), selectedObjects.count > 0 else {
|
||||
window?.title = appDelegate.appName!
|
||||
setSubtitle(appDelegate.unreadCount)
|
||||
window?.title = AppConfig.appName
|
||||
setSubtitle(AccountManager.shared.unreadCount)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,17 @@ import Articles
|
||||
import RSCore
|
||||
import Account
|
||||
|
||||
extension Notification.Name {
|
||||
static let userDidDragFeedToSidebar = Notification.Name("userDidDragFeedToSidebar") // UserInfoKey.draggedFeed
|
||||
}
|
||||
|
||||
struct DraggedFeed { // UserInfoKey.draggedFeed
|
||||
let url: String
|
||||
let name: String?
|
||||
let account: Account?
|
||||
let folder: Folder?
|
||||
}
|
||||
|
||||
@objc final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource {
|
||||
|
||||
let treeController: TreeController
|
||||
@ -473,19 +484,23 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
|
||||
func acceptSingleNonLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> Bool {
|
||||
|
||||
guard nodeIsDropTarget(parentNode), index == NSOutlineViewDropOnItemIndex else {
|
||||
return false
|
||||
}
|
||||
|
||||
// Show the add-feed sheet.
|
||||
let feedToAdd: DraggedFeed
|
||||
if let account = parentNode.representedObject as? Account {
|
||||
appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: nil)
|
||||
feedToAdd = DraggedFeed(url: draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: nil)
|
||||
} else {
|
||||
let account = parentNode.parent?.representedObject as? Account
|
||||
let folder = parentNode.representedObject as? Folder
|
||||
appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder)
|
||||
feedToAdd = DraggedFeed(url: draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder)
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: .userDidDragFeedToSidebar, object: self, userInfo: [UserInfoKey.draggedFeed: feedToAdd])
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,14 @@ extension NSApplication: ScriptingObjectContainer {
|
||||
return "application"
|
||||
}
|
||||
|
||||
private var scriptingAppDelegate: AppDelegate {
|
||||
NSApplication.shared.delegate as! AppDelegate
|
||||
}
|
||||
|
||||
@objc(currentArticle)
|
||||
func currentArticle() -> ScriptableArticle? {
|
||||
var scriptableArticle: ScriptableArticle?
|
||||
if let currentArticle = appDelegate.scriptingCurrentArticle {
|
||||
if let currentArticle = scriptingAppDelegate.scriptingCurrentArticle {
|
||||
if let feed = currentArticle.feed {
|
||||
let scriptableFeed = ScriptableFeed(feed, container: self)
|
||||
scriptableArticle = ScriptableArticle(currentArticle, container: scriptableFeed)
|
||||
@ -40,7 +44,7 @@ extension NSApplication: ScriptingObjectContainer {
|
||||
|
||||
@objc(selectedArticles)
|
||||
func selectedArticles() -> NSArray {
|
||||
let articles = appDelegate.scriptingSelectedArticles
|
||||
let articles = scriptingAppDelegate.scriptingSelectedArticles
|
||||
let scriptableArticles: [ScriptableArticle] = articles.compactMap { article in
|
||||
if let feed = article.feed, let account = feed.account {
|
||||
let scriptableFeed = ScriptableFeed(feed, container: ScriptableAccount(account))
|
||||
|
@ -53,14 +53,14 @@ final class UnreadFeed: PseudoFeed {
|
||||
|
||||
init() {
|
||||
|
||||
self.unreadCount = appDelegate.unreadCount
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: appDelegate)
|
||||
self.unreadCount = AccountManager.shared.unreadCount
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: AccountManager.shared)
|
||||
}
|
||||
|
||||
@objc func unreadCountDidChange(_ note: Notification) {
|
||||
|
||||
assert(note.object is AppDelegate)
|
||||
unreadCount = appDelegate.unreadCount
|
||||
assert(note.object is AccountManager)
|
||||
unreadCount = AccountManager.shared.unreadCount
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ struct UserInfoKey {
|
||||
static let url = "url"
|
||||
static let articlePath = "articlePath"
|
||||
static let feedIdentifier = "feedIdentifier"
|
||||
static let draggedFeed = "draggedFeed" // DraggedFeed struct
|
||||
|
||||
static let windowState = "windowState"
|
||||
static let windowFullScreenState = "windowFullScreenState"
|
||||
|
Loading…
x
Reference in New Issue
Block a user