From 6aa7e7a087a6144a541de143c6b709abd89cf610 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Sat, 20 Apr 2024 11:17:29 +0300 Subject: [PATCH 1/2] feat(emoji): libsoup cache lookup --- src/Services/Helpers/Image.vala | 8 ++++++++ src/Widgets/Emoji.vala | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Services/Helpers/Image.vala b/src/Services/Helpers/Image.vala index 3db81f1b5..f3e501a2f 100644 --- a/src/Services/Helpers/Image.vala +++ b/src/Services/Helpers/Image.vala @@ -85,4 +85,12 @@ public class Tuba.Helper.Image { cb (result); }); } + + public static Gdk.Paintable? lookup_cache (string uri) { + try { + return Gdk.Texture.from_filename (GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S, cache.cache_dir, GLib.str_hash (uri).to_string ())); + } catch { + return null; + } + } } diff --git a/src/Widgets/Emoji.vala b/src/Widgets/Emoji.vala index c8f89f544..5a29ad3a5 100644 --- a/src/Widgets/Emoji.vala +++ b/src/Widgets/Emoji.vala @@ -25,7 +25,11 @@ public class Tuba.Widgets.Emoji : Adw.Bin { } GLib.Idle.add (() => { - Tuba.Helper.Image.request_paintable (emoji_url, null, on_cache_response); + var cached_paintable = Tuba.Helper.Image.lookup_cache (emoji_url); + if (cached_paintable == null) + Tuba.Helper.Image.request_paintable (emoji_url, null, on_cache_response); + else + on_cache_response (cached_paintable); return GLib.Source.REMOVE; }); } From b795c58f0141fb5143eb07c9e2643923c24a1123 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Fri, 14 Jun 2024 19:00:22 +0300 Subject: [PATCH 2/2] feat: remove idle on emoji --- src/Widgets/Emoji.vala | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Widgets/Emoji.vala b/src/Widgets/Emoji.vala index 5a29ad3a5..14d43465e 100644 --- a/src/Widgets/Emoji.vala +++ b/src/Widgets/Emoji.vala @@ -24,14 +24,11 @@ public class Tuba.Widgets.Emoji : Adw.Bin { shortcode = t_shortcode; } - GLib.Idle.add (() => { - var cached_paintable = Tuba.Helper.Image.lookup_cache (emoji_url); - if (cached_paintable == null) - Tuba.Helper.Image.request_paintable (emoji_url, null, on_cache_response); - else - on_cache_response (cached_paintable); - return GLib.Source.REMOVE; - }); + var cached_paintable = Tuba.Helper.Image.lookup_cache (emoji_url); + if (cached_paintable == null) + Tuba.Helper.Image.request_paintable (emoji_url, null, on_cache_response); + else + on_cache_response (cached_paintable); } void on_cache_response (Gdk.Paintable? data) {