Class: Wsv::Server::BrowserLauncher

Inherits:
Object
  • Object
show all
Defined in:
lib/wsv/server/browser_launcher.rb

Overview

Launches the OS default browser at the served URL when ‘–open` is set. Best-effort: unsupported platforms or spawn failures are logged but never abort the server.

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, tls:, err:) ⇒ BrowserLauncher

Returns a new instance of BrowserLauncher.



11
12
13
14
15
16
# File 'lib/wsv/server/browser_launcher.rb', line 11

def initialize(host:, port:, tls:, err:)
  @host = host
  @port = port
  @tls = tls
  @err = err
end

Instance Method Details

#launchObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wsv/server/browser_launcher.rb', line 18

def launch
  command = platform_command
  unless command
    @err.puts "wsv: --open is not supported on this platform; skipping."
    return
  end

  pid = Process.spawn(*command, url, in: :close, out: File::NULL, err: File::NULL)
  Process.detach(pid)
rescue StandardError => e
  @err.puts "wsv: failed to open browser: #{e.message}"
end