Class: Webview::App
- Inherits:
-
Object
- Object
- Webview::App
- Defined in:
- lib/webview/app.rb
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
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/webview/app.rb', line 8 def initialize(title: nil, width: nil, height: nil, resizable: nil, debug: false) = { title: title, width: width, height: height, resizable: resizable, debug: debug } .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 end |
Instance Method Details
#close ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/webview/app.rb', line 37 def close return true unless app_process app_out.close app_err.close pid = app_process.pid signal('QUIT') begin Timeout.timeout(3) { Process.wait(pid) } rescue Timeout::Error kill end @app_process = nil end |
#join ⇒ Object
53 54 55 56 57 |
# File 'lib/webview/app.rb', line 53 def join return unless app_process && app_process.alive? Process.wait(app_process.pid) rescue Errno::ECHILD end |
#kill ⇒ Object
59 60 61 |
# File 'lib/webview/app.rb', line 59 def kill signal('TERM') end |
#open(url) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/webview/app.rb', line 22 def open(url) return true if @app_process cmd = [ File.('ext/webview_app', ROOT_PATH), "-url '#{url}'" ] .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
63 64 65 66 67 68 69 |
# File 'lib/webview/app.rb', line 63 def signal(name) return false unless app_process&.pid Process.kill(name, app_process.pid) true rescue Errno::ECHILD, Errno::ESRCH false end |