webview 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +93 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/Makefile +14 -0
- data/ext/extconf.rb +8 -0
- data/ext/webview/main.go +87 -0
- data/lib/webview/app.rb +75 -0
- data/lib/webview/version.rb +3 -0
- data/lib/webview.rb +8 -0
- data/webview.gemspec +30 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c48d69ff8dd6f7dbf4220a5a481e4af44e8b542493a9274005378e326764b5c1
|
4
|
+
data.tar.gz: cd11ae6d0ee8627ced9548fe321cf5165b2e4c37d4da096ec5a653ffb24abf7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 56645c7bde105ace3fbe47187add745cd7896a99c6a1e8aa1af120f41d31b0a209770dea7dab8aee986397b876c5faed5b8e3b930581e7de3f9aa61317941627
|
7
|
+
data.tar.gz: e991be01929ad140d398e6054a76af9d5017fcc75580e35210b666725080caac2fc1e1d877195cf2463ab4e7a83118879d00a7bc5d2914fa806c398a7134a533
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
webview (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.3)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
webview!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 jiangzhi.xie
|
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,93 @@
|
|
1
|
+
# Webview
|
2
|
+
|
3
|
+
a webview GUI based on [zserge/webview](https://github.com/zserge/webview)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'webview'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install webview
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
app = Webview::App.new
|
25
|
+
app.open('http://localhost:3000?foo=bar')
|
26
|
+
|
27
|
+
at_exit { app.close }
|
28
|
+
begin
|
29
|
+
app.join
|
30
|
+
rescue Interrupt
|
31
|
+
app.close
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Allow debug page
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
app = Webview::App.new(debug: true)
|
39
|
+
```
|
40
|
+
|
41
|
+
Run with your backend
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
app = Webview::App.new
|
45
|
+
backend = Thread.new { `rails s` }
|
46
|
+
app.open('http://localhost:3000')
|
47
|
+
|
48
|
+
at_exit { app.close }
|
49
|
+
begin
|
50
|
+
app.join
|
51
|
+
rescue Interrupt
|
52
|
+
app.close
|
53
|
+
backend.kill
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
RPC with Javascript
|
58
|
+
|
59
|
+
```javascript
|
60
|
+
window.rpc_cb = function(type, value, user_data) {
|
61
|
+
consloe.log(type, value, user_data)
|
62
|
+
}
|
63
|
+
|
64
|
+
var type = 'openfile'
|
65
|
+
window.external.invoke(type + ',' + 'my_data_id');
|
66
|
+
// Open a dialog. and call rpc_cb('openfile', 'selected_file_path', "my_data_id") after user choice file.
|
67
|
+
|
68
|
+
window.external.invoke('invalid_type' + ',' + 'my_data');
|
69
|
+
// if got a error, will call rpc_cb('error', 'invalid_type', 'my_data')
|
70
|
+
```
|
71
|
+
|
72
|
+
## Javascript RPCs
|
73
|
+
|
74
|
+
* close: close this app window, no callback
|
75
|
+
* fullscreen: no callback
|
76
|
+
* unfullscreen: no callback
|
77
|
+
* openfile: Open a dialog, and call rpc_cb('openfile', path, user_data)
|
78
|
+
* opendir: Open a dialog, and call rpc_cb('opendir', path, user_data)
|
79
|
+
* savefile: Open a dialog, and call rpc_cb('savefile', path, user_data)
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/webview.
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "webview"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ext/Makefile
ADDED
data/ext/extconf.rb
ADDED
data/ext/webview/main.go
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
// webview commit 2019-1-23 16c93bcaeaeb6aa7bb5a1432de3bef0b9ecc44f3
|
2
|
+
|
3
|
+
package main
|
4
|
+
|
5
|
+
import "github.com/zserge/webview"
|
6
|
+
import "flag"
|
7
|
+
import "fmt"
|
8
|
+
import "os"
|
9
|
+
import "strings"
|
10
|
+
|
11
|
+
func EvalCallback(w webview.WebView, name string, value string, userdata string) {
|
12
|
+
value = strings.ReplaceAll(value, "'", "\\'")
|
13
|
+
userdata = strings.ReplaceAll(userdata, "'", "\\'")
|
14
|
+
|
15
|
+
w.Eval(fmt.Sprintf(`
|
16
|
+
(function(){
|
17
|
+
var cb = window.rpc_cb;
|
18
|
+
if (!cb) {
|
19
|
+
console.error("Not found RPC callback window.rpc_cb")
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
cb('%s', '%s', '%s')
|
23
|
+
})()
|
24
|
+
`, name, value, userdata))
|
25
|
+
}
|
26
|
+
|
27
|
+
func handleRPC(w webview.WebView, data string) {
|
28
|
+
s := strings.SplitN(data, ",", 2)
|
29
|
+
action, userdata := s[0], s[1]
|
30
|
+
|
31
|
+
switch {
|
32
|
+
case action == "close":
|
33
|
+
w.Terminate()
|
34
|
+
case action == "fullscreen":
|
35
|
+
w.SetFullscreen(true)
|
36
|
+
case action == "unfullscreen":
|
37
|
+
w.SetFullscreen(false)
|
38
|
+
case action == "open":
|
39
|
+
path := w.Dialog(
|
40
|
+
webview.DialogTypeOpen, webview.DialogFlagFile & webview.DialogFlagDirectory,
|
41
|
+
"Select a file or directory", "")
|
42
|
+
EvalCallback(w, action, path, userdata)
|
43
|
+
case action == "openfile":
|
44
|
+
path := w.Dialog(
|
45
|
+
webview.DialogTypeOpen, webview.DialogFlagFile,
|
46
|
+
"Select a file", "")
|
47
|
+
EvalCallback(w, action, path, userdata)
|
48
|
+
case action == "opendir":
|
49
|
+
path := w.Dialog(
|
50
|
+
webview.DialogTypeOpen, webview.DialogFlagDirectory,
|
51
|
+
"Select a directory", "")
|
52
|
+
EvalCallback(w, action, path, userdata)
|
53
|
+
case action == "savefile":
|
54
|
+
path := w.Dialog(webview.DialogTypeSave, 0, "Save file", "")
|
55
|
+
EvalCallback(w, action, path, userdata)
|
56
|
+
default:
|
57
|
+
EvalCallback(w, "error", action, userdata)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
func main() {
|
62
|
+
urlPtr := flag.String("url", "", "App URL")
|
63
|
+
titlePtr := flag.String("title", "MyApp", "App title")
|
64
|
+
widthPtr := flag.Int("width", 1100, "width of window")
|
65
|
+
heightPtr := flag.Int("height", 800, "height of window")
|
66
|
+
debugPtr := flag.Bool("debug", false, "debug mode")
|
67
|
+
resizablePtr := flag.Bool("resizable", false, "Allow resize window")
|
68
|
+
|
69
|
+
flag.Parse()
|
70
|
+
|
71
|
+
if *urlPtr == "" {
|
72
|
+
fmt.Fprintf(os.Stderr, "URL is required\n")
|
73
|
+
os.Exit(1)
|
74
|
+
}
|
75
|
+
|
76
|
+
w := webview.New(webview.Settings{
|
77
|
+
URL: *urlPtr,
|
78
|
+
Title: *titlePtr,
|
79
|
+
Width: *widthPtr,
|
80
|
+
Height: *heightPtr,
|
81
|
+
Resizable: *resizablePtr,
|
82
|
+
Debug: *debugPtr,
|
83
|
+
ExternalInvokeCallback: handleRPC,
|
84
|
+
})
|
85
|
+
defer w.Exit()
|
86
|
+
w.Run()
|
87
|
+
}
|
data/lib/webview/app.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Webview
|
5
|
+
class App
|
6
|
+
attr_reader :app_out, :app_err, :app_process, :options
|
7
|
+
|
8
|
+
def initialize(title: nil, width: nil, height: nil, resizable: nil, debug: false)
|
9
|
+
@options = {
|
10
|
+
title: title,
|
11
|
+
width: width,
|
12
|
+
height: height,
|
13
|
+
resizable: resizable,
|
14
|
+
debug: debug
|
15
|
+
}
|
16
|
+
@options.delete_if { |k, v| v.nil? }
|
17
|
+
end
|
18
|
+
|
19
|
+
def open(url)
|
20
|
+
return true if @app_process
|
21
|
+
cmd = [
|
22
|
+
File.expand_path('ext/webview_app', ROOT_PATH),
|
23
|
+
"-url '#{url}'"
|
24
|
+
]
|
25
|
+
@options.each do |k, v|
|
26
|
+
case v
|
27
|
+
when true, false then cmd << "-#{k}" if v
|
28
|
+
else cmd << "-#{k} '#{v}'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
exec_cmd(cmd.join(' '))
|
32
|
+
end
|
33
|
+
|
34
|
+
def close
|
35
|
+
return true unless app_process
|
36
|
+
app_out.close
|
37
|
+
app_err.close
|
38
|
+
|
39
|
+
pid = app_process.pid
|
40
|
+
Process.kill('QUIT', pid)
|
41
|
+
begin
|
42
|
+
Timeout.timeout(3) { Process.wait(pid) }
|
43
|
+
rescue Timeout::Error
|
44
|
+
kill
|
45
|
+
rescue Errno::ECHILD
|
46
|
+
end
|
47
|
+
|
48
|
+
@app_process = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def join
|
52
|
+
return unless app_process && app_process.alive?
|
53
|
+
Process.wait(app_process.pid)
|
54
|
+
rescue Errno::ECHILD
|
55
|
+
end
|
56
|
+
|
57
|
+
def kill
|
58
|
+
return unless app_process&.pid
|
59
|
+
Process.kill('TERM', app_process.pid)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def exec_cmd(cmd)
|
65
|
+
app_in, @app_out, @app_err, @app_process = Open3.popen3(cmd)
|
66
|
+
app_in.close
|
67
|
+
if app_process && app_process.alive?
|
68
|
+
true
|
69
|
+
else
|
70
|
+
false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/lib/webview.rb
ADDED
data/webview.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "webview/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "webview"
|
8
|
+
spec.version = Webview::VERSION
|
9
|
+
spec.authors = ["jiangzhi.xie"]
|
10
|
+
spec.email = ["xiejiangzhi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby api for zserge/webview project}
|
13
|
+
spec.description = %q{Ruby api for zserge/webview project}
|
14
|
+
spec.homepage = "https://github.com/xiejiangzhi/webview"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.extensions = ['ext/extconf.rb']
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiangzhi.xie
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Ruby api for zserge/webview project
|
56
|
+
email:
|
57
|
+
- xiejiangzhi@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- ext/Makefile
|
74
|
+
- ext/extconf.rb
|
75
|
+
- ext/webview/main.go
|
76
|
+
- lib/webview.rb
|
77
|
+
- lib/webview/app.rb
|
78
|
+
- lib/webview/version.rb
|
79
|
+
- webview.gemspec
|
80
|
+
homepage: https://github.com/xiejiangzhi/webview
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.0.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Ruby api for zserge/webview project
|
103
|
+
test_files: []
|