Skip to content
Closed
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
2 changes: 1 addition & 1 deletion packages/omamobile-shell/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pkgdesc="Omarchy Mobile's phone profile for the Omarchy shell: status bar, quick
arch=(any)
url="https://github.com/derekross/omarchy-mobile"
license=(MIT GPL-3.0-or-later) # GPL: the squeekboard layout
depends=(omarchy omamobile-apps 'omamobile-omarchy>=0.1.11' 'omamobile-owl-widgets>=0.1.2' bash squeekboard bluez wf-recorder python python-dbus python-gobject
depends=(omarchy omamobile-apps 'omamobile-omarchy>=0.1.11' 'omamobile-notification-snapshot>=1' 'omamobile-owl-widgets>=0.1.2' bash squeekboard bluez wf-recorder python python-dbus python-gobject
which # voice input: voxtype finds wtype and wl-copy with which
pipewire-audio pipewire-pulse pipewire-alsa wireplumber
inotify-tools qt6-declarative
Expand Down
15 changes: 13 additions & 2 deletions packages/omamobile-shell/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,14 +174,20 @@ 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 <app>`. Other senders'
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 <key>` 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.

Expand Down
23 changes: 23 additions & 0 deletions packages/omamobile-shell/plugins/omamobile.bar/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion packages/omamobile-shell/plugins/omamobile.bar/StatusModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "󰂅"
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Item {
property var entry: ({})
// Off while the list is scrolling.
property bool swipeEnabled: true
// Clear all may cancel a swipe before its request is accepted.
property bool clearing: false
property bool forgetAccepted: false
readonly property bool actionable: !!NotificationsModel.tapArgv(entry)
readonly property color foreground: host ? host.foreground : Commons.Color.popups.text

Expand All @@ -32,15 +35,34 @@ Item {
property bool dismissing: false
// 1 in the list; down to 0 as the gap closes after a swipe away.
property real fold: 1
readonly property bool swiping: swipeHandler.active || swipeAnimation.running || dismissing
readonly property bool swiping: swipeHandler.active || swipeAnimation.running || restoreAnimation.running || dismissing

readonly property real naturalHeight: Math.max(44, rowText.implicitHeight + Style.spacing.md * 2)
height: naturalHeight * fold
visible: fold > 0
clip: fold < 1

function restoreSwipe() {
swipeAnimation.stop()
foldAnimation.stop()
fold = 1
dismissing = false
forgetAccepted = false
restoreAnimation.restart()
}

onClearingChanged: if (clearing && dismissing && !forgetAccepted) restoreSwipe()

Connections {
target: row.host
ignoreUnknownSignals: true
function onNotificationForgetFailed(key) {
if (row.forgetAccepted && row.entry.key === key) row.restoreSwipe()
}
}

function finishSwipe() {
var way = NotificationsModel.swipeOutcome(swipeOffset, swipeVelocity, width, Style.space(900))
var way = !clearing ? NotificationsModel.swipeOutcome(swipeOffset, swipeVelocity, width, Style.space(900)) : 0
swipeAnimation.dismiss = way !== 0
swipeAnimation.to = way * (width + Style.space(24))
if (way !== 0) dismissing = true
Expand Down Expand Up @@ -146,6 +168,7 @@ Item {
enabled: row.swipeEnabled && !row.dismissing
onActiveChanged: {
if (active) {
restoreAnimation.stop()
swipeAnimation.stop()
row.swipeVelocity = 0
} else {
Expand All @@ -171,10 +194,22 @@ Item {
easing.type: swipeAnimation.dismiss ? Easing.InQuad : Easing.OutBack
}
ScriptAction {
script: if (swipeAnimation.dismiss) foldAnimation.start()
script: if (swipeAnimation.dismiss) {
if (!row.clearing) foldAnimation.start()
else row.restoreSwipe()
}
}
}

NumberAnimation {
id: restoreAnimation
target: row
property: "swipeOffset"
to: 0
duration: 200
easing.type: Easing.OutBack
}

// The gap closes, then the host takes the entry out of the list (which
// replaces this row) and forgets the notification.
SequentialAnimation {
Expand All @@ -187,7 +222,10 @@ Item {
easing.type: Easing.OutCubic
}
ScriptAction {
script: if (row.host) row.host.forgetNotification(row.entry)
script: {
row.forgetAccepted = !!row.host && row.host.forgetNotification(row.entry)
if (!row.forgetAccepted) row.restoreSwipe()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
// named <timestamp>-<id>.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

Expand Down Expand Up @@ -69,51 +77,81 @@ 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")
var seen = {}
var seen = Object.create(null)
var out = []
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim()
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)
}

// What the shade shows: parse(), less the notifications swiped away.
// `hidden` maps an entry's key to when it was swiped (ms). The service
// `hidden` maps an acknowledged logical key to its reply time (ms). The service
// deletes its file a moment later, so until a read no longer finds the
// 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 (retained for format compatibility).
function shown(raw, hidden, now, graceMs) {
var marks = hidden || {}
var grace = typeof graceMs === "number" ? graceMs : 15000
var all = parse(raw, Infinity)
var present = {}
var present = Object.create(null)
for (var i = 0; i < all.length; i++) present[all[i].key] = true
var kept = {}
for (var key in marks) {
if (!marks.hasOwnProperty(key) || !present[key]) continue
if (Number(now) - Number(marks[key]) <= grace) kept[key] = marks[key]
if (!Object.prototype.hasOwnProperty.call(marks, key) || !present[key]) continue
if (Number(now) - Number(marks[key]) <= grace) Object.defineProperty(kept, key, { value: marks[key], enumerable: true, writable: true, configurable: true })
}
var out = all.filter(function(e) { return !kept.hasOwnProperty(e.key) })
return { entries: out.slice(0, LIMIT), hidden: kept }
var out = all.filter(function(e) { return !Object.prototype.hasOwnProperty.call(kept, e.key) })
return { entries: out.slice(0, LIMIT), hidden: kept, files: all.map(function(e) { return e.file }) }
}

function without(entries, key) {
Expand Down Expand Up @@ -168,12 +206,38 @@ function title(count) {
return count > 0 ? "Notifications · " + count : "Notifications"
}

// Hide only logical keys explicitly acknowledged by the daemon.
function clearResult(raw, code) {
if (code !== 0 || typeof raw !== "string" || raw.length > 65536) return { ok: false, keys: [] }
var value
try { value = JSON.parse(raw) } catch (error) { return { ok: false, keys: [] } }
if (!value || value.version !== 1) return { ok: false, keys: [] }
if (value.result === "legacy") return { ok: true, legacy: true, keys: [] }
if (value.result !== "ok" || !Array.isArray(value.keys) || value.keys.length > 300) return { ok: false, keys: [] }
var seen = Object.create(null), keys = []
for (var i = 0; i < value.keys.length; i++) {
var key = value.keys[i]
if (typeof key !== "string" || !/^[A-Za-z0-9_-]{1,120}$/.test(key)) return { ok: false, keys: [] }
if (!seen[key]) { seen[key] = true; keys.push(key) }
}
return { ok: true, keys: keys }
}
function acknowledge(entries, hidden, keys, now) {
var marks = Object.create(null)
Object.keys(hidden || {}).forEach(function(key) { marks[key] = hidden[key] })
keys.forEach(function(key) { marks[key] = now })
return { hidden: marks, entries: (entries || []).filter(function(entry) { return keys.indexOf(entry.key) < 0 }) }
}

if (typeof module !== "undefined") {
module.exports = {
LIMIT: LIMIT,
clearResult: clearResult,
acknowledge: acknowledge,
plainBody: plainBody,
execArgv: execArgv,
entry: entry,
storeEntry: storeEntry,
parse: parse,
shown: shown,
without: without,
Expand Down
Loading