diff --git a/packages/omamobile-shell/plugins/README.md b/packages/omamobile-shell/plugins/README.md index 5b554f985..6209a381d 100644 --- a/packages/omamobile-shell/plugins/README.md +++ b/packages/omamobile-shell/plugins/README.md @@ -79,7 +79,12 @@ service has no count to read through the host's proxy, so the bar watches the directory (`Qt.labs.folderlistmodel`, a file system watcher, not a poll). The shade records its mark in `~/.local/state/omamobile/notifications-seen` and calls `notificationsSeen` below. A toast that was acted on also lands in -history, so it counts until the shade has been opened. +history, so it counts until the shade has been opened. Omarchy 4.5 keeps the +history in one file instead, `~/.local/state/omarchy/notifications/history.json` +(a JSON array, each row's `ts` in seconds); while that file exists, the bar +counts its rows newer than the mark (`StatusModel.unreadStored`), watching +the file and re-reading it every 30 s, since the service replaces it with +rename(2). **Mobile network and calls:** the cellular icon and the call chip come from `omamobile-cell-watch` and `omamobile-call-watch --observe` (see @@ -169,7 +174,10 @@ history as toasts (`showHistory`) but returns none of it, so the shade reads the files the service keeps, `~/.local/state/omarchy/notifications/*.json` and `history/*.json` (format and rules in `NotificationsModel.js`, tests in `test/notifications-model.js`), when the sheet opens and every 3 s while it -is open. A tap on a row puts the sheet away and runs what a tap on the toast +is open. On Omarchy 4.5, which keeps them in `live.json` and `history.json` +in that directory instead (100 rows over 24 hours, `Store.js`), the shade +reads those two files whenever `history.json` exists, whatever the version +says; `test/notifications-store.sh` runs its commands on both layouts. A tap on a row puts the sheet away and runs what a tap on the toast runs: Omarchy's own action for its toasts (the `omarchy-exec-argv` hint the file keeps), otherwise `omarchy-hyprland-focus-app `. Other senders' live actions die with the toast, so they can't be run from history. @@ -177,6 +185,9 @@ live actions die with the toast, so they can't be run from history. **Clear all** (44 px, two taps: the first turns it into "Clear all?" for 4 s) calls the notification service on this shell instance, `dismissAll` (the toasts on screen move into history) and then `clear` (history is emptied). +Omarchy 4.5 has no `clear`: there, after `dismissAll`, the shade calls +`forget ` for every notification it read (patch 0019 for 4.5, in +omamobile-omarchy's 4.5 series; without it the rows come back). The card takes the room left under the sheet and scrolls past that; it hides in edit mode, or when the sheet leaves no room for it. diff --git a/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml b/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml index 8d82e0cb2..6bd395a12 100644 --- a/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml +++ b/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml @@ -127,6 +127,12 @@ Item { // FolderListModel's file system watcher rather than polled. The shade // writes its mark to notifications-seen and tells this bar by IPC. readonly property string notificationsHistory: Quickshell.env("HOME") + "/.local/state/omarchy/notifications/history" + // Omarchy 4.5 keeps the history in one file in the directory above, + // history.json (StatusModel.unreadStored); while it exists, it is what + // the count reads. The service replaces it with rename(2), which a watch + // can miss, so it is also re-read now and then. + readonly property string notificationsStore: Quickshell.env("HOME") + "/.local/state/omarchy/notifications/history.json" + property bool storeLayout: false property double seenStamp: 0 property int unread: 0 @@ -151,7 +157,23 @@ Item { function onDataChanged() { Qt.callLater(root.countUnread) } } + FileView { + id: historyStore + path: root.notificationsStore + printErrors: false + watchChanges: true + onFileChanged: reload() + onLoaded: { root.storeLayout = true; Qt.callLater(root.countUnread) } + onLoadFailed: { root.storeLayout = false; Qt.callLater(root.countUnread) } + } + + Timer { interval: 30000; repeat: true; running: root.storeLayout; onTriggered: historyStore.reload() } + function countUnread() { + if (storeLayout) { + unread = StatusModel.unreadStored(historyStore.text(), seenStamp) + return + } var names = [] for (var i = 0; i < historyFiles.count; i++) names.push(historyFiles.get(i, "fileName")) unread = StatusModel.unreadCount(names, seenStamp) @@ -160,6 +182,7 @@ Item { // The notification service makes the directory when it starts; if the // bar got there first, watch it again once it can exist. function rewatchHistory() { + historyStore.reload() if (historyFiles.count > 0) return historyFiles.folder = "" historyFiles.folder = "file://" + root.notificationsHistory diff --git a/packages/omamobile-shell/plugins/omamobile.bar/StatusModel.js b/packages/omamobile-shell/plugins/omamobile.bar/StatusModel.js index ec2ae710d..792817ed5 100644 --- a/packages/omamobile-shell/plugins/omamobile.bar/StatusModel.js +++ b/packages/omamobile-shell/plugins/omamobile.bar/StatusModel.js @@ -120,6 +120,22 @@ function unreadCount(names, seen) { return count } +// Omarchy 4.5 keeps its history in one file, history.json: a JSON array of +// rows, each with `ts`, when it arrived, in seconds. The shade's mark is in +// milliseconds, rounded as its NotificationsModel.storeEntry rounds them. +function unreadStored(text, seen) { + var rows = null + try { rows = JSON.parse(String(text === undefined || text === null ? "" : text)) } catch (error) { return 0 } + if (!Array.isArray(rows)) return 0 + var since = parseStamp(seen) + var count = 0 + for (var i = 0; i < rows.length; i++) { + var ts = rows[i] && typeof rows[i] === "object" ? Number(rows[i].ts) : 0 + if (isFinite(ts) && ts > 0 && Math.round(ts * 1000) > since) count++ + } + return count +} + function batteryIcon(percent, charging, full) { if (percent < 0) return "" if (full) return "󰁹" @@ -134,6 +150,6 @@ if (typeof module !== "undefined") { findDevice: findDevice, connectedNetwork: connectedNetwork, wifiIcon: wifiIcon, networkIcon: networkIcon, cellularIcon: cellularIcon, cellGlyph: cellGlyph, cellText: cellText, parseCell: parseCell, callChip: callChip, elapsed: elapsed, batteryIcon: batteryIcon, - stampOf: stampOf, parseStamp: parseStamp, unreadCount: unreadCount + stampOf: stampOf, parseStamp: parseStamp, unreadCount: unreadCount, unreadStored: unreadStored } } diff --git a/packages/omamobile-shell/plugins/omamobile.quicksettings/NotificationsModel.js b/packages/omamobile-shell/plugins/omamobile.quicksettings/NotificationsModel.js index 3eac060e0..49348761a 100644 --- a/packages/omamobile-shell/plugins/omamobile.quicksettings/NotificationsModel.js +++ b/packages/omamobile-shell/plugins/omamobile.quicksettings/NotificationsModel.js @@ -13,6 +13,14 @@ // named -.json, the timestamp in milliseconds since the epoch. // One notification is taken away by that name through the service's forget // call (omamobile-omarchy patch 0019), never by deleting the file here. +// +// Omarchy 4.5 keeps the same notifications in two files instead (its +// shell/plugins/notifications/Store.js): live.json, the toasts on screen, +// and history.json, the closed ones, newest first. Each is one line, a JSON +// array of rows named by a `key` ("n" and base-36 digits), with `ts`, when +// the notification arrived, in seconds. Its forget call (patch 0019 for +// 4.5) takes that key. parse() reads either layout: a line holding an array +// is 4.5's, a line holding an object is one 4.0 file. var LIMIT = 10 @@ -69,10 +77,34 @@ function entry(value) { } } +// One row of Omarchy 4.5's live.json or history.json, in the shape entry() +// gives a 4.0 file: the key is the row's own, and so is the name forget +// takes (`file`); `ts` turns into milliseconds. Null for anything that +// isn't a row with a key 4.5 itself would accept (Store.js KEY). +function storeEntry(value) { + if (!value || typeof value !== "object" || Array.isArray(value)) return null + var key = str(value.key) + if (!/^[A-Za-z0-9_-]{1,120}$/.test(key)) return null + var ts = Number(value.ts) + var timestamp = isFinite(ts) && ts > 0 ? Math.round(ts * 1000) : 0 + return { + key: key, + file: key, + app: str(value.app), + summary: str(value.summary).trim(), + body: plainBody(value.body), + glyph: str(value.glyph), + execArgv: str(value.execArgv), + urgency: typeof value.urgency === "number" ? value.urgency : 1, + timestamp: timestamp + } +} + // The concatenation of every history and on-screen file (`awk 1` over both -// directories), newest first, each notification once (a toast moving into -// history can be read in both places), at most `limit`. Torn lines from a -// crash mid-write are skipped, as Omarchy skips them. +// directories on 4.0, live.json and history.json on 4.5), newest first, +// each notification once (a toast moving into history can be read in both +// places), at most `limit`. Torn lines from a crash mid-write are skipped, +// as Omarchy skips them. function parse(raw, limit) { var max = typeof limit === "number" ? Math.max(0, limit) : LIMIT var lines = str(raw).split("\n") @@ -83,12 +115,17 @@ function parse(raw, limit) { if (!line) continue var value = null try { value = JSON.parse(line) } catch (error) { continue } - if (!value || typeof value !== "object" || Array.isArray(value)) continue - var e = entry(value) - if (!e.summary && !e.body) continue - if (seen[e.key]) continue - seen[e.key] = true - out.push(e) + var rows + if (Array.isArray(value)) rows = value.map(storeEntry) + else if (value && typeof value === "object") rows = [entry(value)] + else continue + for (var j = 0; j < rows.length; j++) { + var e = rows[j] + if (!e || (!e.summary && !e.body)) continue + if (seen[e.key]) continue + seen[e.key] = true + out.push(e) + } } out.sort(function(a, b) { return b.timestamp - a.timestamp }) return out.slice(0, max) @@ -100,7 +137,8 @@ function parse(raw, limit) { // file, the row stays out; a mark older than graceMs (a forget that never // happened, say on an Omarchy without the forget call) lapses, and the row // comes back rather than staying hidden for a notification that is still -// there. Returns the rows and the marks still needed. +// there. Returns the rows, the marks still needed and the forget name of +// every notification read, shown or not (Clear all on 4.5 forgets them). function shown(raw, hidden, now, graceMs) { var marks = hidden || {} var grace = typeof graceMs === "number" ? graceMs : 15000 @@ -113,7 +151,7 @@ function shown(raw, hidden, now, graceMs) { if (Number(now) - Number(marks[key]) <= grace) kept[key] = marks[key] } var out = all.filter(function(e) { return !kept.hasOwnProperty(e.key) }) - return { entries: out.slice(0, LIMIT), hidden: kept } + return { entries: out.slice(0, LIMIT), hidden: kept, files: all.map(function(e) { return e.file }) } } function without(entries, key) { @@ -174,6 +212,7 @@ if (typeof module !== "undefined") { plainBody: plainBody, execArgv: execArgv, entry: entry, + storeEntry: storeEntry, parse: parse, shown: shown, without: without, diff --git a/packages/omamobile-shell/plugins/omamobile.quicksettings/QuickSettings.qml b/packages/omamobile-shell/plugins/omamobile.quicksettings/QuickSettings.qml index 29da95201..55fef7ff1 100644 --- a/packages/omamobile-shell/plugins/omamobile.quicksettings/QuickSettings.qml +++ b/packages/omamobile-shell/plugins/omamobile.quicksettings/QuickSettings.qml @@ -838,11 +838,17 @@ Item { // Clear all goes through the service's own IPC, on this shell instance like // the DND tile: dismissAll moves the toasts on screen into history, then // clear empties history (both run in order on the service's file queue). + // Omarchy 4.5 keeps them in live.json and history.json in the same + // directory instead, and has no clear: where history.json exists, the + // shade reads those two files, and Clear all forgets every notification + // it read once dismissAll has closed the toasts (they keep their keys). readonly property string notificationsDir: Quickshell.env("HOME") + "/.local/state/omarchy/notifications" // Where the bar's unread count starts from: the newest notification the // shade has shown (omamobile.bar reads it at start and hears it by IPC). readonly property string stateDir: Quickshell.env("HOME") + "/.local/state/omamobile" property var notifications: [] + // The forget name of every notification the last read found. + property var notificationFiles: [] property double nowMs: Date.now() property double seenStamp: 0 property double seenWritten: 0 @@ -897,13 +903,16 @@ Item { Process { id: notificationsRead - command: ["sh", "-c", "for f in \"$1\"/*.json \"$1\"/history/*.json; do [ -f \"$f\" ] && awk 1 \"$f\"; done; exit 0", + command: ["sh", "-c", + "if [ -e \"$1/history.json\" ]; then for f in \"$1/live.json\" \"$1/history.json\"; do [ -f \"$f\" ] && awk 1 \"$f\"; done; " + + "else for f in \"$1\"/*.json \"$1\"/history/*.json; do [ -f \"$f\" ] && awk 1 \"$f\"; done; fi; exit 0", "sh", root.notificationsDir] stdout: StdioCollector { waitForEnd: true onStreamFinished: { var view = NotificationsModel.shown(text, root.hiddenNotifications, Date.now()) root.hiddenNotifications = view.hidden + root.notificationFiles = view.files // Only a change replaces the rows: a new list rebuilds every row, and // one being swiped would be dropped from under the finger. if (JSON.stringify(view.entries) !== JSON.stringify(root.notifications)) @@ -964,8 +973,10 @@ Item { notifications = [] if (clearProc.running) return clearProc.command = ["sh", "-c", - "qs ipc -p \"$1\" call notifications dismissAll; qs ipc -p \"$1\" call notifications clear", - "sh", Quickshell.shellDir] + "if [ -e \"$2/history.json\" ]; then shell=$1; shift 2; qs ipc -p \"$shell\" call notifications dismissAll; " + + "for name; do qs ipc -p \"$shell\" call notifications forget \"$name\"; done; " + + "else qs ipc -p \"$1\" call notifications dismissAll; qs ipc -p \"$1\" call notifications clear; fi; exit 0", + "sh", Quickshell.shellDir, root.notificationsDir].concat(notificationFiles) clearProc.running = true } diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 4a9c50b2f..744ada761 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -292,10 +292,15 @@ pass "touch navigation: back, home pill, drawer pull, undo, fields in view" # at its root, the shade reads the directories Omarchy's service writes, and # the bar hears the shade's mark on the IPC target it serves. qs=plugins/omamobile.quicksettings/QuickSettings.qml -grep -cF '"qs ipc -p \"$1\" call notifications dismissAll; qs ipc -p \"$1\" call notifications clear"' "$qs" >/dev/null || fail "Clear all dismisses the toasts, then clears the history" +grep -cF '"else qs ipc -p \"$1\" call notifications dismissAll; qs ipc -p \"$1\" call notifications clear; fi; exit 0"' "$qs" >/dev/null || fail "Clear all dismisses the toasts, then clears the history" grep -cF 'Quickshell.execDetached(["omarchy-menu", "summon", "root"])' "$qs" >/dev/null || fail "the gear opens Omarchy's root menu" grep -cF '"/.local/state/omarchy/notifications"' "$qs" >/dev/null || fail "the shade reads Omarchy's notification files" grep -cF '"/.local/state/omarchy/notifications/history"' plugins/omamobile.bar/Bar.qml >/dev/null || fail "the bar counts Omarchy's notification history" +grep -cF '"/.local/state/omarchy/notifications/history.json"' plugins/omamobile.bar/Bar.qml >/dev/null || fail "the bar counts Omarchy 4.5's history.json" +# Omarchy 4.0's files and 4.5's live.json and history.json, chosen by what +# exists: test/notifications-store.sh runs the shade's own commands on both. +grep -cF '"sh", Quickshell.shellDir, root.notificationsDir].concat(notificationFiles)' "$qs" >/dev/null || fail "Clear all hands every notification read to the clear script" +bash test/notifications-store.sh >/dev/null || { bash test/notifications-store.sh; fail "the shade reads and clears both notification layouts"; } grep -cF 'call omamobile.bar notificationsSeen' "$qs" >/dev/null || fail "the shade tells the bar what it has shown" grep -cF 'function notificationsSeen(stamp: string): string' plugins/omamobile.bar/Bar.qml >/dev/null || fail "the bar serves notificationsSeen" grep -cF '"/.local/state/omamobile/notifications-seen"' plugins/omamobile.bar/Bar.qml >/dev/null || fail "the bar reads the shade's mark at start" diff --git a/packages/omamobile-shell/test/notifications-model.js b/packages/omamobile-shell/test/notifications-model.js index e47a7ac03..262f77cfa 100644 --- a/packages/omamobile-shell/test/notifications-model.js +++ b/packages/omamobile-shell/test/notifications-model.js @@ -134,6 +134,68 @@ test("swipeOutcome: past 35% or a flick goes that way, else back", () => { assert.strictEqual(M.swipeOutcome(300, 0, 0, fling), 0, "no width yet") }) +// Omarchy 4.5's files (shell/plugins/notifications/Store.js): live.json and +// history.json, each one line, a JSON array of rows as Store.persistable and +// Store.closedEntry write them. These rows were made by 4.5.0-3's own +// Store.js (snapshot, persistable, closedEntry, serialise); a verification +// code is stored redacted. +const row45 = (o) => Object.assign({ + key: "nmgx1a2b3", originalId: 3, senderPid: 0, execArgv: "[\"omarchy-launch-wifi\"]", execActions: "", glyph: "", + app: "Signal", appIcon: "signal-desktop", summary: "Ana", body: "See you soon & bye", rawBody: "", + source: "Signal", groupKey: "app:signal", urgency: 1, expireTimeout: 0, duration: 0, ts: 1760000000.123 +}, o) +const closed45 = (o) => Object.assign(row45(o), { closed_ts: 1760000060.5, closed_reason: "dismissed" }, o) +const store45 = (live, history) => JSON.stringify(live) + "\n" + JSON.stringify(history) + "\n" + +test("parse reads Omarchy 4.5's live.json and history.json, newest first", () => { + const raw = store45([row45({ key: "nlive", summary: "on screen", ts: 1760000300.5 })], + [closed45({ key: "nnew", summary: "new", ts: 1760000200 }), closed45({ key: "nold", summary: "old", ts: 1760000100 }), + closed45({ key: "ncode", originalId: 9, app: "", appIcon: "", execArgv: "", source: "", groupKey: "", + summary: "Verification notification", body: "[redacted]", ts: 1760000150, closed_reason: "expired" })]) + const rows = M.parse(raw) + assert.deepStrictEqual(rows.map((r) => r.summary), ["on screen", "new", "Verification notification", "old"]) + assert.deepStrictEqual(rows.map((r) => r.key), ["nlive", "nnew", "ncode", "nold"]) + assert.strictEqual(rows[0].timestamp, 1760000300500, "ts in seconds, as milliseconds") + const [one] = M.parse(store45([], [closed45({})])) + assert.deepStrictEqual(one, { key: "nmgx1a2b3", file: "nmgx1a2b3", app: "Signal", summary: "Ana", body: "See you soon & bye", + glyph: "", execArgv: "[\"omarchy-launch-wifi\"]", urgency: 1, timestamp: 1760000000123 }) + assert.deepStrictEqual(M.tapArgv(one), ["omarchy-launch-wifi"]) +}) + +test("on 4.5 each row carries its key, which forget takes", () => { + const [row] = M.parse(store45([], [closed45({ key: "nabc_1-Z" })])) + assert.strictEqual(row.file, "nabc_1-Z") + assert.match(row.file, /^[A-Za-z0-9_-]{1,120}$/, "the shape 4.5's Store.KEY accepts") +}) + +test("4.5: a row in both files shows once; rows without a usable key or text are skipped", () => { + const raw = store45([row45({ key: "nsame", summary: "live copy" })], + [closed45({ key: "nsame", summary: "history copy" }), closed45({ key: "bad key" }), closed45({ key: "" }), + closed45({ key: "x".repeat(121) }), closed45({ key: "nempty", summary: "", body: "" }), 7, null, [1], "n"]) + const rows = M.parse(raw) + assert.deepStrictEqual(rows.map((r) => r.summary), ["live copy"]) + assert.deepStrictEqual(M.parse("\n\n"), [], "4.5's files as its service creates them: empty") + assert.deepStrictEqual(M.parse("[]\n[]\n"), []) + assert.strictEqual(M.parse(store45([], [closed45({ ts: "soon" })]))[0].timestamp, 0, "no usable ts: no age") +}) + +test("4.5: shown hides a swiped row until it is gone, and lists every key for Clear all", () => { + const history = Array.from({ length: 12 }, (_, i) => closed45({ key: "n" + i, ts: 1760000000 + i })) + let view = M.shown(store45([], history), { n11: 900 }, 1000) + assert.strictEqual(view.entries.length, M.LIMIT) + assert.strictEqual(view.entries[0].key, "n10") + assert.deepStrictEqual(view.hidden, { n11: 900 }) + assert.strictEqual(view.files.length, 12, "every row read, not only the ten shown") + view = M.shown(store45([], history.slice(0, 11)), view.hidden, 1000) + assert.deepStrictEqual(view.hidden, {}) +}) + +test("4.0: shown lists every file name for Clear all too", () => { + const raw = Array.from({ length: 11 }, (_, i) => file({ timestamp: 100 + i, id: i })).join("\n") + assert.strictEqual(M.shown(raw, {}, 0).files.length, 11) + assert.strictEqual(M.shown(raw, {}, 0).files[0], "110-10.json") +}) + let failed = 0 for (const [name, fn] of tests) { try { diff --git a/packages/omamobile-shell/test/notifications-store.sh b/packages/omamobile-shell/test/notifications-store.sh new file mode 100644 index 000000000..976ed666f --- /dev/null +++ b/packages/omamobile-shell/test/notifications-store.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# The notification shade's shell commands, taken out of QuickSettings.qml +# and run against both of Omarchy's layouts in a throwaway directory: the +# read (one file per notification under notifications/ and history/ on +# 4.0; live.json and history.json on 4.5, chosen by whether history.json +# exists) and Clear all (dismissAll then clear on 4.0; dismissAll, then +# forget for every notification read, on 4.5), with a fake qs that only +# records its calls. The rows come out through NotificationsModel.js. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +qs=plugins/omamobile.quicksettings/QuickSettings.qml +fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } +pass() { printf 'ok - %s\n' "$1"; } + +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +# The script of `.command = ["sh", "-c", "…" + "…",` as sh gets it: the +# QML string literals joined (they are JSON-compatible). +script() { + python3 - "$qs" "$1" <<'PY' +import json, re, sys +text = open(sys.argv[1]).read() +m = re.search(re.escape(sys.argv[2]) + r'\s*\[\s*"sh",\s*"-c",\s*((?:"(?:[^"\\]|\\.)*"\s*\+?\s*)+),', text) +if not m: sys.exit("no command for " + sys.argv[2]) +print("".join(json.loads(s) for s in re.findall(r'"(?:[^"\\]|\\.)*"', m.group(1))), end="") +PY +} +read_sh=$(script 'command:') && [[ $read_sh == *history.json* ]] || fail "found the shade's read in $qs" +clear_sh=$(script 'clearProc.command =') || fail "found Clear all in $qs" + +mkdir -p "$tmp/bin" +printf '#!/bin/sh\necho "qs $*" >>"%s/calls"\n' "$tmp" >"$tmp/bin/qs"; chmod +x "$tmp/bin/qs" +rows() { node -e ' + const M = require(process.argv[1]); let raw = "" + process.stdin.on("data", (d) => raw += d).on("end", () => { + const v = M.shown(raw, {}, 0) + console.log(v.entries.map((e) => e.summary).join(",") + " | " + v.files.join(",")) + })' "$PWD/plugins/omamobile.quicksettings/NotificationsModel.js"; } + +# Omarchy 4.0.6: a toast on screen and two in history, one file each, as +# its serializePopup writes them (NotificationLogic.js). +d=$tmp/v40/notifications; mkdir -p "$d/history" "$d/images" +one() { printf '{"id":%s,"originalId":%s,"app":"App","appIcon":"","summary":"%s","body":"","image":"","glyph":"","execArgv":"","urgency":1,"expireTimeout":0,"timestamp":%s}\n' "$2" "$2" "$3" "$1"; } +one 3000 3 live >"$d/3000-3.json" +one 2000 2 newer >"$d/history/2000-2.json" +one 1000 1 older >"$d/history/1000-1.json" +got=$(sh -c "$read_sh" sh "$d" | rows) +[[ $got == "live,newer,older | 3000-3.json,2000-2.json,1000-1.json" ]] || fail "4.0: the shade reads the toasts and history/ ($got)" +: >"$tmp/calls" +PATH=$tmp/bin:$PATH sh -c "$clear_sh" sh /shell "$d" 3000-3.json 2000-2.json 1000-1.json +[[ $(cat "$tmp/calls") == $'qs ipc -p /shell call notifications dismissAll\nqs ipc -p /shell call notifications clear' ]] \ + || fail "4.0: Clear all is dismissAll, then clear, and nothing else ($(cat "$tmp/calls"))" +pass "notification shade on Omarchy 4.0: reads one file each, clears through dismissAll and clear" + +# Omarchy 4.5.0: live.json and history.json, one JSON array each (Store.js), +# next to 4.0 leftovers its migration had not removed yet, which must not +# show; then the files as its service first creates them, empty. +d=$tmp/v45/notifications; mkdir -p "$d/history" +row() { printf '{"key":"%s","originalId":1,"senderPid":0,"execArgv":"","execActions":"","glyph":"","app":"App","appIcon":"","summary":"%s","body":"","rawBody":"","source":"App","groupKey":"app:app","urgency":1,"expireTimeout":0,"duration":0,"ts":%s%s}' "$@"; } +printf '[%s]\n' "$(row nlive live 3.5 '')" >"$d/live.json" +printf '[%s,%s]\n' "$(row nnew newer 2 ',"closed_ts":9,"closed_reason":"dismissed"')" "$(row nold older 1 ',"closed_ts":8,"closed_reason":"expired"')" >"$d/history.json" +one 5000 5 leftover >"$d/history/5000-5.json" +one 6000 6 stray >"$d/6000-6.json" +got=$(sh -c "$read_sh" sh "$d" | rows) +[[ $got == "live,newer,older | nlive,nnew,nold" ]] || fail "4.5: the shade reads live.json and history.json only ($got)" +: >"$tmp/calls" +PATH=$tmp/bin:$PATH sh -c "$clear_sh" sh /shell "$d" nlive nnew nold +[[ $(cat "$tmp/calls") == $'qs ipc -p /shell call notifications dismissAll\nqs ipc -p /shell call notifications forget nlive\nqs ipc -p /shell call notifications forget nnew\nqs ipc -p /shell call notifications forget nold' ]] \ + || fail "4.5: Clear all is dismissAll, then forget for each key ($(cat "$tmp/calls"))" +rm -rf "$d/history" "$d/6000-6.json"; : >"$d/live.json"; : >"$d/history.json" +got=$(sh -c "$read_sh" sh "$d" | rows) +[[ $got == " | " ]] || fail "4.5: empty files, no rows ($got)" +: >"$tmp/calls" +PATH=$tmp/bin:$PATH sh -c "$clear_sh" sh /shell "$d" +[[ $(cat "$tmp/calls") == "qs ipc -p /shell call notifications dismissAll" ]] || fail "4.5: Clear all with nothing read is dismissAll alone" +pass "notification shade on Omarchy 4.5: reads live.json and history.json, clears through dismissAll and forget" diff --git a/packages/omamobile-shell/test/quicksettings-render b/packages/omamobile-shell/test/quicksettings-render index fba4058e7..4c986065c 100755 --- a/packages/omamobile-shell/test/quicksettings-render +++ b/packages/omamobile-shell/test/quicksettings-render @@ -6,7 +6,9 @@ # fit the screen: the real QuickSettings.qml, its layer-shell window a # plain Item, over a throwaway $HOME with a few notifications of our own # in the shade. No backend answers here (no D-Bus, no scripts on PATH), so -# the tiles show as unavailable; it is the layout under review. Runs inside +# the tiles show as unavailable; it is the layout under review. The dark +# theme's notifications are Omarchy 4.0's files, the light theme's 4.5's +# live.json and history.json, so the shade's read runs on both. Runs inside # the OWL conformance container (tests/owl/Dockerfile), never on a desktop: # # docker run --rm --network none -u "$(id -u):$(id -g)" -v "$PWD:/src" \ @@ -53,17 +55,30 @@ for theme in tokyo-night catppuccin-latte; do home=/tmp/quicksettings-home-$theme rm -rf "$home"; mkdir -p "$home/.local/state/omarchy/current" "$home/.local/state/omarchy/notifications/history" "$home/.config/omamobile" ln -sfn "/themes/$theme" "$home/.local/state/omarchy/current/theme" - # Three notifications of our own in the history, as Omarchy's service - # writes them (one line each, named -.json). - python3 - "$home/.local/state/omarchy/notifications/history" <<'PY' + # Three notifications of our own, as Omarchy's service writes them: on + # 4.0 one line per file in history/, named -.json; on 4.5 + # one on screen in live.json and two in history.json (Store.js). + python3 - "$home/.local/state/omarchy/notifications" "$theme" <<'PY' import json, sys -d = sys.argv[1] +d, theme = sys.argv[1:] rows = [(1760000300000, 1, "Signal", "Ana", "See you soon"), (1760000200000, 2, "Omarchy", "Update available", "Omarchy 4.0.7 is ready to install"), (1760000100000, 3, "Clock", "Alarm", "Tomorrow 07:00")] -for ts, i, app, summary, body in rows: - with open("%s/%d-%d.json" % (d, ts, i), "w") as f: - f.write(json.dumps({"id": i, "originalId": i, "app": app, "appIcon": "", "summary": summary, "body": body, "image": "", "glyph": "", - "execArgv": "", "urgency": 1, "expireTimeout": 0, "timestamp": ts}) + "\n") +if theme == "catppuccin-latte": + def row(ts, i, app, summary, body, **closed): + return dict({"key": "n%d" % i, "originalId": i, "senderPid": 0, "execArgv": "", "execActions": "", "glyph": "", "app": app, "appIcon": "", + "summary": summary, "body": body, "rawBody": "", "source": app, "groupKey": "app:" + app.lower(), "urgency": 1, + "expireTimeout": 0, "duration": 0, "ts": ts / 1000}, **closed) + with open(d + "/live.json", "w") as f: + f.write(json.dumps([row(*rows[0])]) + "\n") + with open(d + "/history.json", "w") as f: + f.write(json.dumps([row(*r, closed_ts=r[0] / 1000 + 60, closed_reason="dismissed") for r in rows[1:]]) + "\n") + with open(d + "/quiet.json", "w") as f: + f.write(json.dumps({"dnd": False}) + "\n") +else: + for ts, i, app, summary, body in rows: + with open("%s/history/%d-%d.json" % (d, ts, i), "w") as f: + f.write(json.dumps({"id": i, "originalId": i, "app": app, "appIcon": "", "summary": summary, "body": body, "image": "", "glyph": "", + "execArgv": "", "urgency": 1, "expireTimeout": 0, "timestamp": ts}) + "\n") PY python3 - "$out" "$theme" > "$h/job-$theme.json" <<'PY' import json, sys @@ -122,6 +137,7 @@ for name, g in geo.items(): json.dumps([parts.get("handle"), parts.get("settingsButton")])) has_shade = "shade" in parts check(name + ": the notification shade shows", has_shade and inside(parts["shade"], screen, 1) and parts["shade"]["h"] >= 100, json.dumps(parts.get("shade"))) + check(name + ": the shade read all three notifications", g["notifications"] == 3, str(g["notifications"])) if has_shade: beside = parts["shade"]["x"] >= parts["sheet"]["x"] + parts["sheet"]["w"] if landscape else parts["shade"]["y"] >= parts["sheet"]["y"] + parts["sheet"]["h"] check(name + ": the shade is %s the sheet" % ("beside" if landscape else "under"), beside and apart(parts["sheet"], parts["shade"])) diff --git a/packages/omamobile-shell/test/status-model.js b/packages/omamobile-shell/test/status-model.js index 3fd059373..b239fb966 100644 --- a/packages/omamobile-shell/test/status-model.js +++ b/packages/omamobile-shell/test/status-model.js @@ -51,3 +51,22 @@ assert.strictEqual(M.unreadCount([], 0), 0) assert.strictEqual(M.unreadCount(files.filter((f) => f !== "3000-3.json"), "2000"), 0, "the unread one forgotten") assert.strictEqual(M.unreadCount(files.filter((f) => f !== "1000-1.json"), "2000"), 1, "a seen one forgotten") console.log("ok - status model: unread notifications") + +// Omarchy 4.5: history.json, a JSON array of rows with `ts` in seconds (as +// 4.5.0-3's Store.closedEntry writes them); the shade's mark is the newest +// ts it showed, in milliseconds. +const hist45 = JSON.stringify([{ key: "n3", ts: 3, closed_ts: 9, closed_reason: "dismissed" }, + { key: "n2", ts: 2.0004, closed_ts: 8, closed_reason: "expired" }, + { key: "n1", ts: 1, closed_ts: 7, closed_reason: "dismissed" }]) + "\n" +assert.strictEqual(M.unreadStored(hist45, 0), 3, "nothing seen yet: every history row") +assert.strictEqual(M.unreadStored(hist45, "2000"), 1, "only what arrived after the newest one the shade showed") +assert.strictEqual(M.unreadStored(hist45, 3000), 0) +assert.strictEqual(M.unreadStored(JSON.stringify([{ ts: 1.9996 }]), 2000), 0, "rounded as the shade rounds") +assert.strictEqual(M.unreadStored("", 0), 0, "the empty file the service creates") +assert.strictEqual(M.unreadStored("[]\n", 0), 0) +assert.strictEqual(M.unreadStored("{\"ts\": 5}", 0), 0, "not an array") +assert.strictEqual(M.unreadStored(JSON.stringify({ length: 1, 0: { ts: 5 } }), 0), 0, "not an array, even one that looks like it") +assert.strictEqual(M.unreadStored("[{\"ts\": 5", 0), 0, "torn") +assert.strictEqual(M.unreadStored(JSON.stringify([null, 4, { ts: "x" }, { ts: -1 }, {}, { ts: 5 }]), 0), 1) +assert.strictEqual(M.unreadStored(undefined, 0), 0) +console.log("ok - status model: unread notifications on Omarchy 4.5") diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 52c3f2af3..24c5d10d2 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.124 +0.2.125