From 3d249b8d10ba7d73837c0527f03bccb0783e2fe8 Mon Sep 17 00:00:00 2001 From: JC-comp <147694781+JC-comp@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:18:54 +0800 Subject: [PATCH] Fix: Initialization and Error Handling for Libnotify (#2659) * fix libnotify * Add notification error handling --- src/log.d | 9 +++++++-- src/notifications/dnotify.d | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/log.d b/src/log.d index b1354349..049c46ff 100644 --- a/src/log.d +++ b/src/log.d @@ -99,8 +99,13 @@ class LogBuffer { shared void notify(string message) { // Use dnotify's functionality for GUI notifications, if GUI notifications is enabled version(Notifications) { - auto n = new Notification("Log Notification", message, "IGNORED"); - n.show(); + try { + auto n = new Notification("Log Notification", message, "IGNORED"); + n.show(); + } catch (NotificationError e) { + sendGUINotification = false; + addLogEntry("Unable to send notification; disabled in the following: " ~ e.message); + } } } diff --git a/src/notifications/dnotify.d b/src/notifications/dnotify.d index 1cc09356..bcd96239 100644 --- a/src/notifications/dnotify.d +++ b/src/notifications/dnotify.d @@ -79,11 +79,11 @@ void init(in char[] name) { alias notify_is_initted is_initted; alias notify_uninit uninit; -static this() { +shared static this() { init(__FILE__); } -static ~this() { +shared static ~this() { uninit(); }