Skip to content

Commit

Permalink
Improve icon id retrieving mechanism in preferences
Browse files Browse the repository at this point in the history
- update the list when an indicator is added while preferences are open
- fixes a bug where the icons are not added any more once the extension is started (the reason why `_addToRecentIcons` is called in `_showIfReady`)
  • Loading branch information
aunetx authored and Finii committed Mar 4, 2022
1 parent 1d7c112 commit 8864f89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
18 changes: 11 additions & 7 deletions indicatorStatusIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,6 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon {
}
});

const settings = SettingsManager.getDefaultGSettings();
const iconIDs = settings.get_value('recent-icons').deep_unpack();
if (this._indicator.id && !iconIDs.includes(this._indicator.id)) {
iconIDs.push(this._indicator.id);
settings.set_value('recent-icons', new GLib.Variant('as', iconIDs));
}

this._showIfReady();
}

Expand Down Expand Up @@ -243,13 +236,24 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon {
}
}

_addToRecentIcons() {
const settings = SettingsManager.getDefaultGSettings();
const iconIDs = settings.get_value('recent-icons').deep_unpack();

if (this._indicator.id && !iconIDs.includes(this._indicator.id)) {
iconIDs.push(this._indicator.id);
settings.set_value('recent-icons', new GLib.Variant('as', iconIDs));
}
}

_showIfReady() {
if (!this.isReady())
return;

this._updateLabel();
this._updateStatus();
this._updateMenu();
this._addToRecentIcons();

super._showIfReady();
}
Expand Down
21 changes: 16 additions & 5 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,27 @@ class AppIndicatorPreferences extends Gtk.Box {
iconIDListStore.set_column_types([
GObject.TYPE_STRING,
]);
const iconIDs = this._settings.get_value('recent-icons').deep_unpack();
iconIDs.forEach(v => {
iconIDListStore.set(iconIDListStore.append(), [0], [v]);
});
const iconIDListTrack = [];
const iconIDTreeView = new Gtk.TreeView({
model: iconIDListStore,
model: iconIDListStore
});
const iconIDTreeViewColumn = new Gtk.TreeViewColumn({
title: 'Recent Indicator IDs',
});

const update_recent_icons = _ => {
const iconIDs = this._settings.get_value('recent-icons').deep_unpack();
iconIDs.forEach(v => {
if (!iconIDListTrack.includes(v)) {
iconIDListStore.set(iconIDListStore.append(), [0], [v]);
iconIDListTrack.push(v);
}
});
}

this._settings.connect('changed::recent-icons', update_recent_icons);
update_recent_icons();

const standardCellRenderer = new Gtk.CellRendererText();
iconIDTreeViewColumn.pack_start(standardCellRenderer, true);
iconIDTreeViewColumn.add_attribute(standardCellRenderer, 'text', 0);
Expand Down

0 comments on commit 8864f89

Please sign in to comment.