summarylogtreecommitdiffstats
path: root/stable.patch
blob: ea7f0c26471ad77848ed6f29872da3725a03ecfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
From 926171f6343b6420b532140dd2f4dc2e43fd9d2c Mon Sep 17 00:00:00 2001
From: Harald Weiner <timeraider@gmx.at>
Date: Sun, 23 Jul 2017 02:14:23 +0200
Subject: [PATCH 1/4] fixes #184 (port to WebKit2Gtk)

---
 remarkable/RemarkableWindow.py | 63 +++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 16 deletions(-)

diff --git a/remarkable/RemarkableWindow.py b/remarkable/RemarkableWindow.py
index ffbc70b..893dc27 100644
--- a/remarkable/RemarkableWindow.py
+++ b/remarkable/RemarkableWindow.py
@@ -24,10 +24,10 @@
 import gi
 gi.require_version('Gtk', '3.0')
 gi.require_version('GtkSource', '3.0')
-gi.require_version('WebKit', '3.0')
+gi.require_version('WebKit2', '4.0')
 
 from bs4 import BeautifulSoup
-from gi.repository import Gdk, Gtk, GtkSource, Pango, WebKit
+from gi.repository import Gdk, Gtk, GtkSource, Pango, WebKit2
 from locale import gettext as _
 from urllib.request import urlopen
 import markdown
@@ -113,10 +113,10 @@ def finish_initializing(self, builder): # pylint: disable=E1002
         self.text_buffer.connect("changed", self.on_text_view_changed)
         self.text_view.set_buffer(self.text_buffer)
         self.text_view.set_wrap_mode(Gtk.WrapMode.WORD)
-
-        self.live_preview = WebKit.WebView()
-        self.live_preview.connect("console-message", self._javascript_console_message) # Suppress .js output
-        self.live_preview.zoom_out()
+        
+        my_settings = self.create_webkit_settings()
+        self.live_preview = WebKit2.WebView.new_with_settings(my_settings)
+        self.zoom_out(self.live_preview)
 
         self.scrolledwindow_text_view = Gtk.ScrolledWindow()
         self.scrolledwindow_text_view.add(self.text_view)
@@ -624,11 +624,11 @@ def on_toolbutton_redo_clicked(self, widget):
         self.redo(self)
 
     def on_toolbutton_zoom_in_clicked(self, widget):
-        self.live_preview.zoom_in()
+        self.zoom_in(self.live_preview)
         self.scrollPreviewToFix(self)
 
     def on_toolbutton_zoom_out_clicked(self, widget):
-        self.live_preview.zoom_out()
+        self.zoom_out(self.live_preview)
         self.scrollPreviewToFix(self)
 
     def redo(self, widget):
@@ -1249,7 +1249,7 @@ def on_menuitem_handwritten_activate(self, widget):
         styles.css = styles.handwriting_css
         self.update_style(self)
         self.update_live_preview(self)
-        self.live_preview.zoom_in()
+        self.zoom_in(self.live_preview)
         self.remarkable_settings['style'] = "handwriting_css"
         self.write_settings()
 
@@ -1347,12 +1347,12 @@ def on_menuitem_feedback_activate(self, widget):
         window_feedback.set_title("Feedback Form")
         window_feedback.set_default_size(640, 640)
         window_feedback.set_position(Gtk.WindowPosition.CENTER)
-        feedback_browser = WebKit.WebView()
-        feedback_browser.connect("console-message", self._javascript_console_message) # Suppress .js output
+        my_settings = self.create_webkit_settings()
+        feedback_browser = WebKit2.WebView.new_with_settings(my_settings)
         feedback_scroller = Gtk.ScrolledWindow()
         feedback_scroller.add(feedback_browser)
         window_feedback.add(feedback_scroller)
-        feedback_browser.open("https://jamiemcgowan.typeform.com/to/ng5Lhc")
+        feedback_browser.load_uri("https://jamiemcgowan.typeform.com/to/ng5Lhc")
         window_feedback.show_all()
 
     def on_menuitem_about_activate(self, widget):
@@ -1443,14 +1443,45 @@ def update_live_preview(self, widet):
         html = self.default_html_start + html_middle + self.default_html_end
 
         # Update the display, supporting relative paths to local images
-        self.live_preview.load_string(html, "text/html", "utf-8", "file://{}".format(os.path.abspath(self.name)))
+        self.live_preview.load_html(html, "file://{}".format(os.path.abspath(self.name)))
 
     """
-        This function suppresses the messages from the WebKit (live preview) console
+        This function returns WebKit settings instance to suppress
+        the messages from the WebKit (live preview) console
     """
-    def _javascript_console_message(self, view, message, line, sourceid):
-        return True
+    def create_webkit_settings(self):
+        result = WebKit2.Settings()
+        result.set_enable_write_console_messages_to_stdout(False) # Suppress .js output
+        return result
 
+    """
+        This function implements zoom_in for WebKit2.WebView
+    """
+    def zoom_in(self, webView):
+        zoom_level = webView.get_zoom_level()
+        zoom_level = zoom_level + self.get_zoom_step()
+        webView.set_zoom_level(zoom_level)
+
+    """
+        This function implements zoom_out for WebKit2.WebView
+    """
+    def zoom_out(self, webView):
+        zoom_level = webView.get_zoom_level()
+        zoom_level = zoom_level - self.get_zoom_step()
+        webView.set_zoom_level(zoom_level)
+
+    """
+        This function returns the same magic number as in previous WebKit API:
+        https://lazka.github.io/pgi-docs/WebKit-3.0/classes/WebSettings.html#WebKit.WebSettings.props.zoom_step
+    """
+    def get_zoom_step(self):
+        return 0.10000000149011612
+
+    """
+        This function resets the zoom_level to the default value
+    """
+    def reset_zoom_level(self, webView):
+       webView.set_zoom_level(1.0)
 
     """
         This function deletes any temporary files that were created during execution

From 63dc24917dfd36d7c4a7265dc3a0020deb75593c Mon Sep 17 00:00:00 2001
From: Harald Weiner <timeraider@gmx.at>
Date: Fri, 28 Jul 2017 07:07:57 +0200
Subject: [PATCH 2/4] fixes #175 (Live Preview Mode Executes JavaScript)

---
 data/ui/RemarkableWindow.ui    |  9 +++++++++
 remarkable/RemarkableWindow.py | 26 ++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/data/ui/RemarkableWindow.ui b/data/ui/RemarkableWindow.ui
index ab0007c..ca2396e 100644
--- a/data/ui/RemarkableWindow.ui
+++ b/data/ui/RemarkableWindow.ui
@@ -405,6 +405,15 @@
                         <property name="active">True</property>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="menuitem_js">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Enable Java-Script</property>
+                        <property name="use_underline">True</property>
+                        <property name="active">True</property>
+                      </object>
+                    </child>
                     <child>
                       <object class="GtkCheckMenuItem" id="menuitem_vertical_layout">
                         <property name="visible">True</property>
diff --git a/remarkable/RemarkableWindow.py b/remarkable/RemarkableWindow.py
index 893dc27..6856042 100644
--- a/remarkable/RemarkableWindow.py
+++ b/remarkable/RemarkableWindow.py
@@ -114,8 +114,8 @@ def finish_initializing(self, builder): # pylint: disable=E1002
         self.text_view.set_buffer(self.text_buffer)
         self.text_view.set_wrap_mode(Gtk.WrapMode.WORD)
         
-        my_settings = self.create_webkit_settings()
-        self.live_preview = WebKit2.WebView.new_with_settings(my_settings)
+        self.webkit_settings = self.create_webkit_settings()
+        self.live_preview = WebKit2.WebView.new_with_settings(self.webkit_settings)
         self.zoom_out(self.live_preview)
 
         self.scrolledwindow_text_view = Gtk.ScrolledWindow()
@@ -199,7 +199,8 @@ def check_settings(self):
         if not os.path.isfile(self.settings_path):
             self.remarkable_settings = {}
             self.remarkable_settings['css'] = '' 
-            self.remarkable_settings['font'] = "Sans 10"  
+            self.remarkable_settings['font'] = "Sans 10"
+            self.remarkable_settings['js'] = True
             self.remarkable_settings['line-numbers'] = True
             self.remarkable_settings['live-preview'] = True
             self.remarkable_settings['nightmode'] = False       
@@ -234,6 +235,12 @@ def load_settings(self):
             # Disable word wrap on startup
             self.builder.get_object("menuitem_word_wrap").set_active(False)
             self.on_menuitem_word_wrap_activate(self)
+        
+        if not 'js' in self.remarkable_settings:
+           self.remarkable_settings['js'] = True
+        if self.remarkable_settings['js'] == False:
+            # Disable Live Preview on startup
+            self.builder.get_object("menuitem_js").set_active(False)
 
         if self.remarkable_settings['live-preview'] == False:
             # Disable Live Preview on startup
@@ -810,7 +817,16 @@ def toggle_live_preview(self, widget):
             self.builder.get_object("toolbar1").set_visible(True)
             self.update_live_preview(self)
         self.write_settings()
-
+    
+    def on_menuitem_js_activate(self, widget):
+        self.toggle_js(self)
+    
+    def toggle_js(self, widget):
+        state = self.webkit_settings.get_enable_javascript()
+        state = not state
+        self.remarkable_settings['js'] = state
+        self.webkit_settings.set_enable_javascript(state)
+        self.write_settings()
 
     def on_menuitem_swap_activate(self, widget):
         if self.live_preview.get_visible():
@@ -1452,6 +1468,8 @@ def update_live_preview(self, widet):
     def create_webkit_settings(self):
         result = WebKit2.Settings()
         result.set_enable_write_console_messages_to_stdout(False) # Suppress .js output
+        #js = self.remarkable_settings['js']
+        result.set_enable_javascript(True) # JS-Kill-Switch for issue #175
         return result
 
     """

From 1b05770885a1bbfc8b21fdb877267b4bf9fb5e88 Mon Sep 17 00:00:00 2001
From: Mikael Blomstrand <mbloms@kth.se>
Date: Wed, 4 Apr 2018 13:07:30 +0200
Subject: [PATCH 3/4] Spellcheck error message adapted to arch.

---
 remarkable/RemarkableWindow.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/remarkable/RemarkableWindow.py b/remarkable/RemarkableWindow.py
index 6856042..a77f74c 100644
--- a/remarkable/RemarkableWindow.py
+++ b/remarkable/RemarkableWindow.py
@@ -47,7 +47,7 @@
     from gtkspellcheck import SpellChecker
     spellcheck_enabled = True
 except:
-    print("*Spellchecking not enabled.\n*To enable spellchecking install pygtkspellcheck\n*https://pypi.python.org/pypi/pygtkspellcheck/")
+    print("*Spellchecking not enabled.\n*To enable spellchecking install python-gtkspellcheck.\npacman -S --asdeps python-gtkspellcheck")
     spellcheck_enabled = False
 
 import logging

From eb33c22a6bf4100443b75e33e9897a85ad09d014 Mon Sep 17 00:00:00 2001
From: Mikael Blomstrand <mbloms@kth.se>
Date: Wed, 4 Apr 2018 13:12:26 +0200
Subject: [PATCH 4/4] `import styles` correctly

---
 remarkable/RemarkableWindow.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/remarkable/RemarkableWindow.py b/remarkable/RemarkableWindow.py
index a77f74c..e838330 100644
--- a/remarkable/RemarkableWindow.py
+++ b/remarkable/RemarkableWindow.py
@@ -36,7 +36,7 @@
 import re, subprocess, datetime, os, webbrowser, _thread, sys, locale
 import tempfile
 import traceback
-import styles
+from remarkable import styles
 import unicodedata
 import warnings
 import datetime