Skip to content

Commit

Permalink
Ensure notification service is available when sending a notification
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davfsa committed Jan 12, 2025
1 parent fab3a8c commit 9d6f550
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Check failure on line 278 in src/lib/utils.ts

View workflow job for this annotation

GitHub Actions / code_quality

Expected an assignment or function call and instead saw an expression

let command = 'notify-send';
command += ` "${notifPayload.summary} "`;
if (notifPayload.body) command += ` "${notifPayload.body}" `;
Expand Down

0 comments on commit 9d6f550

Please sign in to comment.