From 9d6f55062d701559c876c3ac9084388526671996 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 12 Jan 2025 19:20:17 +0100 Subject: [PATCH 1/2] 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 --- src/lib/utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 898d91811..272523153 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -11,6 +11,7 @@ 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 { notifdService } from './constants/services.ts'; /** * Handles errors by throwing a new Error with a message. @@ -270,6 +271,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; + let command = 'notify-send'; command += ` "${notifPayload.summary} "`; if (notifPayload.body) command += ` "${notifPayload.body}" `; From d018ab20b21708ab14ababc3b25be858fdca19b6 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 12 Jan 2025 19:32:47 +0100 Subject: [PATCH 2/2] Add eslint-disable-line --- src/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 272523153..240fcb69a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -275,7 +275,7 @@ export function Notify(notifPayload: NotificationArgs): void { // ensures that notifdService has been instantiated and, as such, // that the notification daemon is active and the notification // will be handled - notifdService; + notifdService; // eslint-disable-line @typescript-eslint/no-unused-expressions let command = 'notify-send'; command += ` "${notifPayload.summary} "`;