Class: XscreenUsbUnlocker::Application
- Inherits:
-
Object
- Object
- XscreenUsbUnlocker::Application
- Defined in:
- lib/xscreen_usb_unlocker/app.rb
Instance Attribute Summary collapse
-
#banner ⇒ Object
Returns the value of attribute banner.
-
#long_description ⇒ Object
Returns the value of attribute long_description.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #config_dir ⇒ Object
- #daemonize(*params, &block) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #kill_daemon ⇒ Object
-
#name ⇒ Object
return the name of the app, for now this is just the cmd ran, later it will be something generated but more unique.
- #pids ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
31 32 33 34 35 36 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 31 def initialize @version = '0.0.0' @banner = 'A bin snippet by Ernie Brodeur that does . . . something.' @long_description = '' @plugins = [] end |
Instance Attribute Details
#banner ⇒ Object
Returns the value of attribute banner.
6 7 8 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 6 def @banner end |
#long_description ⇒ Object
Returns the value of attribute long_description.
7 8 9 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 7 def long_description @long_description end |
#plugins ⇒ Object
Returns the value of attribute plugins.
8 9 10 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 8 def plugins @plugins end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 5 def version @version end |
Instance Method Details
#cache_dir ⇒ Object
16 17 18 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 16 def cache_dir "#{Dir.home}/.cache/erniebrodeur/#{App.name}/" end |
#config_dir ⇒ Object
20 21 22 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 20 def config_dir "#{Dir.home}/.config/erniebrodeur/#{App.name}/" end |
#daemonize(*params, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 38 def daemonize(*params, &block) if params[0] && !params[0][:multiple_pids] && pids puts_or_log :info, "#{App.name} appears to be running (#{pids}), only one allowed, exiting." exit end puts_or_log :info, "Forking to background." Process.daemon block.call end |
#kill_daemon ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 49 def kill_daemon if !pids puts_or_log :fatal, "No pids found, exiting." end pids.each do |p| puts_or_log :info, "Killing #{p}" `kill -TERM #{p}` end end |
#name ⇒ Object
return the name of the app, for now this is just the cmd ran, later it will be something generated but more unique.
12 13 14 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 12 def name $0.split("/").last end |
#pids ⇒ Object
24 25 26 27 28 29 |
# File 'lib/xscreen_usb_unlocker/app.rb', line 24 def pids a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{App.name}.*-[dD].*/}.map {|x| x.pid} a.delete $$ return a if a.any? nil end |