Skip to content

Commit

Permalink
improve sound volume test function to check new volume without saving
Browse files Browse the repository at this point in the history
  • Loading branch information
rand256 committed Nov 28, 2019
1 parent 330a826 commit c4dd261
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions client/settings-sound-voice.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,30 @@

function handleSoundVolumeSettingsTestButton() {
loadingBarSettingsSoundVolume.setAttribute("indeterminate", "indeterminate");
fn.prequest("api/test_sound_volume", "PUT")
.then(null, (err) => fn.notificationToastError(err))
let currentVolume = 0;
fn.prequest("api/get_sound_volume", "GET")
.then(res => { currentVolume = res; })
.then(res => {
if (currentVolume !== +soundVolumeInputVolume.value) {
return fn.prequestWithPayload("api/set_sound_volume", JSON.stringify({
volume: soundVolumeInputVolume.value
}), "PUT");
} else {
return true;
}
})
.then(res => fn.prequest("api/test_sound_volume", "PUT"))
.then(res => { return new Promise((resolve,reject) => setTimeout(() => resolve(),1e3)); })
.then(res => {
if (currentVolume !== +soundVolumeInputVolume.value) {
return fn.prequestWithPayload("api/set_sound_volume", JSON.stringify({
volume: currentVolume
}), "PUT");
} else {
return true;
}
})
.catch((err) => fn.notificationToastError(err))
.finally(() => loadingBarSettingsSoundVolume.removeAttribute("indeterminate"));
};

Expand Down

0 comments on commit c4dd261

Please sign in to comment.