From 00e9343c71e13fba3565340494d1e21d0f605469 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 28 Oct 2025 12:58:33 -0700 Subject: [PATCH] Import WindowsNotifications unconditionally --- app/WindowsNotifications.main.ts | 54 +++++++++++++++++--------------- app/main.main.ts | 16 +++------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/app/WindowsNotifications.main.ts b/app/WindowsNotifications.main.ts index d39d82f68e..0a53382bdf 100644 --- a/app/WindowsNotifications.main.ts +++ b/app/WindowsNotifications.main.ts @@ -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}` - ); - } -}); + }); +} diff --git a/app/main.main.ts b/app/main.main.ts index 565779edca..d9016c77fc 100644 --- a/app/main.main.ts +++ b/app/main.main.ts @@ -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) => { // 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) {