lib/flammarion/revelator.rb in flammarion-0.1.9 vs lib/flammarion/revelator.rb in flammarion-0.1.10pre1

- old
+ new

@@ -23,11 +23,13 @@ if RbConfig::CONFIG["host_os"] =~ /cygwin|mswin|mingw/ development_mode = ENV["FLAMMARION_DEVELOPMENT"] == "true" else development_mode = system("lsof -i:#{4567}", out: '/dev/null') and File.exist?("#{File.dirname(__FILE__)}/../html/source/index.html.slim") end - host = "file://#{File.dirname(File.absolute_path(__FILE__))}/../html/build/index.html" + host_path = File.absolute_path(File.join(File.dirname(File.absolute_path(__FILE__)), "/../html/build/index.html")) + host_path = `cygpath -w '#{host_path}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin" + host = "file://#{host_path}" host = "http://localhost:4567/" if development_mode @expect_title = options[:title] || "Flammarion-#{rand.to_s[2..-1]}" url = "#{host}?path=#{@window_id}&port=#{server.port}&title=#{@expect_title}" @browser_options = options.merge({url: url, development_mode: development_mode}) @@ -56,34 +58,36 @@ @@browsers = [] def self.browser(name, &block) @@browsers << OpenStruct.new(name: name, method:define_method(name, block)) end - browser :chrome_windows do |options| - return false unless RbConfig::CONFIG["host_os"] =~ /cygwin|mswin|mingw/ - file_path = File.absolute_path(File.join(File.dirname(__FILE__), "..")) - file_path = `cygpath -w '#{file_path}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin" - resource = %[file\://#{file_path}/html/build/index.html] - resource = "http://localhost:4567/" if options[:development_mode] - chrome_path = CHROME_PATH - chrome_path = `cygpath -u '#{CHROME_PATH}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin" - return false unless File.exist?(chrome_path) - Process.detach(spawn(chrome_path, %[--app=#{resource}?path=#{@window_id}&port=#{server.port}&title="#{options[:title] || "Flammarion%20Engraving"}"])) - end - browser :osx do |options| return false unless RbConfig::CONFIG["host_os"] =~ /darwin|mac os/ executable = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" @chrome.in, @chrome.out, @chrome.err, @chrome.thread = Open3.popen3("'#{executable}' --app='#{options[:url]}'") return true if @chrome.in end browser :electron do |options| if which('electron') then - Process.detach(spawn("electron #{File.dirname(File.absolute_path(__FILE__))}/../../electron '#{options[:url]}' #{options[:width]} #{options[:height]}")) + electron_path = "#{File.dirname(File.absolute_path(__FILE__))}/../../electron" + electron_path = `cygpath -w #{electron_path}`.strip if RbConfig::CONFIG["host_os"] == "cygwin" + Process.detach(spawn("electron '#{electron_path}' '#{options[:url]}' #{options[:width]} #{options[:height]}")) return true end false + end + + browser :chrome_windows do |options| + return false unless RbConfig::CONFIG["host_os"] =~ /cygwin|mswin|mingw/ + file_path = File.absolute_path(File.join(File.dirname(__FILE__), "..")) + file_path = `cygpath -w '#{file_path}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin" + resource = %[file\://#{file_path}/html/build/index.html] + resource = "http://localhost:4567/" if options[:development_mode] + chrome_path = CHROME_PATH + chrome_path = `cygpath -u '#{CHROME_PATH}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin" + return false unless File.exist?(chrome_path) + Process.detach(spawn(chrome_path, %[--app=#{resource}?path=#{@window_id}&port=#{server.port}&title="#{options[:title] || "Flammarion%20Engraving"}"])) end browser :chrome do |options| %w[google-chrome google-chrome-stable chromium chromium-browser chrome].each do |executable| next unless which(executable)