From 999ae517c6544938a712422c9dd3cc210a319ebd Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 3 Sep 2013 14:10:56 -0400 Subject: [PATCH] controls: fix display of volume/position when values are unknown Like when mpd is stopped and you connect for the first time. --- main.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 5b05cee..208f996 100644 --- a/main.js +++ b/main.js @@ -356,20 +356,25 @@ function update_ui(state, cmd) { }); /* Update the status tab. */ - var time; - if ('time' in state) + var time, percent; + if ('time' in state) { // When stopped, there is no time field at all. time = state.time.split(':'); - else + percent = Math.floor((0.0 + time[0]) * 100 / (0.0 + time[1])); + } else { time = [0, 0]; + percent = 0; + } ui_mpc_seekcur.max = time[1]; ui_mpc_seekcur.value = time[0]; - percent = Math.floor((0.0 + time[0]) * 100 / (0.0 + time[1])); ui_mpc_seekcur.title = 'seekcur (' + percent + '%)'; ui_mpc_currtime.innerText = [pretty_time(time[0]), pretty_time(time[1]), percent + '%'].join(' / '); - ui_mpc_setvol.value = state.volume; - ui_mpc_setvol.title = 'setvol (' + state.volume + '%)'; + ui_mpc_setvol.title = 'setvol'; + if ('volume' in state) { + ui_mpc_setvol.value = state.volume; + ui_mpc_setvol.title += ' (' + state.volume + '%)'; + } [ 'consume', 'random', 'repeat', 'single', -- 2.39.5