Skip to content
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Added
- Add alarm sound to timers
[#1120](https://github.com/nextcloud/cookbook/pull/1120) @MarcelRobitaille

### Changed
- Create build script for GitHub pages with GitHub actions to allow for custom building
[#1203](https://github.com/nextcloud/cookbook/pull/1203) @christianlupus
Expand Down
Binary file added assets/alarm-continuous.mp3
Binary file not shown.
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/components/RecipeTimer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
</template>

<script>
import { linkTo } from "@nextcloud/router"

import { showSimpleAlertModal } from "cookbook/js/modals"

export default {
Expand Down Expand Up @@ -63,6 +65,18 @@ export default {
},
mounted() {
this.resetTimeDisplay()
// Start loading the sound early so it's ready to go when we need to
// play it

// Source for the sound https://pixabay.com/sound-effects/alarm-clock-short-6402/
// Voted by poll https://nextcloud.christian-wolf.click/nextcloud/apps/polls/s/Wke3s6CscDwQEjPV
this.audio = new Audio(
linkTo("cookbook", "assets/alarm-continuous.mp3")
)

// For now, the alarm should play continuously until it is dismissed
// See https://github.com/nextcloud/cookbook/issues/671#issuecomment-1279030452
this.audio.loop = true
},
methods: {
onTimerEnd() {
Expand All @@ -71,7 +85,18 @@ export default {
window.setTimeout(async () => {
// The short timeout is needed or Vue doesn't have time to update the countdown
// display to display 00:00:00

// Ensure audio starts at the beggining
// If it's paused midway, by default it will resume from that point
this.audio.currentTime = 0
// Start playing audio to alert the user that the timer is up
this.audio.play()

await showSimpleAlertModal(t("cookbook", "Cooking time is up!"))

// Stop audio after the alert is confirmed
this.audio.pause()

// cookbook.notify(t('cookbook', 'Cooking time is up!'))
$this.countdown = null
$this.showFullTime = false
Expand Down