Skip to content

Commit

Permalink
Begin Notification Center support: notifier helper app; docktileplugi…
Browse files Browse the repository at this point in the history
…n, support for NSUserNotificationCenterDelegate methods
  • Loading branch information
gregneagle committed Apr 15, 2015
1 parent 9d6de2e commit 42e2cf1
Show file tree
Hide file tree
Showing 19 changed files with 1,715 additions and 21 deletions.
@@ -0,0 +1,30 @@
/*
File: DockTilePlugIn.h
Copyright 2015 Greg Neagle.
Liberally adapted from Apple sample code:
https://developer.apple.com/library/mac/samplecode/DockTile/Listings/DockTilePlugIn_DockTilePlugIn_h.html
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import <Cocoa/Cocoa.h>

@interface DockTilePlugIn : NSObject <NSDockTilePlugIn> {
id updateObserver;
}

@property(retain) id updateObserver;
@end
@@ -0,0 +1,62 @@
/*
File: DockTilePlugIn.m
Copyright 2015 Greg Neagle.
Liberally adapted from Apple sample code:
https://developer.apple.com/library/mac/samplecode/DockTile/Listings/DockTilePlugIn_DockTilePlugIn_h.html
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "DockTilePlugIn.h"

@implementation DockTilePlugIn

@synthesize updateObserver;

static void updateCount(NSDockTile *tile) {
CFPreferencesAppSynchronize(CFSTR("ManagedInstalls"));
NSInteger count = CFPreferencesGetAppIntegerValue(CFSTR("PendingUpdateCount"), CFSTR("ManagedInstalls"), NULL);
if (count) {
[tile setBadgeLabel:[NSString stringWithFormat:@"%ld", (long)count]];
} else {
[tile setBadgeLabel: nil];
}
}

- (void)setDockTile:(NSDockTile *)dockTile {
if (dockTile) {
// Attach an observer that will update the count in the dock tile whenever it changes
self.updateObserver = [[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"com.googlecode.munki.managedsoftwareupdate.dock.updateschanged" object:nil queue:nil usingBlock:^(NSNotification *notification) {
updateCount(dockTile); // Note that this block captures (and retains) dockTile for use later. Also note that it does not capture self, which means -dealloc may be called even while the notification is active. Although it's not clear this needs to be supported, this does eliminate a potential source of leaks.
}];
updateCount(dockTile); // Make sure count is updated as soon as we are invoked
} else {
// Strictly speaking this may not be necessary (since the plug-in may be terminated when it's removed from the dock),
/// but it's good practice
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self.updateObserver];
self.updateObserver = nil;
}
}

- (void)dealloc {
if (self.updateObserver) {
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self.updateObserver];
self.updateObserver = nil;
}
[super dealloc];
}

@end
26 changes: 26 additions & 0 deletions code/apps/Managed Software Center/MSCDockTilePlugin/Info.plist
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.googlecode.munki.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 The Munki Project. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string>DockTile</string>
</dict>
</plist>

0 comments on commit 42e2cf1

Please sign in to comment.