launchy 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/README +7 -6
- data/lib/launchy.rb +8 -0
- data/lib/launchy/gemspec.rb +9 -13
- data/lib/launchy/spawnable/application.rb +87 -39
- data/lib/launchy/spawnable/browser.rb +49 -9
- data/lib/launchy/version.rb +2 -2
- data/spec/spawnable_application_spec.rb +1 -1
- metadata +3 -3
data/CHANGES
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
== Changelog
|
2
2
|
|
3
|
+
=== Version 0.2.0 - 2007-08-11
|
4
|
+
|
5
|
+
* rework browser finding
|
6
|
+
** manual override with LAUNCHY_BROWSER environment variable
|
7
|
+
** on *nix use desktop application launcher with fallback to list of browsers
|
8
|
+
* On windows, switch to 'start' command and remove dependency on win32-process
|
9
|
+
* removed win32 gem
|
10
|
+
* Add debug output by setting LAUNCHY_DEBUG environment variable to 'true'
|
11
|
+
|
3
12
|
=== Version 0.1.2 - 2007-08-11
|
4
13
|
|
5
14
|
* forked child exits without calling at_exit handlers
|
data/README
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
== launchy
|
2
2
|
|
3
|
-
* Homepage[http://copiousfreetime.rubyforge.org/
|
3
|
+
* Homepage[http://copiousfreetime.rubyforge.org/launchy/]
|
4
4
|
* {Rubyforge Project}[http://rubyforge.org/projects/copiousfreetime]
|
5
5
|
* email jeremy at hinegardner dot org
|
6
6
|
|
7
7
|
== DESCRIPTION
|
8
8
|
|
9
|
-
Launchy is helper class for launching
|
9
|
+
Launchy is helper class for launching cross-platform applications in a
|
10
|
+
fire and forget manner.
|
10
11
|
|
11
|
-
There are application concepts (browser, email client, etc) that are
|
12
|
-
|
13
|
-
|
14
|
-
application
|
12
|
+
There are application concepts (browser, email client, etc) that are common
|
13
|
+
across all platforms, and they may be launched differently on each
|
14
|
+
platform. Launchy is here to make a common approach to launching
|
15
|
+
external application from within ruby programs.
|
15
16
|
|
16
17
|
== FEATURES
|
17
18
|
|
data/lib/launchy.rb
CHANGED
@@ -29,6 +29,14 @@ module Launchy
|
|
29
29
|
$stderr.puts "Unable to launch #{params.join(' ')}"
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
# Setting the LAUNCHY_DEBUG environment variable to 'true' will spew
|
34
|
+
# debug information to $stderr
|
35
|
+
def log(msg)
|
36
|
+
if ENV['LAUNCHY_DEBUG'] == 'true' then
|
37
|
+
$stderr.puts "LAUNCHY_DEBUG: #{msg}"
|
38
|
+
end
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
data/lib/launchy/gemspec.rb
CHANGED
@@ -11,18 +11,18 @@ module Launchy
|
|
11
11
|
spec.rubyforge_project = "copiousfreetime"
|
12
12
|
spec.author = "Jeremy Hinegardner"
|
13
13
|
spec.email = "jeremy@hinegardner.org"
|
14
|
-
spec.homepage = "http://
|
14
|
+
spec.homepage = "http://copiousfreetime.rubyforge.org/launchy/"
|
15
15
|
|
16
16
|
spec.summary = "A helper to launch apps from within ruby programs."
|
17
17
|
spec.description = <<-DESC
|
18
|
-
Launchy is helper class for launching
|
19
|
-
|
20
|
-
|
21
|
-
There are application concepts (browser, email client,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
Launchy is helper class for launching cross-platform applications in a
|
19
|
+
fire and forget manner.
|
20
|
+
|
21
|
+
There are application concepts (browser, email client, etc) that are common
|
22
|
+
across all platforms, and they may be launched differently on each
|
23
|
+
platform. Launchy is here to make a common approach to launching
|
24
|
+
external application from within ruby programs.
|
25
|
+
|
26
26
|
DESC
|
27
27
|
|
28
28
|
spec.extra_rdoc_files = FileList["CHANGES", "LICENSE", "README"]
|
@@ -48,10 +48,6 @@ module Launchy
|
|
48
48
|
spec.remote_site_dir = "#{spec.name}/"
|
49
49
|
|
50
50
|
end
|
51
|
-
|
52
|
-
SPEC_WIN32 = SPEC.dup
|
53
|
-
SPEC_WIN32.add_dependency("win32-process")
|
54
|
-
SPEC_WIN32.platform = Gem::Platform::WIN32
|
55
51
|
end
|
56
52
|
|
57
53
|
|
@@ -16,65 +16,113 @@ module Launchy
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def find_application_class_for(*args)
|
19
|
-
|
19
|
+
Launchy.log "finding application classes for [#{args.join(' ')}]"
|
20
|
+
application_classes.find do |klass|
|
21
|
+
if klass.handle?(*args) then
|
22
|
+
Launchy.log " #{klass.name}"
|
23
|
+
true
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Determine the appropriate desktop environment for *nix machine. Currently this is
|
31
|
+
# linux centric. The detection is based upon the detection used by xdg-open from
|
32
|
+
# http://portland.freedesktop.org/wiki/XdgUtils
|
33
|
+
def nix_desktop_environment
|
34
|
+
de = :generic
|
35
|
+
if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then
|
36
|
+
de = :kde
|
37
|
+
elsif ENV["GNOME_DESKTOP_SESSION_ID"] then
|
38
|
+
de = :gnome
|
39
|
+
elsif find_executable("xprop") then
|
40
|
+
if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then
|
41
|
+
de = :xfce
|
42
|
+
end
|
43
|
+
end
|
44
|
+
Launchy.log "nix_desktop_environment => #{de}"
|
45
|
+
return de
|
46
|
+
end
|
47
|
+
|
48
|
+
# find an executable in the available paths
|
49
|
+
# mkrf did such a good job on this I had to borrow it.
|
50
|
+
def find_executable(bin,*paths)
|
51
|
+
paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
|
52
|
+
paths.each do |path|
|
53
|
+
file = File.join(path,bin)
|
54
|
+
if File.executable?(file) then
|
55
|
+
Launchy.log "found executable #{file}"
|
56
|
+
return file
|
57
|
+
end
|
58
|
+
end
|
59
|
+
Launchy.log "Unable to find `#{bin}' in paths #{paths.join(', ')}"
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# return the current 'host_os' string from ruby's configuration
|
64
|
+
def my_os
|
65
|
+
::Config::CONFIG['host_os']
|
66
|
+
end
|
67
|
+
|
68
|
+
# detect what the current os is and return :windows, :darwin or :nix
|
69
|
+
def my_os_family(test_os = my_os)
|
70
|
+
case test_os
|
71
|
+
when /mswin/i
|
72
|
+
family = :windows
|
73
|
+
when /windows/i
|
74
|
+
family = :windows
|
75
|
+
when /darwin/i
|
76
|
+
family = :darwin
|
77
|
+
when /mac os/i
|
78
|
+
family = :darwin
|
79
|
+
when /solaris/i
|
80
|
+
family = :nix
|
81
|
+
when /bsd/i
|
82
|
+
family = :nix
|
83
|
+
when /linux/i
|
84
|
+
family = :nix
|
85
|
+
when /cygwin/i
|
86
|
+
family = :nix
|
87
|
+
else
|
88
|
+
$stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug to #{Launchy::SPEC.email}"
|
89
|
+
family = :unknown
|
90
|
+
end
|
20
91
|
end
|
21
92
|
end
|
22
93
|
|
23
94
|
# find an executable in the available paths
|
24
|
-
# mkrf did such a good job on this I had to borrow it.
|
25
95
|
def find_executable(bin,*paths)
|
26
|
-
|
27
|
-
paths.each do |path|
|
28
|
-
file = File.join(path,bin)
|
29
|
-
return file if File.executable?(file)
|
30
|
-
end
|
31
|
-
return nil
|
96
|
+
Application.find_executable(bin,*paths)
|
32
97
|
end
|
33
98
|
|
34
99
|
# return the current 'host_os' string from ruby's configuration
|
35
100
|
def my_os
|
36
|
-
|
101
|
+
Application.my_os
|
37
102
|
end
|
38
103
|
|
39
|
-
# detect what the current os is and return :windows, :darwin
|
104
|
+
# detect what the current os is and return :windows, :darwin or :nix
|
40
105
|
def my_os_family(test_os = my_os)
|
41
|
-
|
42
|
-
when /mswin/i
|
43
|
-
family = :windows
|
44
|
-
when /windows/i
|
45
|
-
family = :windows
|
46
|
-
when /darwin/i
|
47
|
-
family = :darwin
|
48
|
-
when /mac os/i
|
49
|
-
family = :darwin
|
50
|
-
when /solaris/i
|
51
|
-
family = :nix
|
52
|
-
when /bsd/i
|
53
|
-
family = :nix
|
54
|
-
when /linux/i
|
55
|
-
family = :nix
|
56
|
-
when /cygwin/i
|
57
|
-
family = :nix
|
58
|
-
else
|
59
|
-
$stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug."
|
60
|
-
family = :unknown
|
61
|
-
end
|
106
|
+
Application.my_os_family(test_os)
|
62
107
|
end
|
63
108
|
|
64
109
|
# run the command
|
65
110
|
def run(cmd,*args)
|
66
111
|
args.unshift(cmd)
|
112
|
+
cmd_line = args.join(' ')
|
113
|
+
Launchy.log "Spawning on #{my_os_family} : #{cmd_line}"
|
67
114
|
if my_os_family == :windows then
|
68
|
-
|
115
|
+
system cmd_line
|
116
|
+
else
|
117
|
+
# fork and the child process should NOT run any exit handlers
|
118
|
+
child_pid = fork do
|
119
|
+
cmd_line += " > /dev/null 2>&1"
|
120
|
+
system cmd_line
|
121
|
+
exit!
|
122
|
+
end
|
123
|
+
Process.detach(child_pid)
|
69
124
|
end
|
70
|
-
# fork and the child process should NOT run any exit handlers
|
71
|
-
child_pid = fork do
|
72
|
-
system args.join(' ')
|
73
|
-
exit!
|
74
|
-
end
|
75
|
-
Process.detach(child_pid)
|
76
125
|
end
|
77
126
|
end
|
78
127
|
end
|
79
128
|
end
|
80
|
-
|
@@ -4,12 +4,16 @@ require 'uri'
|
|
4
4
|
module Launchy
|
5
5
|
module Spawnable
|
6
6
|
class Browser < Application
|
7
|
-
|
8
|
-
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
|
7
|
+
|
8
|
+
DESKTOP_ENVIRONMENT_BROWSER_LAUNCHERS = {
|
9
|
+
:kde => "kfmclient",
|
10
|
+
:gnome => "gnome-open",
|
11
|
+
:xfce => "exo-open",
|
12
|
+
:generic => "htmlview"
|
13
|
+
}
|
14
|
+
|
15
|
+
FALLBACK_BROWSERS = %w[ firefox seamonkey opera mozilla netscape galeon ]
|
16
|
+
|
13
17
|
class << self
|
14
18
|
def run(*args)
|
15
19
|
Browser.new.visit(args[0])
|
@@ -24,12 +28,36 @@ module Launchy
|
|
24
28
|
return false
|
25
29
|
end
|
26
30
|
end
|
31
|
+
|
32
|
+
# Find a list of potential browser applications to run on *nix machines.
|
33
|
+
# The order is:
|
34
|
+
# 1) What is in ENV['LAUNCHY_BROWSER'] or ENV['BROWSER']
|
35
|
+
# 2) xdg-open
|
36
|
+
# 3) desktop environment launcher program
|
37
|
+
# 4) a list of fallback browsers
|
38
|
+
def nix_app_list
|
39
|
+
browser_cmds = ['xdg-open']
|
40
|
+
browser_cmds << DESKTOP_ENVIRONMENT_BROWSER_LAUNCHERS[nix_desktop_environment]
|
41
|
+
browser_cmds << FALLBACK_BROWSERS
|
42
|
+
browser_cmds.flatten!
|
43
|
+
browser_cmds.delete_if { |b| b.nil? || (b.strip.size == 0) }
|
44
|
+
Launchy.log "*Nix Browser List: #{browser_cmds.join(', ')}"
|
45
|
+
browser_cmds
|
46
|
+
end
|
47
|
+
|
27
48
|
end
|
28
49
|
|
50
|
+
APP_LIST = {
|
51
|
+
:windows => %w[ start ],
|
52
|
+
:darwin => %w[ open ],
|
53
|
+
:nix => nix_app_list,
|
54
|
+
:unknown => [],
|
55
|
+
}
|
56
|
+
|
29
57
|
def initialize
|
30
58
|
raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser
|
31
59
|
end
|
32
|
-
|
60
|
+
|
33
61
|
# returns the list of command line application names for the current os
|
34
62
|
def app_list
|
35
63
|
APP_LIST[my_os_family]
|
@@ -37,7 +65,19 @@ module Launchy
|
|
37
65
|
|
38
66
|
# return the full command line path to the browser or nil
|
39
67
|
def browser
|
40
|
-
@browser
|
68
|
+
if not @browser then
|
69
|
+
if ENV['LAUNCHY_BROWSER'] and File.exists?(ENV['LAUNCHY_BROWSER']) then
|
70
|
+
Launchy.log "Using LAUNCHY_BROWSER environment variable : #{ENV['LAUNCHY_BROWSER']}"
|
71
|
+
@browser = ENV['LAUNCHY_BROWSER']
|
72
|
+
elsif ENV['BROWSER'] and File.exists?(ENV['BROWSER']) then
|
73
|
+
Launchy.log "Using BROWSER environment variable : #{ENV['BROWSER']}"
|
74
|
+
@browser = ENV['BROWSER']
|
75
|
+
else
|
76
|
+
@browser = app_list.collect { |bin| find_executable(bin) }.find { |x| not x.nil? }
|
77
|
+
Launchy.log "Using application list : #{@browser}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
return @browser
|
41
81
|
end
|
42
82
|
|
43
83
|
# launch the browser at the appointed url
|
@@ -47,4 +87,4 @@ module Launchy
|
|
47
87
|
|
48
88
|
end
|
49
89
|
end
|
50
|
-
end
|
90
|
+
end
|
data/lib/launchy/version.rb
CHANGED
@@ -33,6 +33,6 @@ describe Launchy::Spawnable::Application do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should find the correct class to launch an ftp url" do
|
36
|
-
Launchy::Spawnable::Application.find_application_class_for("ftp://
|
36
|
+
Launchy::Spawnable::Application.find_application_class_for("ftp://ftp.ruby-lang.org/pub/ruby/").should == Launchy::Spawnable::Browser
|
37
37
|
end
|
38
38
|
end
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: launchy
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
6
|
+
version: 0.2.0
|
7
7
|
date: 2007-08-12 00:00:00 -06:00
|
8
8
|
summary: A helper to launch apps from within ruby programs.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: jeremy@hinegardner.org
|
12
|
-
homepage: http://
|
12
|
+
homepage: http://copiousfreetime.rubyforge.org/launchy/
|
13
13
|
rubyforge_project: copiousfreetime
|
14
|
-
description: Launchy is helper class for launching
|
14
|
+
description: Launchy is helper class for launching cross-platform applications in a fire and forget manner. There are application concepts (browser, email client, etc) that are common across all platforms, and they may be launched differently on each platform. Launchy is here to make a common approach to launching external application from within ruby programs.
|
15
15
|
autorequire:
|
16
16
|
default_executable: launchy
|
17
17
|
bindir: bin
|