Class: Webview::App
- Inherits:
-
Object
- Object
- Webview::App
- Defined in:
- lib/webview/app.rb
Constant Summary collapse
- SIGNALS_MAPPING =
if Gem.win_platform? { 'QUIT' => 'EXIT', } else {} # don't map end
Instance Attribute Summary collapse
-
#app_err ⇒ Object
readonly
Returns the value of attribute app_err.
-
#app_out ⇒ Object
readonly
Returns the value of attribute app_out.
-
#app_process ⇒ Object
readonly
Returns the value of attribute app_process.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(title: nil, width: nil, height: nil, resizable: nil, debug: false) ⇒ App
constructor
A new instance of App.
- #join ⇒ Object
- #kill ⇒ Object
- #open(url) ⇒ Object
- #signal(name) ⇒ Object
Constructor Details
#initialize(title: nil, width: nil, height: nil, resizable: nil, debug: false) ⇒ App
Returns a new instance of App.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/webview/app.rb', line 16 def initialize(title: nil, width: nil, height: nil, resizable: nil, debug: false) @options = { title: title, width: width, height: height, resizable: resizable, debug: debug } @options.delete_if { |k, v| v.nil? } @app_out = nil @app_err = nil @app_process = nil end |
Instance Attribute Details
#app_err ⇒ Object (readonly)
Returns the value of attribute app_err.
6 7 8 |
# File 'lib/webview/app.rb', line 6 def app_err @app_err end |
#app_out ⇒ Object (readonly)
Returns the value of attribute app_out.
6 7 8 |
# File 'lib/webview/app.rb', line 6 def app_out @app_out end |
#app_process ⇒ Object (readonly)
Returns the value of attribute app_process.
6 7 8 |
# File 'lib/webview/app.rb', line 6 def app_process @app_process end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/webview/app.rb', line 6 def @options end |
Instance Method Details
#close ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/webview/app.rb', line 42 def close return true unless app_process app_out.close app_err.close pid = app_process.pid signal('QUIT') begin Timeout.timeout(3) do begin Process.wait(pid) rescue Errno::ECHILD, Errno::ESRCH, Errno::EINVAL end end rescue Timeout::Error kill end @app_process = nil end |
#join ⇒ Object
63 64 65 66 67 |
# File 'lib/webview/app.rb', line 63 def join return unless app_process && app_process.alive? Process.wait(app_process.pid) rescue Errno::ECHILD, Errno::ESRCH end |
#kill ⇒ Object
69 70 71 |
# File 'lib/webview/app.rb', line 69 def kill signal('KILL') end |
#open(url) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/webview/app.rb', line 30 def open(url) return true if @app_process cmd = [executable, "-url \"#{url}\""] @options.each do |k, v| case v when true, false then cmd << "-#{k}" if v else cmd << "-#{k} \"#{v}\"" end end exec_cmd(cmd.join(' ')) end |
#signal(name) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/webview/app.rb', line 73 def signal(name) return false unless app_process&.pid s = SIGNALS_MAPPING[name] || name Process.kill(Signal.list[s], app_process.pid) true rescue Errno::ECHILD, Errno::ESRCH false end |