signal-desktop/ts/services/notify.ts
2020-07-30 13:08:47 -07:00

34 lines
704 B
TypeScript

function filter(text: string) {
return (text || '')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
type NotificationType = {
platform: string;
icon: string;
message: string;
onNotificationClick: () => void;
silent: boolean;
title: string;
};
export function notify({
platform,
icon,
message,
onNotificationClick,
silent,
title,
}: NotificationType): Notification {
const notification = new window.Notification(title, {
body: platform === 'linux' ? filter(message) : message,
icon,
silent,
});
notification.onclick = onNotificationClick;
return notification;
}