Codebase list gnome-shell-extension-appindicator / 80ec78e
appIndicator: Free the cached pixmaps variants when not needed We used to keep the pixmaps variants saved as cached properties of the proxy but these are just a waste of memory usage once the icon is set, given that we're not going to re-use them as they are in any case until the icon is invalidated which happens only in rare cases. So, once a pixmap is set, unset the cached property and mark it as invalid, in this way next time an icon is requested we can refresh it if that's required Marco Trevisan (TreviƱo) authored 1 year, 2 months ago Marco Trevisan committed 1 year, 2 months ago
1 changed file(s) with 46 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
6060 NORMAL: 0,
6161 ATTENTION: 1,
6262 OVERLAY: 2,
63
64 toPropertyName: (iconType, params = { isPixbuf: false }) => {
65 let propertyName = 'Icon';
66
67 if (iconType === SNIconType.OVERLAY)
68 propertyName = 'OverlayIcon';
69 else if (iconType === SNIconType.ATTENTION)
70 propertyName = 'AttentionIcon';
71
72 return `${propertyName}${params.isPixbuf ? 'Pixmap' : 'Name'}`;
73 },
6374 });
6475
6576 var AppIndicatorProxy = GObject.registerClass({
460471
461472 this._cancellable = new Gio.Cancellable();
462473 this._proxy = new AppIndicatorProxy(busName, object);
474 this._invalidatedPixmapsIcons = new Set();
463475
464476 this._setupProxy().catch(logError);
465477 Util.connectSmart(this._proxy, 'g-properties-changed', this, this._onPropertiesChanged);
604616 return {
605617 theme: this._proxy.IconThemePath,
606618 name: this._proxy.AttentionIconName,
607 pixmap: this._proxy.get_cached_property('AttentionIconPixmap'),
619 pixmap: this._getPixmapProperty(SNIconType.ATTENTION),
608620 };
609621 }
610622
612624 return {
613625 theme: this._proxy.IconThemePath,
614626 name: this._proxy.IconName,
615 pixmap: this._proxy.get_cached_property('IconPixmap'),
627 pixmap: this._getPixmapProperty(SNIconType.NORMAL),
616628 };
617629 }
618630
620632 return {
621633 theme: this._proxy.IconThemePath,
622634 name: this._proxy.OverlayIconName,
623 pixmap: this._proxy.get_cached_property('OverlayIconPixmap'),
635 pixmap: this._getPixmapProperty(SNIconType.OVERLAY),
624636 };
625637 }
626638
745757 this.disconnectAll();
746758 this._proxy.destroy();
747759 this._cancellable.cancel();
760 this._invalidatedPixmapsIcons.clear();
748761
749762 if (this._nameWatcher)
750763 this._nameWatcher.destroy();
751764 delete this._cancellable;
752765 delete this._proxy;
753766 delete this._nameWatcher;
767 }
768
769 _getPixmapProperty(iconType) {
770 const propertyName = SNIconType.toPropertyName(iconType,
771 { isPixbuf: true });
772 const pixmap = this._proxy.get_cached_property(propertyName);
773 const wasInvalidated = this._invalidatedPixmapsIcons.delete(iconType);
774
775 if (!pixmap && wasInvalidated) {
776 this._proxy.refreshProperty(propertyName, {
777 skipEqualityCheck: true,
778 }).catch(e => {
779 if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
780 logError(e);
781 });
782 }
783
784 return pixmap;
785 }
786
787 invalidatePixmapProperty(iconType) {
788 this._invalidatedPixmapsIcons.add(iconType);
789 this._proxy.set_cached_property(
790 SNIconType.toPropertyName(iconType, { isPixbuf: true }), null);
754791 }
755792
756793 _getActivationToken(timestamp) {
13111348
13121349 try {
13131350 this._setGicon(iconType, gicon, iconSize);
1351
1352 if (pixmap && this.gicon) {
1353 // The pixmap has been saved, we can free the variants memory
1354 this._indicator.invalidatePixmapProperty(iconType);
1355 }
1356
13141357 return gicon;
13151358 } catch (e) {
13161359 logError(e, 'Setting GIcon failed');