Class: Pushes::LaunchAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/pushes/launch_agent.rb

Constant Summary collapse

PLIST_NAME =
'ca.heliom.pushes.plist'
DESTINATION =
File.join(ENV['HOME'], 'Library', 'LaunchAgents')
PLIST_PATH =
File.join(DESTINATION, PLIST_NAME)
TEMPLATE_PATH =
File.join('../../..', 'files', "#{PLIST_NAME}.erb")

Instance Method Summary collapse

Instance Method Details

#start(start_interval) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pushes/launch_agent.rb', line 7

def start(start_interval)
  template_file = File.expand_path(TEMPLATE_PATH, __FILE__)
  template_content = File.read(template_file)
  plist_content = ERB.new(template_content).result(binding)

  File.open(PLIST_PATH, 'w+') do |f|
    f.write(plist_content)
  end

  `launchctl load #{PLIST_PATH}`
end

#stopObject



19
20
21
22
23
# File 'lib/pushes/launch_agent.rb', line 19

def stop
  return unless File.exist?(PLIST_PATH)
  `launchctl unload #{PLIST_PATH}`
  FileUtils.rm(PLIST_PATH)
end