lib/launchy/spawnable/application.rb in launchy-0.1.2 vs lib/launchy/spawnable/application.rb in launchy-0.2.0
- old
+ new
@@ -14,67 +14,115 @@
def application_classes
@application_classes ||= []
end
def find_application_class_for(*args)
- application_classes.find { |klass| klass.handle?(*args) }
+ Launchy.log "finding application classes for [#{args.join(' ')}]"
+ application_classes.find do |klass|
+ if klass.handle?(*args) then
+ Launchy.log " #{klass.name}"
+ true
+ else
+ false
+ end
+ end
end
+
+ # Determine the appropriate desktop environment for *nix machine. Currently this is
+ # linux centric. The detection is based upon the detection used by xdg-open from
+ # http://portland.freedesktop.org/wiki/XdgUtils
+ def nix_desktop_environment
+ de = :generic
+ if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then
+ de = :kde
+ elsif ENV["GNOME_DESKTOP_SESSION_ID"] then
+ de = :gnome
+ elsif find_executable("xprop") then
+ if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then
+ de = :xfce
+ end
+ end
+ Launchy.log "nix_desktop_environment => #{de}"
+ return de
+ end
+
+ # find an executable in the available paths
+ # mkrf did such a good job on this I had to borrow it.
+ def find_executable(bin,*paths)
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
+ paths.each do |path|
+ file = File.join(path,bin)
+ if File.executable?(file) then
+ Launchy.log "found executable #{file}"
+ return file
+ end
+ end
+ Launchy.log "Unable to find `#{bin}' in paths #{paths.join(', ')}"
+ return nil
+ end
+
+ # return the current 'host_os' string from ruby's configuration
+ def my_os
+ ::Config::CONFIG['host_os']
+ end
+
+ # detect what the current os is and return :windows, :darwin or :nix
+ def my_os_family(test_os = my_os)
+ case test_os
+ when /mswin/i
+ family = :windows
+ when /windows/i
+ family = :windows
+ when /darwin/i
+ family = :darwin
+ when /mac os/i
+ family = :darwin
+ when /solaris/i
+ family = :nix
+ when /bsd/i
+ family = :nix
+ when /linux/i
+ family = :nix
+ when /cygwin/i
+ family = :nix
+ else
+ $stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug to #{Launchy::SPEC.email}"
+ family = :unknown
+ end
+ end
end
# find an executable in the available paths
- # mkrf did such a good job on this I had to borrow it.
def find_executable(bin,*paths)
- paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
- paths.each do |path|
- file = File.join(path,bin)
- return file if File.executable?(file)
- end
- return nil
+ Application.find_executable(bin,*paths)
end
# return the current 'host_os' string from ruby's configuration
def my_os
- ::Config::CONFIG['host_os']
+ Application.my_os
end
- # detect what the current os is and return :windows, :darwin, :nix or :java
+ # detect what the current os is and return :windows, :darwin or :nix
def my_os_family(test_os = my_os)
- case test_os
- when /mswin/i
- family = :windows
- when /windows/i
- family = :windows
- when /darwin/i
- family = :darwin
- when /mac os/i
- family = :darwin
- when /solaris/i
- family = :nix
- when /bsd/i
- family = :nix
- when /linux/i
- family = :nix
- when /cygwin/i
- family = :nix
- else
- $stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug."
- family = :unknown
- end
+ Application.my_os_family(test_os)
end
# run the command
def run(cmd,*args)
args.unshift(cmd)
+ cmd_line = args.join(' ')
+ Launchy.log "Spawning on #{my_os_family} : #{cmd_line}"
if my_os_family == :windows then
- require 'win32/process'
+ system cmd_line
+ else
+ # fork and the child process should NOT run any exit handlers
+ child_pid = fork do
+ cmd_line += " > /dev/null 2>&1"
+ system cmd_line
+ exit!
+ end
+ Process.detach(child_pid)
end
- # fork and the child process should NOT run any exit handlers
- child_pid = fork do
- system args.join(' ')
- exit!
- end
- Process.detach(child_pid)
end
end
end
end
-