class SystemBrowser::Client

Constants

CLIENT_NAME

The name of the executable of the client application.

ClientNotFoundError
PID_COMMAND

The command that the client sends to the server at the session initialisation.

Attributes

session[W]

@return [SystemBrowser::Session]

Public Class Methods

new() click to toggle source
# File lib/system_browser/client.rb, line 18
def initialize
  @init_pid = nil
end

Public Instance Methods

close() click to toggle source

Destroys the window by sending the SIGINT signal (the window has its own handlers to destroy itself, so it's not our job). Does not wait for anything. @return [void]

# File lib/system_browser/client.rb, line 59
def close
  SLogger.debug("[client] interrupting window (#{@window_pid})...")

  Process.kill(:INT, @window_pid)
end
start() click to toggle source

Spawns a new process in a new process group. I really wanted to find the way to spawn the process in the same group. However, when I do that, I cannot send any signals to the window anymore (the app crashes, because the ruby process exits).

@note +@init_pid+ and +@window_pid+ are two different processes. The client uses +@init_id+ to bootstrap itself and +@window_pid+ is the process that can be used to send signals to the client.

@return [Integer] the process ID of the client application @raise [RuntimeError]

# File lib/system_browser/client.rb, line 34
def start
  executable = self.client_executable

  unless system("which #{executable} > /dev/null 2>&1")
    fail ClientNotFoundError, "executable '#{executable}' is not on your $PATH"
  end

  @init_pid = spawn(executable, pgroup: true)
  Process.wait(@init_pid)

  @init_pid
end
window_pid=(window_pid) click to toggle source

@return [Integer] the process ID of the client process (window).

# File lib/system_browser/client.rb, line 49
def window_pid=(window_pid)
  SLogger.debug("[client] setting window pid (#{window_pid})")
  @window_pid = window_pid
end

Protected Instance Methods

client_executable() click to toggle source
# File lib/system_browser/client.rb, line 67
def client_executable
  case RUBY_PLATFORM
  when /linux/
    CLIENT_NAME
  when /darwin/
    "/Applications/#{CLIENT_NAME}.app/Contents/MacOS/nwjs"
  else
    raise RuntimeError, "unsupported platform #{RUBY_PLATFORM}"
  end
end