diff --git a/Helpers/Duration.js b/Helpers/Duration.js deleted file mode 100644 index 6402051..0000000 --- a/Helpers/Duration.js +++ /dev/null @@ -1,18 +0,0 @@ -// Use to display the time remaining on the Battery widget -function formatVagueHumanReadableDuration(totalSeconds) { - const hours = Math.floor(totalSeconds / 3600); - const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60); - const seconds = totalSeconds - (hours * 3600) - (minutes * 60); - - var str = ""; - if (hours) { - str += hours.toString() + "h"; - } - if (minutes) { - str += minutes.toString() + "m"; - } - if (!hours && !minutes) { - str += seconds.toString() + "s"; - } - return str; -} \ No newline at end of file diff --git a/Modules/Bar/Battery.qml b/Modules/Bar/Battery.qml index b278e71..ac21dcc 100644 --- a/Modules/Bar/Battery.qml +++ b/Modules/Bar/Battery.qml @@ -4,7 +4,6 @@ import Quickshell.Services.UPower import QtQuick.Layouts import qs.Services import qs.Widgets -import "../../Helpers/Duration.js" as Duration NPill { id: root @@ -58,16 +57,22 @@ NPill { textColor: charging ? Colors.accentPrimary : Colors.textPrimary tooltipText: { let lines = [] + + if (testMode) { + lines.push("Time left: " + Time.formatVagueHumanReadableDuration(1234567)) + return lines.join("\n"); + } + if (!root.isReady) { return "" } if (root.battery.timeToEmpty > 0) { - lines.push("Time left: " + Time.formatVagueHumanReadableTime(root.battery.timeToEmpty)) + lines.push("Time left: " + Time.formatVagueHumanReadableDuration(root.battery.timeToEmpty)) } if (root.battery.timeToFull > 0) { - lines.push("Time until full: " + Time.formatVagueHumanReadableTime(root.battery.timeToFull)) + lines.push("Time until full: " + Time.formatVagueHumanReadableDuration(root.battery.timeToFull)) } if (root.battery.changeRate !== undefined) { diff --git a/Services/Time.qml b/Services/Time.qml index 07650db..702e1b9 100644 --- a/Services/Time.qml +++ b/Services/Time.qml @@ -38,6 +38,26 @@ Singleton { + (Settings.data.location.reverseDayMonth ? `${month} ${day}${suffix} ${year}` : `${day}${suffix} ${month} ${year}`) } + // Format an easy to read approximate duration ex: 4h32m + // Used to display the time remaining on the Battery widget + function formatVagueHumanReadableDuration(totalSeconds) { + const hours = Math.floor(totalSeconds / 3600) + const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60) + const seconds = totalSeconds - (hours * 3600) - (minutes * 60) + + var str = "" + if (hours) { + str += hours.toString() + "h" + } + if (minutes) { + str += minutes.toString() + "m" + } + if (!hours && !minutes) { + str += seconds.toString() + "s" + } + return str + } + Timer { interval: 1000 repeat: true