From e5636148cddc335ab91fba8dc51a1f3ddce8e75a Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Fri, 30 Oct 2026 14:06:05 -0400 Subject: [PATCH] omamobile-omarchy 0.1.18: the lock clock follows the bar's 12/24-hour setting On the Pixel 7 Pro the lock glance showed a 24-hour time while the phone bar and the home clock widget showed 12-hour. The bar's clockFormat in ~/.config/omarchy/shell.json is "ddd MMM d h:mm AP". Two faults: - The big glance time used the Qt format "h:mm". Qt counts "h" from 0 to 23 unless the same format has an AM/PM marker, so even with the bar's format read, 2 pm showed as "14:02". It is now built from the hour (h % 12 || 12, with minutes) and still leaves AM/PM out. The small clock over the PIN view keeps "h:mm AP". - shell.json was only read while the glance was active (path gated on the keypad toggle) and asynchronously. A failed read, such as Omarchy replacing the file, cleared the format, and the fallback was the session's Qt locale, which is C/POSIX for the shell and so 24-hour. It is now read at once (blockLoading, a small file), whatever the lock shows, again on every change and whenever the glance comes back. A read that fails or catches a half-written file keeps the last format. The 12/24-hour rule stays the one the bar and the home clock use (omamobile-shell HomeModel.systemTimeFormat): quoted literals ignored, an AM/PM marker or "h" without "H" means 12-hour. Without a clockFormat the lock now follows the bar's own default, HH:mm, so all three still agree; it no longer falls back to the Qt locale. Patch 0023 is revised in place, as #181 did after #176. Tests (test/lock-glance, now under LC_ALL=C as the shell runs): - the maintainer's format is 12-hour before the glance is active, with a 1-12 big time without AM/PM and a small clock with it; - a half-written or missing shell.json keeps the last format; - HH:mm and no clockFormat are 24-hour; - the rule (twelveHour, quoted literals), glanceTime at 14:02, 00:05, 12:30 and 9:41, and barClockFormat's parse. The FileView stand-in now reads at once with blockLoading, as Quickshell does. test/all and tools/pr-check pass, and the series applies with --fuzz=0 to the real aarch64 Omarchy 4.0.6-1 (20 applied). Co-Authored-By: Claude Opus 5.5 --- ...a-glance-view-for-touch-only-devices.patch | 82 +++++++++++++------ packages/omamobile-omarchy/test/lock-glance | 2 + .../omamobile-omarchy/test/lock-glance.qml | 70 +++++++++++++++- .../test/qml-stubs/Quickshell/Io/FileView.qml | 6 +- packages/omamobile-omarchy/version | 2 +- 5 files changed, 133 insertions(+), 29 deletions(-) diff --git a/packages/omamobile-omarchy/patches/0023-lock-a-glance-view-for-touch-only-devices.patch b/packages/omamobile-omarchy/patches/0023-lock-a-glance-view-for-touch-only-devices.patch index 63b08c33a..8f08ea8b7 100644 --- a/packages/omamobile-omarchy/patches/0023-lock-a-glance-view-for-touch-only-devices.patch +++ b/packages/omamobile-omarchy/patches/0023-lock-a-glance-view-for-touch-only-devices.patch @@ -39,8 +39,13 @@ # read" instead of the text. Weather comes from # ~/.local/state/omamobile/weather.json, written by the phone shell's # omamobile-weather service, and is hidden when absent or over 3 h old; the -# lock makes no network calls. The clock follows the bar's clockFormat (shell.json), else -# the locale. On a computer the lock is unchanged. +# lock makes no network calls. The clock is 12- or 24-hour as the phone bar +# and the home screen's clock decide, from the bar's clockFormat (shell.json, +# read at once whatever the lock shows, on every change and whenever the +# glance comes back; a failed read keeps the last), else the bar's default +# (HH:mm), never the session's C/POSIX locale. The big glance time is built +# without AM/PM (Qt's "h" without a marker counts to 23), the small clock +# over the PIN view keeps it. On a computer the lock is unchanged. # # Against Omarchy 4.0.6 (edge 4.0.6-1), after 0003, 0009, 0011, 0014, 0017 # and 0019. @@ -48,7 +53,7 @@ diff --git i/shell/plugins/lock/LockGlance.js w/shell/plugins/lock/LockGlance.js new file mode 100644 --- /dev/null +++ w/shell/plugins/lock/LockGlance.js -@@ -0,0 +1,139 @@ +@@ -0,0 +1,164 @@ +.pragma library +.import "../notifications/NotificationLogic.js" as NotificationLogic + @@ -68,19 +73,44 @@ new file mode 100644 +// A weather reading older than this is not shown. +var WEATHER_MAX_AGE_MS = 3 * 60 * 60 * 1000 + -+// The phone bar's clockFormat (shell.json bar.clockFormat), as the home -+// screen's clock reads it: quoted literals ignored, an AM/PM marker or "h" -+// without "H" means 12-hour. Without one, the locale's short time format. -+function twelveHour(barFormat, localeFormat) { -+ var f = String(barFormat || "").replace(/'[^']*'/g, "") -+ if (!f) f = String(localeFormat || "").replace(/'[^']*'/g, "") ++// The bar's own default time format (omamobile-shell's bar, without a ++// clockFormat): the lock's clock agrees with it. ++var BAR_DEFAULT_FORMAT = "HH:mm" ++ ++// 12- or 24-hour, decided as the phone bar and the home screen's clock decide ++// (omamobile-shell, HomeModel.systemTimeFormat) from the bar's clockFormat ++// (shell.json bar.clockFormat): quoted literals ignored, an AM/PM marker or ++// "h" without "H" means 12-hour. Without one, the bar's default (24-hour), ++// never the session's Qt locale, which is C/POSIX for the shell. ++function twelveHour(barFormat) { ++ var f = String(barFormat || BAR_DEFAULT_FORMAT).replace(/'[^']*'/g, "") + return /a/i.test(f) || (/h/.test(f) && !/H/.test(f)) +} + -+// The large glance time leaves AM/PM out; the small clock over the PIN -+// view keeps it. -+function timeFormat(twelve, withMarker) { -+ return twelve ? (withMarker ? "h:mm AP" : "h:mm") : "HH:mm" ++// The bar's clockFormat from shell.json's text: "" when it has none, null ++// when the text can't be read (a write caught half done), which keeps the ++// last one. ++function barClockFormat(text) { ++ var shell ++ try { shell = JSON.parse(String(text || "")) } catch (e) { return null } ++ if (!shell || typeof shell !== "object") return null ++ return shell.bar && shell.bar.clockFormat ? String(shell.bar.clockFormat) : "" ++} ++ ++// The small clock over the PIN view: a Qt format, with AM/PM in 12-hour. ++function timeFormat(twelve) { ++ return twelve ? "h:mm AP" : "HH:mm" ++} ++ ++// The large glance time, without AM/PM. Built here, not as the Qt format ++// "h:mm": without an AM/PM marker in the same format Qt counts "h" from 0 ++// to 23, so a 12-hour bar got a 24-hour lock ("14:02"). ++function glanceTime(date, twelve) { ++ var d = date instanceof Date ? date : new Date(date) ++ var h = d.getHours() ++ var mm = (d.getMinutes() < 10 ? "0" : "") + d.getMinutes() ++ if (twelve) return (h % 12 || 12) + ":" + mm ++ return (h < 10 ? "0" : "") + h + ":" + mm +} + +function age(timestamp, now) { @@ -192,7 +222,7 @@ diff --git i/shell/plugins/lock/LockGlance.qml w/shell/plugins/lock/LockGlance.q new file mode 100644 --- /dev/null +++ w/shell/plugins/lock/LockGlance.qml -@@ -0,0 +1,624 @@ +@@ -0,0 +1,628 @@ +import QtQuick +import Quickshell +import Quickshell.Io @@ -217,7 +247,8 @@ new file mode 100644 +// clock format and the home screen's last weather reading. Nothing here +// acts on a notification or asks the network. +// -+// On a computer (keypad off) it shows nothing and reads nothing. ++// On a computer (keypad off) it shows nothing and reads nothing but the ++// bar's clock format. +Item { + id: glance + @@ -242,7 +273,7 @@ new file mode 100644 + property string notificationsRaw: "" + property string weatherRaw: "" + readonly property double now: clock.date.getTime() -+ readonly property bool twelveHour: Glance.twelveHour(barClockFormat, Qt.locale().timeFormat(Locale.ShortFormat)) ++ readonly property bool twelveHour: Glance.twelveHour(barClockFormat) + // Swiped away: hidden at once by file name, until a read no longer finds + // the file (the service's forget runs on its file queue), as the shade + // does. A mark the files still show after 15 s lapses (a forget that never @@ -275,6 +306,7 @@ new file mode 100644 + if (!active || (lock && lock.authenticatingPassword)) return + shown = true + expanded = ({}) ++ shellFile.reload() + if (lock.passwordText.length > 0) lock.passwordTextEdited("") + noteActivity() + refresh() @@ -528,16 +560,18 @@ new file mode 100644 + } + + FileView { -+ path: glance.active ? glance.home + "/.config/omarchy/shell.json" : "" ++ // The bar's clock format, read whatever the lock shows, at once (a small ++ // file), again on every change and each time the glance comes back. A ++ // read that fails (shell.json being replaced) keeps the last format. ++ id: shellFile ++ path: glance.home + "/.config/omarchy/shell.json" ++ blockLoading: true + watchChanges: true + printErrors: false + onLoaded: { -+ try { -+ var shell = JSON.parse(text() || "{}") -+ glance.barClockFormat = shell.bar && shell.bar.clockFormat ? String(shell.bar.clockFormat) : "" -+ } catch (e) { glance.barClockFormat = "" } ++ var format = Glance.barClockFormat(text()) ++ if (format !== null) glance.barClockFormat = format + } -+ onLoadFailed: glance.barClockFormat = "" + onFileChanged: reload() + } + @@ -552,7 +586,7 @@ new file mode 100644 + y: Math.max(Style.space(24), glance.pinTop - Style.space(22) - height) + visible: glance.progress < 1 + opacity: 1 - glance.progress -+ text: Qt.formatDateTime(clock.date, Glance.timeFormat(glance.twelveHour, true)) ++ text: Qt.formatDateTime(clock.date, Glance.timeFormat(glance.twelveHour)) + color: Commons.Color.lock.text + font.family: Style.font.family + font.pixelSize: Style.font.display @@ -589,7 +623,7 @@ new file mode 100644 + width: parent.width + horizontalAlignment: Text.AlignHCenter + textFormat: Text.PlainText -+ text: Qt.formatDateTime(clock.date, Glance.timeFormat(glance.twelveHour, false)) ++ text: Glance.glanceTime(clock.date, glance.twelveHour) + color: Commons.Color.lock.text + font.family: Style.font.family + font.weight: Font.Light diff --git a/packages/omamobile-omarchy/test/lock-glance b/packages/omamobile-omarchy/test/lock-glance index 945a1b9e5..a1e5b71cc 100755 --- a/packages/omamobile-omarchy/test/lock-glance +++ b/packages/omamobile-omarchy/test/lock-glance @@ -23,4 +23,6 @@ printf '.pragma library\nvar HOME = "%s"\n' "$work/home" > "$work/TestEnv.js" export QT_QPA_PLATFORM=offscreen QT_QUICK_BACKEND=software QML_DISABLE_DISK_CACHE=1 export QML_XHR_ALLOW_FILE_READ=1 +# The shell runs under the C/POSIX locale on the phone; so does the test. +export LC_ALL=C LANG=C exec "$runner" -import "$here/qml-stubs" -import "$work" -input "$work/tst_lock_glance.qml" diff --git a/packages/omamobile-omarchy/test/lock-glance.qml b/packages/omamobile-omarchy/test/lock-glance.qml index 5d51f97d8..6324137ce 100644 --- a/packages/omamobile-omarchy/test/lock-glance.qml +++ b/packages/omamobile-omarchy/test/lock-glance.qml @@ -8,6 +8,7 @@ import QtQuick import QtTest import Quickshell import "plugins/lock" +import "plugins/lock/LockGlance.js" as Glance import "TestEnv.js" as TestEnv Item { @@ -552,14 +553,79 @@ Item { function test_clock_follows_bar_format() { writeFile(".config/omarchy/shell.json", JSON.stringify({ bar: { clockFormat: "h:mm AP" } })) settle() - verify(/^\d{1,2}:\d\d$/.test(one("lockGlanceTime").text), one("lockGlanceTime").text) - verify(/^\d{1,2}:\d\d (AM|PM)$/i.test(one("lockPinClock").text), one("lockPinClock").text) + verify(/^([1-9]|1[0-2]):\d\d$/.test(one("lockGlanceTime").text), one("lockGlanceTime").text) + verify(/^([1-9]|1[0-2]):\d\d (AM|PM)$/i.test(one("lockPinClock").text), one("lockPinClock").text) writeFile(".config/omarchy/shell.json", JSON.stringify({ bar: { clockFormat: "HH:mm" } })) settle() verify(/^\d\d:\d\d$/.test(one("lockGlanceTime").text), one("lockGlanceTime").text) verify(/^\d\d:\d\d$/.test(one("lockPinClock").text), one("lockPinClock").text) } + // The maintainer's bar: a day, a date and a 12-hour time. The lock reads + // it at once, whether or not the glance is up yet (keypad off here, as + // before the lock-keypad toggle is read), and the session's locale (C, + // test/lock-glance) has no say. + function test_the_bars_12_hour_format_before_the_glance_is_up() { + compare(Qt.locale().name, "C", "the test runs under the C locale, as the shell does") + writeFile(".config/omarchy/shell.json", JSON.stringify({ version: 1, bar: { position: "top", clockFormat: "ddd MMM d h:mm AP" } })) + var view = createTemporaryObject(lockComponent, harness, { keypad: false }) + var g = findAll(view, function(i) { return i.objectName === "lockGlanceView" })[0].parent + compare(g.active, false) + compare(g.twelveHour, true, "12-hour from the bar's format, before the glance is up") + view.keypad = true + compare(g.twelveHour, true) + var pin = findAll(view, function(i) { return i.objectName === "lockPinClock" })[0] + var big = findAll(view, function(i) { return i.objectName === "lockGlanceTime" })[0] + verify(/^\d{1,2}:\d\d (AM|PM)$/i.test(pin.text), "the small clock keeps AM/PM: " + pin.text) + verify(/^([1-9]|1[0-2]):\d\d$/.test(big.text), "the big time is 12-hour without AM/PM: " + big.text) + } + + function test_a_failed_read_keeps_the_format() { + writeFile(".config/omarchy/shell.json", JSON.stringify({ bar: { clockFormat: "h:mm AP" } })) + settle() + compare(glance().twelveHour, true) + writeFile(".config/omarchy/shell.json", "{\"bar\": {\"clockF") + settle() + compare(glance().twelveHour, true, "a half-written file keeps the last format") + writeFile(".config/omarchy/shell.json", "") + settle() + compare(glance().twelveHour, true, "a file being replaced keeps the last format") + writeFile(".config/omarchy/shell.json", JSON.stringify({ bar: { clockFormat: "HH:mm" } })) + settle() + compare(glance().twelveHour, false) + } + + // The same 12/24-hour rule as the bar and the home clock + // (HomeModel.systemTimeFormat in omamobile-shell), and a big time that is + // really 12-hour. + function test_the_rule_and_the_big_time() { + verify(Glance.twelveHour("ddd MMM d h:mm AP")) + verify(Glance.twelveHour("hh:mm")) + verify(Glance.twelveHour("h:mm ap")) + verify(!Glance.twelveHour("HH:mm")) + verify(!Glance.twelveHour("'h' HH:mm"), "quoted literals don't count") + verify(!Glance.twelveHour(""), "no format: the bar's default, HH:mm") + compare(Glance.timeFormat(true), "h:mm AP") + compare(Glance.timeFormat(false), "HH:mm") + compare(Glance.glanceTime(new Date(2026, 9, 30, 14, 2), true), "2:02") + compare(Glance.glanceTime(new Date(2026, 9, 30, 0, 5), true), "12:05") + compare(Glance.glanceTime(new Date(2026, 9, 30, 12, 30), true), "12:30") + compare(Glance.glanceTime(new Date(2026, 9, 30, 9, 41), true), "9:41") + compare(Glance.glanceTime(new Date(2026, 9, 30, 14, 2), false), "14:02") + compare(Glance.glanceTime(new Date(2026, 9, 30, 0, 5), false), "00:05") + compare(Glance.barClockFormat('{"bar": {"clockFormat": "h:mm AP"}}'), "h:mm AP") + compare(Glance.barClockFormat('{"bar": {}}'), "") + compare(Glance.barClockFormat('{"bar": {"clo'), null) + } + + // No clockFormat: the bar shows its default, HH:mm, and so does the lock. + function test_no_bar_format_is_the_bars_default() { + writeFile(".config/omarchy/shell.json", JSON.stringify({ version: 1, bar: { position: "top" } })) + settle() + compare(glance().twelveHour, false) + verify(/^\d\d:\d\d$/.test(one("lockPinClock").text), one("lockPinClock").text) + } + function test_password_first_reveals_the_field() { writeFile(".local/state/omarchy/toggles/credential-password", "1\n") settle() diff --git a/packages/omamobile-omarchy/test/qml-stubs/Quickshell/Io/FileView.qml b/packages/omamobile-omarchy/test/qml-stubs/Quickshell/Io/FileView.qml index f0379519e..211d94cbc 100644 --- a/packages/omamobile-omarchy/test/qml-stubs/Quickshell/Io/FileView.qml +++ b/packages/omamobile-omarchy/test/qml-stubs/Quickshell/Io/FileView.qml @@ -40,8 +40,10 @@ QtObject { } } - onPathChanged: Qt.callLater(reload) - Component.onCompleted: Qt.callLater(reload) + // blockLoading reads at once, as Quickshell's does; otherwise a moment later. + property bool ready: false + onPathChanged: if (ready) { if (blockLoading) reload(); else Qt.callLater(reload) } + Component.onCompleted: { ready = true; if (blockLoading) reload(); else Qt.callLater(reload) } property Connections watcher: Connections { target: Quickshell diff --git a/packages/omamobile-omarchy/version b/packages/omamobile-omarchy/version index 04c5555c6..f8bc4c625 100644 --- a/packages/omamobile-omarchy/version +++ b/packages/omamobile-omarchy/version @@ -1 +1 @@ -0.1.17 +0.1.18