Skip to content

Commit a1dff4a

Browse files
committed
Improve icon id retrieving mechanism in preferences
- 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`)
1 parent 3983063 commit a1dff4a

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

indicatorStatusIcon.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon {
183183
}
184184
});
185185

186-
const settings = SettingsManager.getDefaultGSettings();
187-
const iconIDs = settings.get_value('recent-icons').deep_unpack();
188-
if (this._indicator.id && !iconIDs.includes(this._indicator.id)) {
189-
iconIDs.push(this._indicator.id);
190-
settings.set_value('recent-icons', new GLib.Variant('as', iconIDs));
191-
}
192-
193186
this._showIfReady();
194187
}
195188

@@ -243,13 +236,24 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon {
243236
}
244237
}
245238

239+
_addToRecentIcons() {
240+
const settings = SettingsManager.getDefaultGSettings();
241+
const iconIDs = settings.get_value('recent-icons').deep_unpack();
242+
243+
if (this._indicator.id && !iconIDs.includes(this._indicator.id)) {
244+
iconIDs.push(this._indicator.id);
245+
settings.set_value('recent-icons', new GLib.Variant('as', iconIDs));
246+
}
247+
}
248+
246249
_showIfReady() {
247250
if (!this.isReady())
248251
return;
249252

250253
this._updateLabel();
251254
this._updateStatus();
252255
this._updateMenu();
256+
this._addToRecentIcons();
253257

254258
super._showIfReady();
255259
}

prefs.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,27 @@ class AppIndicatorPreferences extends Gtk.Box {
290290
iconIDListStore.set_column_types([
291291
GObject.TYPE_STRING,
292292
]);
293-
const iconIDs = this._settings.get_value('recent-icons').deep_unpack();
294-
iconIDs.forEach(v => {
295-
iconIDListStore.set(iconIDListStore.append(), [0], [v]);
296-
});
293+
const iconIDListTrack = [];
297294
const iconIDTreeView = new Gtk.TreeView({
298-
model: iconIDListStore,
295+
model: iconIDListStore
299296
});
300297
const iconIDTreeViewColumn = new Gtk.TreeViewColumn({
301298
title: 'Recent Indicator IDs',
302299
});
300+
301+
const update_recent_icons = _ => {
302+
const iconIDs = this._settings.get_value('recent-icons').deep_unpack();
303+
iconIDs.forEach(v => {
304+
if (!iconIDListTrack.includes(v)) {
305+
iconIDListStore.set(iconIDListStore.append(), [0], [v]);
306+
iconIDListTrack.push(v);
307+
}
308+
});
309+
}
310+
311+
this._settings.connect('changed::recent-icons', update_recent_icons);
312+
update_recent_icons();
313+
303314
const standardCellRenderer = new Gtk.CellRendererText();
304315
iconIDTreeViewColumn.pack_start(standardCellRenderer, true);
305316
iconIDTreeViewColumn.add_attribute(standardCellRenderer, 'text', 0);

0 commit comments

Comments
 (0)