Class: DuoRuby::Launcher
- Inherits:
-
Object
- Object
- DuoRuby::Launcher
- Defined in:
- lib/duoruby/launcher.rb
Overview
Starts the server in a child process and opens a native webview window on the main process’s main thread.
GTK requires all calls on the thread that called gtk_init (the OS main thread). The Async/Falcon server runs in a forked child process so each has full ownership of its own event loop. When the window is closed the child is terminated; when the child dies unexpectedly the window closes.
The window title defaults to DuoRuby.config.title, which the application can set in its duoruby.rb config file:
DuoRuby.configure { |c| c.title = "My App" }
Instance Method Summary collapse
-
#initialize(root: Dir.pwd, host: "127.0.0.1", port: nil, title: nil, width: 1280, height: 800) ⇒ Launcher
constructor
A new instance of Launcher.
-
#run(output: $stdout) ⇒ Object
Forks the Async server into a child process, then opens the native window on the main thread.
Constructor Details
#initialize(root: Dir.pwd, host: "127.0.0.1", port: nil, title: nil, width: 1280, height: 800) ⇒ Launcher
Returns a new instance of Launcher.
30 31 32 33 34 35 36 37 38 |
# File 'lib/duoruby/launcher.rb', line 30 def initialize(root: Dir.pwd, host: "127.0.0.1", port: nil, title: nil, width: 1280, height: 800) @root = File.(root) @host = host @port = port || free_port @title = title @width = width @height = height end |
Instance Method Details
#run(output: $stdout) ⇒ Object
Forks the Async server into a child process, then opens the native window on the main thread. Blocks until the window is closed, then terminates the server child.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/duoruby/launcher.rb', line 45 def run(output: $stdout) output.puts "launching http://#{@host}:#{@port}" server_pid = fork { run_server } wait_for_server title = @title || DuoRuby.config.title window = WebviewUtil::Window.new(title: title, width: @width, height: @height) window.navigate("http://#{@host}:#{@port}") window.run ensure if server_pid Process.kill(:TERM, server_pid) rescue nil Process.waitpid(server_pid) rescue nil end end |