browser_app_base 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
- require "./server_app_base"
1
+ $LOAD_PATH << File.dirname(File.expand_path(__FILE__))
2
+
3
+ require "server_app_base"
2
4
  require "json"
3
5
  require "cgi"
4
6
  require "thread"
@@ -18,6 +20,8 @@ class WsServer < Sinatra::Base
18
20
  super
19
21
  @ws_list = []
20
22
  @ws_lock = Mutex.new
23
+ @json_config = nil
24
+ @exec_thread = nil
21
25
  end
22
26
 
23
27
  def ws_send(str)
@@ -28,8 +32,8 @@ class WsServer < Sinatra::Base
28
32
  end
29
33
  end
30
34
 
31
- json_config = nil
32
- exec_thread = nil
35
+ public :ws_send
36
+
33
37
  get "" do
34
38
  if !request.websocket?
35
39
  "no supported"
@@ -47,17 +51,24 @@ class WsServer < Sinatra::Base
47
51
  if $ws_exit_thread != nil
48
52
  puts "ws_exit_thread kill"
49
53
  Thread.kill $ws_exit_thread
54
+ $ws_exit_thread = nil
50
55
  end
51
56
  end
52
57
  ws.onmessage do |msg|
53
58
  puts msg
54
- json = JSON.parse(File.read("#{$home_dir}/config/setting.json"))
55
- json_config = config_json_hash(json)
56
- $app.set_config(json_config)
59
+ begin
60
+ json = JSON.parse(File.read("#{$home_dir}/config/setting.json"))
61
+ @json_config = config_json_hash(json)
62
+ $app.set_config(@json_config)
63
+ rescue
64
+ puts "Failed to load config/setting.json"
65
+ @json_config = {}
66
+ end
67
+
57
68
  if msg =~ /^exec:/
58
- if exec_thread == nil
69
+ if @exec_thread == nil
59
70
  argv = msg.gsub(/^exec:/, "")
60
- exec_thread = Thread.new {
71
+ @exec_thread = Thread.new {
61
72
  begin
62
73
  $app.start(argv.split(",")) do |out|
63
74
  ws_send(out)
@@ -70,7 +81,7 @@ class WsServer < Sinatra::Base
70
81
  ws_send("app_end:error")
71
82
  ensure
72
83
  puts "exit thread"
73
- exec_thread = nil
84
+ @exec_thread = nil
74
85
  end
75
86
  }
76
87
  else
@@ -79,19 +90,20 @@ class WsServer < Sinatra::Base
79
90
  end
80
91
  end
81
92
  if msg =~ /^stop/
82
- if exec_thread
83
- Thread.kill exec_thread
93
+ if @exec_thread
94
+ Thread.kill @exec_thread
84
95
  ws_send("app_end:stop")
85
96
  $app.stop
97
+ @exec_thread = nil
86
98
  end
87
99
  end
88
100
  if msg =~ /^suspend/
89
- if exec_thread
101
+ if @exec_thread
90
102
  $app.suspend
91
103
  end
92
104
  end
93
105
  if msg =~ /^resume/
94
- if exec_thread
106
+ if @exec_thread
95
107
  $app.resume
96
108
  end
97
109
  end
@@ -102,8 +114,8 @@ class WsServer < Sinatra::Base
102
114
  File.open("#{$home_dir}/config/setting.json", "w") do |w|
103
115
  w.puts JSON.pretty_generate(json)
104
116
  end
105
- json_config = config_json_hash(json)
106
- $app.set_config(json_config)
117
+ @json_config = config_json_hash(json)
118
+ $app.set_config(@json_config)
107
119
  rescue
108
120
  # jsonファイルではない
109
121
  ws_send("app_end:error")
@@ -112,7 +124,11 @@ class WsServer < Sinatra::Base
112
124
  if msg =~ /^openfile:/
113
125
  file = msg.gsub(/^openfile:/, "")
114
126
  Thread.new {
115
- system "#{json_config["editor"]} #{CGI.unescapeHTML(file)}"
127
+ if @json_config && @json_config["editor"]
128
+ system "#{@json_config["editor"]} #{CGI.unescapeHTML(file)}"
129
+ else
130
+ puts "Editor not set in config"
131
+ end
116
132
  }
117
133
  end
118
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_app_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masataka kuwayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-11 00:00:00.000000000 Z
11
+ date: 2025-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: facter
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  description: browser application template
98
84
  email:
99
85
  - masataka.kuwayama@gmail.com
@@ -119,13 +105,13 @@ files:
119
105
  - lib/browser_app_base.rb
120
106
  - lib/browser_app_base/version.rb
121
107
  - lib/template/app_load.rb
108
+ - lib/template/common.rb
122
109
  - lib/template/config.ru
123
110
  - lib/template/config/browser.json
124
111
  - lib/template/config/setting.json
125
112
  - lib/template/css/index.css
126
113
  - lib/template/history/history.json
127
114
  - lib/template/html/index.html
128
- - lib/template/html/test.html
129
115
  - lib/template/js/main.js
130
116
  - lib/template/my_app_sample.rb
131
117
  - lib/template/server.rb
File without changes