moses-palmer / pystray

GNU General Public License v3.0
463 stars 57 forks source link

Feature Suggestion: Action when Notification is Clicked #80

Open CesarPazzi opened 3 years ago

CesarPazzi commented 3 years ago

I'm on Windows 10 20H2 19042.685 Python version Python 3.8.2

I just download and started using pystray and just a suggestion... It would be nice to execute a function when notification is clicked.

Something like:

icon.notify("Notification Text", title="Notification Title", MyFunction)

Or if you point me where to look in the code I would like to get my hands on and when I get something I will do a PR

moses-palmer commented 3 years ago

Thank you for your suggestion.

I am not certain whether this is supported by all backends, but you will find the relevant code for Windows here and for Linux here.

I will gladly help if you run into any issues!

DevilXD commented 2 years ago

For Windows, it sounds easy to implement: https://stackoverflow.com/questions/59990706/how-to-capture-users-click-action-when-clicking-on-notifications

No idea how hard would it be to do for Linux. Also, this feature is a +1 from me, I could really use something like this.

sohang3112 commented 10 months ago

@DevilXD Were you able to implement this feature for any platform? IMO the feature can be implemented on some platforms only, and raise NotImplementedError on unsupported platforms.

DevilXD commented 10 months ago

@sohang3112 As I've mentioned in my message, Windows implementation should be possible, per that SO thread. I haven't been able to implement it anywhere myself, I merely pointed out that it should be possible to do so on Windows, relatively easily, by hooking up an additional window manager event to a function call. Again, no idea how it'd work on Linux or other platforms.