browser_app_base 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +8 -0
- data/bin/create_browser_app.rb +23 -0
- data/browser_app_base.gemspec +42 -0
- data/lib/browser_app_base.rb +20 -0
- data/lib/browser_app_base/version.rb +5 -0
- data/lib/template/config.ru +51 -0
- data/lib/template/config/browser.json +4 -0
- data/lib/template/css/index.css +52 -0
- data/lib/template/index.html +39 -0
- data/lib/template/js/main.js +129 -0
- data/lib/template/server.rb +40 -0
- data/lib/template/server_app.rb +25 -0
- data/lib/template/start.rb +58 -0
- data/lib/template/wsserver.rb +50 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9bbd62be060b288835a8ede00b318159fb1cebd6694b21555b919bdde6d3ca1d
|
4
|
+
data.tar.gz: a82cc9b49fce11e7a1d4d609778fd75237f6f03b44999c29ef55dc4db10d433b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60b86bad8e1f12f39b00726153f5a7c9f01d9931cba8cd0f7590d997a00a99ae3e4e7f5ab6b5e866c1e6d8e916da7785bab45bcf7db61deebe4240b56bd18c18
|
7
|
+
data.tar.gz: adb9bcb7f57339e6568dc356bf6bd82a40c5cc56c43995ef66b6b5d71b179cbb391f21bdf774fbb5687e7cf656d74879628b9a0a05cd7a33e0235be1881b64b6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# BrowserAppBase
|
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.
|
4
|
+
|
5
|
+
Windows and Linux browser-based desktop application templates
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'browser_app_base'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install browser_app_base
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
create_browser_app [options]
|
26
|
+
-d, --dir dir_name application directory
|
27
|
+
-h, --help command help
|
28
|
+
|
29
|
+
|
30
|
+
create app templat
|
31
|
+
|
32
|
+
$ create_browser_app -d ~/test/
|
33
|
+
|
34
|
+
start application
|
35
|
+
|
36
|
+
$ cd ~/test/app
|
37
|
+
$ ruby start.rb
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kuwayama1971/BrowserAppBase.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "browser_app_base"
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
opt = OptionParser.new
|
8
|
+
o = {}
|
9
|
+
opt.on("-d dir_name", "--dir dir_name", "application directory") { |v| o[:dir] = v }
|
10
|
+
opt.on("-h", "--help", "command help") { puts opt; exit }
|
11
|
+
begin
|
12
|
+
opt.parse!(ARGV)
|
13
|
+
rescue
|
14
|
+
puts opt
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
if o[:dir] == nil
|
19
|
+
puts opt
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
|
23
|
+
BrowserAppBase.create o[:dir]
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/browser_app_base/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "browser_app_base"
|
7
|
+
spec.version = BrowserAppBase::VERSION
|
8
|
+
spec.authors = ["masataka kuwayama"]
|
9
|
+
spec.email = ["masataka.kuwayama@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "browser app base"
|
12
|
+
spec.description = "browser application template"
|
13
|
+
spec.homepage = "https://github.com/sample/"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
#spec.metadata["allowed_push_host"] = "http://mygemserver.com"
|
17
|
+
#spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
#spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
#spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "bin"
|
27
|
+
#spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
spec.add_dependency "sinatra"
|
34
|
+
spec.add_dependency "sinatra-contrib"
|
35
|
+
spec.add_dependency "sinatra-websocket"
|
36
|
+
spec.add_dependency "thin"
|
37
|
+
spec.add_dependency "json"
|
38
|
+
spec.add_dependency "facter"
|
39
|
+
|
40
|
+
# For more information and examples about making a new gem, checkout our
|
41
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "browser_app_base/version"
|
4
|
+
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
module BrowserAppBase
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
# Your code goes here...
|
11
|
+
|
12
|
+
def self.create(dir)
|
13
|
+
puts "create application base #{dir}"
|
14
|
+
|
15
|
+
FileUtils.mkdir_p dir
|
16
|
+
|
17
|
+
path = File.dirname(File.expand_path(__FILE__))
|
18
|
+
FileUtils.cp_r "#{path}/template", "#{dir}/app"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "sinatra"
|
3
|
+
require "sinatra/contrib"
|
4
|
+
require "sinatra-websocket"
|
5
|
+
require "thin"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
require "./server"
|
9
|
+
require "./wsserver"
|
10
|
+
|
11
|
+
get "/" do
|
12
|
+
File.read("index.html")
|
13
|
+
end
|
14
|
+
|
15
|
+
get "/css/:name.css" do
|
16
|
+
content_type "text/css", :charset => "utf-8"
|
17
|
+
puts "css/#{params[:name]}.css"
|
18
|
+
File.read "css/#{params[:name]}.css"
|
19
|
+
end
|
20
|
+
|
21
|
+
get "/js/:name.js" do
|
22
|
+
content_type "text/javascript", :charset => "utf-8"
|
23
|
+
puts "js/#{params[:name]}.js"
|
24
|
+
File.read "js/#{params[:name]}.js"
|
25
|
+
end
|
26
|
+
|
27
|
+
map "/search" do
|
28
|
+
run Search
|
29
|
+
end
|
30
|
+
|
31
|
+
map "/wsserver" do
|
32
|
+
res = catch(:halt) do
|
33
|
+
run WsServer
|
34
|
+
end
|
35
|
+
puts res
|
36
|
+
end
|
37
|
+
|
38
|
+
configure do
|
39
|
+
set :DoNotReverseLookup, true
|
40
|
+
set :logging, false
|
41
|
+
set :default_encoding, "utf-8"
|
42
|
+
set :server, :thin
|
43
|
+
|
44
|
+
# Thread.start {
|
45
|
+
# }
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
#\ --port 61820
|
50
|
+
|
51
|
+
run Sinatra::Application
|
@@ -0,0 +1,52 @@
|
|
1
|
+
body {
|
2
|
+
color: #000000;
|
3
|
+
background-color: #cac3ec4f;
|
4
|
+
overflow: hidden;
|
5
|
+
}
|
6
|
+
|
7
|
+
hr {
|
8
|
+
color: #ffffff;
|
9
|
+
background-color: #000000;
|
10
|
+
height: 1px; /* 線の太さ */
|
11
|
+
border: 1px; /* 枠の太さ */
|
12
|
+
border-style: solid; /* 枠の種類 */
|
13
|
+
}
|
14
|
+
|
15
|
+
.error {
|
16
|
+
color: red;
|
17
|
+
}
|
18
|
+
|
19
|
+
.outarea {
|
20
|
+
background-color: #FFFFFF;
|
21
|
+
margin: 5px;
|
22
|
+
padding: 5px;
|
23
|
+
width: 95vw;
|
24
|
+
height: 50vh;
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
.inarea {
|
29
|
+
border: thin solid #000000;
|
30
|
+
margin: 5px;
|
31
|
+
padding: 5px;
|
32
|
+
width: 95%;
|
33
|
+
}
|
34
|
+
|
35
|
+
input {
|
36
|
+
background-color: #FAFAFA;
|
37
|
+
margin: 5px;
|
38
|
+
padding: 5px;
|
39
|
+
}
|
40
|
+
|
41
|
+
input.long {
|
42
|
+
width: 90%;
|
43
|
+
background-color: #FAFAFA;
|
44
|
+
margin: 5px;
|
45
|
+
padding: 5px;
|
46
|
+
}
|
47
|
+
|
48
|
+
textarea.long {
|
49
|
+
width: 95vw;
|
50
|
+
height: 50vh;
|
51
|
+
}
|
52
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>RubyAppBase</title>
|
8
|
+
<!-- jQuery -->
|
9
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
10
|
+
<!-- jQuery UI -->
|
11
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
12
|
+
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
|
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">
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<h3>サンプル</h3>
|
20
|
+
<hr>
|
21
|
+
<table>
|
22
|
+
<tr>
|
23
|
+
<td>
|
24
|
+
<input type="button" id="exec" name="exec" value="実行">
|
25
|
+
</td>
|
26
|
+
<td>
|
27
|
+
<input type="button" id="stop" name="stop" value="停止">
|
28
|
+
</td>
|
29
|
+
</tr>
|
30
|
+
</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
|
+
|
35
|
+
<textarea name="log" id="log" class="outarea"></textarea><br/>
|
36
|
+
|
37
|
+
</body>
|
38
|
+
|
39
|
+
</html>
|
@@ -0,0 +1,129 @@
|
|
1
|
+
// main.js
|
2
|
+
|
3
|
+
var $ws = null;
|
4
|
+
|
5
|
+
function server_connect(url) {
|
6
|
+
var ws = new WebSocket(url);
|
7
|
+
ws.onopen = function () {
|
8
|
+
// Web Socket is connected. You can send data by send() method.
|
9
|
+
ws.send("message to send");
|
10
|
+
};
|
11
|
+
ws.onmessage = function (evt) {
|
12
|
+
//alert(evt.data);
|
13
|
+
if (evt.data.match(/^startup:/)) {
|
14
|
+
file_name = evt.data.replace(/^startup:/, "");
|
15
|
+
//alert(file_name);
|
16
|
+
var fs = new ActiveXObject("Scripting.FileSystemObject");
|
17
|
+
var file = fs.CreateTextFile(file_name);
|
18
|
+
file.Close();
|
19
|
+
} 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
|
+
);
|
26
|
+
}
|
27
|
+
|
28
|
+
};
|
29
|
+
ws.onclose = function () {
|
30
|
+
alert("アプリケーションが終了しました!!");
|
31
|
+
$(window).unbind("beforeunload");
|
32
|
+
//window.open('about:blank','_self').close();
|
33
|
+
window.close();
|
34
|
+
};
|
35
|
+
$ws = ws;
|
36
|
+
}
|
37
|
+
|
38
|
+
function send_message(msg) {
|
39
|
+
if ($ws != null) {
|
40
|
+
$ws.send(msg);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
function autocomp(id, url) {
|
45
|
+
$("#" + id).autocomplete({
|
46
|
+
source: function (req, resp) {
|
47
|
+
$.ajax({
|
48
|
+
url: url(),
|
49
|
+
type: "GET",
|
50
|
+
cache: false,
|
51
|
+
dataType: "json",
|
52
|
+
data: {
|
53
|
+
param1: req.term
|
54
|
+
},
|
55
|
+
success: function (o) {
|
56
|
+
resp(o);
|
57
|
+
},
|
58
|
+
error: function (xhr, ts, err) {
|
59
|
+
resp(['']);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
|
63
|
+
}
|
64
|
+
});
|
65
|
+
}
|
66
|
+
|
67
|
+
function get_dirname(path) {
|
68
|
+
var result = path.replace(/\\/g, '/').replace(/\/[^\/]*$/, '');
|
69
|
+
if (result.match(/^[^\/]*\.[^\/\.]*$/)) {
|
70
|
+
result = '';
|
71
|
+
}
|
72
|
+
return result.replace(/\//g, "\\");
|
73
|
+
}
|
74
|
+
|
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
|
+
function dispFile() {
|
92
|
+
var fName = $("#upFile").val();
|
93
|
+
alert('選択したファイルの値は' + fName + 'です');
|
94
|
+
}
|
95
|
+
|
96
|
+
// 起動時の処理
|
97
|
+
$(document).ready(function () {
|
98
|
+
// サーバに接続
|
99
|
+
server_connect("ws://localhost:61820/wsserver")
|
100
|
+
// ウインドウサイズ
|
101
|
+
var width = 600;
|
102
|
+
var height = 700;
|
103
|
+
// ウインドウの位置
|
104
|
+
$(function () {
|
105
|
+
window.resizeTo(width, height);
|
106
|
+
window.moveTo((window.screen.width / 2) - (width / 2), (screen.height / 2) - (height / 2));
|
107
|
+
//window.moveTo(0,0);
|
108
|
+
});
|
109
|
+
|
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);
|
116
|
+
|
117
|
+
// ハンドラ登録
|
118
|
+
$("#file").click(function () {
|
119
|
+
select_file("search_str");
|
120
|
+
});
|
121
|
+
$("#exec").click(function () {
|
122
|
+
send_message("exec:" + $("#upFile").val());
|
123
|
+
});
|
124
|
+
$("#stop").click(function () {
|
125
|
+
send_message("stop");
|
126
|
+
});
|
127
|
+
|
128
|
+
});
|
129
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'kconv'
|
3
|
+
|
4
|
+
class Search < Sinatra::Base
|
5
|
+
helpers Sinatra::Streaming
|
6
|
+
get '' do
|
7
|
+
q_hash = {}
|
8
|
+
puts request.query_string
|
9
|
+
request.query_string.split("&").each do |q|
|
10
|
+
work = q.split("=")
|
11
|
+
if work[1] != nil
|
12
|
+
q_hash[work[0]] = CGI.unescape work[1].toutf8
|
13
|
+
else
|
14
|
+
q_hash[work[0]] = ""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
str = q_hash["path"].gsub(/\\/,"/")
|
18
|
+
puts "str=#{str}"
|
19
|
+
res = []
|
20
|
+
str = str.gsub(/\\/, "/")
|
21
|
+
dir = File.dirname(str)
|
22
|
+
dir = "c:/" if dir == nil
|
23
|
+
file = File.basename(str)
|
24
|
+
file = "/" if file == nil
|
25
|
+
path = "#{dir}/#{file}"
|
26
|
+
if File.exists?(path)
|
27
|
+
path = path + "/*"
|
28
|
+
else
|
29
|
+
path = path + "*"
|
30
|
+
end
|
31
|
+
puts path
|
32
|
+
Dir.glob(path).each do |file|
|
33
|
+
data = {}
|
34
|
+
data["label"] = File.basename(file)
|
35
|
+
data["value"] = file
|
36
|
+
res.push data
|
37
|
+
end
|
38
|
+
JSON.generate res
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
class AppMain
|
3
|
+
def initialize
|
4
|
+
@aboet = false
|
5
|
+
end
|
6
|
+
|
7
|
+
def start(file)
|
8
|
+
begin
|
9
|
+
@abort = false
|
10
|
+
puts file
|
11
|
+
while true
|
12
|
+
yield Time.now.to_s if block_given?
|
13
|
+
sleep 1
|
14
|
+
break if @abort
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
puts $!
|
18
|
+
puts $@
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def stop()
|
23
|
+
@abort = true
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$LOAD_PATH << File.dirname(File.expand_path(__FILE__))
|
3
|
+
|
4
|
+
require "socket"
|
5
|
+
require "rack"
|
6
|
+
require "daemons"
|
7
|
+
require "fileutils"
|
8
|
+
require "kconv"
|
9
|
+
require "json"
|
10
|
+
require "facter"
|
11
|
+
|
12
|
+
# 空きポートを取得
|
13
|
+
def get_unused_port
|
14
|
+
s = TCPServer.open(0)
|
15
|
+
port = s.addr[1]
|
16
|
+
s.close
|
17
|
+
return port
|
18
|
+
end
|
19
|
+
|
20
|
+
# 空きポートを取得
|
21
|
+
port = get_unused_port
|
22
|
+
puts "port=#{port}"
|
23
|
+
|
24
|
+
# config.ruの編集
|
25
|
+
buf = File.read("config.ru").toutf8
|
26
|
+
buf.gsub!(/port [0-9]+/, "port #{port}")
|
27
|
+
File.write("config.ru", buf)
|
28
|
+
|
29
|
+
# main.jsの編集
|
30
|
+
buf = File.read("js/main.js").toutf8
|
31
|
+
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
32
|
+
File.write("js/main.js", buf)
|
33
|
+
|
34
|
+
# index.htaの編集
|
35
|
+
buf = File.read("index.html").toutf8
|
36
|
+
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
37
|
+
File.write("index.html", buf)
|
38
|
+
|
39
|
+
Thread.start {
|
40
|
+
puts "start browser"
|
41
|
+
json_file = File.dirname(File.expand_path(__FILE__)) + "/config/browser.json"
|
42
|
+
json = JSON.parse(File.read json_file)
|
43
|
+
puts json
|
44
|
+
kernel = Facter.value(:kernel)
|
45
|
+
if kernel == "windows"
|
46
|
+
browser = json["chrome_win"]
|
47
|
+
elsif kernel == "Linux"
|
48
|
+
browser = json["chrome_linux"]
|
49
|
+
else
|
50
|
+
browser = json["chrome_win"]
|
51
|
+
end
|
52
|
+
#browser = "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" -app=http://localhost:#{port}"
|
53
|
+
browser += " -app=http://localhost:#{port}"
|
54
|
+
puts browser
|
55
|
+
system browser
|
56
|
+
}
|
57
|
+
|
58
|
+
Rack::Server.start
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "./server_app"
|
2
|
+
$app = AppMain.new
|
3
|
+
|
4
|
+
class WsServer < Sinatra::Base
|
5
|
+
$ws_list = []
|
6
|
+
get "" do
|
7
|
+
if !request.websocket?
|
8
|
+
"no supported"
|
9
|
+
else
|
10
|
+
request.websocket do |ws|
|
11
|
+
ws.onopen do
|
12
|
+
ws.send("startup:#{$startup_file}")
|
13
|
+
$ws_list << ws
|
14
|
+
end
|
15
|
+
ws.onmessage do |msg|
|
16
|
+
puts msg
|
17
|
+
if msg =~ /^exec:/
|
18
|
+
fname = msg.gsub(/^exec:/, "")
|
19
|
+
Thread.new {
|
20
|
+
$app.start fname do |out|
|
21
|
+
ws.send(out)
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
if msg =~ /^stop/
|
26
|
+
$app.stop
|
27
|
+
end
|
28
|
+
if msg == "exit"
|
29
|
+
unless ENV["OCRA"] == "true"
|
30
|
+
halt
|
31
|
+
#exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
ws.onclose do
|
36
|
+
puts "websocket closed"
|
37
|
+
$ws_list.delete(ws)
|
38
|
+
puts $ws_list.size
|
39
|
+
if $ws_list.size == 0
|
40
|
+
puts ENV["OCRA"]
|
41
|
+
unless ENV["OCRA"] == "true"
|
42
|
+
#halt
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: browser_app_base
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- masataka kuwayama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sinatra
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sinatra-contrib
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sinatra-websocket
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thin
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
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
|
+
description: browser application template
|
98
|
+
email:
|
99
|
+
- masataka.kuwayama@gmail.com
|
100
|
+
executables:
|
101
|
+
- create_browser_app.rb
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/create_browser_app.rb
|
112
|
+
- browser_app_base.gemspec
|
113
|
+
- lib/browser_app_base.rb
|
114
|
+
- lib/browser_app_base/version.rb
|
115
|
+
- lib/template/config.ru
|
116
|
+
- lib/template/config/browser.json
|
117
|
+
- lib/template/css/index.css
|
118
|
+
- lib/template/index.html
|
119
|
+
- lib/template/js/main.js
|
120
|
+
- lib/template/server.rb
|
121
|
+
- lib/template/server_app.rb
|
122
|
+
- lib/template/start.rb
|
123
|
+
- lib/template/wsserver.rb
|
124
|
+
homepage: https://github.com/sample/
|
125
|
+
licenses: []
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: 2.4.0
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubygems_version: 3.1.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: browser app base
|
146
|
+
test_files: []
|