browser_app_base 0.0.1 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bbd62be060b288835a8ede00b318159fb1cebd6694b21555b919bdde6d3ca1d
4
- data.tar.gz: a82cc9b49fce11e7a1d4d609778fd75237f6f03b44999c29ef55dc4db10d433b
3
+ metadata.gz: 3565687a000a2d7a0636d2ac47c09de24d87cfe1554777b58d8f9d9ab494102d
4
+ data.tar.gz: a305213755edff63ab70edff0f2011d52c33ee6fd53b9aaddce80865440107c3
5
5
  SHA512:
6
- metadata.gz: 60b86bad8e1f12f39b00726153f5a7c9f01d9931cba8cd0f7590d997a00a99ae3e4e7f5ab6b5e866c1e6d8e916da7785bab45bcf7db61deebe4240b56bd18c18
7
- data.tar.gz: adb9bcb7f57339e6568dc356bf6bd82a40c5cc56c43995ef66b6b5d71b179cbb391f21bdf774fbb5687e7cf656d74879628b9a0a05cd7a33e0235be1881b64b6
6
+ metadata.gz: f2f2cb63d6ff01e6bb39731fd36944a8a4ff96c9b5370ed9b386383bc6c67fe55586d1e6f278d8af17713b542079f1850de0afd820c9b78357d7afc4debb63d8
7
+ data.tar.gz: 200b7d9a67ef7421f52a2d3887b91d3d9c5ab99eda27ccebbf1725718204d25945bc0f31679811d0d4e959561ebed2906de8b98900c9272f80196b6fa9f7640a
@@ -0,0 +1,15 @@
1
+ {
2
+ // IntelliSense を使用して利用可能な属性を学べます。
3
+ // 既存の属性の説明をホバーして表示します。
4
+ // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug Local File",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "cwd": "${workspaceRoot}/lib/template/",
12
+ "program": "${workspaceRoot}/lib/template/start.rb"
13
+ }
14
+ ]
15
+ }
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # BrowserAppBase
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/browser_app_base`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Windows and Linux browser-based desktop application templates.
4
4
 
5
- Windows and Linux browser-based desktop application templates
5
+ You need a Chrome browser to run it.
6
6
 
7
7
  ## Installation
8
8
 
@@ -24,16 +24,41 @@ Or install it yourself as:
24
24
 
25
25
  create_browser_app [options]
26
26
  -d, --dir dir_name application directory
27
+ -a, --app app_name application name
27
28
  -h, --help command help
28
29
 
29
30
 
30
- create app templat
31
+ ## Create app templat
31
32
 
32
- $ create_browser_app -d ~/test/
33
+ $ create_browser_app -d ~/test/ -a MyApp
33
34
 
34
- start application
35
+ ## add application code
36
+ $ cd ~/test/
37
+ $ vi my_app.rb
35
38
 
36
- $ cd ~/test/app
39
+ ```ruby
40
+ class MyApp < AppMainBase
41
+ def start(argv)
42
+ super
43
+ # add application code
44
+ end
45
+
46
+ def stop()
47
+ super
48
+ # add application code
49
+ end
50
+ end
51
+ ```
52
+
53
+ ui application sample
54
+
55
+ index.html
56
+ css/index.css
57
+ js/main.js
58
+
59
+ ## Start application
60
+
61
+ $ cd ~/test/
37
62
  $ ruby start.rb
38
63
 
39
64
  ## Development
@@ -7,6 +7,7 @@ require "optparse"
7
7
  opt = OptionParser.new
8
8
  o = {}
9
9
  opt.on("-d dir_name", "--dir dir_name", "application directory") { |v| o[:dir] = v }
10
+ opt.on("-a app_name", "--app app_name", "application name") { |v| o[:app] = v }
10
11
  opt.on("-h", "--help", "command help") { puts opt; exit }
11
12
  begin
12
13
  opt.parse!(ARGV)
@@ -20,4 +21,4 @@ if o[:dir] == nil
20
21
  exit
21
22
  end
22
23
 
23
- BrowserAppBase.create o[:dir]
24
+ BrowserAppBase.create o
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "browser app base"
12
12
  spec.description = "browser application template"
13
- spec.homepage = "https://github.com/sample/"
13
+ spec.homepage = "https://github.com/kuwayama1971/BrowserAppBase"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
15
 
16
16
  #spec.metadata["allowed_push_host"] = "http://mygemserver.com"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrowserAppBase
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -1,20 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "browser_app_base/version"
4
-
5
4
  require "fileutils"
6
5
 
7
6
  module BrowserAppBase
8
7
  class Error < StandardError; end
9
8
 
10
- # Your code goes here...
9
+ def self.get_app_file(app)
10
+ app_file_name = ""
11
+ app.each_char do |s|
12
+ if s =~ /[A-Z]/
13
+ app_file_name += "_" if app_file_name.size != 0
14
+ app_file_name += s.downcase
15
+ else
16
+ app_file_name += s
17
+ end
18
+ end
19
+ return app_file_name + ".rb"
20
+ end
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
11
33
 
12
- def self.create(dir)
34
+ def self.create(arg)
35
+ dir = arg[:dir]
36
+ app = arg[:app]
13
37
  puts "create application base #{dir}"
14
38
 
15
39
  FileUtils.mkdir_p dir
16
40
 
17
41
  path = File.dirname(File.expand_path(__FILE__))
18
- FileUtils.cp_r "#{path}/template", "#{dir}/app"
42
+ Dir.glob("#{path}/template/*") do |f|
43
+ puts "#{f} => #{dir}"
44
+ FileUtils.cp_r f, "#{dir}/"
45
+ end
46
+
47
+ if app
48
+ app_file = get_app_file(app)
49
+
50
+ load_app = <<"EOS"
51
+ require '#{app_file}'
52
+ $app = #{get_app_name(app)}.new
53
+ EOS
54
+
55
+ File.open("#{dir}/app_load.rb", "w") do |f|
56
+ f.write load_app
57
+ end
58
+
59
+ puts "create #{app_file}"
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)))
64
+ end
19
65
  end
20
66
  end
@@ -0,0 +1,2 @@
1
+ require "my_app_sample.rb"
2
+ $app = MyApp.new
@@ -1,4 +1,4 @@
1
1
  {
2
- "chrome_win": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
2
+ "chrome_win": "start chrome",
3
3
  "chrome_linux": "/bin/google-chrome"
4
4
  }
@@ -0,0 +1,50 @@
1
+ [
2
+ {
3
+ "name": "name1",
4
+ "value": "value1",
5
+ "type": "input",
6
+ "select": "",
7
+ "description": "設定項目1"
8
+ },
9
+ {
10
+ "name": "name2",
11
+ "value": true,
12
+ "type": "checkbox",
13
+ "select": "",
14
+ "description": "有効にする場合はチェック"
15
+ },
16
+ {
17
+ "name": "name3",
18
+ "value": "1",
19
+ "type": "select",
20
+ "select": [
21
+ "1",
22
+ "2",
23
+ "3",
24
+ "4",
25
+ "5"
26
+ ],
27
+ "description": "選択項目"
28
+ },
29
+ {
30
+ "name": "name4",
31
+ "value": "value4",
32
+ "type": "input",
33
+ "select": "",
34
+ "description": "設定項目4"
35
+ },
36
+ {
37
+ "name": "name5",
38
+ "value": "value5",
39
+ "type": "input",
40
+ "select": "",
41
+ "description": "設定項目5"
42
+ },
43
+ {
44
+ "name": "name6",
45
+ "value": "value6",
46
+ "type": "input",
47
+ "select": "",
48
+ "description": "設定項目6"
49
+ }
50
+ ]
@@ -24,6 +24,12 @@ get "/js/:name.js" do
24
24
  File.read "js/#{params[:name]}.js"
25
25
  end
26
26
 
27
+ get "/config/*.*" do |file, ext|
28
+ content_type "text/json", :charset => "utf-8"
29
+ puts "#{file}.#{ext}"
30
+ File.read "config/#{file}.#{ext}"
31
+ end
32
+
27
33
  map "/search" do
28
34
  run Search
29
35
  end
@@ -46,6 +52,6 @@ configure do
46
52
 
47
53
  end
48
54
 
49
- #\ --port 61820
55
+ #\ --port 52538
50
56
 
51
57
  run Sinatra::Application
@@ -22,9 +22,9 @@ hr {
22
22
  padding: 5px;
23
23
  width: 95vw;
24
24
  height: 50vh;
25
+ overflow: auto;
25
26
  }
26
27
 
27
-
28
28
  .inarea {
29
29
  border: thin solid #000000;
30
30
  margin: 5px;
@@ -32,12 +32,6 @@ hr {
32
32
  width: 95%;
33
33
  }
34
34
 
35
- input {
36
- background-color: #FAFAFA;
37
- margin: 5px;
38
- padding: 5px;
39
- }
40
-
41
35
  input.long {
42
36
  width: 90%;
43
37
  background-color: #FAFAFA;
@@ -50,3 +44,60 @@ textarea.long {
50
44
  height: 50vh;
51
45
  }
52
46
 
47
+ .ui-widget {
48
+ font-size: 12px;
49
+ }
50
+
51
+ .ui-autocomplete {
52
+ max-height: 200px;
53
+ max-width: 500px;
54
+ overflow-y: auto;
55
+ overflow-x: auto;
56
+ padding-right: 10px;
57
+ }
58
+
59
+ #jquery-ui-autocomplete label {
60
+ float: left;
61
+ margin-right: 0.5em;
62
+ color: black;
63
+ }
64
+
65
+ .ui-dialog {
66
+ position: absolute;
67
+ top: 0;
68
+ left: 0;
69
+ padding: .2em;
70
+ outline: 0;
71
+ }
72
+
73
+ .long {
74
+ width: 90%;
75
+ }
76
+
77
+ #setting_dialog {
78
+ color: #796fe9;
79
+ background-color: #000000;
80
+ }
81
+
82
+ .setting_name {
83
+ width: 200px;
84
+ color: #796fe9;
85
+ background-color: #000000;
86
+ }
87
+
88
+ .setting_value {
89
+ width: 300px;
90
+ color: #796fe9;
91
+ background-color: #000000;
92
+ }
93
+
94
+ .setting_checkbox {
95
+ color: #796fe9;
96
+ background-color: #000000;
97
+ }
98
+
99
+ ul.log {
100
+ list-style-type: decimal;
101
+ font-size: 10px;
102
+ color: #5d0a94;
103
+ }
@@ -11,8 +11,8 @@
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:61820/js/main.js"></script>
15
- <link rel="stylesheet" href="http://localhost:61820/css/index.css" type="text/css">
14
+ <script src="http://localhost:52538/js/main.js"></script>
15
+ <link rel="stylesheet" href="http://localhost:52538/css/index.css" type="text/css">
16
16
  </head>
17
17
 
18
18
  <body>
@@ -26,13 +26,39 @@
26
26
  <td>
27
27
  <input type="button" id="stop" name="stop" value="停止">
28
28
  </td>
29
+ <td>
30
+ <div id="setting_dialog" style="display:none;">
31
+ <dl id="wrap"></dl>
32
+ </div>
33
+ <input type="button" id="setting" value="設定" />
34
+ </td>
35
+ </tr>
36
+ </table>
37
+
38
+ <div id="dialog1" style="display:none;">
39
+ <input class="inarea" type="text" name="search_str" id="search_str">
40
+ </div>
41
+ <table>
42
+ <tr>
43
+ <td class="long"><input class="inarea" type="text" id="upFile" name="upFile"></td>
44
+ <td><input type="button" id="select_file" value="ファイル選択" /></td>
45
+ </tr>
46
+ </table>
47
+
48
+ <div id="dialog2" style="display:none;">
49
+ <input class="inarea" type="text" name="search_str2" id="search_str2">
50
+ </div>
51
+ <table>
52
+ <tr>
53
+ <td class="long"><input class="inarea" type="text" id="upDir" name="upDir"></td>
54
+ <td><input type="button" id="select_dir" value="フォルダ選択" /></td>
29
55
  </tr>
30
56
  </table>
31
- <input class="inarea" type="text" value="ファイル名を入力" name="search_str" id="search_str">
32
- <input class="inarea" type="file" id="upFile" name="upFile" value="upFile"><br>
33
- <input type="button" value="確認" onclick="dispFile()">
34
57
 
35
- <textarea name="log" id="log" class="outarea"></textarea><br/>
58
+ <div class="outarea">
59
+ <ul name="log" id="log" class="log">
60
+ </ul>
61
+ </div>
36
62
 
37
63
  </body>
38
64
 
@@ -1,6 +1,7 @@
1
1
  // main.js
2
2
 
3
3
  var $ws = null;
4
+ var $auto_scroll = true;
4
5
 
5
6
  function server_connect(url) {
6
7
  var ws = new WebSocket(url);
@@ -13,18 +14,13 @@ function server_connect(url) {
13
14
  if (evt.data.match(/^startup:/)) {
14
15
  file_name = evt.data.replace(/^startup:/, "");
15
16
  //alert(file_name);
16
- var fs = new ActiveXObject("Scripting.FileSystemObject");
17
- var file = fs.CreateTextFile(file_name);
18
- file.Close();
19
17
  } else {
20
- var log = $('#log').val() + evt.data + "\n";
21
- $('#log').val(log);
22
- var psconsole = $('#log');
23
- psconsole.scrollTop(
24
- psconsole[0].scrollHeight - psconsole.height()
25
- );
18
+ var log = "<li>" + evt.data + "</li>";
19
+ $('#log').append(log);
20
+ if ($auto_scroll) {
21
+ $('.outarea').scrollTop($('.outarea').get(0).scrollHeight);
22
+ }
26
23
  }
27
-
28
24
  };
29
25
  ws.onclose = function () {
30
26
  alert("アプリケーションが終了しました!!");
@@ -41,11 +37,20 @@ function send_message(msg) {
41
37
  }
42
38
  }
43
39
 
44
- function autocomp(id, url) {
40
+ function autocomp(id, file_kind) {
45
41
  $("#" + id).autocomplete({
42
+ autoFocus: true,
43
+ minLength: 0,
44
+ delay: 0,
45
+ select: function (event, ui) {
46
+ console.log(ui.item.value);
47
+ jQuery("#" + id).val(ui.item.value);
48
+ //jQuery(this).autocomplete("search", "");
49
+ $(this).keydown();
50
+ },
46
51
  source: function (req, resp) {
47
52
  $.ajax({
48
- url: url(),
53
+ url: "http://localhost:52538/search?path=" + $("#" + id).val() + "&kind=" + file_kind,
49
54
  type: "GET",
50
55
  cache: false,
51
56
  dataType: "json",
@@ -61,6 +66,142 @@ function autocomp(id, url) {
61
66
  });
62
67
 
63
68
  }
69
+ }).focus(function () {
70
+ //jQuery(this).autocomplete("search", "");
71
+ $(this).keydown();
72
+ });
73
+ }
74
+
75
+ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_name) {
76
+ $("#" + select_file).click(function () {
77
+ autocomp(search_id, file_kind);
78
+ $(".ui-autocomplete").css("z-index", 1000);
79
+ $("#" + search_id).val("/");
80
+ $("#" + dialog_id).dialog({
81
+ modal: true
82
+ , show: "slide" //表示時のアニメーション
83
+ , hide: "explode" //閉じた時のアニメーション
84
+ , title: "Select File" //ダイアログのタイトル
85
+ , width: 580 //ダイアログの横幅
86
+ , height: 400 //ダイアログの高さ
87
+ , resizable: true //リサイズ可
88
+ , closeOnEscape: false //[ESC]キーで閉じられなくする
89
+ , draggable: true //ダイアログの移動を可に
90
+ , buttons: {
91
+ "OK": function () { //OKボタン
92
+ $("#" + file_name).val($("#" + search_id).val());
93
+ $(this).dialog("close");
94
+ $("#" + search_id).autocomplete("destroy");
95
+ },
96
+ "Cancel": function () { //Cancelボタン
97
+ $(this).dialog("close");
98
+ $("#" + search_id).autocomplete("destroy");
99
+ }
100
+ }
101
+ });
102
+ });
103
+ }
104
+
105
+ function setting_dialog(open_id, dialog_id, json_file) {
106
+ $("#" + open_id).click(function () {
107
+ $("#" + dialog_id).val = $(function () {
108
+ $("dl#wrap").empty();
109
+ $.getJSON(json_file, function (s) {
110
+ for (var i in s) {
111
+ if (s[i].type == "input") {
112
+ var h = "<table><tr>"
113
+ + "<td class='setting_name'>" + s[i].description + "</td>"
114
+ + "<td><input class='setting_value' type='text' " + "id=" + s[i].name + "_value " + "value=" + s[i].value + ">"
115
+ + "</td></tr></table>"
116
+ $("dl#wrap").append(h);
117
+ } else if (s[i].type == "checkbox") {
118
+ var h = "<table><tr>";
119
+ h += "<td class='setting_name'>" + s[i].description + "</td>";
120
+ if (s[i].value == true) {
121
+ h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s[i].name + "_value checked ></td>";
122
+ } else {
123
+ h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s[i].name + "_value ></td>";
124
+ }
125
+ h += "</tr></table>";
126
+ $("dl#wrap").append(h);
127
+ } else if (s[i].type == "select") {
128
+ var h = "<table><tr>";
129
+ h += "<td class='setting_name'>" + s[i].description + "</td>";
130
+ h += "<td> <select class='setting_value' id=" + s[i].name + "_value " + ">";
131
+ s[i].select.forEach(e => {
132
+ if (e == s[i].value) {
133
+ h += "<option value=" + e + " selected >" + e + "</option>";
134
+ } else {
135
+ h += "<option value=" + e + ">" + e + "</option>";
136
+ }
137
+ });
138
+ h += "</select></td>";
139
+ h += "</tr></table>";
140
+ $("dl#wrap").append(h);
141
+ } else {
142
+ console.log("type=" + s[i].type);
143
+ }
144
+ }
145
+ });
146
+ });
147
+ $("#" + dialog_id).dialog({
148
+ modal: true
149
+ , show: "slide" //表示時のアニメーション
150
+ , hide: "explode" //閉じた時のアニメーション
151
+ , title: "Setting" //ダイアログのタイトル
152
+ , width: 580 //ダイアログの横幅
153
+ , height: 400 //ダイアログの高さ
154
+ , resizable: true //リサイズ可
155
+ , closeOnEscape: false //[ESC]キーで閉じられなくする
156
+ , draggable: true //ダイアログの移動を可に
157
+ , buttons: {
158
+ "OK": function () { //OKボタン
159
+ var json_data = []
160
+ $.getJSON(json_file, function (s) {
161
+ for (var i in s) {
162
+ console.log(s[i].name);
163
+ if (s[i].type == "input") {
164
+ var data = {};
165
+ data["name"] = s[i].name;
166
+ data["value"] = $("#" + s[i].name + "_value").val();
167
+ data["type"] = s[i].type;
168
+ data["select"] = s[i].select;
169
+ data["description"] = s[i].description;
170
+ json_data.push(data);
171
+ }
172
+ else if (s[i].type == "checkbox") {
173
+ var data = {};
174
+ data["name"] = s[i].name;
175
+ if ($("#" + s[i].name + "_value:checked").val() == "on") {
176
+ data["value"] = true;
177
+ } else {
178
+ data["value"] = false;
179
+ }
180
+ data["type"] = s[i].type;
181
+ data["select"] = s[i].select;
182
+ data["description"] = s[i].description;
183
+ json_data.push(data);
184
+ } else if (s[i].type == "select") {
185
+ var data = {};
186
+ data["name"] = s[i].name;
187
+ data["value"] = $("#" + s[i].name + "_value" + " option:selected").val();
188
+ data["type"] = s[i].type;
189
+ data["select"] = s[i].select;
190
+ data["description"] = s[i].description;
191
+ json_data.push(data);
192
+ } else {
193
+ console.log("type=" + s[i].type);
194
+ }
195
+ }
196
+ $ws.send("setting:" + JSON.stringify(json_data));
197
+ });
198
+ $(this).dialog("close");
199
+ },
200
+ "Cancel": function () { //Cancelボタン
201
+ $(this).dialog("close");
202
+ }
203
+ }
204
+ });
64
205
  });
65
206
  }
66
207
 
@@ -72,22 +213,6 @@ function get_dirname(path) {
72
213
  return result.replace(/\//g, "\\");
73
214
  }
74
215
 
75
- function select_file(id) {
76
- var file = $("#" + id).val();
77
- var dir = get_dirname(file);
78
- if (dir != "") {
79
- dir = dir + "\\*.*";
80
- } else {
81
- dir = "c:\\*.*";
82
- }
83
- var path = "";
84
- //alert(dir);
85
- //path = HtmlDlgHelper.openfiledlg(dir,"*.db","database(*.db)|*.db|all(*.*)|*.*|Text file(*.txt)|*.txt|");
86
- path = HtmlDlgHelper.openfiledlg(dir, "", "all(*.*)|*.*|Text file(*.txt)|*.txt|");
87
- $("#" + id).val(path);
88
- return (path);
89
- }
90
-
91
216
  function dispFile() {
92
217
  var fName = $("#upFile").val();
93
218
  alert('選択したファイルの値は' + fName + 'です');
@@ -96,10 +221,10 @@ function dispFile() {
96
221
  // 起動時の処理
97
222
  $(document).ready(function () {
98
223
  // サーバに接続
99
- server_connect("ws://localhost:61820/wsserver")
224
+ server_connect("ws://localhost:52538/wsserver")
100
225
  // ウインドウサイズ
101
- var width = 600;
102
- var height = 700;
226
+ var width = 800;
227
+ var height = 600;
103
228
  // ウインドウの位置
104
229
  $(function () {
105
230
  window.resizeTo(width, height);
@@ -107,23 +232,35 @@ $(document).ready(function () {
107
232
  //window.moveTo(0,0);
108
233
  });
109
234
 
110
- // オートコンプリート設定
111
- var getUrl = function () {
112
- var url = "http://localhost:61820/search?path=" + $("#search_str").val();
113
- return url;
114
- };
115
- autocomp("search_str", getUrl);
235
+ $('.outarea').scroll(function () {
236
+ var h = $('.outarea').get(0).scrollHeight - $('.outarea').innerHeight();
237
+ console.log("scrollEnd=" + Math.abs($('.outarea').scrollTop() - h));
238
+ if (Math.abs($('.outarea').scrollTop() - h) < 5) {
239
+ // 最後までスクロールしている
240
+ // 自動スクロールON
241
+ $auto_scroll = true;
242
+ } else {
243
+ // 自動スクロールOFF
244
+ $auto_scroll = false;
245
+ }
246
+ //console.log("auto_scroll=" + $auto_scroll);
247
+ });
116
248
 
117
249
  // ハンドラ登録
118
- $("#file").click(function () {
119
- select_file("search_str");
250
+ $("#stop").click(function () {
251
+ send_message("stop");
120
252
  });
253
+
121
254
  $("#exec").click(function () {
255
+ $('#log').empty();
122
256
  send_message("exec:" + $("#upFile").val());
123
257
  });
124
- $("#stop").click(function () {
125
- send_message("stop");
126
- });
258
+
259
+ select_file_dialog("search_str", "file", "dialog1", "select_file", "upFile");
260
+
261
+ select_file_dialog("search_str2", "dir", "dialog2", "select_dir", "upDir");
262
+
263
+ setting_dialog("setting", "setting_dialog", "config/setting.json");
127
264
 
128
265
  });
129
266
 
@@ -1,15 +1,18 @@
1
1
  # -*- coding: utf-8 -*-
2
- class AppMain
3
- def initialize
4
- @aboet = false
5
- end
2
+ require "server_app_base.rb"
6
3
 
7
- def start(file)
4
+ class MyApp < AppMainBase
5
+ def start(argv)
6
+ super
8
7
  begin
9
8
  @abort = false
10
- puts file
9
+ puts argv
10
+ argv.each do |v|
11
+ yield v if block_given?
12
+ end
11
13
  while true
12
14
  yield Time.now.to_s if block_given?
15
+ yield @config["name1"]
13
16
  sleep 1
14
17
  break if @abort
15
18
  end
@@ -20,6 +23,6 @@ class AppMain
20
23
  end
21
24
 
22
25
  def stop()
23
- @abort = true
26
+ super
24
27
  end
25
28
  end
@@ -1,9 +1,9 @@
1
- require 'json'
2
- require 'kconv'
1
+ require "json"
2
+ require "kconv"
3
3
 
4
4
  class Search < Sinatra::Base
5
5
  helpers Sinatra::Streaming
6
- get '' do
6
+ get "" do
7
7
  q_hash = {}
8
8
  puts request.query_string
9
9
  request.query_string.split("&").each do |q|
@@ -14,27 +14,45 @@ class Search < Sinatra::Base
14
14
  q_hash[work[0]] = ""
15
15
  end
16
16
  end
17
- str = q_hash["path"].gsub(/\\/,"/")
17
+ str = q_hash["path"].gsub(/\\/, "/")
18
18
  puts "str=#{str}"
19
+ kind = q_hash["kind"].gsub(/\\/, "/")
20
+ puts "kind=#{kind}"
19
21
  res = []
20
22
  str = str.gsub(/\\/, "/")
21
23
  dir = File.dirname(str)
22
- dir = "c:/" if dir == nil
23
24
  file = File.basename(str)
24
- file = "/" if file == nil
25
+ puts "dir=#{dir}"
26
+ puts "file=#{file}"
27
+
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
34
+ else
35
+ dir = "c:/" if dir == nil
36
+ dir = "c:/" if dir == "/"
37
+ end
38
+
25
39
  path = "#{dir}/#{file}"
26
- if File.exists?(path)
40
+ if File.directory?(path)
27
41
  path = path + "/*"
28
42
  else
29
43
  path = path + "*"
30
44
  end
45
+ path.gsub!(/[\/]+/, "/")
31
46
  puts path
32
- Dir.glob(path).each do |file|
47
+ Dir.glob(path, File::FNM_DOTMATCH).each do |file|
33
48
  data = {}
49
+ next if File.basename(file) == "."
50
+ next if kind == "dir" and !File.directory?(file)
34
51
  data["label"] = File.basename(file)
35
- data["value"] = file
52
+ data["label"] += "/" if (File.directory?(file))
53
+ data["value"] = File.expand_path(file)
36
54
  res.push data
37
55
  end
38
- JSON.generate res
56
+ JSON.generate res.sort { |a, b| a["value"] <=> b["value"] }
39
57
  end
40
58
  end
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ class AppMainBase
3
+ def initialize
4
+ @config = nil
5
+ @aboet = false
6
+ @exec = false
7
+ @suspend = false
8
+ end
9
+
10
+ def set_config(config)
11
+ @config = config
12
+ end
13
+
14
+ def start(argv)
15
+ @exec = true
16
+ end
17
+
18
+ def stop()
19
+ @abort = true
20
+ @exec = false
21
+ end
22
+
23
+ def suspend()
24
+ @suspend = true
25
+ end
26
+
27
+ def resume()
28
+ @suspend = false
29
+ end
30
+ end
31
+
32
+ require "app_load.rb"
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
  # -*- coding: utf-8 -*-
2
3
  $LOAD_PATH << File.dirname(File.expand_path(__FILE__))
3
4
 
@@ -22,19 +23,19 @@ port = get_unused_port
22
23
  puts "port=#{port}"
23
24
 
24
25
  # config.ruの編集
25
- buf = File.read("config.ru").toutf8
26
+ buf = File.binread("config.ru").toutf8
26
27
  buf.gsub!(/port [0-9]+/, "port #{port}")
27
- File.write("config.ru", buf)
28
+ File.binwrite("config.ru", buf)
28
29
 
29
30
  # main.jsの編集
30
- buf = File.read("js/main.js").toutf8
31
+ buf = File.binread("js/main.js").toutf8
31
32
  buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
32
- File.write("js/main.js", buf)
33
+ File.binwrite("js/main.js", buf)
33
34
 
34
35
  # index.htaの編集
35
- buf = File.read("index.html").toutf8
36
+ buf = File.binread("index.html").toutf8
36
37
  buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
37
- File.write("index.html", buf)
38
+ File.binwrite("index.html", buf)
38
39
 
39
40
  Thread.start {
40
41
  puts "start browser"
@@ -49,7 +50,6 @@ Thread.start {
49
50
  else
50
51
  browser = json["chrome_win"]
51
52
  end
52
- #browser = "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" -app=http://localhost:#{port}"
53
53
  browser += " -app=http://localhost:#{port}"
54
54
  puts browser
55
55
  system browser
@@ -1,8 +1,18 @@
1
- require "./server_app"
2
- $app = AppMain.new
1
+ require "./server_app_base"
2
+ require "json"
3
+
4
+ def config_json_hash(json)
5
+ config = {}
6
+ json.each do |j|
7
+ config[j["name"]] = j["value"]
8
+ end
9
+ return config
10
+ end
3
11
 
4
12
  class WsServer < Sinatra::Base
5
13
  $ws_list = []
14
+ json_config = nil
15
+ exec_thread = nil
6
16
  get "" do
7
17
  if !request.websocket?
8
18
  "no supported"
@@ -15,16 +25,44 @@ class WsServer < Sinatra::Base
15
25
  ws.onmessage do |msg|
16
26
  puts msg
17
27
  if msg =~ /^exec:/
18
- fname = msg.gsub(/^exec:/, "")
19
- Thread.new {
20
- $app.start fname do |out|
21
- ws.send(out)
22
- end
23
- }
28
+ if exec_thread == nil
29
+ json = JSON.parse(File.read("config/setting.json"))
30
+ json_config = config_json_hash(json)
31
+ $app.set_config(json_config)
32
+ argv = msg.gsub(/^exec:/, "")
33
+ exec_thread = Thread.new {
34
+ $app.start(argv.split(",")) do |out|
35
+ ws.send(out)
36
+ end
37
+ exec_thread = nil
38
+ }
39
+ end
24
40
  end
25
41
  if msg =~ /^stop/
26
- $app.stop
42
+ if exec_thread
43
+ $app.stop
44
+ end
45
+ end
46
+ if msg =~ /^suspend/
47
+ if exec_thread
48
+ $app.suspend
49
+ end
50
+ end
51
+ if msg =~ /^resume/
52
+ if exec_thread
53
+ $app.resume
54
+ end
27
55
  end
56
+ if msg =~ /^setting:/
57
+ json_string = msg.gsub(/^setting:/, "")
58
+ json = JSON.parse(json_string)
59
+ File.open("config/setting.json", "w") do |w|
60
+ w.puts JSON.pretty_generate(json)
61
+ end
62
+ json_config = config_json_hash(json)
63
+ $app.set_config(json_config)
64
+ end
65
+
28
66
  if msg == "exit"
29
67
  unless ENV["OCRA"] == "true"
30
68
  halt
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.1
4
+ version: 0.0.5
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-08-15 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -104,6 +104,7 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
+ - ".vscode/launch.json"
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md
@@ -112,16 +113,19 @@ files:
112
113
  - browser_app_base.gemspec
113
114
  - lib/browser_app_base.rb
114
115
  - lib/browser_app_base/version.rb
116
+ - lib/template/app_load.rb
115
117
  - lib/template/config.ru
116
118
  - lib/template/config/browser.json
119
+ - lib/template/config/setting.json
117
120
  - lib/template/css/index.css
118
121
  - lib/template/index.html
119
122
  - lib/template/js/main.js
123
+ - lib/template/my_app_sample.rb
120
124
  - lib/template/server.rb
121
- - lib/template/server_app.rb
125
+ - lib/template/server_app_base.rb
122
126
  - lib/template/start.rb
123
127
  - lib/template/wsserver.rb
124
- homepage: https://github.com/sample/
128
+ homepage: https://github.com/kuwayama1971/BrowserAppBase
125
129
  licenses: []
126
130
  metadata: {}
127
131
  post_install_message: