Add an option to play audio notifications

This commit is contained in:
Asa Ayers 2017-01-28 11:33:57 -08:00
parent b9c8b4afbb
commit bda0430805
5 changed files with 22 additions and 0 deletions

View file

@ -453,6 +453,10 @@
} }
} }
}, },
"audioNotificationDescription": {
"message": "Play audio notification",
"description": "Description for audio notification setting"
},
"safetyNumbersSettingHeader": { "safetyNumbersSettingHeader": {
"message": "Safety numbers approval", "message": "Safety numbers approval",
"description": "Header for safety numbers setting" "description": "Header for safety numbers setting"

BIN
audio/NewMessage.mp3 Normal file

Binary file not shown.

View file

@ -463,6 +463,11 @@
<label for='notification-setting-off'>{{ disableNotifications }} </label> <label for='notification-setting-off'>{{ disableNotifications }} </label>
</div> </div>
</div> </div>
<br />
<div class='audio-notification-setting'>
<input type='checkbox' name='audio-notification' id='audio-notification'/>
<label for='audio-notification'>{{ audioNotificationDescription }}</label>
</div>
<hr> <hr>
<div class='safety-numbers-settings'> <div class='safety-numbers-settings'>
<h3>{{ safetyNumbersSettingHeader }}</h3> <h3>{{ safetyNumbersSettingHeader }}</h3>

View file

@ -12,6 +12,8 @@
MESSAGE : 'message' MESSAGE : 'message'
}; };
var sound = new Audio('/audio/NewMessage.mp3');
Whisper.Notifications = new (Backbone.Collection.extend({ Whisper.Notifications = new (Backbone.Collection.extend({
initialize: function() { initialize: function() {
this.on('add', _.debounce(this.update.bind(this), 1000)); this.on('add', _.debounce(this.update.bind(this), 1000));
@ -35,6 +37,11 @@
if (this.length === 0) { if (this.length === 0) {
return; return;
} }
var audioNotification = storage.get('audio-notification') || false;
if (audioNotification) {
sound.play();
}
var setting = storage.get('notification-setting') || 'message'; var setting = storage.get('notification-setting') || 'message';
if (setting === SETTINGS.OFF) { if (setting === SETTINGS.OFF) {
return; return;

View file

@ -59,6 +59,11 @@
defaultValue: 'android', defaultValue: 'android',
name: 'theme-setting' name: 'theme-setting'
}); });
new CheckboxView({
el: this.$('.audio-notification-setting'),
defaultValue: false,
name: 'audio-notification'
});
new CheckboxView({ new CheckboxView({
el: this.$('.safety-numbers-settings'), el: this.$('.safety-numbers-settings'),
defaultValue: true, defaultValue: true,
@ -84,6 +89,7 @@
nameOnly: i18n('nameOnly'), nameOnly: i18n('nameOnly'),
safetyNumbersSettingDescription: i18n('safetyNumbersSettingDescription'), safetyNumbersSettingDescription: i18n('safetyNumbersSettingDescription'),
safetyNumbersSettingHeader: i18n('safetyNumbersSettingHeader'), safetyNumbersSettingHeader: i18n('safetyNumbersSettingHeader'),
audioNotificationDescription: i18n('audioNotificationDescription'),
themeAndroidDark: i18n('themeAndroidDark'), themeAndroidDark: i18n('themeAndroidDark'),
}; };
} }