Skip to content

Commit

Permalink
Merge pull request #2086 from samschott/replace-deprecated-webview-ap…
Browse files Browse the repository at this point in the history
…i-usage

Replace deprecated WebView API usage to evaluate javascript on Gtk
  • Loading branch information
samschott committed Aug 17, 2023
2 parents 6096823 + d7cea27 commit 53bb064
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/2085.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WebView no longer uses the deprecated ``run_javascript`` API on Gtk.
14 changes: 10 additions & 4 deletions gtk/src/toga_gtk/widgets/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ def evaluate_javascript(self, javascript, on_result=None):
# Define a callback that will update the future when
# the Javascript is complete.
def gtk_js_finished(webview, task, *user_data):
"""If `run_javascript_finish` from GTK returns a result, unmarshal it, and
"""If `evaluate_javascript_finish` from GTK returns a result, unmarshal it, and
call back with the result."""
try:
js_result = webview.run_javascript_finish(task)
value = js_result.get_js_value()
value = webview.evaluate_javascript_finish(task)
if value.is_boolean():
value = value.to_boolean()
elif value.is_number():
Expand All @@ -103,7 +102,14 @@ def gtk_js_finished(webview, task, *user_data):

# Invoke the javascript method, with a callback that will set
# the future when a result is available.
self.native.run_javascript(javascript, None, gtk_js_finished)
self.native.evaluate_javascript(
script=javascript,
length=len(javascript),
world_name=None,
source_uri=None,
cancellable=None,
callback=gtk_js_finished,
)

# wait for the future, and return the result
return result
Expand Down

0 comments on commit 53bb064

Please sign in to comment.