Move dock badge updating code to new DockBadge.swift.

This commit is contained in:
Brent Simmons 2017-10-05 18:01:18 -07:00
parent 22275edf53
commit 1bbaa3bfa2
3 changed files with 38 additions and 14 deletions

View File

@ -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 = "<group>"; };
84BB4B611F1174D400858766 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Data.xcodeproj; path = Frameworks/Data/Data.xcodeproj; sourceTree = "<group>"; };
84DAEE2F1F86CAFE0058304B /* OPMLImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPMLImporter.swift; sourceTree = "<group>"; };
84DAEE311F870B390058304B /* DockBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DockBadge.swift; path = Evergreen/DockBadge.swift; sourceTree = "<group>"; };
84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDefaults.swift; path = Evergreen/AppDefaults.swift; sourceTree = "<group>"; };
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 */,

View File

@ -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) {

31
Evergreen/DockBadge.swift Normal file
View File

@ -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
}
}