webview_ruby2 0.1.1
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/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +27 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/Rakefile +14 -0
- data/ext/webview/webview.cpp +1 -0
- data/ext/webview/webview.h +1380 -0
- data/lib/webview_ruby/version.rb +5 -0
- data/lib/webview_ruby.rb +83 -0
- metadata +99 -0
data/lib/webview_ruby.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ffi"
|
4
|
+
require 'ffi-compiler/loader'
|
5
|
+
require "json"
|
6
|
+
require_relative "webview_ruby/version"
|
7
|
+
|
8
|
+
module WebviewRuby
|
9
|
+
extend FFI::Library
|
10
|
+
ffi_lib FFI::Compiler::Loader.find('webview-ext')
|
11
|
+
attach_function :webview_create, [:int, :pointer], :pointer
|
12
|
+
attach_function :webview_run, [:pointer], :void
|
13
|
+
attach_function :webview_terminate, [:pointer], :void
|
14
|
+
attach_function :webview_set_title, [:pointer, :string], :void
|
15
|
+
attach_function :webview_set_size, [:pointer, :int, :int, :int], :void
|
16
|
+
attach_function :webview_navigate, [:pointer, :string], :void
|
17
|
+
attach_function :webview_destroy, [:pointer], :void
|
18
|
+
attach_function :webview_bind, [:pointer, :string, :pointer, :pointer], :void
|
19
|
+
attach_function :webview_eval, [:pointer, :string], :void
|
20
|
+
attach_function :webview_init, [:pointer, :string], :void
|
21
|
+
|
22
|
+
class Webview
|
23
|
+
attr_reader :is_running
|
24
|
+
|
25
|
+
def initialize(debug:false)
|
26
|
+
@is_running = false
|
27
|
+
@bindings = {}
|
28
|
+
@window = WebviewRuby.webview_create(debug ? 1 : 0, nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_title(title)
|
32
|
+
WebviewRuby.webview_set_title(@window, title)
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_size(width, height, hint=0)
|
36
|
+
WebviewRuby.webview_set_size(@window, width, height, hint)
|
37
|
+
end
|
38
|
+
|
39
|
+
def navigate(page)
|
40
|
+
WebviewRuby.webview_navigate(@window, page)
|
41
|
+
end
|
42
|
+
|
43
|
+
def run
|
44
|
+
@is_running = true
|
45
|
+
WebviewRuby.webview_run(@window)
|
46
|
+
end
|
47
|
+
|
48
|
+
def terminate
|
49
|
+
@is_running = false
|
50
|
+
WebviewRuby.webview_terminate(@window)
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
WebviewRuby.webview_destroy(@window)
|
55
|
+
end
|
56
|
+
|
57
|
+
def bind(name, func=nil, &block)
|
58
|
+
callback = FFI::Function.new(:void, [:string, :string, :pointer]) do |seq, req, arg|
|
59
|
+
begin
|
60
|
+
params = JSON.parse(req)
|
61
|
+
if func
|
62
|
+
func(*params)
|
63
|
+
else
|
64
|
+
block.call(*params)
|
65
|
+
end
|
66
|
+
rescue StandardError => e
|
67
|
+
print("Error occured: #{e.full_message}. \n\n Going to terminate\n")
|
68
|
+
terminate
|
69
|
+
end
|
70
|
+
end
|
71
|
+
@bindings[callback] = true # save a reference
|
72
|
+
WebviewRuby.webview_bind(@window, name, callback, nil)
|
73
|
+
end
|
74
|
+
|
75
|
+
def eval(js)
|
76
|
+
WebviewRuby.webview_eval(@window, js)
|
77
|
+
end
|
78
|
+
|
79
|
+
def init(js)
|
80
|
+
WebviewRuby.webview_init(@window, js)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webview_ruby2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Concetto Rudilosso
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-06-23 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: ffi
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: ffi-compiler
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
email:
|
55
|
+
- marcoc.r@outlook.com
|
56
|
+
executables: []
|
57
|
+
extensions:
|
58
|
+
- ext/Rakefile
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".rubocop.yml"
|
62
|
+
- CHANGELOG.md
|
63
|
+
- CODE_OF_CONDUCT.md
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- ext/Rakefile
|
72
|
+
- ext/webview/webview.cpp
|
73
|
+
- ext/webview/webview.h
|
74
|
+
- lib/webview_ruby.rb
|
75
|
+
- lib/webview_ruby/version.rb
|
76
|
+
homepage: https://github.com/Maaarcocr/webview_ruby
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata:
|
80
|
+
homepage_uri: https://github.com/Maaarcocr/webview_ruby
|
81
|
+
source_code_uri: https://github.com/Maaarcocr/webview_ruby
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.6.0
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.6.5
|
97
|
+
specification_version: 4
|
98
|
+
summary: Ruby bindings for webview
|
99
|
+
test_files: []
|