Class: XscreenUsbUnlocker::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/xscreen_usb_unlocker/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

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

Returns the value of attribute banner.



6
7
8
# File 'lib/xscreen_usb_unlocker/app.rb', line 6

def banner
  @banner
end

#long_descriptionObject

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

#pluginsObject

Returns the value of attribute plugins.



8
9
10
# File 'lib/xscreen_usb_unlocker/app.rb', line 8

def plugins
  @plugins
end

#versionObject

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_dirObject



16
17
18
# File 'lib/xscreen_usb_unlocker/app.rb', line 16

def cache_dir
  "#{Dir.home}/.cache/erniebrodeur/#{App.name}/"
end

#config_dirObject



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_daemonObject



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

#nameObject

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

#pidsObject



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