real-growl 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/ext/real_growl_api.c CHANGED
@@ -3,11 +3,26 @@
3
3
  VALUE rb_mRealGrowl;
4
4
  VALUE rb_cRealGrowlApplication;
5
5
 
6
+ static void
7
+ free_delegate(id delegate) {
8
+ [delegate release];
9
+ }
10
+
11
+ static VALUE
12
+ alloc_delegate(VALUE klass) {
13
+ return Data_Wrap_Struct(klass, 0, free_delegate, [[RubyDelegate alloc] init]);
14
+ }
15
+
16
+ static NSAutoreleasePool*
17
+ create_autorelease_pool() {
18
+ return [[NSAutoreleasePool alloc] init];
19
+ }
20
+
6
21
  VALUE
7
22
  classMethod_installed(VALUE self) {
8
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
23
+ NSAutoreleasePool *pool = create_autorelease_pool();
9
24
  BOOL installed = [GrowlApplicationBridge isGrowlInstalled];
10
- [pool release];
25
+ [pool drain];
11
26
 
12
27
  if(installed) {
13
28
  return Qtrue;
@@ -18,9 +33,9 @@ classMethod_installed(VALUE self) {
18
33
 
19
34
  VALUE
20
35
  classMethod_running(VALUE self) {
21
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
36
+ NSAutoreleasePool *pool = create_autorelease_pool();
22
37
  BOOL running = [GrowlApplicationBridge isGrowlRunning];
23
- [pool release];
38
+ [pool drain];
24
39
 
25
40
  if(running) {
26
41
  return Qtrue;
@@ -31,47 +46,35 @@ classMethod_running(VALUE self) {
31
46
 
32
47
  VALUE
33
48
  method_notify(VALUE self, VALUE title, VALUE description, VALUE priority, VALUE sticky) {
34
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
49
+ NSAutoreleasePool *pool = create_autorelease_pool();
35
50
 
36
51
  BOOL nsSticky = (sticky == Qtrue) ? YES : NO;
37
52
  NSString *nsTitle = [NSString stringWithCString:STR2CSTR(title) encoding: NSASCIIStringEncoding];
38
53
  NSString *nsDescription = [NSString stringWithCString:STR2CSTR(description) encoding: NSASCIIStringEncoding];
39
54
  [GrowlApplicationBridge notifyWithTitle: nsTitle description: nsDescription notificationName: REAL_GROWL_NOTIFICATION iconData: nil priority: NUM2INT(priority) isSticky:nsSticky clickContext:nil];
40
55
 
41
- [pool release];
56
+ [pool drain];
42
57
 
43
58
  return Qnil;
44
59
  }
45
60
 
46
61
  VALUE
47
62
  method_init(VALUE self, VALUE applicationName) {
48
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
49
- id delegate = NULL;
50
-
51
- Data_Get_Struct(self, RubyDelegate, delegate);
63
+ NSAutoreleasePool *pool = create_autorelease_pool();
64
+ id delegate = NULL;
52
65
 
66
+ Data_Get_Struct(self, RubyDelegate, delegate);
53
67
  NSString *nsAppName = [NSString stringWithCString:STR2CSTR(applicationName) encoding: NSASCIIStringEncoding];
54
68
  [delegate setApplicationName: nsAppName];
55
69
  [GrowlApplicationBridge setGrowlDelegate: delegate];
56
70
 
57
- [pool release];
71
+ [pool drain];
72
+
58
73
  return self;
59
74
  }
60
75
 
61
- static void
62
- free_delegate(id delegate) {
63
- [delegate release];
64
- }
65
-
66
- static VALUE
67
- alloc_delegate(VALUE klass) {
68
- return Data_Wrap_Struct(klass, 0, free_delegate, [[RubyDelegate alloc] init]);
69
- }
70
-
71
-
72
76
  void
73
- Init_real_growl_api() {
74
-
77
+ Init_real_growl_api() {
75
78
  rb_mRealGrowl = rb_define_module("RealGrowl");
76
79
  rb_define_singleton_method(rb_mRealGrowl, "installed?", classMethod_installed, 0);
77
80
  rb_define_singleton_method(rb_mRealGrowl, "running?", classMethod_running, 0);
data/ext/ruby_delegate.h CHANGED
@@ -8,5 +8,5 @@
8
8
  }
9
9
 
10
10
  -(NSDictionary *) registrationDictionaryForGrowl;
11
- @property(nonatomic, assign) NSString *applicationName;
11
+ @property(nonatomic, retain) NSString *applicationName;
12
12
  @end
data/ext/ruby_delegate.m CHANGED
@@ -3,12 +3,23 @@
3
3
  @implementation RubyDelegate
4
4
  @synthesize applicationName;
5
5
 
6
- -(NSDictionary *)registrationDictionaryForGrowl {
7
- if(applicationName == nil) {
8
- applicationName = @"RealGrowl";
6
+ -(id)init {
7
+ if(self = [super init]) {
8
+ applicationName = [@"RealGrowl" retain];
9
+ return self;
9
10
  }
11
+
12
+ return nil;
13
+ }
14
+
15
+ -(NSDictionary *)registrationDictionaryForGrowl {
10
16
  NSArray *notifications = [NSArray arrayWithObject:REAL_GROWL_NOTIFICATION];
11
17
  return [NSDictionary dictionaryWithObjectsAndKeys: [self applicationName], GROWL_APP_ID, [self applicationName], GROWL_APP_NAME, notifications, GROWL_NOTIFICATIONS_ALL, nil];
12
18
  }
13
19
 
20
+ -(void)dealloc {
21
+ [applicationName release];
22
+ [super dealloc];
23
+ }
24
+
14
25
  @end
data/lib/real_growl.rb CHANGED
@@ -12,11 +12,13 @@ module Kernel
12
12
 
13
13
  @__growl_app ||= RealGrowl::Application.new("RealGrowl")
14
14
 
15
- notifications = args.map { |x| x.pretty_inspect }
16
- notifications.each do |x|
17
- @__growl_app.notify('rg', x, Kernel.rg_priority, Kernel.rg_sticky)
15
+ if RealGrowl.running?
16
+ notifications = args.map { |x| x.pretty_inspect }
17
+ notifications.each do |x|
18
+ @__growl_app.notify('rg', x, Kernel.rg_priority, Kernel.rg_sticky)
19
+ end
18
20
  end
19
-
21
+
20
22
  nil
21
23
  end
22
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real-growl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin DeWind
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-13 00:00:00 -05:00
12
+ date: 2010-01-15 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15