browser_app_base 0.0.4 → 0.0.8
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.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/browser_app_base/version.rb +1 -1
- data/lib/browser_app_base.rb +17 -2
- data/lib/template/config.ru +23 -1
- data/lib/template/css/index.css +17 -12
- data/lib/template/index.html +10 -4
- data/lib/template/js/main.js +88 -14
- data/lib/template/server.rb +2 -1
- data/lib/template/start.rb +1 -1
- data/lib/template/wsserver.rb +42 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf40fc8ffcf491a1fba31012f2e8e3aba1089dc14a8de381f420b33a51d2ca3a
|
4
|
+
data.tar.gz: 3279233418b767f81a01350e5eb27f102f84f7b2c791d784ca0d25f8c58508c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d264ee2f1c8d9aed28ea36c523c400d445570fd219271eece7135655831bb02d75c1ad5e4b77eda4fbba7fdeb32ebc7986765c43cc9702e4b8a32ee1351bf199
|
7
|
+
data.tar.gz: 063d377c14dca4341cf963788c3de83a6bc7a6e6ddb93c5abc0bba06f40aa1cbb01596e19b95640ca7a99c11d5b996e1226c73326d9a95305351510dfb5e1a50
|
data/README.md
CHANGED
@@ -61,6 +61,19 @@ ui application sample
|
|
61
61
|
$ cd ~/test/
|
62
62
|
$ ruby start.rb
|
63
63
|
|
64
|
+
## browser setting
|
65
|
+
|
66
|
+
config/browser.json
|
67
|
+
Set the path for your Windows or Linux Chrome browser
|
68
|
+
|
69
|
+
```json
|
70
|
+
{
|
71
|
+
"chrome_win": "start chrome",
|
72
|
+
"chrome_linux": "/bin/google-chrome"
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
|
64
77
|
## Development
|
65
78
|
|
66
79
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/lib/browser_app_base.rb
CHANGED
@@ -19,6 +19,18 @@ module BrowserAppBase
|
|
19
19
|
return app_file_name + ".rb"
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.get_app_name(app)
|
23
|
+
app_name = ""
|
24
|
+
app.each_char do |s|
|
25
|
+
if s =~ /[a-z]/ and app_name.size == 0
|
26
|
+
app_name += s.upcase
|
27
|
+
else
|
28
|
+
app_name += s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return app_name
|
32
|
+
end
|
33
|
+
|
22
34
|
def self.create(arg)
|
23
35
|
dir = arg[:dir]
|
24
36
|
app = arg[:app]
|
@@ -37,7 +49,7 @@ module BrowserAppBase
|
|
37
49
|
|
38
50
|
load_app = <<"EOS"
|
39
51
|
require '#{app_file}'
|
40
|
-
$app =
|
52
|
+
$app = #{get_app_name(app)}.new
|
41
53
|
EOS
|
42
54
|
|
43
55
|
File.open("#{dir}/app_load.rb", "w") do |f|
|
@@ -45,7 +57,10 @@ EOS
|
|
45
57
|
end
|
46
58
|
|
47
59
|
puts "create #{app_file}"
|
48
|
-
|
60
|
+
new_file = "#{dir}/#{app_file}"
|
61
|
+
FileUtils.cp("#{dir}/my_app_sample.rb", new_file)
|
62
|
+
buf = File.binread(new_file)
|
63
|
+
File.binwrite(new_file, buf.gsub(/MyApp/, get_app_name(app)))
|
49
64
|
end
|
50
65
|
end
|
51
66
|
end
|
data/lib/template/config.ru
CHANGED
@@ -30,6 +30,28 @@ get "/config/*.*" do |file, ext|
|
|
30
30
|
File.read "config/#{file}.#{ext}"
|
31
31
|
end
|
32
32
|
|
33
|
+
get "/open_dialog" do
|
34
|
+
dialog_html = <<'EOS'
|
35
|
+
<!DOCTYPE html>
|
36
|
+
<html>
|
37
|
+
<head>
|
38
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
39
|
+
<title>Message Dialog</title>
|
40
|
+
<style type="text/css">
|
41
|
+
<!--
|
42
|
+
body {
|
43
|
+
color: #000000;
|
44
|
+
background-color: #ffffff;
|
45
|
+
overflow: hidden;
|
46
|
+
font-size: 12px;
|
47
|
+
}
|
48
|
+
-->
|
49
|
+
</style>
|
50
|
+
</head>
|
51
|
+
EOS
|
52
|
+
dialog_html += "<body>" + params["msg"] + "</body></html>"
|
53
|
+
end
|
54
|
+
|
33
55
|
map "/search" do
|
34
56
|
run Search
|
35
57
|
end
|
@@ -52,6 +74,6 @@ configure do
|
|
52
74
|
|
53
75
|
end
|
54
76
|
|
55
|
-
#\ --port
|
77
|
+
#\ --port 53492
|
56
78
|
|
57
79
|
run Sinatra::Application
|
data/lib/template/css/index.css
CHANGED
@@ -2,6 +2,7 @@ body {
|
|
2
2
|
color: #000000;
|
3
3
|
background-color: #cac3ec4f;
|
4
4
|
overflow: hidden;
|
5
|
+
font-size: 12px;
|
5
6
|
}
|
6
7
|
|
7
8
|
hr {
|
@@ -22,9 +23,9 @@ hr {
|
|
22
23
|
padding: 5px;
|
23
24
|
width: 95vw;
|
24
25
|
height: 50vh;
|
26
|
+
overflow: auto;
|
25
27
|
}
|
26
28
|
|
27
|
-
|
28
29
|
.inarea {
|
29
30
|
border: thin solid #000000;
|
30
31
|
margin: 5px;
|
@@ -32,12 +33,6 @@ hr {
|
|
32
33
|
width: 95%;
|
33
34
|
}
|
34
35
|
|
35
|
-
input {
|
36
|
-
background-color: #FAFAFA;
|
37
|
-
margin: 5px;
|
38
|
-
padding: 5px;
|
39
|
-
}
|
40
|
-
|
41
36
|
input.long {
|
42
37
|
width: 90%;
|
43
38
|
background-color: #FAFAFA;
|
@@ -50,18 +45,22 @@ textarea.long {
|
|
50
45
|
height: 50vh;
|
51
46
|
}
|
52
47
|
|
48
|
+
.ui-widget {
|
49
|
+
font-size: 12px;
|
50
|
+
}
|
51
|
+
|
53
52
|
.ui-autocomplete {
|
54
|
-
max-height:
|
55
|
-
max-width:
|
53
|
+
max-height: 45vh;
|
54
|
+
max-width: 90wh;
|
56
55
|
overflow-y: auto;
|
57
|
-
overflow-x:
|
58
|
-
padding-right:
|
56
|
+
overflow-x: auto;
|
57
|
+
padding-right: 10px;
|
59
58
|
}
|
59
|
+
|
60
60
|
#jquery-ui-autocomplete label {
|
61
61
|
float: left;
|
62
62
|
margin-right: 0.5em;
|
63
63
|
color: black;
|
64
|
-
font-size: 15px;
|
65
64
|
}
|
66
65
|
|
67
66
|
.ui-dialog {
|
@@ -96,4 +95,10 @@ textarea.long {
|
|
96
95
|
.setting_checkbox {
|
97
96
|
color: #796fe9;
|
98
97
|
background-color: #000000;
|
98
|
+
}
|
99
|
+
|
100
|
+
ul.log {
|
101
|
+
list-style-type: decimal;
|
102
|
+
font-size: 12px;
|
103
|
+
color: #5d0a94;
|
99
104
|
}
|
data/lib/template/index.html
CHANGED
@@ -11,12 +11,15 @@
|
|
11
11
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
12
12
|
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
|
13
13
|
|
14
|
-
<script src="http://localhost:
|
15
|
-
<link rel="stylesheet" href="http://localhost:
|
14
|
+
<script src="http://localhost:53492/js/main.js"></script>
|
15
|
+
<link rel="stylesheet" href="http://localhost:53492/css/index.css" type="text/css">
|
16
16
|
</head>
|
17
17
|
|
18
18
|
<body>
|
19
|
-
<
|
19
|
+
<div id="msg_dialog" style="display:none;">
|
20
|
+
<div id="msg_text">message</div>
|
21
|
+
</div>
|
22
|
+
<h4>GrepFind</h4>
|
20
23
|
<hr>
|
21
24
|
<table>
|
22
25
|
<tr>
|
@@ -55,7 +58,10 @@
|
|
55
58
|
</tr>
|
56
59
|
</table>
|
57
60
|
|
58
|
-
<
|
61
|
+
<div class="outarea">
|
62
|
+
<ul name="log" id="log" class="log">
|
63
|
+
</ul>
|
64
|
+
</div>
|
59
65
|
|
60
66
|
</body>
|
61
67
|
|
data/lib/template/js/main.js
CHANGED
@@ -1,6 +1,51 @@
|
|
1
1
|
// main.js
|
2
2
|
|
3
3
|
var $ws = null;
|
4
|
+
var $auto_scroll = true;
|
5
|
+
var dialog = null;
|
6
|
+
|
7
|
+
function open_dialog(msg) {
|
8
|
+
console.log("msg=" + msg);
|
9
|
+
$("#msg_text").html(msg);
|
10
|
+
$("#msg_dialog").dialog({
|
11
|
+
modal: true
|
12
|
+
, show: "slide" //表示時のアニメーション
|
13
|
+
, hide: "slide" //閉じた時のアニメーション
|
14
|
+
, title: "Message" //ダイアログのタイトル
|
15
|
+
, width: 400 //ダイアログの横幅
|
16
|
+
, height: 200 //ダイアログの高さ
|
17
|
+
, resizable: true //リサイズ可
|
18
|
+
, closeOnEscape: false //[ESC]キーで閉じられなくする
|
19
|
+
, draggable: true //ダイアログの移動を可に
|
20
|
+
, buttons: {
|
21
|
+
"OK": function () { //Cancelボタン
|
22
|
+
$(this).dialog("close");
|
23
|
+
}
|
24
|
+
}
|
25
|
+
});
|
26
|
+
}
|
27
|
+
|
28
|
+
function open_dialog_org(msg) {
|
29
|
+
var top = window.screenTop + 10;
|
30
|
+
var left = window.screenLeft + 10;
|
31
|
+
if (dialog != null) {
|
32
|
+
dialog.close();
|
33
|
+
}
|
34
|
+
var dialog = window.open(
|
35
|
+
"/open_dialog?msg=" + msg,
|
36
|
+
"pop",
|
37
|
+
"width=300, height=100, left=" + left + ", top=" + top
|
38
|
+
);
|
39
|
+
console.log("open dialog dialog=" + dialog);
|
40
|
+
if (dialog == null) {
|
41
|
+
console.log("open dialog retry");
|
42
|
+
setTimeout(function () {
|
43
|
+
open_dialog(msg);
|
44
|
+
}, 1000);
|
45
|
+
} else {
|
46
|
+
dialog.focus();
|
47
|
+
}
|
48
|
+
}
|
4
49
|
|
5
50
|
function server_connect(url) {
|
6
51
|
var ws = new WebSocket(url);
|
@@ -10,18 +55,23 @@ function server_connect(url) {
|
|
10
55
|
};
|
11
56
|
ws.onmessage = function (evt) {
|
12
57
|
//alert(evt.data);
|
58
|
+
|
13
59
|
if (evt.data.match(/^startup:/)) {
|
14
60
|
file_name = evt.data.replace(/^startup:/, "");
|
15
61
|
//alert(file_name);
|
62
|
+
}
|
63
|
+
else if (evt.data.match(/^app_end:normal/)) {
|
64
|
+
open_dialog("終了しました");
|
65
|
+
}
|
66
|
+
else if (evt.data.match(/^app_end:error/)) {
|
67
|
+
open_dialog("<font color='red'>エラーが発生しました</font>");
|
16
68
|
} else {
|
17
|
-
var log =
|
18
|
-
$('#log').
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
);
|
69
|
+
var log = "<li>" + evt.data + "</li>";
|
70
|
+
$('#log').append(log);
|
71
|
+
if ($auto_scroll) {
|
72
|
+
$('.outarea').scrollTop($('.outarea').get(0).scrollHeight);
|
73
|
+
}
|
23
74
|
}
|
24
|
-
|
25
75
|
};
|
26
76
|
ws.onclose = function () {
|
27
77
|
alert("アプリケーションが終了しました!!");
|
@@ -44,14 +94,14 @@ function autocomp(id, file_kind) {
|
|
44
94
|
minLength: 0,
|
45
95
|
delay: 0,
|
46
96
|
select: function (event, ui) {
|
47
|
-
console.log(ui.item.value);
|
97
|
+
//console.log(ui.item.value);
|
48
98
|
jQuery("#" + id).val(ui.item.value);
|
49
99
|
//jQuery(this).autocomplete("search", "");
|
50
100
|
$(this).keydown();
|
51
101
|
},
|
52
102
|
source: function (req, resp) {
|
53
103
|
$.ajax({
|
54
|
-
url: "http://localhost:
|
104
|
+
url: "http://localhost:53492/search?path=" + $("#" + id).val() + "&kind=" + file_kind,
|
55
105
|
type: "GET",
|
56
106
|
cache: false,
|
57
107
|
dataType: "json",
|
@@ -77,7 +127,8 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
|
|
77
127
|
$("#" + select_file).click(function () {
|
78
128
|
autocomp(search_id, file_kind);
|
79
129
|
$(".ui-autocomplete").css("z-index", 1000);
|
80
|
-
$("#" +
|
130
|
+
console.log("name=" + $("#" + file_name).val());
|
131
|
+
$("#" + search_id).val($("#" + file_name).val());
|
81
132
|
$("#" + dialog_id).dialog({
|
82
133
|
modal: true
|
83
134
|
, show: "slide" //表示時のアニメーション
|
@@ -140,7 +191,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
|
|
140
191
|
h += "</tr></table>";
|
141
192
|
$("dl#wrap").append(h);
|
142
193
|
} else {
|
143
|
-
console.log("type=" + s[i].type);
|
194
|
+
//console.log("type=" + s[i].type);
|
144
195
|
}
|
145
196
|
}
|
146
197
|
});
|
@@ -160,7 +211,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
|
|
160
211
|
var json_data = []
|
161
212
|
$.getJSON(json_file, function (s) {
|
162
213
|
for (var i in s) {
|
163
|
-
console.log(s[i].name);
|
214
|
+
//console.log(s[i].name);
|
164
215
|
if (s[i].type == "input") {
|
165
216
|
var data = {};
|
166
217
|
data["name"] = s[i].name;
|
@@ -191,7 +242,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
|
|
191
242
|
data["description"] = s[i].description;
|
192
243
|
json_data.push(data);
|
193
244
|
} else {
|
194
|
-
console.log("type=" + s[i].type);
|
245
|
+
//console.log("type=" + s[i].type);
|
195
246
|
}
|
196
247
|
}
|
197
248
|
$ws.send("setting:" + JSON.stringify(json_data));
|
@@ -219,18 +270,40 @@ function dispFile() {
|
|
219
270
|
alert('選択したファイルの値は' + fName + 'です');
|
220
271
|
}
|
221
272
|
|
273
|
+
function openFile(file) {
|
274
|
+
$ws.send("openfile:" + file);
|
275
|
+
}
|
276
|
+
|
222
277
|
// 起動時の処理
|
223
278
|
$(document).ready(function () {
|
224
279
|
// サーバに接続
|
225
|
-
server_connect("ws://localhost:
|
280
|
+
server_connect("ws://localhost:53492/wsserver")
|
226
281
|
// ウインドウサイズ
|
227
282
|
var width = 800;
|
228
283
|
var height = 600;
|
284
|
+
$(window).resize(function () {
|
285
|
+
$(".outarea").height($(window).height() - 300);
|
286
|
+
});
|
229
287
|
// ウインドウの位置
|
230
288
|
$(function () {
|
231
289
|
window.resizeTo(width, height);
|
232
290
|
window.moveTo((window.screen.width / 2) - (width / 2), (screen.height / 2) - (height / 2));
|
233
291
|
//window.moveTo(0,0);
|
292
|
+
$(".outarea").height($(window).height() - 300);
|
293
|
+
});
|
294
|
+
|
295
|
+
$('.outarea').scroll(function () {
|
296
|
+
var h = $('.outarea').get(0).scrollHeight - $('.outarea').innerHeight();
|
297
|
+
//console.log("scrollEnd=" + Math.abs($('.outarea').scrollTop() - h));
|
298
|
+
if (Math.abs($('.outarea').scrollTop() - h) < 30) {
|
299
|
+
// 最後までスクロールしている
|
300
|
+
// 自動スクロールON
|
301
|
+
$auto_scroll = true;
|
302
|
+
} else {
|
303
|
+
// 自動スクロールOFF
|
304
|
+
$auto_scroll = false;
|
305
|
+
}
|
306
|
+
//console.log("auto_scroll=" + $auto_scroll);
|
234
307
|
});
|
235
308
|
|
236
309
|
// ハンドラ登録
|
@@ -239,6 +312,7 @@ $(document).ready(function () {
|
|
239
312
|
});
|
240
313
|
|
241
314
|
$("#exec").click(function () {
|
315
|
+
$('#log').empty();
|
242
316
|
send_message("exec:" + $("#upFile").val());
|
243
317
|
});
|
244
318
|
|
data/lib/template/server.rb
CHANGED
@@ -48,7 +48,8 @@ class Search < Sinatra::Base
|
|
48
48
|
data = {}
|
49
49
|
next if File.basename(file) == "."
|
50
50
|
next if kind == "dir" and !File.directory?(file)
|
51
|
-
data["label"] = File.
|
51
|
+
data["label"] = File.basename(file)
|
52
|
+
data["label"] += "/" if (File.directory?(file))
|
52
53
|
data["value"] = File.expand_path(file)
|
53
54
|
res.push data
|
54
55
|
end
|
data/lib/template/start.rb
CHANGED
data/lib/template/wsserver.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "./server_app_base"
|
2
2
|
require "json"
|
3
|
+
require "cgi"
|
3
4
|
|
4
5
|
def config_json_hash(json)
|
5
6
|
config = {}
|
@@ -12,6 +13,7 @@ end
|
|
12
13
|
class WsServer < Sinatra::Base
|
13
14
|
$ws_list = []
|
14
15
|
json_config = nil
|
16
|
+
exec_thread = nil
|
15
17
|
get "" do
|
16
18
|
if !request.websocket?
|
17
19
|
"no supported"
|
@@ -24,24 +26,46 @@ class WsServer < Sinatra::Base
|
|
24
26
|
ws.onmessage do |msg|
|
25
27
|
puts msg
|
26
28
|
if msg =~ /^exec:/
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
if exec_thread == nil
|
30
|
+
json = JSON.parse(File.read("config/setting.json"))
|
31
|
+
json_config = config_json_hash(json)
|
32
|
+
$app.set_config(json_config)
|
33
|
+
argv = msg.gsub(/^exec:/, "")
|
34
|
+
exec_thread = Thread.new {
|
35
|
+
begin
|
36
|
+
$app.start(argv.split(",")) do |out|
|
37
|
+
ws.send(out)
|
38
|
+
end
|
39
|
+
ws.send("app_end:normal")
|
40
|
+
rescue
|
41
|
+
puts $!
|
42
|
+
puts $@
|
43
|
+
puts "app_end:err"
|
44
|
+
ws.send("app_end:error")
|
45
|
+
ensure
|
46
|
+
puts "exit thread"
|
47
|
+
exec_thread = nil
|
48
|
+
end
|
49
|
+
}
|
50
|
+
else
|
51
|
+
puts "app_end:err"
|
52
|
+
ws.send("app_end:error")
|
53
|
+
end
|
36
54
|
end
|
37
55
|
if msg =~ /^stop/
|
38
|
-
|
56
|
+
if exec_thread
|
57
|
+
$app.stop
|
58
|
+
end
|
39
59
|
end
|
40
60
|
if msg =~ /^suspend/
|
41
|
-
|
61
|
+
if exec_thread
|
62
|
+
$app.suspend
|
63
|
+
end
|
42
64
|
end
|
43
65
|
if msg =~ /^resume/
|
44
|
-
|
66
|
+
if exec_thread
|
67
|
+
$app.resume
|
68
|
+
end
|
45
69
|
end
|
46
70
|
if msg =~ /^setting:/
|
47
71
|
json_string = msg.gsub(/^setting:/, "")
|
@@ -52,6 +76,12 @@ class WsServer < Sinatra::Base
|
|
52
76
|
json_config = config_json_hash(json)
|
53
77
|
$app.set_config(json_config)
|
54
78
|
end
|
79
|
+
if msg =~ /^openfile:/
|
80
|
+
file = msg.gsub(/^openfile:/, "")
|
81
|
+
Thread.new {
|
82
|
+
system "#{json_config["editor"]} #{CGI.unescapeHTML(file)}"
|
83
|
+
}
|
84
|
+
end
|
55
85
|
|
56
86
|
if msg == "exit"
|
57
87
|
unless ENV["OCRA"] == "true"
|
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.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- masataka kuwayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|