fontmanager: build with libwebkit2gtk41

This commit is contained in:
oreo639 2024-02-25 03:32:39 -08:00
parent 62d7997fb3
commit 0402386f11
2 changed files with 167 additions and 2 deletions

View File

@ -0,0 +1,165 @@
From 5cbec5eab33f6e64c27ead07cdee0098431ad6b9 Mon Sep 17 00:00:00 2001
From: Jerry Casiano <JerryCasiano@gmail.com>
Date: Sun, 18 Feb 2024 16:48:25 -0500
Subject: [PATCH] - Switch to libsoup 3 - Closes #343
---
README.md | 4 +-
README.ro.md | 4 +-
build-aux/Makefile | 2 +-
debian/control | 4 +-
fedora/font-manager.spec | 8 ++--
meson.build | 4 +-
src/font-manager/web/google/GoogleFonts.vala | 44 +++++++++----------
src/font-manager/web/google/WebFont.vala | 45 +++++++++-----------
8 files changed, 54 insertions(+), 61 deletions(-)
diff --git a/build-aux/Makefile b/build-aux/Makefile
index 9a3ffcc8..de737d94 100644
--- a/build-aux/Makefile
+++ b/build-aux/Makefile
@@ -95,7 +95,7 @@ BUILD_DEPENDS = \
python3 \
python-gi-dev \
python3-nautilus \
- libsoup2.4-dev \
+ libsoup3.0-dev \
libwebkit2gtk-4.0-dev \
libnautilus-extension-dev \
libnemo-extension-dev \
diff --git a/meson.build b/meson.build
index 9a66f62e..00b9c45e 100644
--- a/meson.build
+++ b/meson.build
@@ -27,8 +27,8 @@ sqlite = dependency('sqlite3', version: '>= 3.8')
xml = dependency('libxml-2.0', version: '>= 2.9')
if get_option('webkit')
- soup = dependency('libsoup-2.4', version: '>= 2.62')
- webkit = dependency('webkit2gtk-4.0', version: '>= 2.24')
+ soup = dependency('libsoup-3.0', version: '>= 3.4')
+ webkit = dependency('webkit2gtk-4.1', version: '>= 2.42')
add_global_arguments('-D', 'HAVE_WEBKIT', language: 'vala')
endif
diff --git a/src/font-manager/web/google/GoogleFonts.vala b/src/font-manager/web/google/GoogleFonts.vala
index 4dc64fd9..c350cb40 100644
--- a/src/font-manager/web/google/GoogleFonts.vala
+++ b/src/font-manager/web/google/GoogleFonts.vala
@@ -179,35 +179,33 @@ namespace FontManager.GoogleFonts {
foreach (var entry in order) {
string filename = "gfc-%s.json".printf(entry);
var message = new Soup.Message(GET, WEBFONTS.printf(GFC_API_KEY, entry));
- if (session.send_message(message) == Soup.Status.OK) {
+ try {
+ Bytes? bytes = session.send_and_read(message, null);
+ assert(bytes != null);
string filepath = Path.build_filename(get_package_cache_directory(), filename);
- try {
- Bytes bytes = message.response_body.flatten().get_as_bytes();
- File cache_file = File.new_for_path(filepath);
- if (cache_file.query_exists())
- cache_file.delete();
- FileOutputStream stream = cache_file.create(FileCreateFlags.PRIVATE);
- stream.write_bytes_async.begin(bytes, Priority.DEFAULT, null, (obj, res) => {
- try {
- stream.write_bytes_async.end(res);
- stream.close();
- } catch (Error e) {
- warning("Failed to write data for : %s :: %i : %s", filename, e.code, e.message);
- return;
- }
- });
- } catch (Error e) {
- warning("Failed to write data for : %s :: %i : %s", filename, e.code, e.message);
- return;
- }
- Idle.add(update_font_list_cache.callback);
- yield;
- } else {
+ File cache_file = File.new_for_path(filepath);
+ if (cache_file.query_exists())
+ cache_file.delete();
+ FileOutputStream stream = cache_file.create(FileCreateFlags.PRIVATE);
+ stream.write_bytes_async.begin(bytes, Priority.DEFAULT, null, (obj, res) => {
+ try {
+ stream.write_bytes_async.end(res);
+ stream.close();
+ } catch (Error e) {
+ warning("Failed to write data for : %s :: %i : %s", filename, e.code, e.message);
+ return;
+ }
+ });
+ } catch (Error e) {
http_status = message.status_code;
status_message = message.reason_phrase;
warning("Failed to download data for : %s :: %i", filename, (int) message.status_code);
return;
}
+ http_status = message.status_code;
+ status_message = message.reason_phrase;
+ Idle.add(update_font_list_cache.callback);
+ yield;
}
}
diff --git a/src/font-manager/web/google/WebFont.vala b/src/font-manager/web/google/WebFont.vala
index d4f14941..d2b0e0ad 100644
--- a/src/font-manager/web/google/WebFont.vala
+++ b/src/font-manager/web/google/WebFont.vala
@@ -42,35 +42,30 @@ namespace FontManager.GoogleFonts {
string filename = font.get_filename();
string filepath = Path.build_filename(font_dir, filename);
var message = new Soup.Message(GET, font.url);
- if (session.send_message(message) == Soup.Status.OK) {
+ try {
+ Bytes? bytes = session.send_and_read(message, null);
+ assert(bytes != null);
+ File font_file = File.new_for_path(filepath);
+ // File.create errors out if file already exists regardless of flags
+ if (font_file.query_exists())
+ font_file.delete();
+ FileOutputStream stream = font_file.create(FileCreateFlags.PRIVATE);
try {
- Bytes bytes = message.response_body.flatten().get_as_bytes();
- File font_file = File.new_for_path(filepath);
- if (font_file.query_exists())
- font_file.delete();
- FileOutputStream stream = font_file.create(FileCreateFlags.PRIVATE);
- stream.write_bytes_async.begin(bytes, Priority.DEFAULT, null, (obj, res) => {
- try {
- stream.write_bytes_async.end(res);
- stream.close();
- } catch (Error e) {
- warning("Failed to write data for : %s :: %i : %s", filename, e.code, e.message);
- retval = false;
- return;
- }
- });
- if (!retval)
- return false;
+ stream.write_bytes(bytes);
+ stream.close();
} catch (Error e) {
- warning("Failed to write data for : %s :: %i : %s", filename, e.code, e.message);
- return false;
+ retval = false;
+ warning("Failed to write data to file : %s : %s", filepath, e.message);
}
- Idle.add(download_font_files.callback);
- yield;
- } else {
- warning("Failed to download data for : %s :: %i", filename, (int) message.status_code);
- return false;
+ } catch (Error e) {
+ retval = false;
+ warning("Failed to read data for : %s :: %i :: %s",
+ filename,
+ (int) message.status_code,
+ e.message);
}
+ Idle.add(download_font_files.callback);
+ yield;
}
return retval;
}

View File

@ -1,13 +1,13 @@
# Template file for 'fontmanager'
pkgname=fontmanager
version=0.8.8
revision=1
revision=2
build_helper=gir
build_style=meson
configure_args="--buildtype=release"
hostmakedepends="pkg-config yelp-tools vala-devel glib-devel gettext"
makedepends="json-glib-devel sqlite-devel gtk+3-devel fontconfig-devel
libsoup-devel webkit2gtk-devel"
libsoup3-devel libwebkit2gtk41-devel"
short_desc="Font-manager is a simple font management tool for GTK+ environments"
maintainer="Antonio Malcolm <antonio@antoniomalcolm.com>"
license="GPL-3.0-or-later"