feat: Add notifications
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
desktopCapturer,
|
||||
dialog,
|
||||
ipcMain,
|
||||
Notification,
|
||||
shell
|
||||
} from 'electron';
|
||||
import * as fs from 'fs';
|
||||
@@ -33,6 +34,7 @@ import {
|
||||
} from '../update/desktop-updater';
|
||||
import { consumePendingDeepLink } from '../app/deep-links';
|
||||
import { synchronizeAutoStartSetting } from '../app/auto-start';
|
||||
import { getMainWindow, getWindowIconPath } from '../window/create-window';
|
||||
|
||||
const DEFAULT_MIME_TYPE = 'application/octet-stream';
|
||||
const FILE_CLIPBOARD_FORMATS = [
|
||||
@@ -86,6 +88,12 @@ interface ClipboardFilePayload {
|
||||
path?: string;
|
||||
}
|
||||
|
||||
interface DesktopNotificationPayload {
|
||||
body: string;
|
||||
requestAttention?: boolean;
|
||||
title: string;
|
||||
}
|
||||
|
||||
function resolveLinuxDisplayServer(): string {
|
||||
if (process.platform !== 'linux') {
|
||||
return 'N/A';
|
||||
@@ -316,6 +324,69 @@ export function setupSystemHandlers(): void {
|
||||
|
||||
ipcMain.handle('get-desktop-settings', () => getDesktopSettingsSnapshot());
|
||||
|
||||
ipcMain.handle('show-desktop-notification', async (_event, payload: DesktopNotificationPayload) => {
|
||||
const title = typeof payload?.title === 'string' ? payload.title.trim() : '';
|
||||
const body = typeof payload?.body === 'string' ? payload.body : '';
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
if (!title) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Notification.isSupported()) {
|
||||
try {
|
||||
const notification = new Notification({
|
||||
title,
|
||||
body,
|
||||
icon: getWindowIconPath(),
|
||||
silent: true
|
||||
});
|
||||
|
||||
notification.on('click', () => {
|
||||
if (!mainWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
if (!mainWindow.isVisible()) {
|
||||
mainWindow.show();
|
||||
}
|
||||
|
||||
mainWindow.focus();
|
||||
});
|
||||
|
||||
notification.show();
|
||||
} catch {
|
||||
// Ignore notification center failures and still attempt taskbar attention.
|
||||
}
|
||||
}
|
||||
|
||||
if (payload?.requestAttention && mainWindow && (mainWindow.isMinimized() || !mainWindow.isFocused())) {
|
||||
mainWindow.flashFrame(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle('request-window-attention', () => {
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
if (!mainWindow || (!mainWindow.isMinimized() && mainWindow.isFocused())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mainWindow.flashFrame(true);
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle('clear-window-attention', () => {
|
||||
getMainWindow()?.flashFrame(false);
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-auto-update-state', () => getDesktopUpdateState());
|
||||
|
||||
ipcMain.handle('get-auto-update-server-health', async (_event, serverUrl: string) => {
|
||||
|
||||
Reference in New Issue
Block a user