DevilXD / TwitchDropsMiner

An app that allows you to AFK mine timed Twitch drops, with automatic drop claiming and channel switching.
MIT License
1.44k stars 149 forks source link

Linux: System tray icon only updates after clicking the "Minimize to Tray" button #511

Closed guihkx closed 2 days ago

guihkx commented 2 days ago

(This is a follow-up to my observation in https://github.com/DevilXD/TwitchDropsMiner/issues/207#issuecomment-2200942627)

So, I discovered that the system tray icon on Linux does update, but only after clicking on the "Minimize to Tray" button.

In the video below, I showcase this "broken"(?) behavior...

I start TDM with --tray so the tray icon gets loaded. The initial icon file is set to maint.ico. Then, after I disable "Priority Only" mining and hit the "Reload" button, TDM finds new drops to mine, but the tray icon doesn't update accordingly:

https://github.com/DevilXD/TwitchDropsMiner/assets/626206/d5c84148-ac6b-4abc-8749-a88a8ce681e6

In this next video, I do the exact same as above, but with one addition: I click the "Minimize to Tray" button after disabling "Priority Only" mining, and then the tray icon does update accordingly:

https://github.com/DevilXD/TwitchDropsMiner/assets/626206/cee2fe5e-6e31-4d5d-b14b-a811815139ed

A couple of things to note:

Lastly, my tests were done on commit 18a03353efae21e3569cec43bac4e7bf4e899076, with KDE Plasma 6 with Python 3.12.

DevilXD commented 2 days ago

Hello,

Hmm. Well, first of all, the icon is not supposed to always be displayed. When you click on the "Minimize to Tray" button for the first time, a new thread is created, that starts updating and handling the icon, including setting up the right click menu, updating the picture, mouse-over text, etc. But when you restore the main application window, the icon is hidden by setting it's visibility flag to False. The end result is that when you restore the application window, the icon simply disappears from the tray. Minimizing to tray again simply sets the visibility flag back to True and the icon reappears.

https://github.com/DevilXD/TwitchDropsMiner/blob/18a03353efae21e3569cec43bac4e7bf4e899076/gui.py#L1121-L1132

That is, that's how it works on Windows. On Linux, the icon seems to stick around for some reason, like on your video. The thing is, everything else still applies - the visibility flag should make the icon disappear, but instead, the icon seems to stay. And when it does stay, it "freezes" in it's last state like you describe, since it wasn't supposed to show anything. Basically - if you see the main application window, the icon won't update it's appearance.

I'm not really sure how to tackle this. The old way of managing the icon was to close the management thread completely, and then delete the entire icon handler, each time the user would restore the main window back - but you've said it broke the icon on some Linux systems, so we've changed it to the visibility flag: https://github.com/DevilXD/TwitchDropsMiner/pull/216/commits/52af7cd399739971c4508c6439d692ee717c13e9

If you'd like to, you can play around with the old approach, by replacing self.icon.visible = False with the commented out self.stop() line in the restore method on L1130 of gui.py.

guihkx commented 2 days ago

Well, first of all, the icon is not supposed to always be displayed.

Oooh, that clarifies so much for me now.

You see, KDE allows us to configure how tray icons are displayed:

image

In the two videos above, I had TDM's tray icon set to "Always shown", so that's the reason for the odd behavior.

By setting that option to "Shown when relevant" (which is the default option for every app, by the way), then the behavior is much more close to Windows':

https://github.com/DevilXD/TwitchDropsMiner/assets/626206/8e8b96f4-6b7d-4ffe-82b4-2bcc41a3a980

The only small peculiarity is that when the app is not minimized to tray, we can still access its tray icon under KDE's "Status and Notifications" sub menu:

image

But otherwise, I think this actually working as intended! :)

DevilXD commented 2 days ago

the behavior is much more close to Windows'

Yeah, it's like, exactly how it works on Windows on that video now. Either you see the tray icon, or you see the main window, never both at once.

As for the other "small peculiarity", that's something unfortunately not much can be done about, besides making it so that the tray icon is always visible, window open or not. I mean, I could consider making a change that'd allow this, but then a new option enabling the tray icon would be needed. For now though, it'll need to stay like this.