Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22977 from mancas/bug1053684
Browse files Browse the repository at this point in the history
Bug 1053684 - [Clock] The Alarm sound volume is set at maximum r=mcav
  • Loading branch information
mcav authored and rvandermeulen committed Aug 21, 2014
1 parent 60cedd4 commit c6836ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
33 changes: 23 additions & 10 deletions apps/clock/js/audio_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ define(function(require) {
return Math.round(volume * SYSTEM_VOLUME_MAX);
}

function requestAlarmSystemVolume() {
// Asynchronously load the alarm volume from mozSettings.
return new Promise(function(resolve, reject) {
var lock = navigator.mozSettings.createLock();
var req = lock.get(VOLUME_SETTING);
req.onsuccess = function() {
var volume = systemVolumeToFloat(req.result[VOLUME_SETTING]);
if (isValidVolume(volume)) {
globalVolumeManager._volume = volume;
resolve(volume);
}
};

req.onerror = function() {
var DEFAULT_VOLUME = 1.0;
resolve(DEFAULT_VOLUME);
};
});
}

function VolumeManager() {
this.VOLUME_KEY = 'defaultAlarmVolume';
this.DEFAULT_VOLUME = 1.0;
Expand All @@ -44,16 +64,6 @@ define(function(require) {
navigator.mozSettings.addObserver(
VOLUME_SETTING,
this.onSystemAlarmVolumeChange.bind(this));

// Asynchronously load the alarm volume from mozSettings.
var lock = navigator.mozSettings.createLock();
var req = lock.get(VOLUME_SETTING);
req.onsuccess = function() {
var volume = systemVolumeToFloat(req.result[VOLUME_SETTING]);
if (isValidVolume(volume)) {
this._volume = volume; // Do not use the setter here.
}
}.bind(this);
}
}

Expand Down Expand Up @@ -174,6 +184,9 @@ define(function(require) {
getAlarmVolume: function() {
return globalVolumeManager.volume;
},
requestAlarmVolume: function() {
return requestAlarmSystemVolume();
},
setAlarmVolume: function(volume, cb) {
globalVolumeManager.setVolume(volume, cb);
},
Expand Down
5 changes: 4 additions & 1 deletion apps/clock/js/panels/alarm_edit/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ Utils.extend(AlarmEdit.prototype, {
// to be "undefined" rather than "".
this.element.dataset.id = this.alarm.id || '';
this.inputs.name.value = this.alarm.label;
this.inputs.volume.value = AudioManager.getAlarmVolume();

AudioManager.requestAlarmVolume().then(function(volume) {
this.inputs.volume.value = AudioManager.getAlarmVolume();
}.bind(this));

// Init time, repeat, sound, snooze selection menu.
this.initTimeSelect();
Expand Down

0 comments on commit c6836ff

Please sign in to comment.