small code cleanup and added components/ folder for reusable code
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Io
|
||||
import "../../config" as Cfg
|
||||
import "../../components"
|
||||
|
||||
PanelWindow {
|
||||
id: root
|
||||
@@ -17,46 +17,12 @@ PanelWindow {
|
||||
WlrLayershell.exclusiveZone: -1
|
||||
mask: Region {}
|
||||
|
||||
readonly property string tz: Cfg.Config.timezone || ""
|
||||
|
||||
property int tzOffsetMin: 0
|
||||
TimezoneProvider { id: timezone }
|
||||
|
||||
property string fullDateString: ""
|
||||
property int typedChars: 0
|
||||
property string secondsString: ""
|
||||
|
||||
onTzOffsetMinChanged: {
|
||||
updateDate(new Date())
|
||||
}
|
||||
|
||||
Process {
|
||||
id: tzProc
|
||||
command: ["bash", "-c", "TZ=" + (root.tz || "UTC") + " date +%z"]
|
||||
running: root.tz !== ""
|
||||
stdout: SplitParser {
|
||||
onRead: data => {
|
||||
var s = data.trim()
|
||||
if (s.length < 5) return
|
||||
var sign = (s[0] === "-") ? -1 : 1
|
||||
var h = parseInt(s.substring(1, 3), 10)
|
||||
var m = parseInt(s.substring(3, 5), 10)
|
||||
root.tzOffsetMin = sign * (h * 60 + m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 1800000; running: root.tz !== ""; repeat: true
|
||||
onTriggered: tzProc.running = true
|
||||
}
|
||||
|
||||
function toTz(date) {
|
||||
if (!tz) return date
|
||||
return new Date(date.getTime()
|
||||
+ date.getTimezoneOffset() * 60000
|
||||
+ root.tzOffsetMin * 60000)
|
||||
}
|
||||
|
||||
function startTyping() {
|
||||
typedChars = 0
|
||||
secondsText.opacity = 0
|
||||
@@ -65,14 +31,14 @@ PanelWindow {
|
||||
|
||||
function updateDate(d) {
|
||||
let now = d || new Date()
|
||||
fullDateString = toTz(now).toLocaleDateString(Qt.locale(),
|
||||
fullDateString = timezone.toTz(now).toLocaleDateString(Qt.locale(),
|
||||
Cfg.Config.dateFormat === "DMY" ? "dddd, d MMMM yyyy" : "dddd, MMMM d, yyyy")
|
||||
startTyping()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
let d = new Date()
|
||||
secondsString = Qt.formatTime(toTz(d), "hh:mm:ss")
|
||||
secondsString = Qt.formatTime(timezone.toTz(d), "hh:mm:ss")
|
||||
updateDate(d)
|
||||
}
|
||||
|
||||
@@ -140,7 +106,7 @@ PanelWindow {
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
let d = new Date()
|
||||
let tzd = toTz(d)
|
||||
let tzd = timezone.toTz(d)
|
||||
secondsString = Qt.formatTime(tzd, "hh:mm:ss")
|
||||
if (tzd.getHours() === 0 && tzd.getMinutes() === 0 && tzd.getSeconds() === 0)
|
||||
updateDate(d)
|
||||
|
||||
Reference in New Issue
Block a user