Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created May 21, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v6ak/6ef6768103587bc273fb to your computer and use it in GitHub Desktop.
Save v6ak/6ef6768103587bc273fb to your computer and use it in GitHub Desktop.
PoC of unified libnotify for Qubes
#!/usr/bin/env python
#
# q6-notification-proxy - Lightweight notification-deamon-proxy for Qubes OS
# Receives Desktop Notifications (including libnotify / notify-send)
# See: http://www.galago-project.org/specs/notification/0.9/index.html
#
# The code comes from statnot, but it is significantly modified by v6ak. There is jusst a little code from the original app
#
# Note: VERY early prototype, to get feedback.
#
# Copyright (c) 2009-2011, 2015 by the authors
# http://code.k2h.se (original statnot developer(s))
# https://contact.v6ak.com (q6-nofitication-proxy developer)
# Please report bugs or feature requests by e-mail.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import dbus.service
import dbus.mainloop.glib
import gobject
import subprocess
class NotificationFetcher(dbus.service.Object):
_id = 0
@dbus.service.method("org.freedesktop.Notifications",
in_signature='susssasa{ss}i',
out_signature='u')
def Notify(self, app_name, notification_id, app_icon,
summary, body, actions, hints, expire_timeout):
if not notification_id:
self._id += 1
notification_id = self._id
p = subprocess.Popen(["/usr/lib/qubes/qrexec-client-vm", "dom0", "qubes.Notify"], stdin=subprocess.PIPE)
p.communicate(summary + "\n" + app_name + "\n" + body)
print notification_id
return notification_id
@dbus.service.method("org.freedesktop.Notifications", in_signature='', out_signature='as')
def GetCapabilities(self):
return ("body")
@dbus.service.signal('org.freedesktop.Notifications', signature='uu')
def NotificationClosed(self, id_in, reason_in):
pass
@dbus.service.method("org.freedesktop.Notifications", in_signature='u', out_signature='')
def CloseNotification(self, id):
pass
@dbus.service.method("org.freedesktop.Notifications", in_signature='', out_signature='ssss')
def GetServerInformation(self):
return ("statnot", "http://code.k2h.se", "0.0.2", "1")
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.Notifications", session_bus)
nf = NotificationFetcher(session_bus, '/org/freedesktop/Notifications')
context = gobject.MainLoop().get_context()
while 1:
context.iteration(True)
#!/bin/bash
set -u
set -e
set -o pipefail
function sanitize {
iconv -f utf-8 -t utf-8
}
sanitize | (
read title
read app
body="$(cat)"
notify-send \
-a "$QREXEC_REMOTE_DOMAIN: $app" \
--icon "/var/lib/qubes/appvms/$QREXEC_REMOTE_DOMAIN/icon.png" \
-- "$QREXEC_REMOTE_DOMAIN: $title" "$QREXEC_REMOTE_DOMAIN: $body"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment