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 <jaskiratpal.singh@outlook.com>
This commit is contained in:
@@ -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}" `;
|
||||
|
||||
Reference in New Issue
Block a user