Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
2 changes: 1 addition & 1 deletion src/config/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function discoverConfigFiles(projectRoot?: string): Promise<string[
* This ensures the plugin fails fast on misconfiguration rather than
* silently using defaults.
*/
export async function loadConfig(projectRoot?: string): Promise<Config> {
export async function loadConfig(projectRoot: string): Promise<Config> {
const filePaths = await discoverConfigFiles(projectRoot);
const configs: Record<string, unknown>[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/config/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
36 changes: 21 additions & 15 deletions src/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const terminalMap: Record<string, { icon: string; appName: string }> = {
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;

Expand All @@ -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;
Expand Down
Loading