diff options
Diffstat (limited to 'src/utils/notification.js')
-rw-r--r-- | src/utils/notification.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils/notification.js b/src/utils/notification.js new file mode 100644 index 0000000..a248dc8 --- /dev/null +++ b/src/utils/notification.js @@ -0,0 +1,34 @@ +import { Button, notification } from "antd"; + +const audio = new Audio('alarm.mp3'); +audio.preload = "auto"; + +export const timerComplete = (sound, browserNotifications, timer) => { + timer.started = false; // останавливаем + timer.time = 0; + + if (sound) { + audio.currentTime = 0; + audio.play(); + } + + // уведомление + if (browserNotifications) { + const notif = new Notification("Мультитаймер", { + body: `Сработал ${timer.name}`, + icon: "/logo192.png", + }); + notif.onclick = () => { + audio.pause(); + }; + } else { + notification.open({ + message: `Сработал ${timer.name}`, + description: (sound && (<Button type="primary" onClick={() => audio.pause()}>Звук выкл.</Button>)), + duration: 12, + onClose: () => { + audio.pause(); + }, + }); + } +} |