Class: Launchy::Application::Browser

Inherits:
Launchy::Application show all
Defined in:
lib/launchy/applications/browser.rb

Overview

The class handling the browser application and all of its schemes

Instance Attribute Summary

Attributes inherited from Launchy::Application

#host_os_family, #ruby_engine, #runner

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Launchy::Application

find_executable, #find_executable, for_scheme, handles?, #initialize, #run, scheme_list

Methods included from DescendantTracker

#children, #find_child, #inherited

Constructor Details

This class inherits a constructor from Launchy::Application

Class Method Details

.schemesObject


6
7
8
# File 'lib/launchy/applications/browser.rb', line 6

def self.schemes
  %w[ http https ftp file ]
end

Instance Method Details

#app_listObject

use a call back mechanism to get the right app_list that is decided by the host_os_family class.


34
35
36
# File 'lib/launchy/applications/browser.rb', line 34

def app_list
  host_os_family.app_list( self )
end

#browserObject

Get the full commandline of what we are going to add the uri to


47
48
49
50
51
52
53
54
55
# File 'lib/launchy/applications/browser.rb', line 47

def browser
  possibilities = (browser_env + app_list).flatten
  possibilities.each do |p|
    Launchy.log "#{self.class.name} : possibility : #{p}"
  end
  b = possibilities.shift
  Launchy.log "#{self.class.name} : Using browser value '#{b}'"
  return b
end

#browser_envObject


38
39
40
41
42
43
44
# File 'lib/launchy/applications/browser.rb', line 38

def browser_env
  return [] unless ENV['BROWSER']
  browser_env = ENV['BROWSER'].split( File::PATH_SEPARATOR )
  browser_env.flatten!
  browser_env.delete_if { |b| b.nil? || (b.strip.size == 0) }
  return browser_env
end

#cygwin_app_listObject


14
15
16
# File 'lib/launchy/applications/browser.rb', line 14

def cygwin_app_list
  [ "cmd /C start 'launchy' /d" ]
end

#darwin_app_listObject


18
19
20
# File 'lib/launchy/applications/browser.rb', line 18

def darwin_app_list
  [ find_executable( "open" ) ]
end

#nix_app_listObject


22
23
24
25
26
27
28
29
30
# File 'lib/launchy/applications/browser.rb', line 22

def nix_app_list
  nix_de = Launchy::Detect::NixDekstopEnvironment.browser
  app_list = %w[ xdg-open ]
  app_list << nix_de.browser
  app_list << nix_de.fallback_browsers
  app_list.flatten!
  app_list.delete_if { |b| b.nil? || (b.strip.size == 0) }
  app_list.collect { |bin| find_executable( bin ) }.find_all { |x| not x.nil? }
end

#open(uri, options = {}) ⇒ Object

final assembly of the command and do %s substitution www.catb.org/~esr/BROWSER/index.html


59
60
61
62
63
64
65
66
# File 'lib/launchy/applications/browser.rb', line 59

def open( uri, options = {} )
  b = browser
  args = [ uri.to_s ]
  if b =~ /%s/ then
    b.gsub!( /%s/, args.shift )
  end
  run( b, args )
end

#windows_app_listObject


10
11
12
# File 'lib/launchy/applications/browser.rb', line 10

def windows_app_list
  [  'start "Launchy" /d']
end