lib/flammarion/revelator.rb in flammarion-0.3.0 vs lib/flammarion/revelator.rb in flammarion-1.0.0
- old
+ new
@@ -15,18 +15,15 @@
class SetupError < StandardError; end
# @api private
# @todo This all needs a lot of clean up
module Revelator
- CHROME_PATH = ENV["FLAMMARION_REVELATOR_PATH"] || 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
+ CHROME_PATH = ENV["FLAMMARION_REVELATOR_PATH"] || 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
def open_a_window(options = {})
development_mode = Flammarion.development_mode?
- 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
+ host = "http://localhost:#{server.webrick_port}/"
@expect_title = options[:title] || "Flammarion"
url = "#{host}?path=#{@window_id}&port=#{server.port}&title=#{@expect_title}"
@browser_options = options.merge({url: url, development_mode: development_mode})
@requested_browser = ENV["FLAMMARION_BROWSER"] || options[:browser]
@@ -71,16 +68,33 @@
return true
end
false
end
+ browser :chrome_wsl do |options|
+ # Check for WSL, idea from https://github.com/hashicorp/vagrant/blob/master/lib/vagrant/util/platform.rb
+ return false unless File.file?('/proc/version') &&
+ File.open('/proc/version', &:gets).downcase.include?("microsoft")
+
+ # Convert to path in WSL
+ chrome_path = `wslpath '#{CHROME_PATH}'`.strip
+ return false unless File.exist?(chrome_path)
+
+ # url = "file://#{`wslpath -m '#{file_path}'`.strip}"
+ url = "http://localhost:#{server.webrick_port}/"
+
+ cmdString = %['#{chrome_path}' --app='#{url}?port=#{server.port}&path=#{@window_id}&title="#{options[:title] || "Flammarion%20Engraving"}"']
+
+ @chrome.in, @chrome.out, @chrome.err, @chrome.thread = Open3.popen3(cmdString)
+ return true if @chrome.in
+ 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]
+ resource = "http://localhost:#{server.webrick_port}/"
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
@@ -114,9 +128,10 @@
end
end
private
def self.development_mode?
+ return true
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