mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
Import WindowsNotifications unconditionally
This commit is contained in:
@@ -12,41 +12,45 @@ import {
|
|||||||
import { createLogger } from '../ts/logging/log.std.js';
|
import { createLogger } from '../ts/logging/log.std.js';
|
||||||
import { AUMID } from './startup_config.main.js';
|
import { AUMID } from './startup_config.main.js';
|
||||||
import type { WindowsNotificationData } from '../ts/services/notifications.preload.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
|
// eslint-disable-next-line local-rules/file-suffix
|
||||||
import { renderWindowsToast } from './renderWindowsToast.dom.js';
|
import { renderWindowsToast } from './renderWindowsToast.dom.js';
|
||||||
|
|
||||||
const log = createLogger('WindowsNotifications');
|
|
||||||
|
|
||||||
export { sendDummyKeystroke };
|
export { sendDummyKeystroke };
|
||||||
|
|
||||||
const notifier = new Notifier(AUMID);
|
const log = createLogger('WindowsNotifications');
|
||||||
|
|
||||||
const NOTIFICATION_ID = {
|
if (OS.isWindows()) {
|
||||||
group: 'group',
|
const notifier = new Notifier(AUMID);
|
||||||
tag: 'tag',
|
|
||||||
};
|
|
||||||
|
|
||||||
ipc.handle(
|
const NOTIFICATION_ID = {
|
||||||
'windows-notifications:show',
|
group: 'group',
|
||||||
(_event: IpcMainInvokeEvent, data: WindowsNotificationData) => {
|
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 {
|
try {
|
||||||
// First, clear all previous notifications - we want just one notification at a time
|
|
||||||
notifier.remove(NOTIFICATION_ID);
|
notifier.remove(NOTIFICATION_ID);
|
||||||
notifier.show(renderWindowsToast(data), NOTIFICATION_ID);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.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}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ import { getOwn } from '../ts/util/getOwn.std.js';
|
|||||||
import { safeParseLoose, safeParseUnknown } from '../ts/util/schemas.std.js';
|
import { safeParseLoose, safeParseUnknown } from '../ts/util/schemas.std.js';
|
||||||
import { getAppErrorIcon } from '../ts/util/getAppErrorIcon.node.js';
|
import { getAppErrorIcon } from '../ts/util/getAppErrorIcon.node.js';
|
||||||
import { promptOSAuth } from '../ts/util/os/promptOSAuthMain.main.js';
|
import { promptOSAuth } from '../ts/util/os/promptOSAuthMain.main.js';
|
||||||
|
import { sendDummyKeystroke } from './WindowsNotifications.main.js';
|
||||||
|
|
||||||
const { chmod, realpath, writeFile } = fsExtra;
|
const { chmod, realpath, writeFile } = fsExtra;
|
||||||
const { get, pick, isNumber, isBoolean, some, debounce, noop } = lodash;
|
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);
|
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() {
|
function showWindow() {
|
||||||
if (!mainWindow) {
|
if (!mainWindow) {
|
||||||
return;
|
return;
|
||||||
@@ -271,7 +261,9 @@ if (!process.mas) {
|
|||||||
app.on('second-instance', (_e: Electron.Event, argv: Array<string>) => {
|
app.on('second-instance', (_e: Electron.Event, argv: Array<string>) => {
|
||||||
// Workaround to let AllowSetForegroundWindow succeed.
|
// Workaround to let AllowSetForegroundWindow succeed.
|
||||||
// See https://www.npmjs.com/package/@signalapp/windows-dummy-keystroke for a full explanation of why this is needed.
|
// 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
|
// Someone tried to run a second instance, we should focus our window
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
|
|||||||
Reference in New Issue
Block a user