Time: improved human readable time + fixed a few tooltips.
This commit is contained in:
parent
85d94aca01
commit
8426e36f46
4 changed files with 27 additions and 31 deletions
|
|
@ -78,23 +78,31 @@ Singleton {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format an easy to read approximate duration ex: 4h32m
|
// Format an easy to read approximate duration ex: 4h32m
|
||||||
// Used to display the time remaining on the Battery widget
|
// Used to display the time remaining on the Battery widget, computer uptime, etc..
|
||||||
function formatVagueHumanReadableDuration(totalSeconds) {
|
function formatVagueHumanReadableDuration(totalSeconds) {
|
||||||
const hours = Math.floor(totalSeconds / 3600)
|
if (typeof totalSeconds !== 'number' || totalSeconds < 0) {
|
||||||
const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60)
|
return '0s';
|
||||||
const seconds = totalSeconds - (hours * 3600) - (minutes * 60)
|
}
|
||||||
|
|
||||||
var str = ""
|
// Floor the input to handle decimal seconds
|
||||||
if (hours) {
|
totalSeconds = Math.floor(totalSeconds);
|
||||||
str += hours.toString() + "h"
|
|
||||||
}
|
const days = Math.floor(totalSeconds / 86400);
|
||||||
if (minutes) {
|
const hours = Math.floor((totalSeconds % 86400) / 3600);
|
||||||
str += minutes.toString() + "m"
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
}
|
const seconds = totalSeconds % 60;
|
||||||
|
|
||||||
|
const parts = [];
|
||||||
|
if (days) parts.push(`${days}d`);
|
||||||
|
if (hours) parts.push(`${hours}h`);
|
||||||
|
if (minutes) parts.push(`${minutes}m`);
|
||||||
|
|
||||||
|
// Only show seconds if no hours and no minutes
|
||||||
if (!hours && !minutes) {
|
if (!hours && !minutes) {
|
||||||
str += seconds.toString() + "s"
|
parts.push(`${seconds}s`);
|
||||||
}
|
}
|
||||||
return str
|
|
||||||
|
return parts.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ NIconButton {
|
||||||
colorBorderHover: Color.transparent
|
colorBorderHover: Color.transparent
|
||||||
|
|
||||||
icon: Settings.data.nightLight.enabled ? "bedtime" : "bedtime_off"
|
icon: Settings.data.nightLight.enabled ? "bedtime" : "bedtime_off"
|
||||||
tooltipText: `Night light: ${Settings.data.nightLight.enabled ? "enabled" : "disabled"}\nLeft click to toggle.\nRight click to access settings.`
|
tooltipText: `Night light: ${Settings.data.nightLight.enabled ? "enabled." : "disabled"}\nLeft click to toggle.\nRight click to access settings.`
|
||||||
onClicked: Settings.data.nightLight.enabled = !Settings.data.nightLight.enabled
|
onClicked: Settings.data.nightLight.enabled = !Settings.data.nightLight.enabled
|
||||||
|
|
||||||
onRightClicked: {
|
onRightClicked: {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ NIconButton {
|
||||||
property real scaling: 1.0
|
property real scaling: 1.0
|
||||||
|
|
||||||
icon: Settings.data.bar.useDistroLogo ? "" : "widgets"
|
icon: Settings.data.bar.useDistroLogo ? "" : "widgets"
|
||||||
tooltipText: "Open side panel"
|
tooltipText: "Open side panel."
|
||||||
sizeRatio: 0.8
|
sizeRatio: 0.8
|
||||||
|
|
||||||
colorBg: Color.mSurfaceVariant
|
colorBg: Color.mSurfaceVariant
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ NBox {
|
||||||
}
|
}
|
||||||
NIconButton {
|
NIconButton {
|
||||||
icon: "settings"
|
icon: "settings"
|
||||||
tooltipText: "Open settings"
|
tooltipText: "Open settings."
|
||||||
onClicked: {
|
onClicked: {
|
||||||
settingsPanel.requestedTab = SettingsPanel.Tab.General
|
settingsPanel.requestedTab = SettingsPanel.Tab.General
|
||||||
settingsPanel.open(screen)
|
settingsPanel.open(screen)
|
||||||
|
|
@ -69,7 +69,7 @@ NBox {
|
||||||
NIconButton {
|
NIconButton {
|
||||||
id: powerButton
|
id: powerButton
|
||||||
icon: "power_settings_new"
|
icon: "power_settings_new"
|
||||||
tooltipText: "Power menu"
|
tooltipText: "Power menu."
|
||||||
onClicked: {
|
onClicked: {
|
||||||
powerPanel.open(screen)
|
powerPanel.open(screen)
|
||||||
sidePanel.close()
|
sidePanel.close()
|
||||||
|
|
@ -79,7 +79,7 @@ NBox {
|
||||||
NIconButton {
|
NIconButton {
|
||||||
id: closeButton
|
id: closeButton
|
||||||
icon: "close"
|
icon: "close"
|
||||||
tooltipText: "Close side panel"
|
tooltipText: "Close side panel."
|
||||||
onClicked: {
|
onClicked: {
|
||||||
sidePanel.close()
|
sidePanel.close()
|
||||||
}
|
}
|
||||||
|
|
@ -104,19 +104,7 @@ NBox {
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
var uptimeSeconds = parseFloat(this.text.trim().split(' ')[0])
|
var uptimeSeconds = parseFloat(this.text.trim().split(' ')[0])
|
||||||
var minutes = Math.floor(uptimeSeconds / 60) % 60
|
uptimeText = Time.formatVagueHumanReadableDuration(uptimeSeconds)
|
||||||
var hours = Math.floor(uptimeSeconds / 3600) % 24
|
|
||||||
var days = Math.floor(uptimeSeconds / 86400)
|
|
||||||
|
|
||||||
// Format the output
|
|
||||||
if (days > 0) {
|
|
||||||
uptimeText = days + "d " + hours + "h"
|
|
||||||
} else if (hours > 0) {
|
|
||||||
uptimeText = hours + "h" + minutes + "m"
|
|
||||||
} else {
|
|
||||||
uptimeText = minutes + "m"
|
|
||||||
}
|
|
||||||
|
|
||||||
uptimeProcess.running = false
|
uptimeProcess.running = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue