Coder Social home page Coder Social logo

copiousfreetime / launchy Goto Github PK

View Code? Open in Web Editor NEW
774.0 12.0 60.0 441 KB

A helper for launching cross-platform applications in a fire and forget manner.

Home Page: https://github.com/copiousfreetime/launchy

License: ISC License

Ruby 98.19% Shell 1.81%
launchy ruby commandline browser

launchy's Introduction

launchy

Build Status

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.

FEATURES

Currently only launching a browser is supported.

SYNOPSIS

You can use launchy on the commandline, within the Capybara and Rspec-rails testing environment, or via its API.

Commandline

% launchy https://www.ruby-lang.org/

There are additional command line options, use launchy --help to see them.

Using the BROWSER environment variable

Launchy has a predefined set of common browsers on each platform that it attempts to use, and of course it is not exhaustive. As a fallback you can make use of the somewhat standard BROWSER environment variable.

BROWSER works in a similar same way to PATH. It is a colon (:) separated list of commands to try. You can also put in a %s in the command and the URL you are attempting to open will be substituted there.

As an example if you set BROWSER=/usr/local/bin/firefox-bin -new-tab '%s':/usr/local/bin/google-chrome-stable and you call Launchy.open("https://www.ruby-lang.org/") then Launchy will try, in order:

  • /usr/local/bin/firefox-bin -new-tab 'https://www.ruby-lang.org'
  • /usr/local/bin/google-chrome-stable https://www.ruby-lang.org

Additional links on the use of BROWSER as an environment variable.

Capybara Testing

First, install Capybara and Rspec for Rails. Capybara provides the following method:

save_and_open_page

When inserted into your code at the place where you would like to open your program, and when rspec is run, Capybara displays this message:

Page saved to /home/code/my_app_name/tmp/capybara/capybara-current-date-and-time.html with save_and_open_page.
Please install the launchy gem to open page automatically.

With Launchy installed, when rspec is run again, it will launch an unstyled instance of the specific page. It can be especially useful when debugging errors in integration tests. For example:

context "signin" do
  it "lets a user sign in" do
    visit root_path
    click_link signin_path
    save_and_open_page
    page.should have_content "Enter your login information"
  end
end

Public API

In the vein of Semantic Versioning, this is the sole supported public API.

Launchy.open( uri, options = {} ) { |exception| }

At the moment, the only available options are:

:debug        Turn on debugging output
:application  Explicitly state what application class is going to be used
:host_os      Explicitly state what host operating system to pretend to be
:dry_run      Do nothing and print the command that would be executed on $stdout

If Launchy.open is invoked with a block, then no exception will be thrown, and the block will be called with the parameters passed to #open along with the exception that was raised.

An example of using the public API:

Launchy.open( "https://www.ruby-lang.org" )

An example of using the public API and using the error block:

uri = "https://www.ruby-lang.org"
Launchy.open( uri ) do |exception|
  puts "Attempted to open #{uri} and failed because #{exception}"
end

ISC LICENSE

https://opensource.org/licenses/isc-license.txt

Copyright (c) 2007-2020 Jeremy Hinegardner

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

launchy's People

Contributors

bogdan avatar colbell avatar copiousfreetime avatar coreyhaines avatar fjtkfm avatar gioele avatar jeremymoritz avatar marcrohloff avatar mrtorrent avatar postmodern avatar schmich avatar simi avatar stephenjudkins avatar sunaku avatar supremebeing7 avatar wijet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

launchy's Issues

cannot get gem installed w Rails3.rc1 (sorry I closed the issue... mistake !)

no launchy* in cache folder

I tested again creating a new testapp from scratch (try it ...)

rails new testapp

inserting only launchy in the Gemfile
Gemfile -----
source 'http://rubygems.org'
gem 'rails', '3.0.0.rc'
gem 'sqlite3-ruby', :require => 'sqlite3'

gem 'launchy'

bundle install

/Users/yves/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:111:in `initialize': No metadata found! (Gem::Package::FormatError)

from /Users/yves/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:17:in `new

JRuby support

It would be great to get support for JRuby, which doesn't have fork.

Currently, using launchy produces:
NotImplementedError: fork is unsafe and disabled by default on JRuby

Do not raise exception of no launching program is found

From @mfn comment on #29

While testing out https://github.com/gitlabhq/gitlabhq I came across this issue while playing around with it; this problem has nothing to do with gitlabhq, it's just that with latest launch due their Gemlock I can see this:

gitlab@vserv03:~/gitlabhq$ bundle exec launchy http://slashdot.org/
sh: xprop: not found
/home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/detect/runner.rb:41:in `shell_commands': undefined method `shellsplit' for nil:NilClass (NoMethodError)
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/detect/runner.rb:104:in `block in wet_run'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/detect/runner.rb:103:in `fork'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/detect/runner.rb:103:in `wet_run'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/detect/runner.rb:61:in `run'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/application.rb:58:in `run'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/applications/browser.rb:76:in `open'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy.rb:30:in `open'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/cli.rb:72:in `good_run'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/cli.rb:80:in `run'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/bin/launchy:4:in `<top (required)>'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/bin/launchy:19:in `load'
        from /home/gitlab/gitlabhq/vendor/bundle/ruby/1.9.1/bin/launchy:19:in `<main>'

It does not actually exhibit a real problem, it's just during e.g. loading the initial database there's seems to be something done using launchy which spams the screen full. After some searching I figured out it relates to launchy and did this simply test case.

I don't have cucumber installed, but I can give you the ruby output:

gitlab@vserv03:~/gitlabhq$ bundle exec ruby -rrbconfig -e "puts ::RbConfig::CONFIG['host_os']"
linux-gnu

This is a headless server so naturally there is no window manager installed thus no Xcfe and no xprop:

gitlab@vserv03:~/gitlabhq$ grep -r xprop *
vendor/bundle/ruby/1.9.1/gems/launchy-2.0.5/lib/launchy/detect/nix_desktop_environment.rb:        %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0

hth

[FEATURE] Open Steam URI

I'm not sure if this if I'm supposed to put this here put I figured you can just close it otherwise. I know that Launchy currently only supports opening HTTP URI's but I would like to propose a feature to open Steam links.

Example link:
steam://connect/81.0.1.1:27015/

This will open Steam and I think that Steam itself recognizes which game the server is running, starts the correct game and connects to the server

Don't use ~> with Addressable.

Please use >= 2.2.6 for Addressable instead of ~> 2.2.6. This is creating problems with dependencies that are impossible to satisfy, and it's utterly pointless because Addressable is just about the most stable library in the entire Ruby ecosystem. Applications should use ~> requirements, but libraries should avoid them like the plague, and use them only when there is a library with a known breaking change (or a history of constant breaking changes) and updating the library would require significant effort.

Bug: Launchy#open does not support { :debug => true }

While investigating #62, I noticed the API around Launchy#open is inconsistent and yields unexpected results:

  1. Specifying :debug => true does not enable debug output, you must instead specify :debug => 'true' (string vs. bool). In comparison, :dry_run => true does work, as does :dry_run => 'true'.

  2. The following prints [false, true], but I would expect it to print [false, false].

    ENV['LAUNCHY_DEBUG'] = 'true'
    ENV['LAUNCHY_DRY_RUN'] = 'true'
    
    p [Launchy.debug?.nil?, Launchy.dry_run?.nil?]

    The problem is Launchy#debug? checks the environment every time while Launchy#dry_run? does not.

  3. The following prints ["true", true, "true"], but I would expect it to print [true, true, true].

    Launchy.extract_global_options(:dry_run => 'true')
    d1 = Launchy.dry_run?
    
    Launchy.extract_global_options(:dry_run => true)
    d2 = Launchy.dry_run?
    
    ENV['LAUNCHY_DRY_RUN'] = 'true'
    Launchy.extract_global_options({})
    d3 = Launchy.dry_run?
    
    p [d1, d2, d3]

    The issue here is that Launchy#dry_run? can return a different type depending on how it was set. It should be consistent and always return a bool regardless of how it was set.

This all makes the API tough to work with, so I'll do the following to fix it while trying to maintain compatibility with existing clients:

  1. Support both true and 'true' for the :debug and :dry_run options.
  2. Always have Launchy#dry_run? check the environment just like Launchy#debug? does.
  3. Launchy#dry_run? and Launchy#debug? will always return boolean values, never strings. This should not affect users doing if Launchy.dry_run? then ... end, but could affect users inspecting the return value on a deeper level (e.g. checking the class). I seriously doubt anyone actually does this, so I think this change is fine.

Let me know if this sounds reasonable and I'll make the changes.

Chris

t authorize --display-url raises an exception on headless hosts

They redirect me here from: sferik/t-ruby#95
Problem is when I want to authorize application, with "gem t authorize --display-url" I got following message:
"Welcome! Before you can use t, you'll first need to register an
application with Twitter. Just follow the steps below:

Sign in to the Twitter Developer site and click "Create a new application".
Complete the required fields and submit the form. Note: Your application must have a unique name. We recommend: "/t".
Go to the Settings tab of your application, and change the Access setting to "Read, Write and Access direct messages".
Go to the Details tab to view the consumer key and secret, which you'll need to copy and paste below when prompted.

Press [Enter] to open the Twitter Developer site."

and when I press [Enter] i got next error:

"xprop: unable to open display ''
/var/lib/gems/1.9.1/gems/launchy-2.2.0/lib/launchy/applications/browser.rb:62:in browser_cmdline': Unable to find a browser command. If this is unexpected, Please rerun with environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file a bug at https://github.com/copiousfreetime/launchy/issues/new (Launchy::CommandNotFoundError)
from /var/lib/gems/1.9.1/gems/launchy-2.2.0/lib/launchy/applications/browser.rb:66:incmd_and_args'
from /var/lib/gems/1.9.1/gems/launchy-2.2.0/lib/launchy/applications/browser.rb:77:in open'
from /var/lib/gems/1.9.1/gems/launchy-2.2.0/lib/launchy.rb:29:inopen'
from /var/lib/gems/1.9.1/gems/t-1.7.1/lib/t/cli.rb:82:in authorize'
from /var/lib/gems/1.9.1/gems/thor-0.18.1/lib/thor/command.rb:27:inrun'
from /var/lib/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation.rb:120:in invoke_command'
from /var/lib/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:363:indispatch'
from /var/lib/gems/1.9.1/gems/thor-0.18.1/lib/thor/base.rb:439:in start'
from /var/lib/gems/1.9.1/gems/t-1.7.1/bin/t:18:in'
from /usr/local/bin/t:19:in load'
from /usr/local/bin/t:19:in'
goran@ubuntu-server:~$
"
I am using:
ubuntu server (12.04.02)
ruby version ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]
t version 1.7.1

How do I debug "Unable to launch"?

Launchy is "unable to launch" both .html and .png files on my mac. I can't figure out where these error strings come from; and I'm not sure how to debug it. Suggestions?

LAUNCHY_DEBUG: Launchy::Application : finding application classes for [/Users/drnic/Sites/app/tmp/capybara/screenshot-2012-08-26-09-53-51.png]
LAUNCHY_DEBUG: Launchy::Application : Trying Launchy::Browser
LAUNCHY_DEBUG: Launchy::Browser : testing if [/Users/drnic/Sites/app/tmp/capybara/screenshot-2012-08-26-09-53-51.png] (String) is a url.
LAUNCHY_DEBUG: Launchy : Unable to launch /Users/drnic/Sites/app/tmp/capybara/screenshot-2012-08-26-09-53-51.png
Unable to launch /Users/drnic/Sites/app/tmp/capybara/screenshot-2012-08-26-09-53-51.png

UTF-8 urls cannot be launched

Found while investigating #31

A UTF-8 url passed on the command line fails to open.

http://ja.wikipedia.org/wiki/あ

LAUNCHY_DEBUG: Launchy : Failure in opening http://ja.wikipedia.org/wiki/あ with options {}: bad URI(is not URI?): http://ja.wikipedia.org/wiki/あ
LAUNCHY_DEBUG: /Users/jeremy/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/uri/common.rb:436:in `split'
LAUNCHY_DEBUG: /Users/jeremy/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/uri/common.rb:485:in `parse'
LAUNCHY_DEBUG: ./lib/launchy.rb:28:in `open'
LAUNCHY_DEBUG: ./lib/launchy/cli.rb:72:in `good_run'
LAUNCHY_DEBUG: ./lib/launchy/cli.rb:80:in `run'
LAUNCHY_DEBUG: bin/launchy:4
Failure in opening http://ja.wikipedia.org/wiki/あ with options {}: bad URI(is not URI?): http://ja.wikipedia.org/wiki/あ

Fix browser launching in Linux

Browser launching in Linux has a couple issues. Firstly, lib/launchy/applications/browser.rb:23 has a typo in "NixDekstopEnvironment." Secondly, even with that fixed, Launchy.open reports "undefined method `browser' for Launchy::Detect::NixDesktopEnvironment:Class"

Document API changes

Launchy::Browser.run doesn't seem to work anymore. I'm guessing this is an API change in 2.0, but it took a little while to figure out why Webrat was giving "uninitialized constant Launchy::Browser (NameError)" in save_and_open_page, because the Launchy homepage (http://copiousfreetime.rubyforge.org/launchy/) and the Readme still give examples of the Launchy::Browser usage.

"Can't convert HostOS into String"

I'm using launchy on Crunchbang Linux, which is based on Debian and uses Openbox as a window manager. I have xdg-open installed, and it's working correctly. However, when I run launchy http://www.github.com, I get:

Failure in opening http://www.github.com with options {}: can't convert Launchy::Detect::HostOs into String

After much dropping of putses and experimentation, I fixed it by changing

    found = find_child( :matches?, host_os )

in lib/launchy/detect/host_os_family.rb:detect to

    found = find_child( :matches?, host_os.host_os )

So is this due to some quirk in my OS, or is it a bug proper? Do you want me to submit a pull request?

Thanks.

Push Launchy 1.0 to Rubygems

It's tagged here, but I can't use it because it's not on Rubygems. And using the :git option of bundler doesn't work because you're using Bones.

Thanks!

Problems launching urls with querystring in Windows

Hi,

Launchy is attempting to launch browser using the command line in Windows, but without escaping ampersands in the querystring. The ampersand is used to separate multiple commands on line, and therefore a special character.

To reproduce, try launching a url such as "http://www.google.ca?foo=bar&test" - you'll get an error similar to the following:

"test is not recognized as an internal or external command, operable program or batch file."

To fix, escape the ampersand with a carot: "http://www.google.ca?foo=bar^&test"

Btw, there's a command in windows for launching the default browser called "start".

Cheers,
Mike

save_and_open_page error: Launchy::ApplicationNotFoundError

As reported from an email, and on StackOverflow http://stackoverflow.com/questions/16137410/launchyapplicationnotfounderror

Email

Output from 
 1) Integrations GET /integrations works! (now write some real specs)
     ←[31mFailure/Error:←[0m ←[31msave_and_open_page←[0m
     ←[31mLaunchy::ApplicationNotFoundError←[0m:
       ←[31mNo application found to handle 'C:/D/code/rails_proj/nbhy/tmp/capybara/capybara-201304282139536283905128.html'←[0m
←[36m     # ./spec/features/integrations_spec.rb:97:in `block (2 levels) in <top (required)>'←[0m
group :development, :test do 
  gem "rspec-rails", ">= 2.0.0"
  gem 'capybara'
  gem 'launchy'
  gem 'factory_girl_rails' 
end

StackOverflow

1) index page my first test
 Failure/Error: save_and_open_page
 Launchy::ApplicationNotFoundError:
   No application found to handle 'C:/Sites/Sublist_v2/tmp/capybara/capybara-201304211638563116158687.html'
 # ./spec/features/comics_page_spec.rb:6:in `block (2 levels) in <top (required)>'
group :development, :test do
    gem 'spork-rails'
    gem 'rspec-rails'
    gem 'factory_girl_rails'    
end

group :test do 
    gem 'faker'
    gem 'capybara'
    gem 'launchy'
    gem 'database_cleaner'
    gem 'shoulda-matchers'
end

Launchy::Browser#run with spaces in the page (on Windows)

I was trying to use webrat's save_and_open page on Windows and kept just getting an empty command prompt opening up. I did some digging around and figured out that it seems to be because I was working in My Documents, which contains a space in the folder name.

It turns out that the start command needs a title to be passed to it first:

http://stackoverflow.com/questions/72671/how-to-create-batch-file-in-windows-using-start-with-a-path-and-command-with-sp

I guess it must be a fluke that it works when there are no spaces in the page.

I'm going to try and make a patch.

launchy launching a command prompt instead of a browser on Win XP

I'm using launchy with cucumber and whenever I add a 'show me the page' step to my scenarios, I get a command prompt instead of a firefox viewing the actual page. This only happens on my Win XP, I have the same setup on a windows vista machine and it works perfectly.

Launchy and FireFox 6

Not sure if this is the result of upgradingy capybara, selenium, or Firefox, but I'm getting the following error when trying to open a page for viewing with Launch:

.Unable to launch /some/long/path/to/something.html

Capybara 1.0.1
Cucumber-Rails 0.3.2
rspec-rails 2.6.1
selenium-webdriver 2.5.0

On a side note: Thanks for the gem. Can't tell you how much effort and confusion it's saved us by using it.

CLI should show help/usage by default

Typing launchy with no arguments should show help or usage. Instead, it produces this error:

Failure in opening  with options {}: undefined method `scheme' for nil:NilClass

invalid gem format

since this morning , after upgrading my testApp to rails 3 .rc, I cannot run bundle install...

I got an error

/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:111:in `initialize': No metadata found! (Gem::Package::FormatError)
when I suppress from the Gemfile the line about 'launchy' , bundle install runs well..

gem 'launchy'

trying to install it from the console also raise an error :
gem install launchy
ERROR: Error installing launchy:
invalid gem format

too bad I was using it with cucumber-rails

Launchy.open( uri )

#### So, I got this through autotest,

WARNING: You made a call to a deprecated Launchy API. This call should be changed to 'Launchy.open( uri )'
WARNING: I think I was able to find the location that needs to be fixed. Please go look at:
WARNING:
WARNING: /home/Dave/.rvm/gems/ruby-1.9.2-p180/gems/capybara-1.0.0/lib/capybara/util/save_and_open_page.rb:26:in open_in_browser' WARNING: def open_in_browser(path) # :nodoc WARNING: require "launchy" WARNING: Launchy::Browser.run(path) WARNING: rescue LoadError WARNING: warn "Sorry, you need to install launchy (gem install launchy`) and " <<
WARNING:
WARNING: If this is not the case, please file a bug. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new
Failure in opening /home/Dave/Rails/socapp/tmp/capybara/capybara-201107201002297103564985.html with options {}: No application found to handle scheme ''. Known schemes: file, ftp, http, https

######### Then I did this,

/home/Dave/.rvm/gems/ruby-1.9.2-p180/gems/capybara-1.0.0/lib/capybara/util/save_and_open_page.rb

24 def open_in_browser(path) # :nodoc
25 require "launchy"
26 #Launchy.open( uri )
27 Launchy::Browser.run(path)
28 rescue LoadError
29 warn "Sorry, you need to install launchy (gem install launchy) and " <<
30 "make sure it's available to open pages with save_and_open_page."
31 end

24 def open_in_browser(path) # :nodoc
25 require "launchy"
26 Launchy.open( uri )
27 #Launchy::Browser.run(path)
28 rescue LoadError
29 warn "Sorry, you need to install launchy (gem install launchy) and " <<
30 "make sure it's available to open pages with save_and_open_page."
31 end

################ Then I got this through autotest,
  undefined local variable or method `uri' for Capybara:Module (NameError)

Any thoughts?

Do not complain about desktop environment if $BROWSER is set

I am running launchy 2.0.4 on a Linux server. My $BROWSER points to a script that SSHes into a desktop machine and opens the URL (using a network mount if necessary).

This used to work fine in launchy 0.x, but now I get an error saying

 Failure in opening /home/ubuntu/src/mercury/tmp/capybara/capybara-201107252328479878930330.html with options {}: Current Desktop environment not found. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new

I wish launchy would just Trust Me if it sees the $BROWSER variable and call it, even if it hasn't detected a desktop environment.

Application#for_scheme doesn't find scheme in v2.0.3

Launchy 2.0.3 breaks when called within Capybara 1.0.0, Rspec 2.6.0, and Rails 3.1.0.rc4:

save_and_open_page fails with this error:

Failure in opening /path_to_project/tmp/capybara/capybara-2011etc11.html with options {}: No application found to handle scheme ''. Known schemes: file, ftp, http, https

which is a SchemeNotFoundError raised in Application#for_scheme

This fixes the problem but is obviously a ghastly hack:

diff --git a/lib/launchy/application.rb b/lib/launchy/application.rb
index e36eb4d..83f788d 100644
--- a/lib/launchy/application.rb
+++ b/lib/launchy/application.rb
@@ -37,7 +37,9 @@ module Launchy
         if scheme.respond_to?( :scheme ) then
           scheme = scheme.scheme
         end
-
+       # egregious hack
+       scheme = 'file'
+       # end egregious hack
         klass = find_child( :handles?, scheme )
         return klass if klass

I'm not sure what the logic is of the scheme.resond_to?(:scheme) test, but it tests true and then reassigns scheme to scheme.scheme -- which makes scheme blank instead of 'file' as it should be.

text only, no html

Would there be any reason that when I do "Then show me the page" in cucumber that it gives back text only and not the html of the web page?

Launches in Chrome and Firefox

When I use Launchy it opens the URL in both Google Chrome and in Firefox. Google Chrome is my default browser.

Below is the debug output.

The output states that my desktop environment is not found - I run Fluxbox 1.3.2 on Ubuntu 12.04.

$ launchy -d https://github.com/copiousfreetime/launchy
LAUNCHY_DEBUG: Checking if class Launchy::Application::Browser is the one for handles?(https://github.com/copiousfreetime/launchy)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Windows is the one for matches?(linux-gnu)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Darwin is the one for matches?(linux-gnu)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Nix is the one for matches?(linux-gnu)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::RubyEngine::Mri is the one for is_current_engine?(ruby)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Windows is the one for matches?(linux-gnu)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Darwin is the one for matches?(linux-gnu)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Nix is the one for matches?(linux-gnu)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::RubyEngine::Mri is the one for is_current_engine?(ruby)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::NixDesktopEnvironment::Kde is the one for is_current_desktop_environment?()}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::NixDesktopEnvironment::Gnome is the one for is_current_desktop_environment?()}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::NixDesktopEnvironment::Xfce is the one for is_current_desktop_environment?()}
LAUNCHY_DEBUG: Launchy::Application : found executable /usr/bin/xprop
LAUNCHY_DEBUG: Current Desktop environment not found. Please rerun with environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file a bug at https://github.com/copiousfreetime/launchy/issues/new
LAUNCHY_DEBUG: Launchy::Application : found executable /usr/bin/xdg-open
LAUNCHY_DEBUG: Launchy::Application::Browser : possibility : /usr/bin/xdg-open
LAUNCHY_DEBUG: Launchy::Application::Browser : Using browser value '/usr/bin/xdg-open'
LAUNCHY_DEBUG: commandline_normalized => /usr/bin/xdg-open https://github.com/copiousfreetime/launchy
$ Created new window in existing browser session.

No gemspec

Is there a reason for not supplying a gemspec in the git repo? I'm trying to fork/fix a bug and I can't install the gem with bundler's Gemfile because of the missing gemspec. This makes it much more painful to debug issues etc.

Failure in Windows 7

require 'rubygems'
require 'launchy'
Launchy::Browser.run("http://google.com")
# 'http:' is not recognized as an internal or external command, operable program or batch file.

Practically brand new install of Windows 7, 32bit ruby 1.8.7 (2010-01-10 patchlevel 249/mingw32)

Any ideas?

Not Working in Production server

Hi,
I am trying to launch a new browser window through Launchy. Everything works fine in localhost but it stops working when I launch run my app from production server. I have checked the logs and there are no errors either.I am sure I am missing something very basic. My guess is in production, Launchy is unable to find the platform where it needs to perform the action(which in this case, is launching a new browser window)Do I need to setup any application context? If I need to, then where and how should I do it? Let me know.

Any help/suggestion will be really appreciated.

Thanks,
Muntasir

Set default scheme to http

It appears that launchy was designed to launch different types of applications. However, in practice, only web browsers are supported. As such, I believe it makes sense to specify HTTP as the default scheme, both in the library and CLI, such that the following commands will work:

launchy www.ruby-lang.org
Launchy.open 'www.ruby-lang.org'

If you try to run either of this commands currently, you'll receive the somewhat cryptic error:

Failure in opening www.ruby-lang.org with options {}: No application found to handle 'www.ruby-lang.org'

escaping with %-escaped query string

$ ruby -rlaunchy -ve '
p Launchy::VERSION
Launchy.open("http://ja.wikipedia.org/wiki/%E3%81%82", :dry_run => true)
'
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
"2.0.3"
/usr/bin/xdg-open http://ja.wikipedia.org/wiki/\%E3\%81\%82

And this really opens http://ja.wikipedia.org/wiki//%E3/%81/%82 .
At least version "0.4.0", it opened intended URL.

Bug (Windows): Launching through API fails with URLs containing single quote marks

My environment:

  • Windows 7 x64
  • Ruby 1.9.3p392
  • Launchy 2.2.0

Launchy fails when trying to open a URL containing any single quote (') characters. Example:

require 'launchy'
Launchy.open("http://google.com/?q=launchy's+great")

On my machine, this just opens a new command prompt and does not open any browser.

This works fine if I remove the single quote character or encode it as %27. Single quote characters are valid in URLs, though, so this should just work without needing to encode.

Launchy debug output:

LAUNCHY_DEBUG: Checking if class Launchy::Application::Browser is the one for handles?(http://google.com/?q=launchy's+great)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Windows is the one for matches?(mingw32)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::RubyEngine::Mri is the one for is_current_engine?(ruby)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Windows is the one for matches?(mingw32)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::RubyEngine::Mri is the one for is_current_engine?(ruby)}
LAUNCHY_DEBUG: Launchy::Application::Browser : possibility : start /b
LAUNCHY_DEBUG: Launchy::Application::Browser : Using browser value 'start /b'
LAUNCHY_DEBUG: commandline_normalized => start /b http://google.com/?q=launchy's+great
LAUNCHY_DEBUG: Windows: all_args => ["cmd", "/c", "start", "/b", "http://google.com/?q=launchy's+great"]

If I manually run cmd /c start /b http://google.com/?q=launchy's+great from the command line, my default browser opens with the URL correctly.

Here's my guess as to what's happening:

  • I think the final system call to run the command is wrapping the URL in double quotes.
  • Therefore, the command becomes cmd /c start /b "http://google.com/?q=launchy's+great"
  • On Windows, start treats the first double-quoted argument as the window title (see start /?), so it doesn't think there's any specified command or program, which explains why a new command prompt is opened.
  • I think the final command should end up being cmd /c start /b "" "http://google.com/?q=launchy's+great" (note the empty quotes specifying the title argument).

I haven't had a chance to dig through the code much. If I get some time, I'll fork and fix this.

Thanks & regards,
Chris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.