27 lines
711 B
TypeScript
27 lines
711 B
TypeScript
import { Notification, type NotificationConstructorOptions } from "electron";
|
|
import log from "electron-log/main";
|
|
|
|
function createNotification(
|
|
options: NotificationConstructorOptions,
|
|
context = options.title,
|
|
): Notification {
|
|
const notification = new Notification(options);
|
|
|
|
notification.on("failed", (_event, error) => {
|
|
log.warn(`Notification failed${context ? ` (${context})` : ""}:`, error);
|
|
});
|
|
|
|
return notification;
|
|
}
|
|
|
|
function showNotification(
|
|
options: NotificationConstructorOptions,
|
|
context?: string,
|
|
): Notification {
|
|
const notification = createNotification(options, context);
|
|
notification.show();
|
|
return notification;
|
|
}
|
|
|
|
export { createNotification, showNotification };
|