lib/yardview/application_window.rb in yardview_gtk3-0.3.0 vs lib/yardview/application_window.rb in yardview_gtk3-0.4.0
- old
+ new
@@ -14,15 +14,18 @@
Yardview.application.active_window.__send__(handler_name)
end
end
end
- def initialize(application)
+ attr_accessor :port
+
+ def initialize(application, port: port_num)
super application: application
set_title 'YardView'
set_icon GdkPixbuf::Pixbuf.new resource: '/com/github/kojix2/yardview/ruby.png'
+ @port = port
start_yard_server
create_gui
end
def create_gui
@@ -30,21 +33,21 @@
Process.kill(:INT, @yard)
@yard = nil
end
at_exit { Process.kill(:INT, @yard) unless @yard.nil? }
@view = WebKit2Gtk::WebView.new
- @view.load_uri('http://localhost:8808')
+ @view.load_uri("http://localhost:#{port}")
box.add @view, expand: true, fill: true
@view.show
end
def port_open?(port)
!system("lsof -i:#{port}", out: '/dev/null')
end
def on_home_clicked
- @view.load_uri('http://localhost:8808')
+ @view.load_uri("http://localhost:#{port}")
end
def on_back_clicked
@view.go_back
end
@@ -56,14 +59,14 @@
def on_refresh_clicked
@view.reload
end
def start_yard_server
- if port_open? 8808
- @yard = spawn('yard server -g -p 8808 --reload')
+ if port_open? port
+ @yard = spawn("yard server -g -p #{port} --reload")
sleep 1
else
- raise 'port 8808 is in use!'
+ raise "port #{port} is in use!"
end
end
end
end