Import WindowsNotifications unconditionally

This commit is contained in:
Fedor Indutny
2025-10-28 12:58:33 -07:00
committed by GitHub
parent a5b90fdca9
commit 00e9343c71
2 changed files with 33 additions and 37 deletions

View File

@@ -12,41 +12,45 @@ import {
import { createLogger } from '../ts/logging/log.std.js';
import { AUMID } from './startup_config.main.js';
import type { WindowsNotificationData } from '../ts/services/notifications.preload.js';
import OS from '../ts/util/os/osMain.node.js';
// eslint-disable-next-line local-rules/file-suffix
import { renderWindowsToast } from './renderWindowsToast.dom.js';
const log = createLogger('WindowsNotifications');
export { sendDummyKeystroke };
const notifier = new Notifier(AUMID);
const log = createLogger('WindowsNotifications');
const NOTIFICATION_ID = {
group: 'group',
tag: 'tag',
};
if (OS.isWindows()) {
const notifier = new Notifier(AUMID);
ipc.handle(
'windows-notifications:show',
(_event: IpcMainInvokeEvent, data: WindowsNotificationData) => {
const NOTIFICATION_ID = {
group: 'group',
tag: 'tag',
};
ipc.handle(
'windows-notifications:show',
(_event: IpcMainInvokeEvent, data: WindowsNotificationData) => {
try {
// First, clear all previous notifications - we want just one
// notification at a time
notifier.remove(NOTIFICATION_ID);
notifier.show(renderWindowsToast(data), NOTIFICATION_ID);
} catch (error) {
log.error(
`Windows Notifications: Failed to show notification: ${error.stack}`
);
}
}
);
ipc.handle('windows-notifications:clear-all', () => {
try {
// First, clear all previous notifications - we want just one notification at a time
notifier.remove(NOTIFICATION_ID);
notifier.show(renderWindowsToast(data), NOTIFICATION_ID);
} catch (error) {
log.error(
`Windows Notifications: Failed to show notification: ${error.stack}`
`Windows Notifications: Failed to clear notifications: ${error.stack}`
);
}
}
);
ipc.handle('windows-notifications:clear-all', () => {
try {
notifier.remove(NOTIFICATION_ID);
} catch (error) {
log.error(
`Windows Notifications: Failed to clear notifications: ${error.stack}`
);
}
});
});
}

View File

@@ -135,6 +135,7 @@ import { getOwn } from '../ts/util/getOwn.std.js';
import { safeParseLoose, safeParseUnknown } from '../ts/util/schemas.std.js';
import { getAppErrorIcon } from '../ts/util/getAppErrorIcon.node.js';
import { promptOSAuth } from '../ts/util/os/promptOSAuthMain.main.js';
import { sendDummyKeystroke } from './WindowsNotifications.main.js';
const { chmod, realpath, writeFile } = fsExtra;
const { get, pick, isNumber, isBoolean, some, debounce, noop } = lodash;
@@ -234,17 +235,6 @@ const CLI_LANG = cliOptions.lang as string | undefined;
setupCrashReports(log, showDebugLogWindow, FORCE_ENABLE_CRASH_REPORTS);
let sendDummyKeystroke: undefined | (() => void);
if (OS.isWindows()) {
try {
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
const windowsNotifications = require('./WindowsNotifications.main.js');
sendDummyKeystroke = windowsNotifications.sendDummyKeystroke;
} catch (error) {
log.error('Failed to initialize Windows Notifications:', error.stack);
}
}
function showWindow() {
if (!mainWindow) {
return;
@@ -271,7 +261,9 @@ if (!process.mas) {
app.on('second-instance', (_e: Electron.Event, argv: Array<string>) => {
// Workaround to let AllowSetForegroundWindow succeed.
// See https://www.npmjs.com/package/@signalapp/windows-dummy-keystroke for a full explanation of why this is needed.
sendDummyKeystroke?.();
if (OS.isWindows()) {
sendDummyKeystroke();
}
// Someone tried to run a second instance, we should focus our window
if (mainWindow) {