refactor: extract overlay visibility and ipc helper services

This commit is contained in:
2026-02-09 20:19:59 -08:00
parent a1846ba23d
commit 3f36c3d85b
7 changed files with 675 additions and 451 deletions

View File

@@ -0,0 +1,55 @@
import { Notification, nativeImage } from "electron";
import * as fs from "fs";
export function showDesktopNotification(
title: string,
options: { body?: string; icon?: string },
): void {
const notificationOptions: {
title: string;
body?: string;
icon?: Electron.NativeImage | string;
} = { title };
if (options.body) {
notificationOptions.body = options.body;
}
if (options.icon) {
const isFilePath =
typeof options.icon === "string" &&
(options.icon.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(options.icon));
if (isFilePath) {
if (fs.existsSync(options.icon)) {
notificationOptions.icon = options.icon;
} else {
console.warn("Notification icon file not found:", options.icon);
}
} else if (
typeof options.icon === "string" &&
options.icon.startsWith("data:image/")
) {
const base64Data = options.icon.replace(/^data:image\/\w+;base64,/, "");
try {
const image = nativeImage.createFromBuffer(
Buffer.from(base64Data, "base64"),
);
if (image.isEmpty()) {
console.warn(
"Notification icon created from base64 is empty - image format may not be supported by Electron",
);
} else {
notificationOptions.icon = image;
}
} catch (err) {
console.error("Failed to create notification icon from base64:", err);
}
} else {
notificationOptions.icon = options.icon;
}
}
const notification = new Notification(notificationOptions);
notification.show();
}