Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

windows notifiaction

  • Loading branch information...
commit 02448b857520ebc84de6b3d266575c8a7a6aa1ec 1 parent 51750c6
stereobooster authored May 21, 2011
1  Gemfile
@@ -15,4 +15,5 @@ end
15 15
 if Config::CONFIG['target_os'] =~ /mswin|mingw/i
16 16
   gem 'win32console', :require => false
17 17
   gem 'rb-fchange', '>= 0.0.2', :require => false
  18
+  gem 'rb-notifu', :require => false
18 19
 end
24  lib/guard/notifier.rb
@@ -15,6 +15,8 @@ def self.turn_on
15 15
         require_growl
16 16
       when /linux/i
17 17
         require_libnotify
  18
+      when /mswin|mingw/i
  19
+        require_rbnotifu
18 20
       end
19 21
     end
20 22
 
@@ -29,6 +31,9 @@ def self.notify(message, options = {})
29 31
         when /linux/i
30 32
           require_libnotify # need for guard-rspec formatter that is called out of guard scope
31 33
           Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
  34
+        when /mswin|mingw/i
  35
+          require_rbnotifu
  36
+          RbNotifu.show :message => message, :title => title, :type => image_level(image)
32 37
         end
33 38
       end
34 39
     end
@@ -54,6 +59,19 @@ def self.image_path(image)
54 59
       end
55 60
     end
56 61
 
  62
+    def self.image_level(image)
  63
+      case image
  64
+      when :failed
  65
+        :error
  66
+      when :pending
  67
+        :warn
  68
+      when :success
  69
+        :info
  70
+      else
  71
+        :info
  72
+      end
  73
+    end
  74
+    
57 75
     def self.require_growl
58 76
       require 'growl'
59 77
     rescue LoadError
@@ -68,5 +86,11 @@ def self.require_libnotify
68 86
       UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
69 87
     end
70 88
 
  89
+    def self.require_rbnotifu
  90
+      require 'rbnotifu'
  91
+    rescue LoadError
  92
+      turn_off
  93
+      UI.info "Please install rbnotifu gem for Windows notification support and add it to your Gemfile"
  94
+    end
71 95
   end
72 96
 end
19  spec/guard/notifier_spec.rb
@@ -36,6 +36,21 @@
36 36
         it { should_not be_enabled }
37 37
       end
38 38
     end
  39
+    
  40
+    if windows?
  41
+      if rbnotifu_installed?
  42
+        it "uses rbnotifu on Windows" do
  43
+          RbNotifu::show(
  44
+            :message      => "great",
  45
+            :title   => 'Guard',
  46
+            :type => :info
  47
+          )
  48
+        end
  49
+      else
  50
+        it { should_not be_enabled }
  51
+      end
  52
+    end
  53
+
39 54
   end
40 55
 
41 56
   describe ".turn_off" do
@@ -49,6 +64,10 @@
49 64
         Libnotify.should_not_receive(:show)
50 65
         subject.notify 'great', :title => 'Guard'
51 66
       end
  67
+    elsif windows? && rbnotifu_installed?
  68
+      it "prevents the notifications" do
  69
+        
  70
+      end
52 71
     end
53 72
 
54 73
     it { should_not be_enabled }
7  spec/support/gems_helper.rb
@@ -10,4 +10,11 @@ def libnotify_installed?
10 10
   true
11 11
 rescue LoadError
12 12
   false
  13
+end
  14
+
  15
+def rbnotifu_installed?
  16
+  require 'rb-notifu'
  17
+  true
  18
+rescue LoadError
  19
+  false
13 20
 end

0 notes on commit 02448b8

Please sign in to comment.
Something went wrong with that request. Please try again.