From 1bbaa3bfa25fcdce83c0ca81f9dd34428d6d6935 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 5 Oct 2017 18:01:18 -0700 Subject: [PATCH] Move dock badge updating code to new DockBadge.swift. --- Evergreen.xcodeproj/project.pbxproj | 4 ++++ Evergreen/AppDelegate.swift | 17 +++------------- Evergreen/DockBadge.swift | 31 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 Evergreen/DockBadge.swift diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 3dc3d2356..965a3b191 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -79,6 +79,7 @@ 84BB4B771F11753300858766 /* Data.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B681F1174D400858766 /* Data.framework */; }; 84BB4B781F11753300858766 /* Data.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B681F1174D400858766 /* Data.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84DAEE301F86CAFE0058304B /* OPMLImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DAEE2F1F86CAFE0058304B /* OPMLImporter.swift */; }; + 84DAEE321F870B390058304B /* DockBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DAEE311F870B390058304B /* DockBadge.swift */; }; 84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */; }; 84FB9A2F1EDCD6C4003D53B9 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; }; 84FB9A301EDCD6C4003D53B9 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -437,6 +438,7 @@ 84B070011ED3821800F0B54B /* RSTextDrawing.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSTextDrawing.xcodeproj; path = Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj; sourceTree = ""; }; 84BB4B611F1174D400858766 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Data.xcodeproj; path = Frameworks/Data/Data.xcodeproj; sourceTree = ""; }; 84DAEE2F1F86CAFE0058304B /* OPMLImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPMLImporter.swift; sourceTree = ""; }; + 84DAEE311F870B390058304B /* DockBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DockBadge.swift; path = Evergreen/DockBadge.swift; sourceTree = ""; }; 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDefaults.swift; path = Evergreen/AppDefaults.swift; sourceTree = ""; }; 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Frameworks/Vendor/Sparkle.framework; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ @@ -667,6 +669,7 @@ 849C64671ED37A5D003D8FC0 /* Assets.xcassets */, 849C64691ED37A5D003D8FC0 /* Main.storyboard */, 849C64631ED37A5D003D8FC0 /* AppDelegate.swift */, + 84DAEE311F870B390058304B /* DockBadge.swift */, 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */, 842E45CD1ED8C308000A8B52 /* AppNotifications.swift */, 842E45DC1ED8C54B000A8B52 /* Browser.swift */, @@ -1178,6 +1181,7 @@ 849A97791ED9EC04007D329B /* TimelineStringUtilities.swift in Sources */, 849A97981ED9EFAA007D329B /* Node-Extensions.swift in Sources */, 849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */, + 84DAEE321F870B390058304B /* DockBadge.swift in Sources */, 849A97831ED9EC63007D329B /* StatusBarView.swift in Sources */, 849A97431ED9EAA9007D329B /* AddFolderWindowController.swift in Sources */, 849A97921ED9EF65007D329B /* IndeterminateProgressWindowController.swift in Sources */, diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index ba910098f..0c29ce80b 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -28,10 +28,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { var addFolderWindowController: AddFolderWindowController? let themeLoader = VSThemeLoader() private let appNewsURLString = "https://ranchero.com/evergreen/feed.json" + private let dockBadge = DockBadge() var unreadCount = 0 { didSet { - updateBadgeCoalesced() + dockBadge.update() } } @@ -39,6 +40,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { NSWindow.allowsAutomaticWindowTabbing = false super.init() + dockBadge.appDelegate = self } // MARK: - NSApplicationDelegate @@ -97,19 +99,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { } } - // MARK: Badge - - private func updateBadgeCoalesced() { - - rs_performSelectorCoalesced(#selector(updateBadge), with: nil, afterDelay: 0.01) - } - - @objc dynamic func updateBadge() { - - let label = unreadCount > 0 ? "\(unreadCount)" : "" - NSApplication.shared.dockTile.badgeLabel = label - } - // MARK: Notifications func unreadCountDidChange(_ note: Notification) { diff --git a/Evergreen/DockBadge.swift b/Evergreen/DockBadge.swift new file mode 100644 index 000000000..18bf39490 --- /dev/null +++ b/Evergreen/DockBadge.swift @@ -0,0 +1,31 @@ +// +// DockBadge.swift +// Evergreen +// +// Created by Brent Simmons on 10/5/17. +// Copyright © 2017 Ranchero Software. All rights reserved. +// + +import Foundation +import RSCore + +@objc final class DockBadge: NSObject { + + weak var appDelegate: AppDelegate? + + func update() { + + rs_performSelectorCoalesced(#selector(updateBadge), with: nil, afterDelay: 0.01) + } + + @objc dynamic func updateBadge() { + + guard let appDelegate = appDelegate else { + return + } + + let unreadCount = appDelegate.unreadCount + let label = unreadCount > 0 ? "\(unreadCount)" : "" + NSApplication.shared.dockTile.badgeLabel = label + } +}