From b1526445f341242ebe7c76df69633246f25a2bb1 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sat, 1 Mar 2025 08:45:07 +0100 Subject: [PATCH] Ensure notification service is available when sending a notification (#720) * Ensure notification service is available when sending a notification This is a bit of a weird patch for a fundamental order-of-execution issue. The bundler (esbuild) can sometimes place the `notifdService` instantiation bellow the code calling `Notify`, which would causes the `notify-send` execution to fail. To avoid this, we can make it seem like `notifdService` is being used inside `Notify`, so that it is always placed above the usage of the function, ensuring that we always have a notification daemon running * Add eslint-disable-line * Update src/lib/utils.ts --------- Co-authored-by: Jas Singh --- src/lib/utils.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 902d2b2..e49b2d5 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -11,6 +11,9 @@ import options from '../options'; import { Astal, Gdk, Gtk } from 'astal/gtk3'; import AstalApps from 'gi://AstalApps?version=0.1'; import { exec, execAsync } from 'astal/process'; +import AstalNotifd from 'gi://AstalNotifd?version=0.1'; + +const notifdService = AstalNotifd.get_default(); /** * Handles errors by throwing a new Error with a message. @@ -270,6 +273,12 @@ export function normalizePath(path: string): string { * @param notifPayload The notification arguments containing summary, body, appName, iconName, urgency, timeout, category, transient, and id. */ export function Notify(notifPayload: NotificationArgs): void { + // This line does nothing useful at runtime, but when bundling, it + // ensures that notifdService has been instantiated and, as such, + // that the notification daemon is active and the notification + // will be handled + notifdService; // eslint-disable-line @typescript-eslint/no-unused-expressions + let command = 'notify-send'; command += ` "${notifPayload.summary} "`; if (notifPayload.body) command += ` "${notifPayload.body}" `;