From c221f7cdb6284f4038764cf5ac4bb70089f6e57a Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 20 Nov 2020 22:41:33 +0100 Subject: [PATCH] Do not show hours when duration is shorter #14 --- clapper_src/controls.js | 9 +++++---- clapper_src/misc.js | 13 +++++++++---- clapper_src/widget.js | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/clapper_src/controls.js b/clapper_src/controls.js index 9445c56a..85c1f4a8 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -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); } diff --git a/clapper_src/misc.js b/clapper_src/misc.js index cfa1e8ff..0d6605da 100644 --- a/clapper_src/misc.js +++ b/clapper_src/misc.js @@ -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); - time -= hours * 3600; + 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}`; } diff --git a/clapper_src/widget.js b/clapper_src/widget.js index 270ac753..7a26401a 100644 --- a/clapper_src/widget.js +++ b/clapper_src/widget.js @@ -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(); }