Commit 8a8ff811 authored by intrigeri's avatar intrigeri
Browse files

Dump initial GNotification research and tests results.

parent b72d9bf7
* Needs GLib 2.40 (in Jessie).
* Intro: <https://wiki.gnome.org/HowDoI/GNotification>
* "applications using GNotification should be able to be started as
a D-Bus service, using GApplication." =>
<https://wiki.gnome.org/HowDoI/DBusApplicationLaunching>
* "gnome-shell uses desktop files to find extra information (app icon,
name) about the sender of the notification. If you don't have
a desktop file whose base name matches the application id, then your
notification will not show up". We'll see.
* If it's deemed overkill, or just too painful, to port every single
script that needs to send notifications with actions to
"GApplication + D-Bus activation + actions support" properly,
a solution could be to let them all pretend to be the
`org.boum.tails.OpenURL` or similar app in the simplest possible
way, i.e. create a GApplication object merely to be able to send the
notification or use the private D-Bus API to
`org.gtk.Notifications`.
And then, we need only one single real GApplication that can react
to actions with parameters.
A potential problem with this approach is that if a given
GApplication is running already, another process pretending to be
the same can't send notifications (reproducer code follows; the
private D-Bus API allows to workaround this problem, but has other
ones, read on). So, in practice if we go this way the URL opener app
must have a lifetime close to zero, otherwise when clicking on
multiple notifications buttons in a row, some actions won't be
triggered (i.e. URLs won't be opened).
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use 5.10.1;
use Gtk3;
use Glib::Object::Introspection;
use Try::Tiny;
Glib::Object::Introspection->setup(
basename => 'Gio',
version => '2.0',
package => 'Gio'
);
my $app_id = 'org.gnome.gedit';
my $app = Gtk3::Application->new($app_id, []);
$app->register() || die "Could not register app";
my $notification = Gio::Notification->new('My notification title');
$notification->set_body("My notification body");
$notification->add_button("OK", 'app.new-document');
# If gedit is already running, this fails with:
# GLib-GIO-CRITICAL **: g_application_send_notification:
# assertion '!g_application_get_is_remote (application)' failed
$app->send_notification("my-notification-id", $notification)
or die "Could not send notification";
* private D-Bus API (`org.gtk.Notifications`):
<https://wiki.gnome.org/Projects/GLib/GNotification> ... maybe an
option whenever language bindings are not good enough, but so far
I (intrigeri) was not able to add buttons to it:
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use 5.10.1;
use Net::DBus;
Net::DBus
->session
->get_service("org.gtk.Notifications")
->get_object("/org/gtk/Notifications")
->as_interface("org.gtk.Notifications")
->AddNotification('org.gnome.gedit', 'whatever-notification-id', {
title => 'my notification title',
body => 'my notification body',
# Works... when 'buttons' is not passed
'default-action' => 'app.new-window',
# Does not work, for some reason
buttons => [
{ label => "New window", action => "app.new-window"},
{ label => "New document", action => "app.new-document"},
],
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment