| Class | Launchy::Browser |
| In: |
lib/launchy/browser.rb
lib/launchy/browser.rb |
| Parent: | Application |
# File lib/launchy/browser.rb, line 9
9: def desktop_environment_browser_launchers
10: @desktop_environment_browser_launchers ||= {
11: :kde => "kfmclient",
12: :gnome => "gnome-open",
13: :xfce => "exo-open",
14: :generic => "htmlview"
15: }
16: end
# File lib/launchy/browser.rb, line 9
9: def desktop_environment_browser_launchers
10: @desktop_environment_browser_launchers ||= {
11: :kde => "kfmclient",
12: :gnome => "gnome-open",
13: :xfce => "exo-open",
14: :generic => "htmlview"
15: }
16: end
# File lib/launchy/browser.rb, line 17
17: def fallback_browsers
18: @fallback_browsers ||= %w[ firefox seamonkey opera mozilla netscape galeon ]
19: end
# File lib/launchy/browser.rb, line 17
17: def fallback_browsers
18: @fallback_browsers ||= %w[ firefox seamonkey opera mozilla netscape galeon ]
19: end
return true if this class can handle the given parameter(s)
# File lib/launchy/browser.rb, line 25
25: def handle?(*args)
26: begin
27: Launchy.log "#{self.name} : testing if [#{args[0]}] (#{args[0].class}) is a url."
28: uri = URI.parse(args[0])
29: result = %w[http https ftp file].include?(uri.scheme)
30: rescue Exception => e
31: # hmm... why does rcov not see that this is executed ?
32: Launchy.log "#{self.name} : not a url, #{e}"
33: return false
34: end
35: end
return true if this class can handle the given parameter(s)
# File lib/launchy/browser.rb, line 25
25: def handle?(*args)
26: begin
27: Launchy.log "#{self.name} : testing if [#{args[0]}] (#{args[0].class}) is a url."
28: uri = URI.parse(args[0])
29: result = %w[http https ftp file].include?(uri.scheme)
30: rescue Exception => e
31: # hmm... why does rcov not see that this is executed ?
32: Launchy.log "#{self.name} : not a url, #{e}"
33: return false
34: end
35: end
# File lib/launchy/browser.rb, line 38
38: def initialize
39: @browser = nil
40: @nix_app_list = []
41: raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser
42: end
# File lib/launchy/browser.rb, line 38
38: def initialize
39: @browser = nil
40: @nix_app_list = []
41: raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser
42: end
return the full command line path to the browser or nil
# File lib/launchy/browser.rb, line 73
73: def browser
74: if not @browser then
75: if ENV['LAUNCHY_BROWSER'] and File.exists?(ENV['LAUNCHY_BROWSER']) then
76: Launchy.log "#{self.class.name} : Using LAUNCHY_BROWSER environment variable : #{ENV['LAUNCHY_BROWSER']}"
77: @browser = ENV['LAUNCHY_BROWSER']
78: elsif ENV['BROWSER'] and File.exists?(ENV['BROWSER']) then
79: Launchy.log "#{self.class.name} : Using BROWSER environment variable : #{ENV['BROWSER']}"
80: @browser = ENV['BROWSER']
81: elsif app_list.size > 0 then
82: @browser = app_list.first
83: Launchy.log "#{self.class.name} : Using application list : #{@browser}"
84: else
85: msg = "Unable to launch. No Browser application found."
86: Launchy.log "#{self.class.name} : #{msg}"
87: $stderr.puts msg
88: end
89: end
90: return @browser
91: end
return the full command line path to the browser or nil
# File lib/launchy/browser.rb, line 73
73: def browser
74: if not @browser then
75: if ENV['LAUNCHY_BROWSER'] and File.exists?(ENV['LAUNCHY_BROWSER']) then
76: Launchy.log "#{self.class.name} : Using LAUNCHY_BROWSER environment variable : #{ENV['LAUNCHY_BROWSER']}"
77: @browser = ENV['LAUNCHY_BROWSER']
78: elsif ENV['BROWSER'] and File.exists?(ENV['BROWSER']) then
79: Launchy.log "#{self.class.name} : Using BROWSER environment variable : #{ENV['BROWSER']}"
80: @browser = ENV['BROWSER']
81: elsif app_list.size > 0 then
82: @browser = app_list.first
83: Launchy.log "#{self.class.name} : Using application list : #{@browser}"
84: else
85: msg = "Unable to launch. No Browser application found."
86: Launchy.log "#{self.class.name} : #{msg}"
87: $stderr.puts msg
88: end
89: end
90: return @browser
91: end
# File lib/launchy/browser.rb, line 44
44: def desktop_environment_browser_launchers
45: self.class.desktop_environment_browser_launchers
46: end
# File lib/launchy/browser.rb, line 44
44: def desktop_environment_browser_launchers
45: self.class.desktop_environment_browser_launchers
46: end
# File lib/launchy/browser.rb, line 48
48: def fallback_browsers
49: self.class.fallback_browsers
50: end
# File lib/launchy/browser.rb, line 48
48: def fallback_browsers
49: self.class.fallback_browsers
50: end
Find a list of potential browser applications to run on *nix machines. The order is:
1) What is in ENV['LAUNCHY_BROWSER'] or ENV['BROWSER']
2) xdg-open
3) desktop environment launcher program
4) a list of fallback browsers
# File lib/launchy/browser.rb, line 58
58: def nix_app_list
59: if @nix_app_list.empty?
60: browser_cmds = ['xdg-open']
61: browser_cmds << desktop_environment_browser_launchers[nix_desktop_environment]
62: browser_cmds << fallback_browsers
63: browser_cmds.flatten!
64: browser_cmds.delete_if { |b| b.nil? || (b.strip.size == 0) }
65: Launchy.log "#{self.class.name} : Initial *Nix Browser List: #{browser_cmds.join(', ')}"
66: @nix_app_list = browser_cmds.collect { |bin| find_executable(bin) }.find_all { |x| not x.nil? }
67: Launchy.log "#{self.class.name} : Filtered *Nix Browser List: #{@nix_app_list.join(', ')}"
68: end
69: @nix_app_list
70: end
Find a list of potential browser applications to run on *nix machines. The order is:
1) What is in ENV['LAUNCHY_BROWSER'] or ENV['BROWSER']
2) xdg-open
3) desktop environment launcher program
4) a list of fallback browsers
# File lib/launchy/browser.rb, line 58
58: def nix_app_list
59: if @nix_app_list.empty?
60: browser_cmds = ['xdg-open']
61: browser_cmds << desktop_environment_browser_launchers[nix_desktop_environment]
62: browser_cmds << fallback_browsers
63: browser_cmds.flatten!
64: browser_cmds.delete_if { |b| b.nil? || (b.strip.size == 0) }
65: Launchy.log "#{self.class.name} : Initial *Nix Browser List: #{browser_cmds.join(', ')}"
66: @nix_app_list = browser_cmds.collect { |bin| find_executable(bin) }.find_all { |x| not x.nil? }
67: Launchy.log "#{self.class.name} : Filtered *Nix Browser List: #{@nix_app_list.join(', ')}"
68: end
69: @nix_app_list
70: end