nserver 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/README.txt +11 -0
- data/lib/nserver.rb +30 -10
- metadata +2 -2
    
        data/History.txt
    CHANGED
    
    
    
        data/README.txt
    CHANGED
    
    | @@ -41,6 +41,16 @@ Assuming you have a NServer::Server instance running, you can use the client lik | |
| 41 41 |  | 
| 42 42 | 
             
              NServer::Client.notify("My test message goes here").
         | 
| 43 43 |  | 
| 44 | 
            +
            There is also support for building messages to send.
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              require 'nserver'
         | 
| 47 | 
            +
              
         | 
| 48 | 
            +
              msg = NServer::Message.new
         | 
| 49 | 
            +
              msg.text = "My text"
         | 
| 50 | 
            +
              msg.title = "Test Message"
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              NServer::Client.notify( msg )
         | 
| 53 | 
            +
             | 
| 44 54 | 
             
            Or, if you want a easy command line client:
         | 
| 45 55 |  | 
| 46 56 | 
             
              % nclient "Message"
         | 
| @@ -58,6 +68,7 @@ If you're NServer is listening on another mahcine, you can: | |
| 58 68 | 
             
            * daemons
         | 
| 59 69 | 
             
            * rnotify
         | 
| 60 70 | 
             
            * gtk
         | 
| 71 | 
            +
            * yaml
         | 
| 61 72 |  | 
| 62 73 | 
             
            == INSTALL:
         | 
| 63 74 |  | 
    
        data/lib/nserver.rb
    CHANGED
    
    | @@ -8,9 +8,10 @@ end | |
| 8 8 | 
             
            require 'gserver'
         | 
| 9 9 | 
             
            require 'socket'
         | 
| 10 10 | 
             
            require 'ipaddr'
         | 
| 11 | 
            +
            require 'yaml'
         | 
| 11 12 |  | 
| 12 13 | 
             
            module NServer
         | 
| 13 | 
            -
              VERSION = '1.1. | 
| 14 | 
            +
              VERSION = '1.1.3'
         | 
| 14 15 | 
             
              class Server < GServer
         | 
| 15 16 | 
             
                # Create a NServer::Server instance
         | 
| 16 17 | 
             
                #
         | 
| @@ -52,17 +53,17 @@ module NServer | |
| 52 53 | 
             
                  @allowed_clients = opts[:allow]
         | 
| 53 54 |  | 
| 54 55 | 
             
                  Notify.init("Notification Server")
         | 
| 55 | 
            -
                  tray_icon = Gtk::StatusIcon.new
         | 
| 56 | 
            -
                  tray_icon.icon_name = opts[:tray_icon]
         | 
| 56 | 
            +
                  @tray_icon = Gtk::StatusIcon.new
         | 
| 57 | 
            +
                  @tray_icon.icon_name = opts[:tray_icon]
         | 
| 57 58 | 
             
                  #tray_icon.file = File.join( File.dirname(__FILE__), 'icons', 'default.png')
         | 
| 58 | 
            -
                  tray_icon.tooltip = "NServer"
         | 
| 59 | 
            +
                  @tray_icon.tooltip = "NServer"
         | 
| 59 60 |  | 
| 60 | 
            -
                  @notification = Notify::Notification::new("X", nil, nil, tray_icon)
         | 
| 61 | 
            +
                  @notification = Notify::Notification::new("X", nil, nil, @tray_icon)
         | 
| 61 62 | 
             
                  @notification.timeout = opts[:msg_timeout]
         | 
| 62 63 |  | 
| 63 64 | 
             
                  Thread.new { Gtk.main }
         | 
| 64 65 | 
             
                  sleep 5
         | 
| 65 | 
            -
                  tray_icon.embedded? || raise("Failed to setup tray icon.")
         | 
| 66 | 
            +
                  @tray_icon.embedded? || raise("Failed to setup tray icon.")
         | 
| 66 67 |  | 
| 67 68 | 
             
                  ## Setup msg thread
         | 
| 68 69 | 
             
                  @msg_thread = Thread.new(self, @check_interval) do |server, intv|
         | 
| @@ -75,8 +76,9 @@ module NServer | |
| 75 76 |  | 
| 76 77 | 
             
                # Display the message
         | 
| 77 78 | 
             
                def notify(msg)
         | 
| 78 | 
            -
                  @notification.update("Message Received", msg.text, nil)
         | 
| 79 | 
            +
                  @notification.update((msg.title or "Message Received"), msg.text, nil)
         | 
| 79 80 | 
             
                  @notification.urgency = msg.priority
         | 
| 81 | 
            +
                  #@tray_icon.tooltip = msg.title
         | 
| 80 82 | 
             
                  @notification.show
         | 
| 81 83 | 
             
                end
         | 
| 82 84 |  | 
| @@ -85,6 +87,11 @@ module NServer | |
| 85 87 | 
             
                  @msg_list << Message.new(msg, priority)
         | 
| 86 88 | 
             
                end
         | 
| 87 89 |  | 
| 90 | 
            +
                # Add an actual message object
         | 
| 91 | 
            +
                def add_message_obj(msg)
         | 
| 92 | 
            +
                  @msg_list << msg
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
             | 
| 88 95 | 
             
                # Display the next message, if any.
         | 
| 89 96 | 
             
                def process
         | 
| 90 97 | 
             
                  if @msg_list.size > 0
         | 
| @@ -113,6 +120,11 @@ module NServer | |
| 113 120 | 
             
                  if msg == "EXITNOW"
         | 
| 114 121 | 
             
                    notify("Shutting down.")
         | 
| 115 122 | 
             
                    self.shutdown
         | 
| 123 | 
            +
                  elsif msg =~ /^--- !ruby\/object:NServer::Message/
         | 
| 124 | 
            +
                    ## Yaml message?
         | 
| 125 | 
            +
                    m = YAML.load( msg )
         | 
| 126 | 
            +
                    add_message_obj(m)
         | 
| 127 | 
            +
                    io.puts "OK"
         | 
| 116 128 | 
             
                  else
         | 
| 117 129 | 
             
                    priority = :normal
         | 
| 118 130 | 
             
                    if msg =~ /^(.*?):/
         | 
| @@ -150,12 +162,18 @@ module NServer | |
| 150 162 | 
             
                  @host_ip = ( opts[:host] or '127.0.0.1' )
         | 
| 151 163 | 
             
                  @host_port = ( opts[:port] or '10001' ).to_i
         | 
| 152 164 | 
             
                end
         | 
| 153 | 
            -
             | 
| 165 | 
            +
                
         | 
| 166 | 
            +
                # Send a notification.  If `msg` is a Message object, send it, and ignore
         | 
| 167 | 
            +
                # supplied priority
         | 
| 154 168 | 
             
                def notify( msg, priority = :normal )
         | 
| 155 169 | 
             
                  begin
         | 
| 156 170 | 
             
                    sock = TCPSocket.new(@host_ip, @host_port)
         | 
| 157 171 | 
             
                    sleep(0.1) ## Needs delay, or wait until prompt.
         | 
| 158 | 
            -
                     | 
| 172 | 
            +
                    if msg.is_a? NServer::Message
         | 
| 173 | 
            +
                      sock.write( msg.to_yaml + "\n.\n" )
         | 
| 174 | 
            +
                    else
         | 
| 175 | 
            +
                      sock.write("#{priority.to_s.upcase}:#{msg}\n.\n")
         | 
| 176 | 
            +
                    end
         | 
| 159 177 | 
             
                    sock.close
         | 
| 160 178 | 
             
                  rescue Errno::ECONNREFUSED
         | 
| 161 179 | 
             
                    raise NoServerAvailable.new
         | 
| @@ -207,11 +225,13 @@ module NServer | |
| 207 225 | 
             
                PRIORITIES = [:low, :normal, :critical]
         | 
| 208 226 |  | 
| 209 227 | 
             
                attr :text, :writable => true
         | 
| 228 | 
            +
                attr :title, :writable => true
         | 
| 210 229 | 
             
                attr :priority, :writable => true
         | 
| 211 230 |  | 
| 212 | 
            -
                def initialize( text = "", priority = :normal )
         | 
| 231 | 
            +
                def initialize( text = "", priority = :normal, title = nil )
         | 
| 213 232 | 
             
                  @text = text
         | 
| 214 233 | 
             
                  @priority = ( PRIORITIES.index( priority ) or 1 )
         | 
| 234 | 
            +
                  @title = title
         | 
| 215 235 | 
             
                end
         | 
| 216 236 | 
             
              end
         | 
| 217 237 |  | 
    
        metadata
    CHANGED
    
    | @@ -3,8 +3,8 @@ rubygems_version: 0.9.4.5 | |
| 3 3 | 
             
            specification_version: 2
         | 
| 4 4 | 
             
            name: nserver
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 1.1. | 
| 7 | 
            -
            date: 2007-11- | 
| 6 | 
            +
              version: 1.1.3
         | 
| 7 | 
            +
            date: 2007-11-10 00:00:00 -05:00
         | 
| 8 8 | 
             
            summary: Notification server for ruby using libnotify
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib
         |