Skip to content

Commit 1c6dde2

Browse files
Add notification support to timers
1 parent 9284b06 commit 1c6dde2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/components/RecipeTimer.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export default {
6363
this.resetTimeDisplay()
6464
},
6565
},
66+
async created() {
67+
this.notificationPermission = await Notification.requestPermission()
68+
},
6669
mounted() {
6770
this.resetTimeDisplay()
6871
// Start loading the sound early so it's ready to go when we need to
@@ -92,12 +95,20 @@ export default {
9295
// Start playing audio to alert the user that the timer is up
9396
this.audio.play()
9497
95-
await showSimpleAlertModal(t("cookbook", "Cooking time is up!"))
98+
const message = t("cookbook", "Cooking time is up!")
99+
100+
if (this.notificationPermission === "granted") {
101+
const notification = new Notification(message)
102+
notification.addEventListener("error", (error) => {
103+
// eslint-disable-next-line no-console
104+
console.error("Error showing notification:", error)
105+
})
106+
}
107+
108+
await showSimpleAlertModal(message)
96109
97110
// Stop audio after the alert is confirmed
98111
this.audio.pause()
99-
100-
// cookbook.notify(t('cookbook', 'Cooking time is up!'))
101112
$this.countdown = null
102113
$this.showFullTime = false
103114
$this.resetTimeDisplay()

0 commit comments

Comments
 (0)