Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@
# 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.
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
+
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
+
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
+ }
+
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/omamobile-omarchy/test/lock-glance
Original file line number Diff line number Diff line change
Expand Up @@ -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"
70 changes: 68 additions & 2 deletions packages/omamobile-omarchy/test/lock-glance.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-omarchy/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.17
0.1.18