rafatosta / zapzap

WhatsApp desktop application written in Pyqt6 + PyQt6-WebEngine.
https://rtosta.com/zapzap-web/
GNU General Public License v3.0
146 stars 7 forks source link

Clicking on Notification in Gnome does not surface ZapZap window #16

Closed saiduc closed 2 years ago

saiduc commented 2 years ago

Thanks for your great work on this project. I am using v2.2 from Flathub on Fedora 35, Gnome Version 41.3 in Wayland. The application correctly runs in the background and shows notifications for new messages.

Clicking on the message does not surface the ZapZap window, and instead I have to click on the icon in the tray.

rafatosta commented 2 years ago

This occurs if the window is closed. I still haven't found a solution to this without setting actions to notifications. The ideal is to click and the window appears without the need for an action.

saiduc commented 2 years ago

Currently I can see that the actions in org.freedesktop.Notifications.Notify are empty. Is the easiest thing to do to set the action to be a function that surfaces the window? Perhaps the on_show function in main_windows.py? I am happy to work on this if you cannot currently.

rafatosta commented 2 years ago

Currently I can see that the actions in org.freedesktop.Notifications.Notify are empty. Is the easiest thing to do to set the action to be a function that surfaces the window? Perhaps the on_show function in main_windows.py? I am happy to work on this if you cannot currently.

I will be very grateful and happy with your contribution. Can I wait with commit? Say yes 😁😁😁

rafatosta commented 2 years ago

Currently I can see that the actions in org.freedesktop.Notifications.Notify are empty. Is the easiest thing to do to set the action to be a function that surfaces the window? Perhaps the on_show function in main_windows.py? I am happy to work on this if you cannot currently.

Look at the notify_test bench. It's a solution used the actions of the notification, may not work as I would like. When clicking on the body of the notification, the notification is closed, only if you click on the button It works. That is, if the notification goes to the notification area when clicking, the window will not open. Did you understand?

saiduc commented 2 years ago

Yes, I understand, I will look at that in the next few days 😄

BaderSZ commented 2 years ago

I can take a look at this if it's ok, @saiduc. A solution with QtDBus and with dbus is possible.

rafatosta commented 2 years ago

I can take a look at this if it's ok, @saiduc. A solution with QtDBus and with dbus is possible.

😍😍 Thank you very much. Now I'm at work, as soon as possible I do the merge and build.

BaderSZ commented 2 years ago

I found it ridiculously difficult to get QtDBus to work with interface signals and slots. Would QSystemTrayNotify work, or would you prefer a direct dbus solution instead?

rafatosta commented 2 years ago

I found it ridiculously difficult to get QtDBus to work with interface signals and slots. Would QSystemTrayNotify work, or would you prefer a direct dbus solution instead?

If your solution works I don't see why not use it. Soon I do the merge and test in gnome

rafatosta commented 2 years ago

The solution with QSystemTray.message didn't work on gnome. I will keep Qdbus for now

rafatosta commented 2 years ago

The solution with QSystemTray.message didn't work on gnome. I will keep Qdbus for now

BaderSZ commented 2 years ago

The solution with QSystemTray.message didn't work on gnome. I will keep Qdbus for now

Okay, I'll try to find a better solution and test in the weekend.

saiduc commented 2 years ago

Thanks @BaderSZ for doing this, I hadn't gotten round to it yet.

BaderSZ commented 2 years ago

@saiduc No problem. I use the app often enough and thought I'd help out since I had the time.

@rafatosta could you give me more info on the issue. Is this just the same issue @saiduc had, or something else:

I use AwesomeWM, so I'll install GNOME (hopefully I don't have to use Wayland) and figure out what the exact problem is. Googling shows we're not the only ones.

rafatosta commented 2 years ago

@saiduc No problem. I use the app often enough and thought I'd help out since I had the time.

@rafatosta could you give me more info on the issue. Is this just the same issue @saiduc had, or something else:

  • Did the tray icon show up or not?
  • Did the notification show?
  • Did the clicking not work?

I use AwesomeWM, so I'll install GNOME (hopefully I don't have to use Wayland) and figure out what the exact problem is. Googling shows we're not the only ones.

Notifications only appeared in the notification center. The popup didn't appear and the event didn't work either.

BaderSZ commented 2 years ago

My investigation so far:

This is definitely solvable, but I can't find a proper way check if GNOME is the desktop environment, especially since newer versions don't set environment variables. I'll keep thinking and hope I find a good answer.

rafatosta commented 2 years ago

My investigation so far:

  • The geniuses in the GNOME design team decided that modern GNOME won't show any tray icons without an extension like Appindicator.
  • If we want popup style notifications in GNOME, we'll likely have to implement Gio.Notification.

This is definitely solvable, but I can't find a proper way check if GNOME is the desktop environment, especially since newer versions don't set environment variables. I'll keep thinking and hope I find a good answer.

Gio is exclusive to GTK. And yes, the icon on Tray is not something native to Gnome.

BaderSZ commented 2 years ago

Gio is exclusive to GTK. And yes, the icon on Tray is not something native to Gnome.

Yes. I can try to figure out a solution around that (there are a few examples without having to create a GtkApplication). It also adds a dependency.

rafatosta commented 2 years ago

There is an option to copy Telegram, but that would remove the power of DE, do not disturb will not work as expected. In addition to the "so-called visual consistency" of the DEs. image

BaderSZ commented 2 years ago

I did take a look at Telegram Desktop, but their solution is a bit long, and in another language. It uses Gio too.

rafatosta commented 2 years ago

I did take a look at Telegram Desktop, but their solution is a bit long, and in another language. It uses Gio too.

Very interesting the implementation of Telegram... is using dbus. The image I sent is by implementing a widget that works as a notification.

Look at this about the lib gi

https://wiki.archlinux.org/title/Desktop_notifications#Python

No need for a GtkApplication image

Doc: https://developer-old.gnome.org/glibmm/stable/classGio_1_1DBus_1_1Connection.html

BaderSZ commented 2 years ago

We would have to use DBus anyways. Thanks for the links, I'll try something out soon. :)

rafatosta commented 2 years ago

With Gi it has the same behavior as what I already implemented =( Run this code and see the behavior

from gi.repository import Notify, GLib import gi gi.require_version('Notify', '0.7')

loop = GLib.MainLoop()

class Notification(): def init(self, summary, body): Notify.init('Yum Extender') icon = "yumex-dnf" self.notification = Notify.Notification.new(summary, body, icon) self.notification.set_timeout(5000) # timeout 5s self.notification.add_action( 'open', 'Open Yum Extender', self.callback) self.notification.add_action('apply', 'Apply Updates', self.callback) self.notification.connect('closed', self.on_closed)

def show(self):
    self.notification.show()

def callback(self, widget, action):
    print("notify-action", action)

def on_closed(self, widget):
    print("fim")
    loop.quit()

def main(): notify = Notification('New Updates', '33 available updates ')

notify.connect('notify-action', on_notify_action)

notify.show()

def on_notify_action(widget, action): print(action)

if name == 'main': main() loop.run()

BaderSZ commented 2 years ago

Did you implement the changes in the desktop file?

[Desktop Entry]
...
StartupNotify=true
DBusActivatable=true
X-GNOME-UsesNotifications=true
rafatosta commented 2 years ago

Did you implement the changes in the desktop file?

[Desktop Entry]
...
StartupNotify=true
DBusActivatable=true
X-GNOME-UsesNotifications=true

I'll look into this further and update the .desktop. Thanks

rafatosta commented 2 years ago

Now I remembered why I didn't use Dbus for notifications. I couldn't get it to work, this error always appears. I was never able to identify and resolve this error.

image

Run this code and send the answer, please.

https://pastebin.com/wbZ2JHSf

BaderSZ commented 2 years ago

Busy day, sorry.

Run this code and send the answer, please.

https://pastebin.com/wbZ2JHSf

Works fine for me, but i am on X11. I'll testing a few solutions now and get back to you. Granted, it's midnight where I'm from, so you might see a response when you wake up. :smile:

rafatosta commented 2 years ago

Busy day, sorry.

Run this code and send the answer, please. https://pastebin.com/wbZ2JHSf

Works fine for me, but i am on X11. I'll testing a few solutions now and get back to you. Granted, it's midnight where I'm from, so you might see a response when you wake up. smile

Here it didn't even work on X11. I think I have a solution for this, in a few minutes I will commit.

BaderSZ commented 2 years ago

Here it didn't even work on X11. I think I have a solution for this, in a few minutes I will commit.

Sure. I was thinking of making a floating QWidget (similar to this) instead.

rafatosta commented 2 years ago

Here it didn't even work on X11. I think I have a solution for this, in a few minutes I will commit.

Sure. I was thinking of making a floating QWidget (similar to this) instead.

Yes, it's an excellent idea. My suggestion is to keep both, dbus and via Qwidget and let the user choose (like Telegram-Desktop), what do you think?

BaderSZ commented 2 years ago

That works, but then we'd have to build a settings dialog as well. Which one should be the default?

rafatosta commented 2 years ago

That works, but then we'd have to build a settings dialog as well. Which one should be the default?

Let's see which works best first, don't you think?

rafatosta commented 2 years ago

That works, but then we'd have to build a settings dialog as well. Which one should be the default?

Let's see which works best first, don't you think?

I posted a workaround to the problem. It's not ideal, but it works

rafatosta commented 2 years ago

@BaderSZ

I created this mini project with the same structure as zapzap so that we can test the implementations more easily. Because it is a web page that triggers notifications, which makes it excellent.

https://github.com/rafatosta/pyqt6-dbus

BaderSZ commented 2 years ago

sweet. testing then pushing.

rafatosta commented 2 years ago

The solution is to define a desktop-entry variable in Hint. I took advantage of it and remodeled it as I allowed it to be more general and customizable.

Credit for implementing notifications: https://gist.github.com/KurtJacobson/7a7739bcc97e374ce133a64646a6f5fc

Dbus Protocol Documentation https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html

BaderSZ commented 2 years ago

Great! if it works, it works.

rafatosta commented 2 years ago

Great! if it works, it works.

I'll build it in flatpak and as soon as I finish I'll send the link

rafatosta commented 2 years ago

Great! if it works, it works.

flatpak install --user https://dl.flathub.org/build-repo/83955/com.rtosta.zapzap.flatpakref