chupa-text-decomposer-webkit 1.0.2 → 1.0.3
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 +4 -4
- data/chupa-text-decomposer-webkit.gemspec +1 -1
- data/doc/text/news.md +7 -1
- data/lib/chupa-text/decomposers/webkit.rb +56 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8517897f7ddbaa789f62ac121f66f875eb6a1dfe
|
4
|
+
data.tar.gz: 3783319afd02620126d691e9b4c3cce5fa04d8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c097c1800d2cbafb859216bc2218ceab2f2005ae8b0c2f2d82eaf42d6c326a1d48411c14e14fdafd2ce54d5d603a658557e0fbfdd04031f02494e3d0c749a12
|
7
|
+
data.tar.gz: 9465dd3692b81e47fdb5d10147a66f4cc6744561db76b14157d66bcb7f2e3793e0ea4777cd1c0e6b16d7ffda6dc3784dc9f0e8f57faa04432e68e7f1867afa92
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
Gem::Specification.new do |spec|
|
24
24
|
spec.name = "chupa-text-decomposer-webkit"
|
25
|
-
spec.version = "1.0.
|
25
|
+
spec.version = "1.0.3"
|
26
26
|
spec.homepage = "https://github.com/ranguba/chupa-text-decomposer-webkit"
|
27
27
|
spec.authors = ["Kouhei Sutou"]
|
28
28
|
spec.email = ["kou@clear-code.com"]
|
data/doc/text/news.md
CHANGED
@@ -66,7 +66,29 @@ module ChupaText
|
|
66
66
|
window.add(view)
|
67
67
|
window.show_all
|
68
68
|
|
69
|
-
|
69
|
+
status = {
|
70
|
+
finished: false,
|
71
|
+
screenshot: nil,
|
72
|
+
}
|
73
|
+
prepare_screenshot(data, view, status)
|
74
|
+
debug do
|
75
|
+
"#{log_tag}[load][html] #{data.uri}"
|
76
|
+
end
|
77
|
+
view.load_html(data.body, data.uri.to_s)
|
78
|
+
|
79
|
+
main_context = GLib::MainContext.default
|
80
|
+
timeout(compute_timeout_second, view, main_context, status) do
|
81
|
+
until status[:finished]
|
82
|
+
main_context.iteration(true)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
window.destroy
|
87
|
+
|
88
|
+
status[:screenshot]
|
89
|
+
end
|
90
|
+
|
91
|
+
def prepare_screenshot(data, view, status)
|
70
92
|
view.signal_connect("load-changed") do |_, load_event|
|
71
93
|
debug do
|
72
94
|
"#{log_tag}[load][#{load_event.nick}] #{view.uri}"
|
@@ -75,19 +97,19 @@ module ChupaText
|
|
75
97
|
case load_event
|
76
98
|
when WebKit2Gtk::LoadEvent::FINISHED
|
77
99
|
view.get_snapshot(:full_document, :none) do |_, result|
|
78
|
-
finished = true
|
100
|
+
status[:finished] = true
|
79
101
|
snapshot_surface = view.get_snapshot_finish(result)
|
80
102
|
unless snapshot_surface.width.zero?
|
81
103
|
png = convert_snapshot_surface_to_png(data, snapshot_surface)
|
82
|
-
screenshot = Screenshot.new("image/png",
|
83
|
-
|
84
|
-
|
104
|
+
status[:screenshot] = Screenshot.new("image/png",
|
105
|
+
[png].pack("m*"),
|
106
|
+
"base64")
|
85
107
|
end
|
86
108
|
end
|
87
109
|
end
|
88
110
|
end
|
89
111
|
view.signal_connect("load-failed") do |_, _, failed_uri, error|
|
90
|
-
finished = true
|
112
|
+
status[:finished] = true
|
91
113
|
error do
|
92
114
|
message = "failed to load URI: #{failed_uri}: "
|
93
115
|
message << "#{error.class}(#{error.code}): #{error.message}"
|
@@ -95,18 +117,6 @@ module ChupaText
|
|
95
117
|
end
|
96
118
|
true
|
97
119
|
end
|
98
|
-
debug do
|
99
|
-
"#{log_tag}[load][html] #{data.uri}"
|
100
|
-
end
|
101
|
-
view.load_html(data.body, data.uri.to_s)
|
102
|
-
|
103
|
-
main_context = GLib::MainContext.default
|
104
|
-
until finished
|
105
|
-
main_context.iteration(true)
|
106
|
-
end
|
107
|
-
window.destroy
|
108
|
-
|
109
|
-
screenshot
|
110
120
|
end
|
111
121
|
|
112
122
|
def convert_snapshot_surface_to_png(data, snapshot_surface)
|
@@ -129,6 +139,34 @@ module ChupaText
|
|
129
139
|
png.string
|
130
140
|
end
|
131
141
|
|
142
|
+
def timeout(second, view, main_context, status)
|
143
|
+
timeout_id = nil
|
144
|
+
timeout_source = GLib::Timeout.source_new_seconds(second)
|
145
|
+
timeout_source.set_callback do
|
146
|
+
timeout_id = nil
|
147
|
+
status[:finished] = true
|
148
|
+
error do
|
149
|
+
message = "timeout to load URI: #{second}s: #{view.uri}"
|
150
|
+
"#{log_tag}[load][timeout] #{message}"
|
151
|
+
end
|
152
|
+
GLib::Source::REMOVE
|
153
|
+
end
|
154
|
+
timeout_id = timeout_source.attach(main_context)
|
155
|
+
yield
|
156
|
+
GLib::Source.remove(timeout_id) if timeout_id
|
157
|
+
end
|
158
|
+
|
159
|
+
def compute_timeout_second
|
160
|
+
default_timeout = 5
|
161
|
+
timeout_string =
|
162
|
+
ENV["CHUPA_TEXT_DECOMPOSER_WEBKIT_TIMEOUT"] || default_timeout.to_s
|
163
|
+
begin
|
164
|
+
Integer(timeout_string)
|
165
|
+
rescue ArgumentError
|
166
|
+
default_timeout
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
132
170
|
def log_tag
|
133
171
|
"[decomposer][webkit]"
|
134
172
|
end
|