aboutsummaryrefslogtreecommitdiff
path: root/src/utils/notification.js
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-06-03 19:04:53 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-06-03 19:04:53 +0300
commit0e7b36c2d443306325f17bb8850f5bb6176202bf (patch)
tree86629d4fe05d73f2d77dad423cc37d5a612430f3 /src/utils/notification.js
parent15d75cdc37e1459f7d11d004005d4305a6377ffd (diff)
initialHEADmaster
Diffstat (limited to 'src/utils/notification.js')
-rw-r--r--src/utils/notification.js34
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();
+ },
+ });
+ }
+}