2023-08-01 16:06:29 +00:00
|
|
|
// Copyright 2017 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { ipcMain as ipc } from 'electron';
|
|
|
|
import type { IpcMainInvokeEvent } from 'electron';
|
|
|
|
|
|
|
|
import {
|
2024-08-26 17:16:10 +00:00
|
|
|
Notifier,
|
|
|
|
sendDummyKeystroke,
|
|
|
|
} from '@indutny/simple-windows-notifications';
|
2023-08-01 16:06:29 +00:00
|
|
|
|
|
|
|
import * as log from '../ts/logging/log';
|
|
|
|
import { AUMID } from './startup_config';
|
|
|
|
import type { WindowsNotificationData } from '../ts/services/notifications';
|
|
|
|
import { renderWindowsToast } from './renderWindowsToast';
|
|
|
|
|
2024-08-26 17:16:10 +00:00
|
|
|
export { sendDummyKeystroke };
|
|
|
|
|
|
|
|
const notifier = new Notifier(AUMID);
|
2023-08-01 16:06:29 +00:00
|
|
|
|
2024-08-26 17:16:10 +00:00
|
|
|
const NOTIFICATION_ID = {
|
|
|
|
group: 'group',
|
|
|
|
tag: 'tag',
|
|
|
|
};
|
2023-08-01 16:06:29 +00:00
|
|
|
|
|
|
|
ipc.handle(
|
|
|
|
'windows-notifications:show',
|
|
|
|
(_event: IpcMainInvokeEvent, data: WindowsNotificationData) => {
|
|
|
|
try {
|
|
|
|
// First, clear all previous notifications - we want just one notification at a time
|
2024-08-26 17:16:10 +00:00
|
|
|
notifier.remove(NOTIFICATION_ID);
|
|
|
|
notifier.show(renderWindowsToast(data), NOTIFICATION_ID);
|
2023-08-01 16:06:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
`Windows Notifications: Failed to show notification: ${error.stack}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ipc.handle('windows-notifications:clear-all', () => {
|
|
|
|
try {
|
2024-08-26 17:16:10 +00:00
|
|
|
notifier.remove(NOTIFICATION_ID);
|
2023-08-01 16:06:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
`Windows Notifications: Failed to clear notifications: ${error.stack}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|