launchy 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +8 -1
- data/Manifest.txt +3 -16
- data/exe/launchy +5 -0
- data/launchy.gemspec +32 -0
- data/lib/launchy/application.rb +24 -21
- data/lib/launchy/applications/browser.rb +68 -63
- data/lib/launchy/argv.rb +11 -6
- data/lib/launchy/cli.rb +29 -29
- data/lib/launchy/descendant_tracker.rb +14 -12
- data/lib/launchy/detect/host_os.rb +21 -18
- data/lib/launchy/detect/host_os_family.rb +94 -53
- data/lib/launchy/detect/nix_desktop_environment.rb +74 -69
- data/lib/launchy/detect.rb +7 -3
- data/lib/launchy/error.rb +2 -0
- data/lib/launchy/os_family.rb +2 -0
- data/lib/launchy/runner.rb +25 -17
- data/lib/launchy/version.rb +7 -5
- data/lib/launchy.rb +69 -65
- metadata +10 -103
- data/Rakefile +0 -29
- data/bin/launchy +0 -4
- data/spec/application_spec.rb +0 -43
- data/spec/applications/browser_spec.rb +0 -73
- data/spec/cli_spec.rb +0 -74
- data/spec/detect/host_os_family_spec.rb +0 -42
- data/spec/detect/host_os_spec.rb +0 -19
- data/spec/detect/nix_desktop_environment_spec.rb +0 -27
- data/spec/launchy_spec.rb +0 -142
- data/spec/mock_application.rb +0 -13
- data/spec/spec_helper.rb +0 -8
- data/spec/tattle-host-os.yaml +0 -427
- data/spec/version_spec.rb +0 -11
- data/tasks/default.rake +0 -250
- data/tasks/this.rb +0 -208
- /data/{LICENSE → LICENSE.txt} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7001cb9d1f872b482b6356d68289a022fdc12d57a128b1efe264e598d794d2a8
|
4
|
+
data.tar.gz: 0a76868c2abfc6da776b6d62c2d5be2ef1e872a37ffc244207030653aa16da9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34bb32f9dcedf678f7d22ac4dbb3febfb565609738f4150efb0000ca4b1867bdadd12b76cb1441c49d25015cfa43a9a651aa5f2a5bd2929468bb63822f4bf741
|
7
|
+
data.tar.gz: 462cce3f0d4c1239e16a3667428d0e54aedb7b5d0bcad9762ae8c3e65020882c45da1614882893af16b6db2dcf467782abc62a503d3d8ed6818c288aba6fdaea
|
data/HISTORY.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Launchy Changelog
|
2
|
+
## Version 3.0.1 - 2024-05-03
|
3
|
+
* Added rubocop and fix all the warnings
|
4
|
+
* Fix rubygem changelog_uri - Spone
|
5
|
+
* Update the semaphore flow
|
6
|
+
* Update the ruby test matrix
|
7
|
+
* Change to Gemfile for development
|
8
|
+
|
2
9
|
## Version 3.0.0 - 2024-03-03
|
3
10
|
* Remove unused `deprecated.rb` file - <https://github.com/copiousfreetime/launchy/issues/148>
|
4
|
-
* Update supported ruby
|
11
|
+
* Update supported ruby version to be 3.x
|
5
12
|
* use the `:application` parameter - <https://github.com/copiousfreetime/launchy/issues/121>
|
6
13
|
* adjust the semaphore configuration to allow better caching
|
7
14
|
* replace the homegrown process runner with [`childprocess`](https://rubygems.org/gems/childprocess)
|
data/Manifest.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
CONTRIBUTING.md
|
2
2
|
HISTORY.md
|
3
|
-
LICENSE
|
3
|
+
LICENSE.txt
|
4
4
|
Manifest.txt
|
5
5
|
README.md
|
6
|
-
|
7
|
-
|
6
|
+
exe/launchy
|
7
|
+
launchy.gemspec
|
8
8
|
lib/launchy.rb
|
9
9
|
lib/launchy/application.rb
|
10
10
|
lib/launchy/applications/browser.rb
|
@@ -19,16 +19,3 @@ lib/launchy/error.rb
|
|
19
19
|
lib/launchy/os_family.rb
|
20
20
|
lib/launchy/runner.rb
|
21
21
|
lib/launchy/version.rb
|
22
|
-
spec/application_spec.rb
|
23
|
-
spec/applications/browser_spec.rb
|
24
|
-
spec/cli_spec.rb
|
25
|
-
spec/detect/host_os_family_spec.rb
|
26
|
-
spec/detect/host_os_spec.rb
|
27
|
-
spec/detect/nix_desktop_environment_spec.rb
|
28
|
-
spec/launchy_spec.rb
|
29
|
-
spec/mock_application.rb
|
30
|
-
spec/spec_helper.rb
|
31
|
-
spec/tattle-host-os.yaml
|
32
|
-
spec/version_spec.rb
|
33
|
-
tasks/default.rake
|
34
|
-
tasks/this.rb
|
data/exe/launchy
ADDED
data/launchy.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# DO NOT EDIT - This file is automatically generated
|
2
|
+
# Make changes to Manifest.txt and/or Rakefile and regenerate
|
3
|
+
# -*- encoding: utf-8 -*-
|
4
|
+
# stub: launchy 3.0.1 ruby lib
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "launchy".freeze
|
8
|
+
s.version = "3.0.1".freeze
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
11
|
+
s.metadata = { "bug_tracker_uri" => "https://github.com/copiousfreetime/launchy/issues", "changelog_uri" => "https://github.com/copiousfreetime/launchy/blob/master/HISTORY.md", "homepage_uri" => "https://github.com/copiousfreetime/launchy", "source_code_uri" => "https://github.com/copiousfreetime/launchy" } if s.respond_to? :metadata=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Jeremy Hinegardner".freeze]
|
14
|
+
s.bindir = "exe".freeze
|
15
|
+
s.date = "2024-05-03"
|
16
|
+
s.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 applications from within ruby programs.".freeze
|
17
|
+
s.email = "jeremy@copiousfreetime.org".freeze
|
18
|
+
s.executables = ["launchy".freeze]
|
19
|
+
s.extra_rdoc_files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze]
|
20
|
+
s.files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze, "exe/launchy".freeze, "launchy.gemspec".freeze, "lib/launchy.rb".freeze, "lib/launchy/application.rb".freeze, "lib/launchy/applications/browser.rb".freeze, "lib/launchy/argv.rb".freeze, "lib/launchy/cli.rb".freeze, "lib/launchy/descendant_tracker.rb".freeze, "lib/launchy/detect.rb".freeze, "lib/launchy/detect/host_os.rb".freeze, "lib/launchy/detect/host_os_family.rb".freeze, "lib/launchy/detect/nix_desktop_environment.rb".freeze, "lib/launchy/error.rb".freeze, "lib/launchy/os_family.rb".freeze, "lib/launchy/runner.rb".freeze, "lib/launchy/version.rb".freeze]
|
21
|
+
s.homepage = "https://github.com/copiousfreetime/launchy".freeze
|
22
|
+
s.licenses = ["ISC".freeze]
|
23
|
+
s.rdoc_options = ["--main".freeze, "README.md".freeze, "--markup".freeze, "tomdoc".freeze]
|
24
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze)
|
25
|
+
s.rubygems_version = "3.5.9".freeze
|
26
|
+
s.summary = "Launchy is helper class for launching cross-platform applications in a fire and forget manner.".freeze
|
27
|
+
|
28
|
+
s.specification_version = 4
|
29
|
+
|
30
|
+
s.add_runtime_dependency(%q<addressable>.freeze, ["~> 2.8".freeze])
|
31
|
+
s.add_runtime_dependency(%q<childprocess>.freeze, ["~> 5.0".freeze])
|
32
|
+
end
|
data/lib/launchy/application.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
2
4
|
module Launchy
|
3
5
|
#
|
4
6
|
# Application is the base class of all the application types that launchy may
|
@@ -18,60 +20,61 @@ module Launchy
|
|
18
20
|
# Find the application that handles the given uri.
|
19
21
|
#
|
20
22
|
# returns the Class that can handle the uri
|
21
|
-
def handling(
|
22
|
-
klass = find_child(
|
23
|
+
def handling(uri)
|
24
|
+
klass = find_child(:handles?, uri)
|
23
25
|
return klass if klass
|
26
|
+
|
24
27
|
raise ApplicationNotFoundError, "No application found to handle '#{uri}'"
|
25
28
|
end
|
26
29
|
|
27
30
|
# Find the application with the given name
|
28
31
|
#
|
29
32
|
# returns the Class that has the given name
|
30
|
-
def for_name(
|
31
|
-
klass = find_child(
|
33
|
+
def for_name(name)
|
34
|
+
klass = find_child(:has_name?, name)
|
32
35
|
return klass if klass
|
36
|
+
|
33
37
|
raise ApplicationNotFoundError, "No application found named '#{name}'"
|
34
38
|
end
|
35
39
|
|
36
40
|
# Find the given executable in the available paths
|
37
41
|
#
|
38
42
|
# returns the path to the executable or nil if not found
|
39
|
-
def find_executable(
|
40
|
-
paths = Launchy.path.split(
|
43
|
+
def find_executable(bin, *paths)
|
44
|
+
paths = Launchy.path.split(File::PATH_SEPARATOR) if paths.empty?
|
41
45
|
paths.each do |path|
|
42
|
-
file = File.join(
|
43
|
-
if File.executable?(
|
44
|
-
Launchy.log "#{
|
46
|
+
file = File.join(path, bin)
|
47
|
+
if File.executable?(file)
|
48
|
+
Launchy.log "#{name} : found executable #{file}"
|
45
49
|
return file
|
46
50
|
end
|
47
51
|
end
|
48
|
-
Launchy.log "#{
|
49
|
-
|
52
|
+
Launchy.log "#{name} : Unable to find `#{bin}' in #{paths.join(', ')}"
|
53
|
+
nil
|
50
54
|
end
|
51
55
|
|
52
56
|
# Does this class have the given name-like string?
|
53
57
|
#
|
54
58
|
# returns true if the class has the given name
|
55
|
-
def has_name?(
|
56
|
-
qname.to_s.downcase ==
|
59
|
+
def has_name?(qname)
|
60
|
+
qname.to_s.downcase == name.split("::").last.downcase
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
|
-
attr_reader :host_os_family
|
61
|
-
attr_reader :runner
|
64
|
+
attr_reader :host_os_family, :runner
|
62
65
|
|
63
66
|
def initialize
|
64
67
|
@host_os_family = Launchy::Detect::HostOsFamily.detect
|
65
68
|
@runner = Launchy::Runner.new
|
66
69
|
end
|
67
70
|
|
68
|
-
def find_executable(
|
69
|
-
Application.find_executable(
|
71
|
+
def find_executable(bin, *paths)
|
72
|
+
Application.find_executable(bin, *paths)
|
70
73
|
end
|
71
74
|
|
72
|
-
def run(
|
73
|
-
runner.run(
|
75
|
+
def run(cmd, *args)
|
76
|
+
runner.run(cmd, *args)
|
74
77
|
end
|
75
78
|
end
|
76
79
|
end
|
77
|
-
require
|
80
|
+
require "launchy/applications/browser"
|
@@ -1,82 +1,87 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# The class handling the browser application and all of its schemes
|
4
|
-
#
|
5
|
-
class Browser < Launchy::Application
|
6
|
-
def self.schemes
|
7
|
-
%w[ http https ftp file ]
|
8
|
-
end
|
1
|
+
# frozen_string_literal: true
|
9
2
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module Launchy
|
4
|
+
class Application
|
5
|
+
#
|
6
|
+
# The class handling the browser application and all of its schemes
|
7
|
+
#
|
8
|
+
class Browser < Launchy::Application
|
9
|
+
def self.schemes
|
10
|
+
%w[http https ftp file]
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
13
|
+
def self.handles?(uri)
|
14
|
+
return true if schemes.include?(uri.scheme)
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
true if File.exist?(uri.path)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
19
|
+
def windows_app_list
|
20
|
+
['start "launchy" /b']
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
list.find_all { |argv| argv.valid? }
|
32
|
-
end
|
23
|
+
def cygwin_app_list
|
24
|
+
['cmd /C start "launchy" /b']
|
25
|
+
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
27
|
+
# hardcode this to open?
|
28
|
+
def darwin_app_list
|
29
|
+
[find_executable("open")]
|
30
|
+
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
return browser_env
|
46
|
-
end
|
32
|
+
def nix_app_list
|
33
|
+
nix_de = Launchy::Detect::NixDesktopEnvironment.detect
|
34
|
+
list = nix_de.browsers
|
35
|
+
list.find_all(&:valid?)
|
36
|
+
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
# use a call back mechanism to get the right app_list that is decided by the
|
39
|
+
# host_os_family class.
|
40
|
+
def app_list
|
41
|
+
host_os_family.app_list(self)
|
52
42
|
end
|
53
|
-
|
54
|
-
|
43
|
+
|
44
|
+
def browser_env
|
45
|
+
return [] unless ENV["BROWSER"]
|
46
|
+
|
47
|
+
browser_env = ENV["BROWSER"].split(File::PATH_SEPARATOR)
|
48
|
+
browser_env.flatten!
|
49
|
+
browser_env.delete_if { |b| b.nil? || b.strip.empty? }
|
50
|
+
browser_env
|
55
51
|
end
|
56
52
|
|
57
|
-
|
53
|
+
# Get the full commandline of what we are going to add the uri to
|
54
|
+
def browser_cmdline
|
55
|
+
browser_env.each do |p|
|
56
|
+
Launchy.log "#{self.class.name} : possibility from BROWSER environment variable : #{p}"
|
57
|
+
end
|
58
|
+
app_list.each do |p|
|
59
|
+
Launchy.log "#{self.class.name} : possibility from app_list : #{p}"
|
60
|
+
end
|
61
|
+
|
62
|
+
possibilities = (browser_env + app_list).flatten
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
if (browser = possibilities.shift)
|
65
|
+
Launchy.log "#{self.class.name} : Using browser value '#{browser}'"
|
66
|
+
return browser
|
67
|
+
end
|
68
|
+
raise Launchy::CommandNotFoundError,
|
69
|
+
"Unable to find a browser command. If this is unexpected, #{Launchy.bug_report_message}"
|
62
70
|
end
|
63
|
-
raise Launchy::CommandNotFoundError, "Unable to find a browser command. If this is unexpected, #{Launchy.bug_report_message}"
|
64
|
-
end
|
65
71
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
cmd
|
72
|
+
def cmd_and_args(uri, _options = {})
|
73
|
+
cmd = browser_cmdline.to_s
|
74
|
+
args = [uri.to_s]
|
75
|
+
cmd.gsub!("%s", args.shift) if cmd.include?("%s")
|
76
|
+
[cmd, args]
|
71
77
|
end
|
72
|
-
[cmd, args]
|
73
|
-
end
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
# final assembly of the command and do %s substitution
|
80
|
+
# http://www.catb.org/~esr/BROWSER/index.html
|
81
|
+
def open(uri, options = {})
|
82
|
+
cmd, args = cmd_and_args(uri, options)
|
83
|
+
run(cmd, args)
|
84
|
+
end
|
80
85
|
end
|
81
86
|
end
|
82
87
|
end
|
data/lib/launchy/argv.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Launchy
|
4
|
+
# Internal: Ecapsulate the commandline argumens passed to Launchy
|
5
|
+
#
|
2
6
|
class Argv
|
3
7
|
attr_reader :argv
|
4
|
-
|
8
|
+
|
9
|
+
def initialize(*args)
|
5
10
|
@argv = args.flatten
|
6
11
|
end
|
7
12
|
|
8
13
|
def to_s
|
9
|
-
@argv.join(
|
14
|
+
@argv.join(" ")
|
10
15
|
end
|
11
16
|
|
12
17
|
def to_str
|
@@ -18,18 +23,18 @@ module Launchy
|
|
18
23
|
end
|
19
24
|
|
20
25
|
def valid?
|
21
|
-
|
26
|
+
!blank? && executable?
|
22
27
|
end
|
23
28
|
|
24
29
|
def blank?
|
25
|
-
@argv.empty? ||
|
30
|
+
@argv.empty? || @argv.first.strip.empty?
|
26
31
|
end
|
27
32
|
|
28
33
|
def executable?
|
29
|
-
::Launchy::Application.find_executable(
|
34
|
+
::Launchy::Application.find_executable(@argv.first)
|
30
35
|
end
|
31
36
|
|
32
|
-
def ==(
|
37
|
+
def ==(other)
|
33
38
|
@argv == other.argv
|
34
39
|
end
|
35
40
|
end
|
data/lib/launchy/cli.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
2
4
|
|
3
5
|
module Launchy
|
6
|
+
# Internal: Command line interface for Launchy
|
7
|
+
#
|
4
8
|
class Cli
|
5
|
-
|
6
9
|
attr_reader :options
|
10
|
+
|
7
11
|
def initialize
|
8
12
|
@options = {}
|
9
13
|
end
|
@@ -15,70 +19,66 @@ module Launchy
|
|
15
19
|
op.separator ""
|
16
20
|
op.separator "Launch Options:"
|
17
21
|
|
18
|
-
op.on(
|
19
|
-
|
22
|
+
op.on("-a", "--application APPLICATION",
|
23
|
+
"Explicitly specify the application class to use in the launch") do |app|
|
20
24
|
@options[:application] = app
|
21
25
|
end
|
22
26
|
|
23
|
-
op.on(
|
24
|
-
|
27
|
+
op.on("-d", "--debug",
|
28
|
+
"Force debug. Output lots of information.") do |_d|
|
25
29
|
@options[:debug] = true
|
26
30
|
end
|
27
31
|
|
28
|
-
op.on(
|
32
|
+
op.on("-n", "--dry-run", "Don't launchy, print the command to be executed on stdout") do |_x|
|
29
33
|
@options[:dry_run] = true
|
30
34
|
end
|
31
35
|
|
32
|
-
op.on(
|
33
|
-
|
36
|
+
op.on("-o", "--host-os HOST_OS",
|
37
|
+
"Force launchy to behave as if it was on a particular host os.") do |os|
|
34
38
|
@options[:host_os] = os
|
35
39
|
end
|
36
40
|
|
37
|
-
|
38
41
|
op.separator ""
|
39
42
|
op.separator "Standard Options:"
|
40
43
|
|
41
|
-
op.on(
|
44
|
+
op.on("-h", "--help", "Print this message.") do |_h|
|
42
45
|
$stdout.puts op.to_s
|
43
46
|
exit 0
|
44
47
|
end
|
45
48
|
|
46
|
-
op.on(
|
49
|
+
op.on("-v", "--version", "Output the version of Launchy") do |_v|
|
47
50
|
$stdout.puts "Launchy version #{Launchy::VERSION}"
|
48
51
|
exit 0
|
49
52
|
end
|
50
|
-
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
def parse(
|
55
|
-
parser.parse!(
|
56
|
-
|
57
|
-
rescue ::OptionParser::ParseError =>
|
58
|
-
error_output(
|
56
|
+
def parse(argv, _env)
|
57
|
+
parser.parse!(argv)
|
58
|
+
true
|
59
|
+
rescue ::OptionParser::ParseError => e
|
60
|
+
error_output(e)
|
59
61
|
end
|
60
62
|
|
61
|
-
def good_run(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
return false
|
67
|
-
end
|
63
|
+
def good_run(argv, env)
|
64
|
+
return false unless parse(argv, env)
|
65
|
+
|
66
|
+
Launchy.open(argv.shift, options) { |e| error_output(e) }
|
67
|
+
true
|
68
68
|
end
|
69
69
|
|
70
|
-
def error_output(
|
70
|
+
def error_output(error)
|
71
71
|
$stderr.puts "ERROR: #{error}"
|
72
72
|
Launchy.log "ERROR: #{error}"
|
73
73
|
error.backtrace.each do |bt|
|
74
74
|
Launchy.log bt
|
75
75
|
end
|
76
76
|
$stderr.puts "Try `#{parser.program_name} --help' for more information."
|
77
|
-
|
77
|
+
false
|
78
78
|
end
|
79
79
|
|
80
|
-
def run(
|
81
|
-
exit 1 unless good_run(
|
80
|
+
def run(argv = ARGV, env = ENV)
|
81
|
+
exit 1 unless good_run(argv, env)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
2
4
|
|
3
5
|
module Launchy
|
4
6
|
#
|
@@ -9,7 +11,7 @@ module Launchy
|
|
9
11
|
# end
|
10
12
|
#
|
11
13
|
# or
|
12
|
-
#
|
14
|
+
#
|
13
15
|
# class Foo
|
14
16
|
# class << self
|
15
17
|
# include DescendantTracker
|
@@ -20,29 +22,29 @@ module Launchy
|
|
20
22
|
# them in a Set that is available via the 'children' method.
|
21
23
|
#
|
22
24
|
module DescendantTracker
|
23
|
-
def inherited(
|
24
|
-
|
25
|
-
|
25
|
+
def inherited(klass)
|
26
|
+
super
|
27
|
+
return unless klass.instance_of?(Class)
|
28
|
+
|
29
|
+
children << klass
|
26
30
|
end
|
27
31
|
|
28
32
|
#
|
29
33
|
# The list of children that are registered
|
30
34
|
#
|
31
35
|
def children
|
32
|
-
unless defined? @children
|
33
|
-
|
34
|
-
end
|
35
|
-
return @children
|
36
|
+
@children = [] unless defined? @children
|
37
|
+
@children
|
36
38
|
end
|
37
39
|
|
38
40
|
#
|
39
41
|
# Find one of the child classes by calling the given method
|
40
|
-
# and passing all the rest of the parameters to that method in
|
42
|
+
# and passing all the rest of the parameters to that method in
|
41
43
|
# each child
|
42
|
-
def find_child(
|
44
|
+
def find_child(method, *args)
|
43
45
|
children.find do |child|
|
44
46
|
Launchy.log "Checking if class #{child} is the one for #{method}(#{args.join(', ')})}"
|
45
|
-
child.send(
|
47
|
+
child.send(method, *args)
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -1,32 +1,35 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
class HostOs
|
3
|
+
require "rbconfig"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Launchy
|
6
|
+
module Detect
|
7
|
+
# Internal: Determine the host operating system that Launchy is running on
|
8
|
+
#
|
9
|
+
class HostOs
|
10
|
+
attr_reader :host_os
|
11
|
+
alias to_s host_os
|
12
|
+
alias to_str host_os
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
def initialize(host_os = nil)
|
15
|
+
@host_os = host_os
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
return if @host_os
|
18
|
+
|
19
|
+
if (@host_os = override_host_os)
|
15
20
|
Launchy.log "Using LAUNCHY_HOST_OS override value of '#{Launchy.host_os}'"
|
16
21
|
else
|
17
22
|
@host_os = default_host_os
|
18
23
|
end
|
19
24
|
end
|
20
|
-
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
def default_host_os
|
27
|
+
::RbConfig::CONFIG["host_os"].downcase
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
def override_host_os
|
31
|
+
Launchy.host_os
|
32
|
+
end
|
28
33
|
end
|
29
|
-
|
30
34
|
end
|
31
|
-
|
32
35
|
end
|