Class: PasteHub::NotificationCenter

Inherits:
PluginBase show all
Defined in:
lib/pastehub/plugin/notification_center.rb

Instance Method Summary collapse

Constructor Details

#initializeNotificationCenter



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pastehub/plugin/notification_center.rb', line 39

def initialize()
  @enable = false
  case RbConfig::CONFIG['host_os']
  when /^darwin/
    # MacOS X
    @notifier_path = RbConfig::CONFIG['bindir'] + "/" + "terminal-notifier"
    if File.exist?( @notifier_path )
      @enable = true
    end
  end
end

Instance Method Details

#display_configObject



51
52
53
54
55
# File 'lib/pastehub/plugin/notification_center.rb', line 51

def display_config
  if @enable
    STDERR.puts( "Info: found terminal-notifier for MacOS X." )
  end
end

#newly_arrived(message) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pastehub/plugin/notification_center.rb', line 57

def newly_arrived(message)
  config = PasteHub::Config.instance
  if @enable
    str = if config.notifyMessageMax < message.size
            message[0...config.notifyMessageMax] + " ..."
          else
            message
          end
    url_option = ''
    util = PasteHub::Util.new
    if util.pulloutURL( str )
      url_option = '-open \'' + util.pulloutURL( str ) + '\''
    end
    command = sprintf( "%s -title 'PasteHub' -message '\\%s' %s", @notifier_path, str, url_option )
    system( command )
  end
  nil
end