Fix icon theme access for GNOME Shell 44

This commit is contained in:
Neil Bird 2023-07-16 12:18:50 +01:00
parent eec90bf952
commit fae82334a6
2 changed files with 19 additions and 8 deletions

View file

@ -85,6 +85,16 @@ class PiHole extends panelMenu.Button
// Create a Soup session with which to do requests // Create a Soup session with which to do requests
this.SoupSession = new Soup.Session(); this.SoupSession = new Soup.Session();
// Access icon theme and keep it up to date
const stsettings = St.Settings.get();
this.IconTheme = new Gtk.IconTheme();
this.IconTheme.set_theme_name( stsettings.gtk_icon_theme );
let this_ = this;
stsettings.connect( 'notify::gtk-icon-theme', (settings_,key_) => {
this_.IconTheme.set_theme_name( settings_.gtk_icon_theme );
this_.setIcon();
});
// Create button/icon // Create button/icon
this.Icon = new St.Icon({ style_class: 'system-status-icon' }); this.Icon = new St.Icon({ style_class: 'system-status-icon' });
this.add_child( this.Icon ); this.add_child( this.Icon );
@ -198,14 +208,15 @@ class PiHole extends panelMenu.Button
// Get custom icon from theme or file // Get custom icon from theme or file
getCustomIcon(icon_name) getCustomIcon(icon_name)
{ {
let icon_path = PiHoleExtMetadata.dir.get_child('icons').get_child( icon_name + ".svg" ).get_path(); // Themed?
let theme = Gtk.IconTheme.get_default(); if (this.IconTheme.has_icon(icon_name))
if (theme)
{ {
let theme_icon = theme.lookup_icon( icon_name, -1, 2 ); this.dprint("setting new icon " + icon_name + " from theme");
if (theme_icon) return Gio.ThemedIcon({name: icon_name});
icon_path = theme_icon.get_filename();
} }
// Falback to included icons
let icon_path = PiHoleExtMetadata.dir.get_child('icons').get_child( icon_name + ".svg" ).get_path();
this.dprint("setting new icon from " + icon_path); this.dprint("setting new icon from " + icon_path);
return Gio.FileIcon.new( Gio.File.new_for_path( icon_path ) ); return Gio.FileIcon.new( Gio.File.new_for_path( icon_path ) );
} }

View file

@ -1,10 +1,10 @@
{ {
"shell-version": ["43"], "shell-version": ["44"],
"uuid": "pi-hole@fnxweb.com", "uuid": "pi-hole@fnxweb.com",
"name": "pi-hole", "name": "pi-hole",
"url" : "https://github.com/fnxweb/gnome-shell-pi-hole", "url" : "https://github.com/fnxweb/gnome-shell-pi-hole",
"description": "Status and basic controls of local Pi-Hole", "description": "Status and basic controls of local Pi-Hole",
"settings-schema": "org.gnome.shell.extensions.fnxweb-pi-hole", "settings-schema": "org.gnome.shell.extensions.fnxweb-pi-hole",
"gettext-domain": "gnome-shell-extension-fnxweb-pi-hole", "gettext-domain": "gnome-shell-extension-fnxweb-pi-hole",
"version": 5 "version": 7
} }