Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indicator for recent icon IDs in prefs dialog #312

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Finii
Copy link
Contributor

@Finii Finii commented Oct 22, 2021

Back story:

When Mattermost updated the icon design recently someone decided there that a black-on-transparent tray icon would be a good idea. Unfortunately the vanilla Ubuntu Gnome TopBar is black, so the icon is black on black 😒

Then came the new ability to exchange icons. 🎉 This is really great and works as expected, also with icon paths given (as '/home/blah/fasel.png' for ex). Although the documentation for the feature is like nonexisting.

But then came up the question: What is the ID I need to put into the new dialog? How am I supposed to find that out?
The Mattermost icon ID is by the way Mattermost1 😒

image
Mattermost icon 2nd from left with Transparent Shell Top Bar to make it visible

[why]
When someone wants to exchange an icon with a custom one the icon name
is needed. That can be nontrivial to find it out.

[how]
Just collect all icon names that we encountered since the extension has
been started and list these names below the icon replacement table in
the settings dialog.

This is how it looks on my machine:
image

Implementation details:

  • Recent IDs are stored in the settings object (maybe not a good choice)
  • Are purged on extension (re)start
  • Sometimes they are purged for other reasons :-(
  • Are added whenever a new icon ID is encountered (with no locking)

Maybe it can be solved in a better way, this was just a Friday morning project. But I guess this improves the usability of the new custom icon functionality for ordinary users quite a bit.

I will try to improve on the spurious purges of the list. Fixed with force push.

@Finii Finii force-pushed the master branch 3 times, most recently from 999a794 to 3983063 Compare October 22, 2021 12:58
@3v1n0
Copy link
Collaborator

3v1n0 commented Oct 22, 2021

Ok, looks intresting.

I'll see if I can define another way to get such icons though, without bothering gsettings

@Finii
Copy link
Contributor Author

Finii commented Oct 26, 2021

Just wanted to link @andia89's #287, as this is kind of a follow up.

@Faetu
Copy link

Faetu commented Oct 29, 2021

Hi Finii

Good idea! I tested it on my computer, but it doesn't update the list by itself. Do I have to restart Gnome when a new tray appears?

best regards

@Finii
Copy link
Contributor Author

Finii commented Oct 30, 2021

Do I have to restart Gnome when a new tray appears?

Well, you need to restart Gnome after you updated the extension (like alt-F2 r on X) (or 🙄 on Wayland)
After that it should start collecting icon IDs and add them to the settings dialog. You need to close and open the dialog to update the info, I believe.

@aunetx
Copy link

aunetx commented Feb 28, 2022

Ok, looks intresting.

I'll see if I can define another way to get such icons though, without bothering gsettings

I don't think there is any other (trivial) way, as the preferences cannot easily interfere with the shell or any running extension, even itself -- or at least I did not find how it could. Another option would be writing to a temporary file, but then gsettings really is cleaner, I guess?

By the way, this is a great addition -- I had a very hard time finding ids for appindicators some weeks ago, it easily took me more than and hour... I guess I'm not very good at it :)

I will try to update this by allowing the preferences to update automatically when a new icon is added, without needed to close the preferences.

@aunetx
Copy link

aunetx commented Feb 28, 2022

Here is a patch, which:

  • 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)
diff --git a/indicatorStatusIcon.js b/indicatorStatusIcon.js
index 9eee93a..a245f0f 100644
--- a/indicatorStatusIcon.js
+++ b/indicatorStatusIcon.js
@@ -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();
     }
 
@@ -243,6 +236,16 @@ 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;
@@ -250,6 +253,7 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon {
         this._updateLabel();
         this._updateStatus();
         this._updateMenu();
+        this._addToRecentIcons();
 
         super._showIfReady();
     }
diff --git a/prefs.js b/prefs.js
index 80a94c3..919de10 100644
--- a/prefs.js
+++ b/prefs.js
@@ -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);

I can make this a proper PR if you want, however this might just add noise for nothing.

@Finii
Copy link
Contributor Author

Finii commented Mar 2, 2022

You can add to my PR if you like - collaborator thing sent. In this way there will not be multiple PRs doing the same thing.
(Of course you could also create your own PR if you believe that is better.)

And then one can keep the PR rebased on master and wait ;-) 3v1n0 is rather busy with more important repos I believe ;)

@aunetx
Copy link

aunetx commented Mar 3, 2022

Ok thanks, I will commit it to your repo then!

I don't have much time to rebase it right now, but I guess this PR will wait here anyway so there is no hurry :)

@aunetx
Copy link

aunetx commented Mar 3, 2022

Sorry, I somehow pushed to the wrong branch, this is ok now

[why]
When someone wants to exchange an icon with a custom one the icon name
is needed. That can be nontrivial to find it out.

[how]
Just collect all icon names that we encountered since the extension has
been started and list these names below the icon replacement table in
the settings dialog.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii
Copy link
Contributor Author

Finii commented Mar 4, 2022

Rebase on master; force push.

Works beautifully on my machine! Thank you 👍

@Finii
Copy link
Contributor Author

Finii commented Mar 4, 2022

Ah there is some eslint stuff, will fix that. Force push again imminent.

@Finii Finii force-pushed the master branch 2 times, most recently from 2f33912 to 0df9f2d Compare March 4, 2022 07:00
- 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`)
@Finii
Copy link
Contributor Author

Finii commented Mar 4, 2022

@aunetx Had to remove your _, because there is a const one at global scope 😒

@aunetx
Copy link

aunetx commented Mar 4, 2022

@Finii sorry if that caused some problem, tell me if you need anything else :)

@Finii
Copy link
Contributor Author

Finii commented Mar 4, 2022

@aunetx All good, thank you very much. :-) Let's hope @3v1n0 finds time to review and decide on this; in the meanwhile I will keep this rebased on master (when I notice new commits on master).

extension.js Outdated
@@ -42,6 +43,8 @@ function init() {
watchDog.destroy();
};
/* eslint-enable no-undef */
const settings = SettingsManager.getDefaultGSettings();
settings.reset('recent-icons'); // clear in preparation of new collection
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said in inline comment, I'd prefer to have another way to handle this.

One method would be using a GAction for example...

@AmirHosseinKarimi
Copy link

Is there any hope for this pull request to merge?

@a-plastic-bag
Copy link

Considering the ongoing problems with the dreaded three dots, I think it'd be a good idea to take a look at adding this again.

@aunetx
Copy link

aunetx commented Apr 9, 2024

I tried to merge the master branch, it works for me on GNOME 46 now, however while trying to merge it I think I changed the branch of this PR... @Finii sorry for this, honestly I am quite bad with git, tell me if I need to change something!

@Finii
Copy link
Contributor Author

Finii commented Apr 9, 2024

@aunetx I guess I do not know what I should do. The two commits you added are ... what? ;-D

@Finii
Copy link
Contributor Author

Finii commented Apr 9, 2024

Ah probably instead of merging the master INTO this branch (d6ca83e) you should have done a rebase of this branch ON master. I usually prefer that because then only the needed-for-this-feature changes are in the PR and nothing already in master.

Otoh rebasing can be a lot of work. But the result of a merge is often incomprehensible.

@aunetx
Copy link

aunetx commented Apr 9, 2024

Ho sorry for this :/ at least I did not touch to your master branch so you can go back to it if you want, but to be honest git always scares me a little bit, exactly because of this kind of things!

Tell me if I can help if I messed up somewhere irremediably

@aunetx
Copy link

aunetx commented Jun 13, 2024

Hello, this seems not to work with last versions, has I done something wrong? This seems weird as it worked some weeks ago...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants