Skip to content

Commit

Permalink
Port to WebKitGTK-6.0 and Libadwaita 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfactotum committed Oct 12, 2023
1 parent e15d95c commit 0019a42
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Dependencies:

- `gjs (>= 1.70)`
- `gtk4`
- `libadwaita`
- `webkit2gtk4`/`webkit2gtk-5.0`
- `libadwaita (>= 1.4)`
- `webkitgtk-6.0`

To install, run `meson builddir && sudo meson install -C builddir`

Expand Down
5 changes: 5 additions & 0 deletions com.github.johnfactotum.QuickLookup.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
</screenshot>
</screenshots>
<releases>
<release version="2.1.0" date="2023-11-12">
<description>
<p>Upgraded to GNOME 45</p>
</description>
</release>
<release version="2.0.0" date="2021-11-14">
<description>
<p>Ported to GTK 4</p>
Expand Down
6 changes: 3 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('com.github.johnfactotum.QuickLookup',
version: '2.0.0',
version: '2.1.0',
meson_version: '>=0.49'
)

Expand All @@ -16,8 +16,8 @@ glib2_dep = dependency('glib-2.0')
gio2_dep = dependency('gio-2.0')
gjs_dep = dependency('gjs-1.0', version: '>=1.70')
gtk4_dep = dependency('gtk4')
webkit_dep = dependency('webkit2gtk-5.0')
libadwaita_dep = dependency('libadwaita-1')
webkit_dep = dependency('webkitgtk-6.0')
libadwaita_dep = dependency('libadwaita-1', version: '>=1.4')

bin_conf = configuration_data()
bin_conf.set('PACKAGE_VERSION', meson.project_version())
Expand Down
29 changes: 14 additions & 15 deletions quick-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

imports.gi.versions.Gio = '2.0'
imports.gi.versions.Gtk = '4.0'
imports.gi.versions.WebKit2 = '5.0'
imports.gi.versions.WebKit = '6.0'
imports.gi.versions.Adw = '1'
const { GLib, Gio, Gtk, Gdk, WebKit2, Adw } = imports.gi
const { GLib, Gio, Gtk, Gdk, WebKit, Adw } = imports.gi
const System = imports.system

const pkg = {
Expand Down Expand Up @@ -72,10 +72,10 @@ const scriptRunner = webView => {
}
const manager = webView.get_user_content_manager()
manager.connect(`script-message-received::handler`, (_, result) => {
try { handler(JSON.parse(result.get_js_value().to_string())) }
try { handler(JSON.parse(result.to_string())) }
catch (e) { log(e) }
})
const success = manager.register_script_message_handler('handler')
const success = manager.register_script_message_handler('handler', null)
if (!success) throw new Error('failed to register message handler')

const exec = (func, params) => {
Expand All @@ -88,14 +88,14 @@ const scriptRunner = webView => {
.catch(e => globalThis.webkit.messageHandlers.handler.postMessage(
JSON.stringify({ token: "${token}", ok: false, payload: e.message })))`
const promise = makePromise(token)
webView.run_javascript(script, null, () => {})
webView.evaluate_javascript(script, -1, null, null, null, () => {})
return promise
}
const eval = exp => new Promise((resolve, reject) =>
webView.run_javascript(`JSON.stringify(${exp})`, null, (_, result) => {
webView.evaluate_javascript(`JSON.stringify(${exp})`, -1, null, null, null, (_, result) => {
try {
const jsResult = webView.run_javascript_finish(result)
const str = jsResult.get_js_value().to_string()
const jscValue = webView.evaluate_javascript_finish(result)
const str = jscValue.to_string()
const value = str !== 'undefined' ? JSON.parse(str) : null
resolve(value)
} catch (e) {
Expand Down Expand Up @@ -159,8 +159,8 @@ const wiktionary = ({ word, language }) => fetch('${apiURL}' + word)
globalThis.wiktionary = wiktionary
})()`

const webView = new WebKit2.WebView({
settings: new WebKit2.Settings({
const webView = new WebKit.WebView({
settings: new WebKit.Settings({
enable_javascript_markup: false,
enable_write_console_messages_to_stdout: true,
allow_universal_access_from_file_urls: true,
Expand Down Expand Up @@ -300,9 +300,8 @@ const applicationWindowXml = `<?xml version="1.0" encoding="UTF-8"?><interface>
<property name="default-width">480</property>
<property name="title">Quick Lookup</property>
<property name="content">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<property name="title-widget">
<object class="GtkSearchEntry" id="query-entry">
Expand All @@ -313,7 +312,7 @@ const applicationWindowXml = `<?xml version="1.0" encoding="UTF-8"?><interface>
<child type="start">
<object class="GtkButton">
<property name="icon-name">go-previous-symbolic</property>
<property name="tooltip-text">Go back</property>
<property name="tooltip-text">Back</property>
<property name="action-name">win.go-back</property>
</object>
</child>
Expand Down Expand Up @@ -372,7 +371,7 @@ const applicationWindowXml = `<?xml version="1.0" encoding="UTF-8"?><interface>
</child>
</object>
</child>
<child>
<child type="bottom">
<object class="GtkActionBar">
<child type="center">
<object class="GtkComboBoxText" id="lang-combo">
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0019a42

Please sign in to comment.