Skip to content

Commit 66d5668

Browse files
committed
fixed entrySound playing too often
1 parent df060e5 commit 66d5668

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

web/speakerbob/src/App.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ export default class App extends Vue {
5858
}
5959
6060
private async playEntrySound () {
61-
const skipCookieName = 'skipEntrySound'
61+
const timeoutKey = 'entrySoundTimeout'
6262
63-
// check for a skip cookie
64-
if (Cookies.get(skipCookieName)) {
65-
return
63+
// check timeout
64+
const timeoutRaw = localStorage.getItem(timeoutKey)
65+
if (timeoutRaw) {
66+
const now: Date = new Date()
67+
const timeout: Date = new Date(parseInt(timeoutRaw))
68+
69+
if (now < timeout) {
70+
return
71+
}
6672
}
6773
6874
// load the user's entry sound
@@ -76,10 +82,10 @@ export default class App extends Vue {
7682
// play the user's entry sound
7783
await this.$api.put(`/sound/sounds/${preferences.entrySoundId}/play/`)
7884
79-
// set the skip cookie
80-
const expires = new Date()
81-
expires.setMinutes(expires.getMinutes() + 15)
82-
Cookies.set(skipCookieName, 'true', { expires, path: '/noop' })
85+
// set timeout
86+
const newTimeout = new Date()
87+
newTimeout.setMinutes(newTimeout.getMinutes() + 15)
88+
localStorage.setItem(timeoutKey, newTimeout.getTime().toString())
8389
}
8490
}
8591
</script>

0 commit comments

Comments
 (0)