[polari] urlPreview: Only request thumbnails of previews which are mapped



commit 87b3044f5853106e7abc0ccacd6097c94e0d4065
Author: Philip Withnall <withnall endlessm com>
Date:   Wed May 6 17:04:06 2020 +0100

    urlPreview: Only request thumbnails of previews which are mapped
    
    Most of the time, a user will not look at half of the chatrooms they’re
    idling in, so there’s no need to thumbnail all the URIs which appear in
    those rooms (or even load the cached thumbnails). Defer that until the
    `urlPreview` is actually mapped.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    https://gitlab.gnome.org/GNOME/polari/-/merge_requests/157

 src/urlPreview.js | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/src/urlPreview.js b/src/urlPreview.js
index f17e0be4..e388b78b 100644
--- a/src/urlPreview.js
+++ b/src/urlPreview.js
@@ -87,6 +87,7 @@ var URLPreview = GObject.registerClass({
         styleContext.add_class('url-preview');
         styleContext.add_class(Gtk.STYLE_CLASS_BACKGROUND);
 
+        this._imageLoaded = false;
         this._image = new Gtk.Image({
             icon_name: 'image-loading-symbolic',
             visible: true,
@@ -100,18 +101,26 @@ var URLPreview = GObject.registerClass({
         });
         this._label.get_style_context().add_class(Gtk.STYLE_CLASS_DIM_LABEL);
         this.add(this._label);
+    }
 
-        Thumbnailer.getDefault().getThumbnail(this.uri, filename => {
-            this._image.set_from_file(filename);
+    vfunc_map() {
+        if (!this._imageLoaded) {
+            this._imageLoaded = true;
 
-            let title = null;
-            if (this._image.pixbuf)
-                title = this._image.pixbuf.get_option('tEXt::Title');
+            Thumbnailer.getDefault().getThumbnail(this.uri, filename => {
+                this._image.set_from_file(filename);
 
-            if (title) {
-                this._label.set_label(title);
-                this.tooltip_text = title;
-            }
-        });
+                let title = null;
+                if (this._image.pixbuf)
+                    title = this._image.pixbuf.get_option('tEXt::Title');
+
+                if (title) {
+                    this._label.set_label(title);
+                    this.tooltip_text = title;
+                }
+            });
+        }
+
+        super.vfunc_map();
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]