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.
@@ -10,70 +10,67 @@
10
10
  <!-- jQuery UI -->
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
-
14
13
  <script src="js/main.js"></script>
15
- <link rel="stylesheet" href="css/index.css" type="text/css">
14
+ <link rel="stylesheet" href="../css/index.css" type="text/css">
16
15
  </head>
17
16
 
18
17
  <body>
19
- <div id="msg_dialog" style="display:none;">
18
+ <div id="msg_dialog" class="dialog" style="display:none;">
20
19
  <div id="msg_text">message</div>
21
20
  </div>
22
- <h4>RubyAppBase</h4>
23
- <hr>
24
- <!-- menu -->
25
- <div id="setting_dialog" style="display:none;">
26
- <dl id="wrap"></dl>
27
- </div>
28
- <div>
29
- <ul class="menu">
30
- <Li><a href="#" id="exec" name="exec">実行</a></li>
31
- <li><a href="#" id="stop" name="stop">停止</a></li>
32
- <li>
21
+ <div class="main-title-row">
22
+ <h2 class="main-title">RubyAppBase</h2>
23
+ <div class="main-title-actions">
24
+ <a href="#" id="exec" name="exec" class="btn primary">実行</a>
25
+ <a href="#" id="stop" name="stop" class="btn danger">停止</a>
26
+ <div class="btn primary menu-title" style="position:relative;">
33
27
  設定
34
- <ul class="menuSub">
28
+ <ul class="menuSub" style="right:0; left:auto; min-width:120px;">
35
29
  <li><a href="#" id="setting">設定</a></li>
36
30
  <li><a href="#" id="save_setting">設定保存</a></li>
37
31
  <li><a href="#" id="load_setting">設定読み込み</a></li>
38
32
  </ul>
39
- </li>
40
- <!--
41
- <li>
42
- menu3
43
- <ul class="menuSub">
44
- <li><a href="#">menu3-1</a></li>
45
- <li><a href="#">menu3-2</a></li>
46
- </ul>
47
- </li>
48
- -->
49
- </ul>
33
+ </div>
34
+ </div>
50
35
  </div>
51
-
52
- <div id="dialog1" style="display:none;">
53
- <input class="inarea" type="search" name="search_str" id="search_str">
36
+ <hr>
37
+ <div id="setting_dialog" class="dialog" style="display:none;">
38
+ <dl id="wrap"></dl>
54
39
  </div>
55
- <table>
56
- <tr>
57
- <td class="long"><input class="inarea" type="search" id="upFile" name="upFile"></td>
58
- <td><input type="button" id="select_file" value="ファイル選択" /></td>
59
- </tr>
60
- </table>
61
40
 
62
- <div id="dialog2" style="display:none;">
63
- <input class="inarea" type="search" name="search_str2" id="search_str2">
64
- </div>
65
- <table>
66
- <tr>
67
- <td class="long"><input class="inarea" type="search" id="upDir" name="upDir"></td>
68
- <td><input type="button" id="select_dir" value="フォルダ選択" /></td>
69
- </tr>
70
- </table>
41
+ <section class="input-section">
42
+ <div id="dialog1" class="dialog" style="display:none;">
43
+ <input class="inarea" type="search" name="search_str" id="search_str">
44
+ </div>
45
+ <table>
46
+ <tr>
47
+ <td class="long">
48
+ <input class="inarea" type="search" id="upFile" name="upFile" placeholder="ファイルを選択...">
49
+ </td>
50
+ <td>
51
+ <input type="button" id="select_file" value="ファイル選択" class="btn secondary" />
52
+ </td>
53
+ </tr>
54
+ </table>
71
55
 
72
- <div class="outarea">
73
- <ul name="log" id="log" class="log">
74
- </ul>
75
- </div>
56
+ <div id="dialog2" class="dialog" style="display:none;">
57
+ <input class="inarea" type="search" name="search_str2" id="search_str2">
58
+ </div>
59
+ <table>
60
+ <tr>
61
+ <td class="long">
62
+ <input class="inarea" type="search" id="upDir" name="upDir" placeholder="フォルダを選択...">
63
+ </td>
64
+ <td>
65
+ <input type="button" id="select_dir" value="フォルダ選択" class="btn secondary" />
66
+ </td>
67
+ </tr>
68
+ </table>
69
+ </section>
76
70
 
71
+ <section class="outarea">
72
+ <ul name="log" id="log" class="log"></ul>
73
+ </section>
77
74
  </body>
78
75
 
79
76
  </html>
@@ -8,18 +8,18 @@ var dialog_timeout = null;
8
8
  function open_dialog(msg, timeout = 0) {
9
9
  console.log("msg=" + msg);
10
10
  $("#msg_text").html(msg);
11
- d = $("#msg_dialog").dialog({
12
- modal: true
13
- , show: "slide" //表示時のアニメーション
14
- , hide: "slide" //閉じた時のアニメーション
15
- , title: "Message" //ダイアログのタイトル
16
- , width: 500 //ダイアログの横幅
17
- , height: 300 //ダイアログの高さ
18
- , resizable: true //リサイズ可
19
- , closeOnEscape: false //[ESC]キーで閉じられなくする
20
- , draggable: true //ダイアログの移動を可に
21
- , buttons: {
22
- "OK": function () { //Cancelボタン
11
+ var d = $("#msg_dialog").dialog({
12
+ modal: true,
13
+ show: "slide", //表示時のアニメーション
14
+ hide: "slide", //閉じた時のアニメーション
15
+ title: "Message", //ダイアログのタイトル
16
+ width: 500, //ダイアログの横幅
17
+ height: 300, //ダイアログの高さ
18
+ resizable: true, //リサイズ可
19
+ closeOnEscape: false, //[ESC]キーで閉じられなくする
20
+ draggable: true, //ダイアログの移動を可に
21
+ buttons: {
22
+ "OK": function () { //OKボタン
23
23
  if (dialog_timeout != null) {
24
24
  clearTimeout(dialog_timeout);
25
25
  }
@@ -40,7 +40,7 @@ function open_dialog_org(msg) {
40
40
  if (dialog != null) {
41
41
  dialog.close();
42
42
  }
43
- var dialog = window.open(
43
+ dialog = window.open(
44
44
  "/open_dialog?msg=" + msg,
45
45
  "pop",
46
46
  "width=300, height=100, left=" + left + ", top=" + top
@@ -78,7 +78,14 @@ function server_connect(url) {
78
78
  open_dialog("<font color='red'>エラーが発生しました</font>");
79
79
  }
80
80
  else if (evt.data.match(/^popup:/)) {
81
- open_dialog(evt.data.replace(/^popup:/, ""), 3000);
81
+ console.log("str=" + evt.data);
82
+ const timeout_str = evt.data.match(/:(\d+):/);
83
+ if (timeout_str && timeout_str[1]) {
84
+ console.log("timeout_str=" + timeout_str[1]);
85
+ open_dialog(evt.data.replace(/^popup:(\d+):/, ""), Number(timeout_str[1]));
86
+ } else {
87
+ open_dialog(evt.data.replace(/^popup:/, ""));
88
+ }
82
89
  } else {
83
90
  var log = "<li>" + evt.data + "</li>";
84
91
  $('#log').append(log);
@@ -176,22 +183,31 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
176
183
  console.log("name=" + $("#" + file_name).val());
177
184
  $("#" + search_id).val($("#" + file_name).val());
178
185
  $("#" + dialog_id).dialog({
179
- modal: true
180
- , show: "slide" //表示時のアニメーション
181
- , hide: "explode" //閉じた時のアニメーション
182
- , title: "Select File" //ダイアログのタイトル
183
- , width: 580 //ダイアログの横幅
184
- , height: 400 //ダイアログの高さ
185
- , resizable: true //リサイズ可
186
- , closeOnEscape: false //[ESC]キーで閉じられなくする
187
- , draggable: true //ダイアログの移動を可に
188
- , buttons: {
189
- "OK": function () { //OKボタン
186
+ modal: true,
187
+ show: "slide",
188
+ hide: "explode",
189
+ title: "Select File",
190
+ width: 580,
191
+ height: 400,
192
+ resizable: true,
193
+ closeOnEscape: false,
194
+ draggable: true,
195
+ open: function (event, ui) {
196
+ // ダイアログの高さを取得
197
+ var dialogHeight = $("#" + dialog_id).height();
198
+ // オートコンプリートリストの高さをダイアログに合わせる
199
+ $(".ui-autocomplete").css({
200
+ "max-height": dialogHeight + "px",
201
+ "overflow-y": "auto"
202
+ });
203
+ },
204
+ buttons: {
205
+ "OK": function () {
190
206
  $("#" + file_name).val($("#" + search_id).val());
191
207
  $(this).dialog("close");
192
208
  $("#" + search_id).autocomplete("destroy");
193
209
  },
194
- "Cancel": function () { //Cancelボタン
210
+ "Cancel": function () {
195
211
  $(this).dialog("close");
196
212
  $("#" + search_id).autocomplete("destroy");
197
213
  }
@@ -202,62 +218,71 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
202
218
 
203
219
  function setting_dialog(open_id, dialog_id, json_file) {
204
220
  var version;
221
+ var is_error = false;
222
+
205
223
  $("#" + open_id).click(function () {
206
- $("#" + dialog_id).val = $(function () {
207
- $("dl#wrap").empty();
208
- $.getJSON(json_file, function (s) {
209
- version = s["version"];
210
- for (var i in s["setting_list"]) {
211
- if (s["setting_list"][i].type == "input") {
212
- var h = "<table><tr>"
213
- + "<td class='setting_name'>" + s["setting_list"][i].description + "</td>"
214
- + "<td><input class='setting_value' type='text' " + "id=" + s["setting_list"][i].name + "_value " + "value=" + "'" + s["setting_list"][i].value + "'" + ">"
215
- + "</td></tr></table>"
216
- $("dl#wrap").append(h);
217
- } else if (s["setting_list"][i].type == "checkbox") {
218
- var h = "<table><tr>";
219
- h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
220
- if (s["setting_list"][i].value == true) {
221
- h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value checked ></td>";
222
- } else {
223
- h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value ></td>";
224
- }
225
- h += "</tr></table>";
226
- $("dl#wrap").append(h);
227
- } else if (s["setting_list"][i].type == "select") {
228
- var h = "<table><tr>";
229
- h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
230
- h += "<td> <select class='setting_value' id=" + s["setting_list"][i].name + "_value " + ">";
231
- s["setting_list"][i].select.forEach(e => {
232
- if (e == s["setting_list"][i].value) {
233
- h += "<option value=" + e + " selected >" + e + "</option>";
234
- } else {
235
- h += "<option value=" + e + ">" + e + "</option>";
236
- }
237
- });
238
- h += "</select></td>";
239
- h += "</tr></table>";
240
- $("dl#wrap").append(h);
224
+ $("dl#wrap").empty();
225
+ $.getJSON(json_file, function (s) {
226
+ version = s["version"];
227
+ for (var i in s["setting_list"]) {
228
+ if (s["setting_list"][i].type == "input") {
229
+ var h = "<table><tr>"
230
+ + "<td class='setting_name'>" + s["setting_list"][i].description + "</td>"
231
+ + "<td><input class='setting_value' type='text' " + "id=" + s["setting_list"][i].name + "_value " + "value='" + s["setting_list"][i].value + "'>"
232
+ + "</td></tr></table>";
233
+ $("dl#wrap").append(h);
234
+ } else if (s["setting_list"][i].type == "textarea") {
235
+ var h = "<table><tr>"
236
+ + "<td class='setting_name'>" + s["setting_list"][i].description + "</td>"
237
+ + "<td><textarea class='setting_value' rows='5' " + "id=" + s["setting_list"][i].name + "_value" + ">"
238
+ + JSON.stringify(s["setting_list"][i].value, null, 2)
239
+ + "</textarea>"
240
+ + "</td></tr></table>";
241
+ $("dl#wrap").append(h);
242
+ } else if (s["setting_list"][i].type == "checkbox") {
243
+ var h = "<table><tr>";
244
+ h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
245
+ if (s["setting_list"][i].value == true) {
246
+ h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value checked ></td>";
241
247
  } else {
242
- //console.log("type=" + s["setting_list"][i].type);
248
+ h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value ></td>";
243
249
  }
250
+ h += "</tr></table>";
251
+ $("dl#wrap").append(h);
252
+ } else if (s["setting_list"][i].type == "select") {
253
+ var h = "<table><tr>";
254
+ h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
255
+ h += "<td> <select class='setting_value' id=" + s["setting_list"][i].name + "_value" + ">";
256
+ s["setting_list"][i].select.forEach(e => {
257
+ if (e == s["setting_list"][i].value) {
258
+ h += "<option value=" + e + " selected >" + e + "</option>";
259
+ } else {
260
+ h += "<option value=" + e + ">" + e + "</option>";
261
+ }
262
+ });
263
+ h += "</select></td>";
264
+ h += "</tr></table>";
265
+ $("dl#wrap").append(h);
266
+ } else {
267
+ //console.log("type=" + s["setting_list"][i].type);
244
268
  }
245
- });
269
+ }
246
270
  });
247
271
  $("#" + dialog_id).dialog({
248
- modal: true
249
- , show: "slide" //表示時のアニメーション
250
- , hide: "explode" //閉じた時のアニメーション
251
- , title: "Setting" //ダイアログのタイトル
252
- , width: 580 //ダイアログの横幅
253
- , height: 400 //ダイアログの高さ
254
- , resizable: true //リサイズ可
255
- , closeOnEscape: false //[ESC]キーで閉じられなくする
256
- , draggable: true //ダイアログの移動を可に
257
- , buttons: {
272
+ modal: true,
273
+ show: "slide", //表示時のアニメーション
274
+ hide: "explode", //閉じた時のアニメーション
275
+ title: "Setting", //ダイアログのタイトル
276
+ width: 650, //ダイアログの横幅
277
+ height: 600, //ダイアログの高さ
278
+ resizable: true, //リサイズ可
279
+ closeOnEscape: false, //[ESC]キーで閉じられなくする
280
+ draggable: true, //ダイアログの移動を可に
281
+ buttons: {
258
282
  "OK": function () { //OKボタン
259
283
  var json_obj = {};
260
284
  var json_data = [];
285
+ is_error = false;
261
286
  $.getJSON(json_file, function (s) {
262
287
  json_obj["version"] = s["version"];
263
288
  for (var i in s["setting_list"]) {
@@ -271,6 +296,20 @@ function setting_dialog(open_id, dialog_id, json_file) {
271
296
  data["description"] = s["setting_list"][i].description;
272
297
  json_data.push(data);
273
298
  }
299
+ else if (s["setting_list"][i].type == "textarea") {
300
+ var data = {};
301
+ data["name"] = s["setting_list"][i].name;
302
+ try {
303
+ data["value"] = JSON.parse($("#" + s["setting_list"][i].name + "_value").val());
304
+ } catch (e) {
305
+ is_error = true;
306
+ alert("JavaScript error:" + e.message + "\n" + $("#" + s["setting_list"][i].name + "_value").val());
307
+ }
308
+ data["type"] = s["setting_list"][i].type;
309
+ data["select"] = s["setting_list"][i].select;
310
+ data["description"] = s["setting_list"][i].description;
311
+ json_data.push(data);
312
+ }
274
313
  else if (s["setting_list"][i].type == "checkbox") {
275
314
  var data = {};
276
315
  data["name"] = s["setting_list"][i].name;
@@ -295,13 +334,23 @@ function setting_dialog(open_id, dialog_id, json_file) {
295
334
  //console.log("type=" + s["setting_list"][i].type);
296
335
  }
297
336
  }
337
+ console.log("OK Button " + is_error);
298
338
  // Jsonデータをサーバに送信
299
- json_obj["setting_list"] = json_data;
300
- $ws.send("setting:" + JSON.stringify(json_obj));
301
- });
302
- $(this).dialog("close");
339
+ if (is_error == false) {
340
+ json_obj["setting_list"] = json_data;
341
+ var json_string = JSON.stringify(json_obj);
342
+ console.log("json_string:" + json_string);
343
+ $ws.send("setting:" + json_string);
344
+ }
345
+ })
346
+ .done(function () {
347
+ if (is_error == false) {
348
+ $("#" + dialog_id).dialog("close");
349
+ }
350
+ });
303
351
  },
304
352
  "Cancel": function () { //Cancelボタン
353
+ console.log("Cancel Button");
305
354
  $(this).dialog("close");
306
355
  }
307
356
  }
@@ -381,10 +430,10 @@ function openFile(file) {
381
430
  $(document).ready(function () {
382
431
 
383
432
  // サーバに接続
384
- server_connect("ws://localhost:35983/wsserver")
433
+ server_connect("ws://localhost:45739/wsserver")
385
434
  window.onload = function (e) {
386
435
  // サーバに接続
387
- //server_connect("ws://localhost:35983/wsserver")
436
+ //server_connect("ws://localhost:45739/wsserver")
388
437
  }
389
438
 
390
439
  // menu
@@ -405,14 +454,14 @@ $(document).ready(function () {
405
454
  var width = 800;
406
455
  var height = 600;
407
456
  $(window).resize(function () {
408
- $(".outarea").height($(window).height() - 220);
457
+ //$(".outarea").height($(window).height() - 220);
409
458
  });
410
459
  // ウインドウの位置
411
460
  $(function () {
412
- window.resizeTo(width, height);
413
- window.moveTo((window.screen.width / 2) - (width / 2), (screen.height / 2) - (height / 2));
414
- //window.moveTo(0,0);
415
- $(".outarea").height($(window).height() - 220);
461
+ // window.resizeTo(width, height);
462
+ // window.moveTo((window.screen.width / 2) - (width / 2), (screen.height / 2) - (height / 2));
463
+ // //window.moveTo(0,0);
464
+ // $(".outarea").height($(window).height() - 220);
416
465
  });
417
466
 
418
467
  $('.outarea').scroll(function () {
@@ -456,4 +505,3 @@ $(document).ready(function () {
456
505
  autocomp_history("upFile", "history.json")
457
506
 
458
507
  });
459
-
@@ -11,8 +11,8 @@ class MyApp < AppMainBase
11
11
  yield v if block_given?
12
12
  end
13
13
 
14
- # Browserにメッセージ送信
15
- app_send("popup:start app #{argv[0]}")
14
+ # Browserにメッセージ送信(3秒表示)
15
+ app_send("popup:3000:start app #{argv[0]}")
16
16
 
17
17
  # 履歴の保存
18
18
  add_history("history.json", argv[0])
@@ -1,23 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ $LOAD_PATH << File.dirname(File.expand_path(__FILE__))
3
+
4
+ require "sinatra"
5
+ require "sinatra/contrib"
6
+ require "sinatra-websocket"
7
+ require "thin"
1
8
  require "json"
2
9
  require "kconv"
10
+ require "cgi"
11
+ require "pathname"
12
+ require "common"
3
13
 
4
14
  class Search < Sinatra::Base
5
15
  helpers Sinatra::Streaming
6
- get "" do
16
+ get "/" do
17
+ content_type "application/json", :charset => "utf-8"
7
18
  q_hash = {}
8
19
  puts request.query_string
9
20
  request.query_string.split("&").each do |q|
10
21
  work = q.split("=")
11
22
  if work[1] != nil
12
- q_hash[work[0]] = CGI.unescape work[1].toutf8
23
+ q_hash[work[0]] = CGI.unescape(work[1].toutf8)
13
24
  else
14
25
  q_hash[work[0]] = ""
15
26
  end
16
27
  end
17
- str = q_hash["path"].gsub(/\\/, "/")
28
+ begin
29
+ str = q_hash["path"].gsub(/\\/, "/")
30
+ rescue
31
+ str = "/"
32
+ end
18
33
  puts "str=#{str}"
34
+ str = "/" if str.to_s == ""
19
35
  kind = q_hash["kind"].gsub(/\\/, "/")
20
36
  puts "kind=#{kind}"
37
+ kind = "file" if kind.to_s == ""
21
38
  res = []
22
39
  str = str.gsub(/\\/, "/")
23
40
  dir = File.dirname(str)
@@ -25,15 +42,13 @@ class Search < Sinatra::Base
25
42
  puts "dir=#{dir}"
26
43
  puts "file=#{file}"
27
44
 
28
- kernel = Facter.value(:kernel)
29
- if kernel == "windows"
30
- dir = "c:/" if dir == nil
31
- dir = "c:/" if dir == "/"
32
- elsif kernel == "Linux"
33
- dir = "/" if dir == nil
45
+ kernel = get_os_type
46
+ if kernel.downcase == "windows"
47
+ dir = "c:/" if dir.nil? || dir == "/"
48
+ elsif kernel.downcase == "linux"
49
+ dir = "/" if dir.nil?
34
50
  else
35
- dir = "c:/" if dir == nil
36
- dir = "c:/" if dir == "/"
51
+ dir = "c:/" if dir.nil? || dir == "/"
37
52
  end
38
53
 
39
54
  path = "#{dir}/#{file}"
@@ -43,16 +58,25 @@ class Search < Sinatra::Base
43
58
  path = path + "*"
44
59
  end
45
60
  path.gsub!(/[\/]+/, "/")
46
- puts path
61
+ puts "path=#{path}"
47
62
  Dir.glob(path, File::FNM_DOTMATCH).each do |file|
48
63
  data = {}
49
64
  next if File.basename(file) == "."
50
65
  next if kind == "dir" and !File.directory?(file)
51
66
  data["label"] = File.basename(file)
52
- data["label"] += "/" if (File.directory?(file))
67
+ data["label"] += "/" if File.directory?(file)
53
68
  data["value"] = File.expand_path(file)
54
69
  res.push data
55
70
  end
71
+ if 0 == res.select { |dir| dir["label"] == "../" }.size
72
+ data = {}
73
+ pp = Pathname(File.expand_path("#{dir}/#{file}"))
74
+ data["label"] = "../"
75
+ data["label"] += "/" if pp.parent.to_s == "/"
76
+ data["value"] = pp.parent.to_s
77
+ data["value"] = "/" if data["value"] =~ /^[\/]+$/
78
+ res.push data
79
+ end
56
80
  JSON.generate res.sort { |a, b| a["value"] <=> b["value"] }
57
81
  end
58
82
  end
@@ -1,17 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require "json"
3
+
2
4
  class AppMainBase
3
5
  def initialize
4
6
  @config = nil
5
- @aboet = false
7
+ @abort = false
6
8
  @exec = false
7
9
  @suspend = false
8
10
  @ws = nil
9
11
  end
10
12
 
11
13
  def app_send(str)
12
- if @ws != nil
13
- @ws.send(str)
14
- end
14
+ @ws&.send(str)
15
15
  end
16
16
 
17
17
  def set_ws(ws)
@@ -26,38 +26,35 @@ class AppMainBase
26
26
  @exec = true
27
27
  end
28
28
 
29
- def stop()
29
+ def stop
30
30
  @abort = true
31
31
  @exec = false
32
32
  end
33
33
 
34
- def suspend()
34
+ def suspend
35
35
  @suspend = true
36
36
  end
37
37
 
38
- def resume()
38
+ def resume
39
39
  @suspend = false
40
40
  end
41
41
 
42
42
  # 履歴の保存
43
43
  def add_history(file, history_data, max = 10)
44
+ history_dir = @config&.fetch(:home_dir, "./") + "history/"
45
+ path = File.join(history_dir, file)
44
46
  begin
45
- buf = File.read "#{$home_dir}history/#{file}"
47
+ buf = File.read(path)
48
+ data = JSON.parse(buf)
46
49
  rescue
47
- buf = ""
48
- end
49
- data = eval(buf)
50
- if data == nil
51
50
  data = []
52
51
  end
53
52
  if history_data.to_s != ""
54
- data.prepend history_data
55
- end
56
- data = data.uniq[0..max - 1]
57
- File.open("#{$home_dir}history/#{file}", "w") do |f|
58
- f.write JSON.pretty_generate data
53
+ data.unshift(history_data)
59
54
  end
55
+ data = data.uniq[0, max]
56
+ File.write(path, JSON.pretty_generate(data))
60
57
  end
61
58
  end
62
59
 
63
- require "app_load.rb"
60
+ require_relative "app_load"
@@ -8,7 +8,7 @@ require "daemons"
8
8
  require "fileutils"
9
9
  require "kconv"
10
10
  require "json"
11
- require "facter"
11
+ require "common"
12
12
 
13
13
  # ログ出力
14
14
  module Output
@@ -24,7 +24,7 @@ module Output
24
24
  alias_method :write_org, :write
25
25
 
26
26
  def initialize(stdout)
27
- @stdout = false
27
+ @stdout = stdout
28
28
  end
29
29
 
30
30
  attr_accessor :stdout
@@ -54,9 +54,9 @@ FileUtils.cd dir
54
54
  pp ARGV
55
55
  if ARGV[0] == "test"
56
56
  $home_dir = "./"
57
- ARGV = []
57
+ ARGV.clear
58
58
  else
59
- $home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/,"") + "/"
59
+ $home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/, "") + "/"
60
60
  end
61
61
  puts "home_dir=#{$home_dir}"
62
62
  FileUtils.mkdir_p("#{$home_dir}/logs")
@@ -85,7 +85,7 @@ buf = File.binread("js/main.js").toutf8
85
85
  buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
86
86
  File.binwrite("js/main.js", buf)
87
87
 
88
- # index.htaの編集
88
+ # index.htmlの編集
89
89
  buf = File.binread("html/index.html").toutf8
90
90
  buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
91
91
  File.binwrite("html/index.html", buf)
@@ -108,10 +108,10 @@ begin
108
108
  json_file = "#{$home_dir}/config/browser.json"
109
109
  json = JSON.parse(File.read json_file)
110
110
  puts json
111
- kernel = Facter.value(:kernel)
112
- if kernel == "windows"
111
+ kernel = get_os_type
112
+ if kernel.downcase == "windows"
113
113
  browser = json["chrome_win"]
114
- elsif kernel == "Linux"
114
+ elsif kernel.downcase == "linux"
115
115
  browser = json["chrome_linux"]
116
116
  else
117
117
  browser = json["chrome_win"]