ev/browser.rb in rwdtorrent-0.04 vs ev/browser.rb in rwdtorrent-0.05
- old
+ new
@@ -14,24 +14,37 @@
filetype = "htmlfile"
application = nil
begin
- Win32::Registry::HKEY_CLASSES_ROOT.open('.html') do |reg|
+ Win32::Registry::HKEY_CLASSES_ROOT.open(".html") do |reg|
filetype = reg[""]
end
- Win32::Registry::HKEY_CLASSES_ROOT.open(filetype + '\shell\open\command') do |reg|
+ Win32::Registry::HKEY_CLASSES_ROOT.open(filetype + "\\shell\\open\\command") do |reg|
application = reg[""]
end
rescue NameError
- $stderr.puts "Only available for Windows."
+ $stderr.puts "Only available for Windows and Cygwin."
end
application
end
+def cygwinbrowser
+ browser, *args = windowsbrowser.splitwords
+ browser = browser.gsub(/\\/, "/")
+ #browser = browser
+
+ args.collect!{|a| a.gsub(/\\/, "/")}
+ #args.collect!{|a| "\"%s\"" % [a.gsub(/\\/, "/")]}
+ #args.collect!{|a| "\"%s\"" % [a]}
+
+ res = "\"%s\" %s" % [browser, args.join(" ")]
+ res
+end
+
def linuxbrowser
application = ""
application = `which galeon 2> /dev/null`.chomp if application.empty?
application = `which mozilla 2> /dev/null`.chomp if application.empty?
@@ -45,28 +58,29 @@
end
def defaultbrowser
res = nil
res = windowsbrowser if windows?
+ res = cygwinbrowser if cygwin?
res = linuxbrowser if linux?
res
end
+def showurlinbrowser(url, browser=defaultbrowser)
+ command = "#{browser} \"#{url}\""
+
+ system(command) or $stderr.puts "Starting of the browser failed, or the browser terminated abnormally.\nCommand => #{command}"
+end
+
def showinbrowser(html, browser=defaultbrowser)
port, io = TCPServer.freeport(7701, 7709)
unless browser.nil?
Thread.new do
begin
- #command = "1234 \"http://localhost:#{port}\"" if linux?
- #command = "L:/prog/MozillaFirefox/firefox.exe \"http://localhost:#{port}\"" if cygwin?
- #command = Win32::Registry::HKEY_CLASSES_ROOT.open('htmlfile\shell\open\command')[0] + " \"http://localhost:#{port}/\"" if windows?
-
- command = "#{browser} \"http://localhost:#{port}\""
-
Thread.pass
- system(command)
+ showurlinbrowser("http://localhost:#{port}/", browser)
rescue
end
end
end