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 0df9f2d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 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
19 changes: 15 additions & 4 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,
});
const iconIDTreeViewColumn = new Gtk.TreeViewColumn({
title: 'Recent Indicator IDs',
});

const updateRecentIcons = (_) => {
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', updateRecentIcons);
updateRecentIcons();

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

0 comments on commit 0df9f2d

Please sign in to comment.