Bug 180813

Summary: [GTK] Notifications broken under flatpak and bubblewrap sandbox
Product: WebKit Reporter: Michael Catanzaro <mcatanzaro>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: aperez, bugs-noreply, mcatanzaro, pgriffis
Priority: P2    
Version: Other   
Hardware: PC   
OS: Linux   
See Also: https://bugs.webkit.org/show_bug.cgi?id=192748
https://bugs.webkit.org/show_bug.cgi?id=212079
https://bugs.webkit.org/show_bug.cgi?id=240347
Bug Depends on:    
Bug Blocks: 218121    

Description Michael Catanzaro 2017-12-14 08:05:07 PST
Notifications do not work under Flatpak. We either need to use the notification portal D-Bus API, or (more likely) use GNotification.

Carlos Garcia wants to keep support for libnotify, so we should use GNotification if there is a GApplication (which will be required for notifications to work under flatpak), and libnotify otherwise.
Comment 1 Michael Catanzaro 2019-07-13 15:48:19 PDT
Using GNotification would also help us fix https://gitlab.gnome.org/GNOME/epiphany/issues/853.
Comment 2 Michael Catanzaro 2019-07-13 15:50:17 PDT
(In reply to Michael Catanzaro from comment #1)
> Using GNotification would also help us fix
> https://gitlab.gnome.org/GNOME/epiphany/issues/853.

We'll need to create a separate WebKit bug for this if we close this one using direct portal access rather than GNotification. But I think GNotification is the way to go. That kills two birds with one stone.
Comment 3 Patrick Griffis 2019-07-13 17:11:18 PDT
GNotification is highly tied to GApplication. So it is unusable in all cases where the application using WebKitGTK doesn't use GApplication.

We already assert that applications using the bubblewrap sandbox use GApplication though so maybe thats a direction we want to move towards?
Comment 4 Patrick Griffis 2019-07-13 17:12:45 PDT
I now realize you covered that but using the portal directly probably avoids the need for GApplication.

libnotify is honestly awful, everything it does is main thread blocking for example, so its best to avoid it and let it die.
Comment 5 Michael Catanzaro 2019-07-13 18:24:25 PDT
So libnotify would be only for fallback regardless.

To use the portal directly, we'd still need to rely on GtkApplication for the app ID in order to solve epiphany#853 I guess?

Matthias previously indicated he'd allow a libnotify-style portal implementation instead of a GApplication-style implementation, but hopefully we won't need that.
Comment 6 Patrick Griffis 2019-07-14 13:26:30 PDT
(In reply to Michael Catanzaro from comment #5)
> So libnotify would be only for fallback regardless.

Well, the `org.freedesktop.Notification` service is the fallback. My point is the literal `libnotify` library is bad.

> To use the portal directly, we'd still need to rely on GtkApplication for
> the app ID in order to solve epiphany#853 I guess?

No, every flatpak contains its own id. GApplication is not required:


    flatpak run --command=sh org.gnome.Epiphany/x86_64/master    
    gdbus call -d org.freedesktop.portal.Desktop -e -o /org/freedesktop/portal/desktop -m org.freedesktop.portal.Notification.AddNotification "''" "{'title': <'foo'>, 'body': <'bar'>}"
    # Works as expected
Comment 7 Michael Catanzaro 2019-07-14 17:24:55 PDT
(In reply to Patrick Griffis from comment #6)
> Well, the `org.freedesktop.Notification` service is the fallback. My point
> is the literal `libnotify` library is bad.

We could stop using it and use org.freedesktop.Notification directly, of course.

> > To use the portal directly, we'd still need to rely on GtkApplication for
> > the app ID in order to solve epiphany#853 I guess?
> 
> No, every flatpak contains its own id. GApplication is not required:
> 
> 
>     flatpak run --command=sh org.gnome.Epiphany/x86_64/master    
>     gdbus call -d org.freedesktop.portal.Desktop -e -o
> /org/freedesktop/portal/desktop -m
> org.freedesktop.portal.Notification.AddNotification "''" "{'title': <'foo'>,
> 'body': <'bar'>}"
>     # Works as expected

Does WebKit have any way to know the flatpak app ID (other than to hope it's the same as the GtkApplication ID)?
Comment 8 Patrick Griffis 2019-07-14 21:52:23 PDT
(In reply to Michael Catanzaro from comment #7)
> Does WebKit have any way to know the flatpak app ID (other than to hope it's
> the same as the GtkApplication ID)?

Sure we can parse `/.flatpak-info`.
Comment 9 Michael Catanzaro 2021-06-30 08:00:38 PDT
(In reply to Michael Catanzaro from comment #0)
> Carlos Garcia wants to keep support for libnotify, so we should use
> GNotification if there is a GApplication (which will be required for
> notifications to work under flatpak), and libnotify otherwise.

Since r279369 we made WebKit crash if the bubblewrap sandbox is enabled but GApplication is not used, so IMO we should just drop use of libnotify.

Applications that aren't using GApplication surely do not need desktop notifications. Even WPE applications that don't use GtkApplication should be expected to use GApplication, as they should all be sandboxed.
Comment 10 Michael Catanzaro 2022-05-11 17:25:20 PDT
Notifications seem to work fine currently, except the urgency is not set properly. I wonder if libnotify learned to use portals.
Comment 11 Michael Catanzaro 2022-05-12 08:46:32 PDT
Follow-up bug for GNotification: bug #240347
Comment 12 Michael Catanzaro 2022-07-28 07:52:39 PDT
(In reply to Michael Catanzaro from comment #10)
> Notifications seem to work fine currently, except the urgency is not set
> properly. I wonder if libnotify learned to use portals.

I was testing with Epiphany, but Epiphany handles notifications manually using GNotification. Oops.
Comment 13 Patrick Griffis 2022-07-29 12:58:10 PDT
libnotify 0.8 uses the notification portal now.

I still agree it should be migrated away from but it probably resolves this issue.
Comment 14 Michael Catanzaro 2022-07-29 13:19:57 PDT
That should certainly resolve this. OK, closing again.

P.S. Maybe we could just add an async API to libnotify. Then there wouldn't really be anything wrong with using libnotify anymore? As long as WebKit doesn't block when showing a notification, it's OK? Well, that's a separate issue, for a separate bug report....
Comment 15 Patrick Griffis 2022-07-29 14:16:50 PDT
(In reply to Michael Catanzaro from comment #14)
> P.S. Maybe we could just add an async API to libnotify. Then there wouldn't
> really be anything wrong with using libnotify anymore? As long as WebKit
> doesn't block when showing a notification, it's OK? Well, that's a separate
> issue, for a separate bug report....

I think its worth doing. Upstream seemed on the fence if libnotify should add async API though.