Drop the dependency on libnotify for notifications on Linux

This commit is contained in:
Kovid Goyal
2019-02-03 11:27:05 +05:30
parent 5957befaad
commit 7ee04b37ac
3 changed files with 42 additions and 15 deletions

View File

@@ -2,7 +2,6 @@
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
import subprocess
from .constants import is_macos, logo_png_file
@@ -23,9 +22,15 @@ if is_macos:
else:
# libnotify depends on GTK, so we are not using it, instead
# use the command line notify-send wrapper it provides
# May want to just implement this in glfw using DBUS
from .fast_data_types import dbus_send_notification
alloc_map = {}
identifier_map = {}
def dbus_notification_created(alloc_id, notification_id):
identifier = alloc_map.get(alloc_id)
if identifier is not None:
identifier_map[identifier] = notification_id
def notify(
title,
@@ -35,16 +40,8 @@ else:
icon=True,
identifier=None
):
cmd = ['notify-send', '-a', application]
if timeout > -1:
cmd.append('-t'), cmd.append(str(timeout))
if icon is True:
icon = logo_png_file
if icon:
cmd.extend(['-i', icon])
subprocess.Popen(
cmd + [title, body],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
)
alloc_id = dbus_send_notification(application, icon, title, body, timeout)
if alloc_id and identifier is not None:
alloc_map[alloc_id] = identifier