DevilXD / TwitchDropsMiner

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

Status Icon in the tray #207

Closed DaCrazyRaccoon closed 2 weeks ago

DaCrazyRaccoon commented 1 year ago

I think it would be a good feature to have the icon in tray either change colour or have a pause, play or stop icon on it depending on whether it is currently watching a stream (Green), waiting for channels to get online (Yellow) or has no drops to watch (Red).

DaCrazyRaccoon commented 1 year ago

Didn't mean to click that my bad.

DevilXD commented 1 year ago

Hello o/

An interesting suggestion. I'd really want to stick to the original purple icon, but I see no harm in adding like an indicator dot to it, in the bottom right corner of the icon. Green for mining, gray for idle. The whole icon could turn dark gray in case the application runs into a fatal error. I'd need to figure out a way how to replace the icons, but it should be possible to do.

@guihkx Just curious, how are icon files handled on Linux? I'd like to avoid making a folder with images specifically for this. I'm thinking about a DLL file containing the icon images, but this is a Windows solution - I'm not sure how this would interact with Linux. I tried searching up a bit about how to use icons from DLL files, but can't find anything specific, so a folder with png files might be the only way to go anyway. Is there some standard way of packing/bundling multiple icon files on Linux, like Windows has?

guihkx commented 1 year ago

Just curious, how are icon files handled on Linux?

I'd say that most desktop apps on Linux tend to install their system tray icons separately from the main binary, which is a bit more organized and has the benefit of allowing users to use custom icon themes, for example.

Is there some standard way of packing/bundling multiple icon files on Linux, like Windows has?

Haha, Linux and 'standard' usually do not go together. :sweat_smile:

As far as I know, there isn't. However, I've seen plenty of applications bundling their own icons into the main executable (mainly Qt apps written in C++), so it's definitely possible. I'm just not aware if there's a common API for that.

I'm thinking about a DLL file containing the icon images, but this is a Windows solution - I'm not sure how this would interact with Linux

That sounds interesting, but I'm not that familiar with Windows to exactly understand how that works. What is the name of this 'interface' on Windows? Perhaps we could find a Linux-equivalent.

so a folder with png files might be the only way to go anyway

I supposed that would too, yeah.

DevilXD commented 1 year ago

most desktop apps on Linux tend to install their system tray icons separately from the main binary I've seen plenty of applications bundling their own icons into the main executable

I've looked into the theme you've linked, and it's "Hardcoded icons" part of README mentions the .desktop file being involved. Apparently there's an Icon=... line involved. The icons can be stored in a common folder of icons, but I think the best approach would be to just use a folder with icon files inside, sort of like the language translation files are currently utilized.

That sounds interesting, but I'm not that familiar with Windows to exactly understand how that works. What is the name of this 'interface' on Windows? Perhaps we could find a Linux-equivalent.

Windows comes with some existing icons for general use, stored inside system DLL files. The system uses those for icons all around the system, where an icon is needed: https://www.digitalcitizen.life/where-find-most-windows-10s-native-icons/

It's easy to set one of the icons as an icon to a link, but using those in Python code is pretty hard. Apparently Pillow can load them just fine, but I'd need to figure out how to open the DLL file and extract the icons from it first. A folder of icon image files just sounds much simpler at this point. I remembered I saw Discord using this approach in the past, here's how it looks: obraz

So, the final implementation will most likely turn the existing icon file into an icons folder, with pickaxe.ico for Windows building, pickaxe.png for Linux building, and then the additional icons suggested per this issue as more png files.

Thank you for your insight!

guihkx commented 1 year ago

I've looked into the theme you've linked, and it's "Hardcoded icons" part of README mentions the .desktop file being involved. Apparently there's an Icon=... line involved.

Precisely. Although, in our case, since you intend to distribute TDM as essentially a portable app, none of these things would really apply, unless we substantially modify how the app currently behaves.

I personally think that's not worth it, at all. Once the existing issues with the Linux build are sorted out, it'll be just as good as the Windows one.

Windows comes with some existing icons for general use, stored inside system DLL files. The system uses those for icons all around the system, where an icon is needed: https://www.digitalcitizen.life/where-find-most-windows-10s-native-icons/

Ah, yes, of course! I do remember changing the icons of folders to back in my Windows XP days. A single DLL would have a bunch of them, yeah...

but I'd need to figure out how to open the DLL file and extract the icons from it first.

I see... I thought there was an API ready for that already. :/

but I think the best approach would be to just use a folder with icon files inside, sort of like the language translation files are currently utilized.

I agree. And this approach would cause less hassle too.

So, the final implementation will most likely turn the existing icon file into an icons folder, with pickaxe.ico for Windows building, pickaxe.png for Linux building, and then the additional icons suggested per this issue as more png files.

Awesome. Although I don't think you need to have a different image format just because of Linux. As I recently discovered, Pillow can handle ico files on Linux as well. :)

DevilXD commented 1 year ago

Pillow can handle ico files on Linux as well.

That's correct, however I'm pretty sure PyInstaller needs a system-supported icon file format to build the executable on said system, which is why I said the pickaxe.ico will need to have it's duplicate as pickaxe.png. Although I haven't really tested building on Linux myself, so you're probably the only one who can say if PyInstaller works with an ico file. If it does, we won't need the duplicate, I guess.

https://github.com/DevilXD/TwitchDropsMiner/blob/5b8b6c7fdda0061a813e968f6ccd23117d42fa84/build.spec#L74

guihkx commented 1 year ago

The Linux CI I set up builds a PyInstaller executable with an ico just fine, yeah. And it shows up correctly on my desktop too:

Screenshot_20230529_053650

I've also tried using the ico while I was messing with the existing system tray feature and it showed up there as well...

However, differently from Windows binaries, it's not possible to embed an icon on an ELF binary to make it show up on file managers:

image

But that's just a visual thing and doesn't negatively affect the program in any way. :p

DevilXD commented 1 year ago

it shows up correctly on my desktop too

That screenshot is from inside the already open application window. It will work there because I'm using PIL.Tkinter.PhotoImage, which is a Tkinter-cross-compatible version of an image opened with Pillow, which can read and write ico files without issue.

The build.spec line I've highlighted is responsible for the executable icon, the one you've just explained that it doesn't show up. But apparently it's not supposed to show up anyway, which I didn't know is a thing, so you can disregard my explanation. In that case, all icons should be ico files, to avoid having to make a duplicate of pickaxe.ico for building specifically on Windows. No pickaxe.png is needed for building on Linux then 🙂

guihkx commented 1 year ago

Yeah, you're right. And if you inspect the CI logs for the PyInstaller step on Linux, the following warning shows up when the icon option set:

WARNING: Ignoring icon; supported only on Windows and macOS!
DaCrazyRaccoon commented 7 months ago

Any updates on whether this is still being worked on, planned or canceled?

DevilXD commented 7 months ago

I can tell you that this is WIP, but the W portion is currently being held back by the main dev (me) having absolutely no time to work on this project in the capacity needed to move it forward efficiently, due to my job putting me in a work delegation since the end of May, and sapping away 10h a day of my time ever since. The remaining time is used to keep this project semi-working in the first place, while this enhancement suggestion isn't strictly necessary for doing so, so it's got a quite low priority.

Regardless, if I ever get enough time to seriously get back to this project, then this is very much still on the table.

DaCrazyRaccoon commented 7 months ago

Sounds good, also I apologize if it sounded like I was rushing you or something like that. I completly understand that this is not an essential feature and people are busy.

DevilXD commented 2 weeks ago

I've actually decided today to get down to this one, and this is the result: picture picture The icons aren't perfect, as it's down to the OS to downscale the images down to something that can be displayed in the system tray... but the colored circle should still be visible enough to inform the user about the miner status. I tried giving it some contrast with the black outline, but it's still not perfect. I don't really want to make the circles bigger though, so it has to stay like this.

https://github.com/DevilXD/TwitchDropsMiner/commit/35c46c2b78ea0a3f2cbb9ea17b18aeab45dd2c5a

@guihkx When you'd find some free time, can you run a quick test on Linux to see if everything works there? I hope I didn't mess it up too much :sweat_smile: If so, well, please let me know so I can fix it =)

guihkx commented 2 weeks ago

Those are really nice!

Nothing broke on the Linux side, but at the same time, the emblem on the tray icon doesn't seem to update when the mining status changes (at least on KDE Plasma 6).

I tested that by enabling priority only mode mining, and then disabling it and clicking on the "Reload" button: I have stuff to mine, but the icon didn't change after that.

I'm not sure if that's a limitation of pystray or a restriction of the AppIndicator protocol, so I'll have to investigate...

Nevertheless, I think this is a minor issue that shouldn't prevent you from closing this (in case you're planning to).

DevilXD commented 2 weeks ago

the emblem on the tray icon doesn't seem to update when the mining status changes

Well, that's unfortunate. They do change appropriately on Windows. I've double-checked it using your method, but the logic for changing those is quite simple, so there's little that can break with it. I'm assuming that Pystray either can't change the icon, or the OS does not entirely support doing so.

Have you checked the AppImage build as well? That's the one I was worried about breaking.

guihkx commented 2 weeks ago

or the OS does not entirely support doing so.

As it's Linux we're talking about, there are many ways to accomplish one thing. 😅

There are at least 3 different system tray protocols that I know of, and I use some apps that can update the tray icon, so I think it's possible in at least one of these protocols. I'm just not sure if that's feasible with Appindicator, which pystray uses.

Have you checked the AppImage build as well? That's the one I was worried about breaking.

Yup. I also tested the PyInstaller build and running from source as well. They're all fine.

DevilXD commented 2 weeks ago

Oh well. I'll close this one for now then. Thank you for your time and checking this for me =)