diff --git a/index.ts b/index.ts index e1858c4..2f5caf0 100644 --- a/index.ts +++ b/index.ts @@ -4,8 +4,8 @@ import { createNotificationScheduler } from "@/notification-scheduler"; import { loadConfig, ConfigError } from "@/config/loader"; import { createResolvedConfig } from "@/config/resolver"; -export const SimpleNotificationPlugin: Plugin = async ({ client }) => { - const config = await loadConfig().catch(async (error) => { +export const SimpleNotificationPlugin: Plugin = async ({ client, directory }) => { + const config = await loadConfig(directory).catch(async (error) => { const message = error instanceof ConfigError ? `Notification plugin config error: ${error.message}` diff --git a/src/config/loader.ts b/src/config/loader.ts index d44062d..f8bc83d 100644 --- a/src/config/loader.ts +++ b/src/config/loader.ts @@ -95,7 +95,7 @@ export async function discoverConfigFiles(projectRoot?: string): Promise { +export async function loadConfig(projectRoot: string): Promise { const filePaths = await discoverConfigFiles(projectRoot); const configs: Record[] = []; diff --git a/src/config/resolver.ts b/src/config/resolver.ts index c909452..cb1a514 100644 --- a/src/config/resolver.ts +++ b/src/config/resolver.ts @@ -30,7 +30,7 @@ export function createResolvedConfig(config: Config): ResolvedConfig { ? (config[configKey] as EventConfig) : undefined; - if (eventConfig?.enabled) { + if (eventConfig?.enabled !== undefined) { return eventConfig.enabled; } diff --git a/src/notification.ts b/src/notification.ts index 4bf141c..4568f55 100644 --- a/src/notification.ts +++ b/src/notification.ts @@ -10,9 +10,10 @@ const terminalMap: Record = { konsole: { icon: "utilities-terminal", appName: "Konsole" }, }; -function getLinuxTerminalInfo(): { icon: string; appName: string } | null { - let cachedTerminal: { icon: string; appName: string } | null | undefined; +// Cache terminal info at module level to persist across calls +let cachedTerminal: { icon: string; appName: string } | null | undefined; +function getLinuxTerminalInfo(): { icon: string; appName: string } | null { if (process.platform !== "linux") return null; if (cachedTerminal !== undefined) return cachedTerminal; @@ -24,20 +25,25 @@ function getLinuxTerminalInfo(): { icon: string; appName: string } | null { let currentPid = process.pid; for (let i = 0; i < 3 && currentPid > 1; i++) { - const status = readFileSync(`/proc/${currentPid}/status`, "utf-8"); - const ppidMatch = status.match(/PPid:\s*(\d+)/); - if (!ppidMatch || !ppidMatch[1]) break; - const ppid = parseInt(ppidMatch[1], 10); - if (ppid <= 1 || ppid === currentPid) break; - - const comm = readFileSync(`/proc/${ppid}/comm`, "utf-8").trim(); - const normalized = comm.replace(/-/g, "_"); - const result = terminalMap[comm] ?? terminalMap[normalized] ?? null; - if (result) { - cachedTerminal = result; - return result; + // /proc may be inaccessible in containers or restricted environments (EACCES/ENOENT) + try { + const status = readFileSync(`/proc/${currentPid}/status`, "utf-8"); + const ppidMatch = status.match(/PPid:\s*(\d+)/); + if (!ppidMatch || !ppidMatch[1]) break; + const ppid = parseInt(ppidMatch[1], 10); + if (ppid <= 1 || ppid === currentPid) break; + + const comm = readFileSync(`/proc/${ppid}/comm`, "utf-8").trim(); + const normalized = comm.replace(/-/g, "_"); + const result = terminalMap[comm] ?? terminalMap[normalized] ?? null; + if (result) { + cachedTerminal = result; + return result; + } + currentPid = ppid; + } catch { + break; } - currentPid = ppid; } cachedTerminal = null;