diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6dc924e..b91e63499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +### Added +- Add browser notification support for timers + [1409](https://github.com/nextcloud/cookbook/pull/1409) @MarcelRobitaille + ### Fixed - Make "None" category string translatable [1323](https://github.com/nextcloud/cookbook/pull/1344) @seyfeb diff --git a/src/components/RecipeTimer.vue b/src/components/RecipeTimer.vue index 35b00d53a..db9d31006 100644 --- a/src/components/RecipeTimer.vue +++ b/src/components/RecipeTimer.vue @@ -16,6 +16,8 @@ import { linkTo } from "@nextcloud/router" import { showSimpleAlertModal } from "cookbook/js/modals" +import * as browserNotifications from "cookbook/js/browser_notifications" + export default { name: "RecipeTimer", props: { @@ -79,6 +81,14 @@ export default { this.audio.loop = true }, methods: { + onTimerStart() { + browserNotifications.requestPermission({ + justification: [ + t("cookbook", "Please enable browser notifications to receive an alert when the timer is over."), + t("cookbook", "You can disable these notifications at any time in the \"Cookbook settings\" dialog."), + ], + }) + }, onTimerEnd() { window.clearInterval(this.countdown) const $this = this @@ -92,12 +102,12 @@ export default { // Start playing audio to alert the user that the timer is up this.audio.play() - await showSimpleAlertModal(t("cookbook", "Cooking time is up!")) + const message = t("cookbook", "Cooking time is up!") + await browserNotifications.notify(message) + await showSimpleAlertModal(message) // Stop audio after the alert is confirmed this.audio.pause() - - // cookbook.notify(t('cookbook', 'Cooking time is up!')) $this.countdown = null $this.showFullTime = false $this.resetTimeDisplay() @@ -126,6 +136,7 @@ export default { if (this.countdown === null) { // Pass this to callback function const $this = this + $this.onTimerStart() this.countdown = window.setInterval(() => { $this.seconds -= 1 if ($this.seconds < 0) { diff --git a/src/components/SimpleAlertModal.vue b/src/components/SimpleAlertModal.vue index bc6f48e49..49fb2ec46 100644 --- a/src/components/SimpleAlertModal.vue +++ b/src/components/SimpleAlertModal.vue @@ -1,7 +1,8 @@