34 lines
704 B
TypeScript
34 lines
704 B
TypeScript
function filter(text: string) {
|
|
return (text || '')
|
|
.replace(/&/g, '&')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
}
|
|
|
|
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;
|
|
}
|