diff --git a/src/Sounds.js b/src/Sounds.js index 4b62788a..4b3a4eb3 100644 --- a/src/Sounds.js +++ b/src/Sounds.js @@ -1,6 +1,8 @@ import Chrome from './Chrome'; import M from './Messages'; +const defaultOptions = { volume: 1.0 }; + function createNotificationSounds() { let sounds = [ { name: M.tone, file: 'f62b45bc.mp3' }, @@ -60,7 +62,7 @@ function createTimerSounds() { return sounds; } -async function play(filename) { +async function play(filename, { volume } = defaultOptions) { if (!filename) { return; } @@ -70,7 +72,13 @@ async function play(filename) { let context = new AudioContext(); let source = context.createBufferSource(); - source.connect(context.destination); + // Adds gain node for volume control + let gain = context.createGain(); + gain.gain.setValueAtTime(volume, context.currentTime); + + source.connect(gain); + gain.connect(context.destination); + source.buffer = await new Promise(async (resolve, reject) => { let content = await Chrome.files.readBinary(filename); context.decodeAudioData(content, buffer => resolve(buffer), error => reject(error)); @@ -93,4 +101,4 @@ export { notification, timer, play -}; \ No newline at end of file +}; diff --git a/src/background/Settings.js b/src/background/Settings.js index 05931612..4f71aa51 100644 --- a/src/background/Settings.js +++ b/src/background/Settings.js @@ -20,7 +20,7 @@ function clone(obj) { class SettingsSchema { get version() { - return 7; + return 8; } get default() { @@ -36,7 +36,8 @@ class SettingsSchema notifications: { desktop: true, tab: true, - sound: null + sound: null, + volume: 1.0 } }, shortBreak: { @@ -50,7 +51,8 @@ class SettingsSchema notifications: { desktop: true, tab: true, - sound: null + sound: null, + volume: 1.0 } }, longBreak: { @@ -65,7 +67,8 @@ class SettingsSchema notifications: { desktop: true, tab: true, - sound: null + sound: null, + volume: 1.0 } }, autostart: { @@ -204,6 +207,17 @@ class SettingsSchema return v7; } + + from7To8(v7) { + let v8 = clone(v7); + v8.version = 8; + + v8.focus.notifications.volume = 1.0; + v8.shortBreak.notifications.volume = 1.0; + v8.longBreak.notifications.volume = 1.0; + + return v8; + } } class PersistentSettings @@ -228,4 +242,4 @@ class PersistentSettings export { SettingsSchema, PersistentSettings -}; \ No newline at end of file +}; diff --git a/src/options/Settings.vue b/src/options/Settings.vue index 4a41aa0b..69d461c3 100644 --- a/src/options/Settings.vue +++ b/src/options/Settings.vue @@ -67,7 +67,7 @@

@@ -103,7 +103,7 @@

@@ -157,7 +157,7 @@

@@ -379,4 +379,4 @@ export default { SoundSelect } }; - \ No newline at end of file + diff --git a/src/options/SoundSelect.vue b/src/options/SoundSelect.vue index c40048b3..68541b15 100644 --- a/src/options/SoundSelect.vue +++ b/src/options/SoundSelect.vue @@ -1,8 +1,20 @@ \ No newline at end of file +