add time second precision config option

This commit is contained in:
end-4
2025-10-05 20:14:57 +02:00
parent f99c390a76
commit 96ed90e2cc
2 changed files with 23 additions and 16 deletions
@@ -373,6 +373,7 @@ Singleton {
property int focus: 1500 property int focus: 1500
property int longBreak: 900 property int longBreak: 900
} }
property bool secondPrecision: false
} }
property JsonObject wallpaperSelector: JsonObject { property JsonObject wallpaperSelector: JsonObject {
+22 -16
View File
@@ -1,10 +1,10 @@
pragma Singleton
pragma ComponentBehavior: Bound
import qs import qs
import qs.modules.common import qs.modules.common
import QtQuick import QtQuick
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
pragma Singleton
pragma ComponentBehavior: Bound
/** /**
* A nice wrapper for date and time strings. * A nice wrapper for date and time strings.
@@ -12,7 +12,11 @@ pragma ComponentBehavior: Bound
Singleton { Singleton {
property var clock: SystemClock { property var clock: SystemClock {
id: clock id: clock
precision: GlobalStates.screenLocked ? SystemClock.Seconds : SystemClock.Minutes // Hack to ensure clock is correct after waking up from suspend precision: {
if (Config.options.time.secondPrecision || GlobalStates.screenLocked)
return SystemClock.Seconds;
return SystemClock.Minutes;
}
} }
property string time: Qt.locale().toString(clock.date, Config.options?.time.format ?? "hh:mm") property string time: Qt.locale().toString(clock.date, Config.options?.time.format ?? "hh:mm")
property string shortDate: Qt.locale().toString(clock.date, Config.options?.time.shortDateFormat ?? "dd/MM") property string shortDate: Qt.locale().toString(clock.date, Config.options?.time.shortDateFormat ?? "dd/MM")
@@ -25,22 +29,25 @@ Singleton {
running: true running: true
repeat: true repeat: true
onTriggered: { onTriggered: {
fileUptime.reload() fileUptime.reload();
const textUptime = fileUptime.text() const textUptime = fileUptime.text();
const uptimeSeconds = Number(textUptime.split(" ")[0] ?? 0) const uptimeSeconds = Number(textUptime.split(" ")[0] ?? 0);
// Convert seconds to days, hours, and minutes // Convert seconds to days, hours, and minutes
const days = Math.floor(uptimeSeconds / 86400) const days = Math.floor(uptimeSeconds / 86400);
const hours = Math.floor((uptimeSeconds % 86400) / 3600) const hours = Math.floor((uptimeSeconds % 86400) / 3600);
const minutes = Math.floor((uptimeSeconds % 3600) / 60) const minutes = Math.floor((uptimeSeconds % 3600) / 60);
// Build the formatted uptime string // Build the formatted uptime string
let formatted = "" let formatted = "";
if (days > 0) formatted += `${days}d` if (days > 0)
if (hours > 0) formatted += `${formatted ? ", " : ""}${hours}h` formatted += `${days}d`;
if (minutes > 0 || !formatted) formatted += `${formatted ? ", " : ""}${minutes}m` if (hours > 0)
uptime = formatted formatted += `${formatted ? ", " : ""}${hours}h`;
interval = Config.options?.resources?.updateInterval ?? 3000 if (minutes > 0 || !formatted)
formatted += `${formatted ? ", " : ""}${minutes}m`;
uptime = formatted;
interval = Config.options?.resources?.updateInterval ?? 3000;
} }
} }
@@ -49,5 +56,4 @@ Singleton {
path: "/proc/uptime" path: "/proc/uptime"
} }
} }