Skip to content

Commit

Permalink
add growl
Browse files Browse the repository at this point in the history
  • Loading branch information
maccman committed Jan 7, 2012
1 parent 7f00413 commit 80c07c1
Show file tree
Hide file tree
Showing 16 changed files with 1,147 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Classes/Commands/GrowlNotifier.h
@@ -0,0 +1,23 @@
//
// Growl.h
// callback-mac
//
// Created by Alex MacCaw on 06/01/2012.
// Copyright (c) 2012 Nitobi Software Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Growl/Growl.h>

#define APP_GROWL_NOTIFICATION @"Growl Notification"

@interface GrowlNotifier : NSObject <GrowlApplicationBridgeDelegate> {

}

- (void) notify:(NSDictionary*)message;
- (NSString *)applicationNameForGrowl;
- (NSImage *)applicationIconForGrowl;
- (NSDictionary *)registrationDictionaryForGrowl;

@end
89 changes: 89 additions & 0 deletions Classes/Commands/GrowlNotifier.m
@@ -0,0 +1,89 @@
//
// Growl.m
// callback-mac
//
// Created by Alex MacCaw on 06/01/2012.
// Copyright (c) 2012 Nitobi Software Inc. All rights reserved.
//

#import "GrowlNotifier.h"

@implementation GrowlNotifier

- (id) init {
if (self = [super init]) {
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSString *growlPath = [[myBundle privateFrameworksPath]
stringByAppendingPathComponent:@"Growl.framework"];
NSBundle *growlBundle = [NSBundle bundleWithPath:growlPath];
if (growlBundle && [growlBundle load]) {
// Register ourselves as a Growl delegate
[GrowlApplicationBridge setGrowlDelegate:self];
} else {
NSLog(@"Could not load Growl.framework");
}
}

return self;
}

- (void) notify:(NSDictionary *)message {
[GrowlApplicationBridge notifyWithTitle:[message valueForKey:@"title"]
description:[message valueForKey:@"content"]
notificationName:APP_GROWL_NOTIFICATION
iconData:nil
priority:0
isSticky:false
clickContext:nil];
}

- (NSString *)applicationNameForGrowl {
return @"Callback";
}

- (NSImage *)applicationIconForGrowl {
return [NSImage imageNamed:@"NSApplicationIcon"];
}

- (NSDictionary *)registrationDictionaryForGrowl {
NSArray *allowedNotifications = [NSArray arrayWithObject:APP_GROWL_NOTIFICATION];
NSArray *defaultNotifications = [NSArray arrayWithObject:APP_GROWL_NOTIFICATION];

NSDictionary *ticket = [NSDictionary dictionaryWithObjectsAndKeys:
allowedNotifications, GROWL_NOTIFICATIONS_ALL,
defaultNotifications, GROWL_NOTIFICATIONS_DEFAULT,
nil];

return ticket;
}

#pragma mark WebScripting Protocol

/* checks whether a selector is acceptable to be called from JavaScript */
+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector
{
if (selector == @selector(notify:))
return NO;

return YES;
}

/* helper function so we don't have to have underscores and stuff in js to refer to the right method */
+ (NSString*) webScriptNameForSelector:(SEL)selector
{
id result = nil;

if (selector == @selector(notify:)) {
result = @"notify";
}

return result;
}

// right now exclude all properties (eg keys)
+ (BOOL) isKeyExcludedFromWebScript:(const char*)name
{
return YES;
}

@end
3 changes: 3 additions & 0 deletions Classes/WebViewDelegate.h
Expand Up @@ -11,13 +11,16 @@

@class Sound;
@class Dock;
@class Growl;

@interface WebViewDelegate : NSObject {
Sound* sound;
Dock* dock;
Growl* growl;
}

@property (nonatomic, retain) Sound* sound;
@property (nonatomic, retain) Dock* dock;
@property (nonatomic, retain) Growl* growl;

@end
5 changes: 5 additions & 0 deletions Classes/WebViewDelegate.m
Expand Up @@ -9,11 +9,13 @@
#import "WebViewDelegate.h"
#import "Sound.h"
#import "Dock.h"
#import "GrowlNotifier.h"

@implementation WebViewDelegate

@synthesize sound;
@synthesize dock;
@synthesize growl;

- (void) webView:(WebView*)webView windowScriptObjectAvailable:(WebScriptObject*)windowScriptObject
{
Expand All @@ -22,6 +24,9 @@ - (void) webView:(WebView*)webView windowScriptObjectAvailable:(WebScriptObject*

if (self.dock == nil) { self.dock = [Dock new]; }
[windowScriptObject setValue:self.dock forKey:@"dock"];

if (self.growl == nil) { self.growl = [GrowlNotifier new]; }
[windowScriptObject setValue:self.growl forKey:@"growl"];
}

/* This logs all errors from Javascript, nifty */
Expand Down
1 change: 1 addition & 0 deletions Growl.framework/Growl
1 change: 1 addition & 0 deletions Growl.framework/Headers
1 change: 1 addition & 0 deletions Growl.framework/Resources
Binary file added Growl.framework/Versions/A/Growl
Binary file not shown.
5 changes: 5 additions & 0 deletions Growl.framework/Versions/A/Headers/Growl.h
@@ -0,0 +1,5 @@
#include <Growl/GrowlDefines.h>

#ifdef __OBJC__
# include <Growl/GrowlApplicationBridge.h>
#endif

0 comments on commit 80c07c1

Please sign in to comment.