Skip to content

Added Notification Center option for Mountain Lion. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
A version of Newt that uses the new Notification Center in Mountain Lion instead of Growl. (Growl is still an option though)

Original:
http://stackapps.com/questions/1993/newt-realtime-new-question-notifications-for-os-x
8 changes: 4 additions & 4 deletions newt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
GCC_VERSION = coop.plausible.blocks.compilers.gcc.4_2;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "resources/newt-Info.plist";
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.5;
SDKROOT = macosx;
};
name = Debug;
};
Expand All @@ -564,12 +564,12 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=0";
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
GCC_VERSION = coop.plausible.blocks.compilers.gcc.4_2;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
PREBINDING = NO;
SDKROOT = macosx10.6;
SDKROOT = macosx;
};
name = Release;
};
Expand Down
7 changes: 7 additions & 0 deletions newt.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,087 changes: 217 additions & 870 deletions resources/English.lproj/PrefPane.xib

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/NewtMenulet.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//- (id)initWithApp:(id *)mainObject;
//@end

@interface NewtMenulet : NSObject <GrowlApplicationBridgeDelegate> {
@interface NewtMenulet : NSObject <GrowlApplicationBridgeDelegate, NSUserNotificationCenterDelegate> {
IBOutlet NSMenu *theMenu;
IBOutlet NSMenuItem *disableButton;
IBOutlet NSMenuItem *silentButton;
Expand Down
65 changes: 50 additions & 15 deletions source/NewtMenulet.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ - (void)awakeFromNib {

sitesDataTimer = [self startTimerWithMethod:@selector(loadStackExchangeNetworkSites) andInterval:60*24];

// initialise Growl
[GrowlApplicationBridge setGrowlDelegate:self];


[GrowlApplicationBridge setGrowlDelegate:self];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];


// experimental
// [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
Expand Down Expand Up @@ -239,13 +242,20 @@ - (void)showReputation:(NSArray *)profiles {
title = [NSString stringWithFormat:@"%d", dif];
}

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"UseGrowl"]) {
[GrowlApplicationBridge notifyWithTitle:title
description:@""
notificationName:@"Reputation Change"
iconData:[site objectForKey:@"icon_data"]
priority:0
isSticky:FALSE
clickContext:url];
} else {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = title;
notification.userInfo = [NSDictionary dictionaryWithObject:url forKey:@"URL"];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
}
}

Expand Down Expand Up @@ -288,21 +298,21 @@ - (void)showReputation:(NSArray *)profiles {
newSize.width = 22;
[image setSize:newSize];

[item setTitle:title];
[item setImage:image];
[image release];
[item setTitle:title];
[item setImage:image];
[image release];
}
}

- (void)clickReputation:(id)sender {
NSArray *sites = [persistence objectForKey:@"most_used_sites"];
int index = [sender tag] - 110;
NSString *siteUrl = [sites objectAtIndex:index];
NSDictionary *site = [persistence siteForKey:siteUrl];
NSObject *userId = [site objectForKey:@"user_id"];
NSString *url = [NSString stringWithFormat:@"%@/users/%@?tab=reputation", siteUrl, userId];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
NSArray *sites = [persistence objectForKey:@"most_used_sites"];
int index = [sender tag] - 110;
NSString *siteUrl = [sites objectAtIndex:index];
NSDictionary *site = [persistence siteForKey:siteUrl];
NSObject *userId = [site objectForKey:@"user_id"];
NSString *url = [NSString stringWithFormat:@"%@/users/%@?tab=reputation", siteUrl, userId];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
}

- (IBAction)retrieveQuestions:(id)sender {
Expand Down Expand Up @@ -382,13 +392,21 @@ - (void)processNewQuestions:(NSDictionary *)data
NSString *url = [NSString stringWithFormat:@"%@/questions/%@", [site objectForKey:@"site_url"], questionId];
NSString *title = [tags componentsJoinedByString:@", "];

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"UseGrowl"]) {
[GrowlApplicationBridge notifyWithTitle:title
description:prepareHTML([question objectForKey:@"title"])
notificationName:@"New Question"
iconData:[site objectForKey:@"icon_data"]
priority:0
isSticky:FALSE
clickContext:url];
} else {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = title;
notification.informativeText = prepareHTML([question objectForKey:@"title"]);
notification.userInfo = [NSDictionary dictionaryWithObject:url forKey:@"URL"];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
}
}

Expand Down Expand Up @@ -439,7 +457,9 @@ - (void)growlNotificationWasClicked:(id)clickContext {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:clickContext]];
}


- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[notification.userInfo objectForKey:@"URL"]]];
}

- (NSTimer *)startTimerWithMethod:(SEL)selector
andInterval:(double)interval {
Expand Down Expand Up @@ -580,13 +600,21 @@ - (void)processCommentsToUser:(NSDictionary *)result
// you can go to the url /questions/{answer_id} and you'll be redirected to the correct question
NSString *url = [NSString stringWithFormat:@"%@/questions/%@", [site objectForKey:@"site_url"], [comment objectForKey:@"post_id"]];

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"UseGrowl"]) {
[GrowlApplicationBridge notifyWithTitle:[NSString stringWithFormat:@"Comment from %@", from]
description:text
notificationName:@"New Comment"
iconData:[site objectForKey:@"icon_data"]
priority:0
isSticky:TRUE
clickContext:url];
} else {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = [NSString stringWithFormat:@"Comment from %@", from];
notification.informativeText = text;
notification.userInfo = [NSDictionary dictionaryWithObject:url forKey:@"URL"];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
}
}

Expand Down Expand Up @@ -644,14 +672,21 @@ - (void)processAnswers:(NSDictionary *)result
// you can go to the url /questions/{answer_id} and you'll be redirected to the correct question
NSString *url = [NSString stringWithFormat:@"%@/questions/%@", [site objectForKey:@"site_url"], answerId];

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"UseGrowl"]) {
[GrowlApplicationBridge notifyWithTitle:[NSString stringWithFormat:@"A new answer by %@", from]
description:@""
notificationName:@"New Answer"
iconData:[site objectForKey:@"icon_data"]
priority:0
isSticky:TRUE
clickContext:url];
}
} else {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = [NSString stringWithFormat:@"A new answer by %@", from];
notification.userInfo = [NSDictionary dictionaryWithObject:url forKey:@"URL"];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
}
}


Expand Down
2 changes: 2 additions & 0 deletions source/PreferencePaneController.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
IBOutlet NSProgressIndicator *profileProgressIndicator;
IBOutlet NSButton *searchUserButton;
IBOutlet NSTextField *profileSearchError;
IBOutlet NSButton *useNotificationCenterCheck;

int activity;

Expand All @@ -65,6 +66,7 @@
- (IBAction)updateStartupLaunchAction:(id)sender;
- (IBAction)selectUserButton:(id)sender;
- (IBAction)confirmUserSelection:(id)sender;
- (IBAction)updateNotificationOption:(id)sender;

- (void)displayPreferences;
- (void)closePreferences;
Expand Down
5 changes: 5 additions & 0 deletions source/PreferencePaneController.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ - (void)willSelect {
[launchOnStartup setState:1];
}

useNotificationCenterCheck.state = ![[NSUserDefaults standardUserDefaults] boolForKey:@"UseGrowl"] ? NSOnState : NSOffState;

NSData *flair = [persistence objectForKey:@"user_flair"];
if (flair != nil) {
Expand Down Expand Up @@ -188,6 +189,10 @@ - (IBAction)updateStartupLaunchAction:(id)sender {
}
}

- (IBAction)updateNotificationOption:(id)sender {
[[NSUserDefaults standardUserDefaults] setBool:(useNotificationCenterCheck.state == NSOffState) forKey:@"UseGrowl"];
}

- (LSSharedFileListItemRef)findStartupItem:(NSString *)appPath {
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);

Expand Down