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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cfa2e299e210eed4fcdafa1f85934d377eb56f1
4
- data.tar.gz: a4658b1c5b840ad94e6185ba1d41e4ba703e83c4
3
+ metadata.gz: 8517897f7ddbaa789f62ac121f66f875eb6a1dfe
4
+ data.tar.gz: 3783319afd02620126d691e9b4c3cce5fa04d8e4
5
5
  SHA512:
6
- metadata.gz: 5ff6407a451e09c91b670b1ee85361bffa7c3ed166d15ef7cd88d1cbc16af1ee0381f7c011d116346090325f6d0237703b331f9d692ca25d5de04d0ed9c283e1
7
- data.tar.gz: 122344f3cfcda27ec94131a933aed1836289c8565c439d09b6e5b37962718db211dece223af7c565fefd4d94fe50627493bbf26ad2b5288ca55224b92353a0c4
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.2"
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"]
@@ -1,10 +1,16 @@
1
1
  # News
2
2
 
3
+ ## 1.0.3: 2017-07-11
4
+
5
+ ### Improvements
6
+
7
+ * Supported timeout.
8
+
3
9
  ## 1.0.2: 2017-07-11
4
10
 
5
11
  ### Improvements
6
12
 
7
- * Reduces required resources.
13
+ * Reduced required resources.
8
14
 
9
15
  ## 1.0.1: 2017-07-11
10
16
 
@@ -66,7 +66,29 @@ module ChupaText
66
66
  window.add(view)
67
67
  window.show_all
68
68
 
69
- finished = false
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
- [png].pack("m*"),
84
- "base64")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chupa-text-decomposer-webkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou