lib/template/wsserver.rb in browser_app_base-0.0.5 vs lib/template/wsserver.rb in browser_app_base-0.0.6

- old
+ new

@@ -1,7 +1,8 @@ require "./server_app_base" require "json" +require "cgi" def config_json_hash(json) config = {} json.each do |j| config[j["name"]] = j["value"] @@ -29,15 +30,28 @@ json = JSON.parse(File.read("config/setting.json")) json_config = config_json_hash(json) $app.set_config(json_config) argv = msg.gsub(/^exec:/, "") exec_thread = Thread.new { - $app.start(argv.split(",")) do |out| - ws.send(out) + begin + $app.start(argv.split(",")) do |out| + ws.send(out) + end + ws.send("app_end:normal") + rescue + puts $! + puts $@ + puts "app_end:err" + ws.send("app_end:error") + ensure + puts "exit thread" + exec_thread = nil end - exec_thread = nil } + else + puts "app_end:err" + ws.send("app_end:error") end end if msg =~ /^stop/ if exec_thread $app.stop @@ -59,9 +73,15 @@ File.open("config/setting.json", "w") do |w| w.puts JSON.pretty_generate(json) end json_config = config_json_hash(json) $app.set_config(json_config) + end + if msg =~ /^openfile:/ + file = msg.gsub(/^openfile:/, "") + Thread.new { + system "#{json_config["editor"]} #{CGI.unescapeHTML(file)}" + } end if msg == "exit" unless ENV["OCRA"] == "true" halt