@@ -108,7 +108,6 @@ @implementation AppController {
108108
109109 NSMutableDictionary *scriptPathMappings;
110110 NSStatusItem *appStatusItem;
111- NSInteger lastCountOfUnread;
112111 NSMenuItem *scriptsMenuItem;
113112 BOOL didCompleteInitialisation;
114113 NSString *searchString;
@@ -121,7 +120,6 @@ -(instancetype)init
121120{
122121 if ((self = [super init ]) != nil ) {
123122 scriptPathMappings = [[NSMutableDictionary alloc ] init ];
124- lastCountOfUnread = 0 ;
125123 appStatusItem = nil ;
126124 scriptsMenuItem = nil ;
127125 didCompleteInitialisation = NO ;
@@ -282,6 +280,12 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNot
282280 options: 0
283281 context: VNAAppControllerObserverContext];
284282
283+ NSUserDefaults *userDefaults = NSUserDefaults .standardUserDefaults ;
284+ [userDefaults addObserver: self
285+ forKeyPath: MAPref_ShowUnreadCounts
286+ options: 0
287+ context: VNAAppControllerObserverContext];
288+
285289 // Load the styles into the main menu.
286290 [self populateStyleMenu ];
287291
@@ -1024,7 +1028,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
10241028 return ;
10251029 }
10261030
1027- if ([keyPath isEqualToString: NSStringFromSelector ( @selector ( numberOfPlugins )) ]) {
1031+ if ([object isEqual: self .pluginManager ]) {
10281032 NSMenu *menu = ((ViennaApp *)NSApp ).articleMenu ;
10291033
10301034 // Remove any previously added plug-in menu items.
@@ -1042,6 +1046,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
10421046
10431047 // Repopulate the menu.
10441048 [self populatePluginsMenu ];
1049+ return ;
1050+ }
1051+
1052+ if ([object isEqual: NSUserDefaults .standardUserDefaults]) {
1053+ if ([keyPath isEqualToString: MAPref_ShowUnreadCounts]) {
1054+ [self showUnreadCountOnApplicationIconAndWindowTitle ];
1055+ }
10451056 }
10461057}
10471058
@@ -1157,10 +1168,6 @@ - (void)handleUpdateUnreadCount:(NSNotification *)nc
11571168- (void )showUnreadCountOnApplicationIconAndWindowTitle {
11581169 @synchronized (NSApp .dockTile ) {
11591170 NSInteger currentCountOfUnread = db.countOfUnread ;
1160- if (currentCountOfUnread == lastCountOfUnread) {
1161- return ;
1162- }
1163- lastCountOfUnread = currentCountOfUnread;
11641171
11651172 // Always update the app status icon first
11661173 [self setAppStatusBarIcon ];
@@ -1170,8 +1177,11 @@ - (void)showUnreadCountOnApplicationIconAndWindowTitle {
11701177 NSApp .dockTile .badgeLabel = nil ;
11711178 self.mainWindowController .unreadCount = 0 ;
11721179 } else {
1173- NSString *countdown = [NSString stringWithFormat: @" %li " , (long )currentCountOfUnread];
1174- NSApp .dockTile .badgeLabel = countdown;
1180+ if ([NSUserDefaults .standardUserDefaults boolForKey: MAPref_ShowUnreadCounts]) {
1181+ NSApp .dockTile .badgeLabel = [NSString stringWithFormat: @" %li " , currentCountOfUnread];
1182+ } else {
1183+ NSApp .dockTile .badgeLabel = nil ;
1184+ }
11751185 self.mainWindowController .unreadCount = currentCountOfUnread;
11761186 }
11771187 }
@@ -1330,21 +1340,34 @@ -(void)showAppInStatusBar
13301340 */
13311341-(void )setAppStatusBarIcon
13321342{
1333- if (appStatusItem != nil ) {
1334- if (lastCountOfUnread == 0 ) {
1335- NSImage *statusBarImage = [NSImage imageNamed: ACImageNameStatusBarIcon];
1336- statusBarImage.template = YES ;
1343+ if (!appStatusItem) {
1344+ return ;
1345+ }
1346+
1347+ NSInteger unreadCount = db.countOfUnread ;
1348+ if (unreadCount == 0 ) {
1349+ NSImage *statusBarImage = [NSImage imageNamed: ACImageNameStatusBarIcon];
1350+ statusBarImage.template = YES ;
1351+ [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1352+ context.allowsImplicitAnimation = YES ;
13371353 appStatusItem.button .image = statusBarImage;
13381354 appStatusItem.button .title = @" " ;
13391355 appStatusItem.button .imagePosition = NSImageOnly;
1340- } else {
1341- NSImage *statusBarImage = [NSImage imageNamed: ACImageNameStatusBarIconUnread];
1342- statusBarImage.template = YES ;
1356+ }];
1357+ } else {
1358+ NSImage *statusBarImage = [NSImage imageNamed: ACImageNameStatusBarIconUnread];
1359+ statusBarImage.template = YES ;
1360+ [NSAnimationContext runAnimationGroup: ^(NSAnimationContext *context) {
1361+ context.allowsImplicitAnimation = YES ;
13431362 appStatusItem.button .image = statusBarImage;
1344- appStatusItem.button .title = [NSString stringWithFormat: @" %ld " , (long )lastCountOfUnread];
1363+ if ([NSUserDefaults .standardUserDefaults boolForKey: MAPref_ShowUnreadCounts]) {
1364+ appStatusItem.button .title = [NSString stringWithFormat: @" %ld " , unreadCount];
1365+ } else {
1366+ appStatusItem.button .title = @" " ;
1367+ }
13451368 appStatusItem.button .imagePosition = NSImageLeading ;
1346- }
1347- }
1369+ }];
1370+ }
13481371}
13491372
13501373/* handleRSSLink
@@ -2922,6 +2945,11 @@ -(void)dealloc
29222945 forKeyPath: NSStringFromSelector (@selector (numberOfPlugins ))
29232946 context: VNAAppControllerObserverContext];
29242947
2948+ NSUserDefaults *userDefaults = NSUserDefaults .standardUserDefaults ;
2949+ [userDefaults removeObserver: self
2950+ forKeyPath: MAPref_ShowUnreadCounts
2951+ context: VNAAppControllerObserverContext];
2952+
29252953 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
29262954}
29272955
0 commit comments