fix(tui): detect Linux user bus socket

This commit is contained in:
metaphorics
2026-08-05 10:51:27 +00:00
parent 06477855d1
commit a6c129533c
2 changed files with 14 additions and 1 deletions
+6 -1
View File
@@ -20,6 +20,8 @@
// iTerm2, WezTerm, …) keep working unchanged and the BEL emission still fires
// for tmux `monitor-bell`, X11 urgency hints, and audible-bell handlers.
import * as fs from "node:fs";
import * as path from "node:path";
import { $which } from "@oh-my-pi/pi-utils";
import type { TerminalId, TerminalNotification } from "./terminal-capabilities";
@@ -42,9 +44,12 @@ export interface DesktopNotifier {
export function hasLinuxDesktopSession(
platform: NodeJS.Platform = process.platform,
env: NodeJS.ProcessEnv = Bun.env,
fileExists: (path: string) => boolean = fs.existsSync,
): boolean {
if (platform !== "linux") return false;
return Boolean(env.DBUS_SESSION_BUS_ADDRESS);
if (env.DBUS_SESSION_BUS_ADDRESS) return true;
const runtimeDir = env.XDG_RUNTIME_DIR;
return Boolean(runtimeDir && fileExists(path.join(runtimeDir, "bus")));
}
/**
+8
View File
@@ -19,6 +19,14 @@ describe("hasLinuxDesktopSession", () => {
expect(hasLinuxDesktopSession("darwin", LINUX_ENV)).toBe(false);
expect(hasLinuxDesktopSession("win32", LINUX_ENV)).toBe(false);
});
it("accepts the systemd user bus socket when the address is not exported", () => {
const env = { XDG_RUNTIME_DIR: "/run/user/1000" };
const fileExists = (path: string) => path === "/run/user/1000/bus";
expect(hasLinuxDesktopSession("linux", env, fileExists)).toBe(true);
expect(hasLinuxDesktopSession("linux", env, () => false)).toBe(false);
});
});
describe("shouldDeliverDesktopNotification", () => {