Do not show hours when duration is shorter #14

This commit is contained in:
Rafostar
2020-11-20 22:41:33 +01:00
parent 7ccd6ad424
commit c221f7cdb6
3 changed files with 17 additions and 9 deletions

View File

@@ -27,8 +27,9 @@ class ClapperControls extends Gtk.Box
this.currentDuration = 0;
this.isPositionDragging = false;
this.durationFormated = '00:00:00';
this.elapsedInitial = '00:00:00/00:00:00';
this.showHours = false;
this.durationFormatted = '00:00';
this.elapsedInitial = '00:00/00:00';
this.buttonsArr = [];
this._addTogglePlayButton();
@@ -98,8 +99,8 @@ class ClapperControls extends Gtk.Box
{
value = value || 0;
let elapsed = Misc.getFormatedTime(value)
+ '/' + this.durationFormated;
let elapsed = Misc.getFormattedTime(value, this.showHours)
+ '/' + this.durationFormatted;
this.elapsedButton.set_label(elapsed);
}

View File

@@ -68,13 +68,18 @@ function inhibitForState(state, window)
debug(`set prevent suspend to: ${isInhibited}`);
}
function getFormatedTime(time)
function getFormattedTime(time, showHours)
{
let hours = ('0' + Math.floor(time / 3600)).slice(-2);
let hours;
if(showHours || time >= 3600) {
hours = ('0' + Math.floor(time / 3600)).slice(-2);
time -= hours * 3600;
}
let minutes = ('0' + Math.floor(time / 60)).slice(-2);
time -= minutes * 60;
let seconds = ('0' + Math.floor(time)).slice(-2);
return `${hours}:${minutes}:${seconds}`;
let parsed = (hours) ? `${hours}:` : '';
return parsed + `${minutes}:${seconds}`;
}

View File

@@ -437,8 +437,10 @@ var Widget = GObject.registerClass({
return;
this.controls.currentDuration = duration;
this.controls.showHours = (duration >= 3600);
this.controls.positionAdjustment.set_upper(duration);
this.controls.durationFormated = Misc.getFormatedTime(duration);
this.controls.durationFormatted = Misc.getFormattedTime(duration);
this.controls.updateElapsedLabel();
}