Skip to content

Commit 029c6ff

Browse files
committed
Add sound effect when countdown completes
This was taken from here: https://freesound.org/people/crz1990/sounds/135873 Resolves #9
1 parent b9c02b5 commit 029c6ff

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/main.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const url = require('url')
77

88
const countdown = require('./countdown')
99

10-
let pomodoroLengthSeconds = 1500 // 25 minutes
10+
let pomodoroLengthSeconds = 5 // 25 minutes
1111
let breakLengthSeconds = 300 // 5 minutes
1212

1313
// Keep a global reference of the window object, if you don't, the window will
@@ -141,8 +141,9 @@ ipcMain.on('pomodoro-start', (evt) => {
141141
countdown.init(pomodoroLengthSeconds, count => {
142142
broadcastEvent("countdown", count)
143143
}, () => {
144+
broadcastEvent('pomodoro-complete')
145+
144146
setTimeout(_ => {
145-
broadcastEvent('pomodoro-complete')
146147
ipcMain.emit('break-start')
147148
}, 1000);
148149
});
@@ -154,9 +155,7 @@ ipcMain.on('break-start', (evt) => {
154155
countdown.init(breakLengthSeconds, count => {
155156
broadcastEvent("countdown", count)
156157
}, () => {
157-
setTimeout(_ => {
158-
broadcastEvent('break-complete')
159-
}, 1000);
158+
broadcastEvent('break-complete')
160159
});
161160

162161
broadcastEvent('break-start')

src/overlay/overlay.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const electron = require('electron')
22
const moment = require('moment')
3+
const path = require('path')
34

45
const ipc = electron.ipcRenderer
56

7+
var audio = new Audio(path.join(__dirname, '..', 'sounds', 'timer.wav'));
8+
69
let pomodoroRunning = false
710

811
const getTimeString = (seconds) => {
@@ -16,10 +19,10 @@ const getTimeString = (seconds) => {
1619
// Respond to events from Main
1720
ipc.on('pomodoro-start', (evt) => { onStart() })
1821
ipc.on('pomodoro-stop', (evt) => { onStop() })
19-
ipc.on('pomodoro-complete', (evt) => { onStop() })
22+
ipc.on('pomodoro-complete', (evt) => { onComplete() })
2023
ipc.on('break-start', (evt) => { onStart() })
2124
ipc.on('break-stop', (evt) => { onStop() })
22-
ipc.on('break-complete', (evt) => { onStop() })
25+
ipc.on('break-complete', (evt) => { onComplete() })
2326
ipc.on('countdown', (evt, count) => { document.getElementById('countdown').innerHTML = getTimeString(count); })
2427

2528
onClickStartStop = function () {
@@ -45,3 +48,8 @@ function onStop() {
4548
el.classList.add("fa-play")
4649
pomodoroRunning = false
4750
}
51+
52+
function onComplete() {
53+
audio.play();
54+
onStop()
55+
}

src/sounds/timer.wav

2.97 MB
Binary file not shown.

0 commit comments

Comments
 (0)