Skip to content
Open
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 @@ -90,6 +90,7 @@ Item {
function close() {
if (editing) finishEditing()
confirmClear = false
notificationDeleteError = ""
opened = false
}

Expand Down Expand Up @@ -822,13 +823,15 @@ Item {
// and a forget only takes one away.
property var hiddenNotifications: ({})
property var forgetQueue: []
property var pendingForget: null
property string notificationDeleteError: ""

function forgetNotification(entry) {
if (!entry || !entry.key || !entry.file) return false
var marks = Object.assign({}, hiddenNotifications)
marks[entry.key] = Date.now()
hiddenNotifications = marks
forgetQueue = forgetQueue.concat([entry.file])
forgetQueue = forgetQueue.concat([{ key: entry.key, file: entry.file }])
// Later, not now: the row asking is a delegate of this list.
Qt.callLater(function() {
root.notifications = NotificationsModel.without(root.notifications, entry.key)
Expand All @@ -839,16 +842,25 @@ Item {

function runForget() {
if (forgetProc.running || forgetQueue.length === 0) return
forgetProc.command = ["sh", "-c",
"dir=$1; shift; for name; do qs ipc -p \"$dir\" call notifications forget \"$name\"; done; exit 0",
"sh", Quickshell.shellDir].concat(forgetQueue)
forgetQueue = []
pendingForget = forgetQueue[0]
forgetQueue = forgetQueue.slice(1)
forgetProc.command = ["qs", "ipc", "-p", Quickshell.shellDir,
"call", "notifications", "forget", pendingForget.file]
forgetProc.running = true
}

Process {
id: forgetProc
onExited: {
stdout: StdioCollector { id: forgetResult; waitForEnd: true }
onExited: function(code) {
var entry = root.pendingForget
root.pendingForget = null
if (code !== 0 || String(forgetResult.text || "").trim() !== "ok") {
var marks = Object.assign({}, root.hiddenNotifications)
if (entry) delete marks[entry.key]
root.hiddenNotifications = marks
root.notificationDeleteError = "Couldn't dismiss notification"
} else root.notificationDeleteError = ""
root.runForget()
notificationsLater.restart()
}
Expand Down Expand Up @@ -1978,7 +1990,7 @@ Item {
anchors.rightMargin: Style.spacing.lg
anchors.verticalCenter: parent.verticalCenter
textFormat: Text.PlainText
text: NotificationsModel.title(root.notifications.length)
text: root.notificationDeleteError || NotificationsModel.title(root.notifications.length)
color: root.foreground
font.family: Style.font.family
font.pixelSize: Style.font.subtitle
Expand Down
3 changes: 2 additions & 1 deletion packages/omamobile-shell/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ grep -cF '"omarchy-shell", "shell", "summon", "omarchy.clipboard"' "$qs" >/dev/n
# list scrolls, and its tap is a DragThreshold TapHandler (no MouseArea,
# which would take the press from the swipe). test/shade-touch drives it.
row=plugins/omamobile.quicksettings/NotificationRow.qml
grep -cF 'call notifications forget \"$name\"' "$qs" >/dev/null || fail "a swiped row is forgotten through the service"
grep -cF '"call", "notifications", "forget", pendingForget.file]' "$qs" >/dev/null || fail "a swiped row is forgotten through the service"
grep -cF 'delegate: NotificationRow {' "$qs" >/dev/null && grep -cF 'swipeEnabled: !shadeList.moving' "$qs" >/dev/null \
|| fail "the shade's rows are NotificationRow, not swiping while the list scrolls"
grep -cE 'rm +(-f +)?.*notifications' "$qs" "$row" >/dev/null && fail "the shade deletes no notification files itself"
Expand Down Expand Up @@ -327,6 +327,7 @@ if command -v node >/dev/null; then
node test/sensor-model.js || fail "fingerprint sensor model"
node test/tiles-model.js || fail "quick-settings tile layout"
node test/notifications-model.js >/dev/null || { node test/notifications-model.js; fail "notification shade model"; }
node test/notification-dismiss.js || fail "notification deletion acknowledgment"
node test/media-model.js >/dev/null || { node test/media-model.js; fail "the shade's media card model"; }
node test/home-model.js || fail "home screen model"
node test/back-model.js || fail "back gesture model"
Expand Down
152 changes: 152 additions & 0 deletions packages/omamobile-shell/test/notification-dismiss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// SPDX-License-Identifier: MIT
// Actual QS functions/callback; the process and display boundaries are inert.
"use strict"
const fs = require("fs")
const path = require("path")
const vm = require("vm")
const assert = require("assert")
const source = fs.readFileSync(process.env.NOTIFICATION_SOURCE ||
path.join(__dirname, "../plugins/omamobile.quicksettings/QuickSettings.qml"), "utf8")
const Model = require("../plugins/omamobile.quicksettings/NotificationsModel.js")

function block(start) {
const begin = source.indexOf("{", start)
let end = begin + 1, depth = 1
while (depth) {
if (source[end] === "{") depth++
if (source[end] === "}") depth--
end++
}
return source.slice(begin, end)
}
function actualFunction(name) {
const start = source.indexOf(" function " + name + "(")
assert(start >= 0, "missing actual function: " + name)
return source.slice(start, source.indexOf("{", start)) + block(start)
}
const processStart = source.indexOf(" id: forgetProc")
assert(processStart >= 0)
const callback = "function(code) " + block(source.indexOf("onExited:", processStart))
const first = { key: "1000-1", file: "1000-1.json", summary: "Fixture one", timestamp: 1000 }
const second = { key: "1001-2", file: "1001-2.json", summary: "Fixture two", timestamp: 1001 }

function fixture() {
const later = []
let refreshes = 0
const c = {
Object, Date, notifications: [first, second], hiddenNotifications: {},
forgetQueue: [], pendingForget: null, notificationDeleteError: "",
editing: false, confirmClear: false, opened: true,
forgetProc: { running: false, command: [] }, forgetResult: { text: "" },
NotificationsModel: Model,
Quickshell: {
shellDir: "/owned-shell",
execDetached() { throw Error("delete must never invoke sender action") }
},
Qt: { callLater: fn => later.push(fn) },
notificationsLater: { restart() { refreshes++ } }
}
c.root = c
vm.createContext(c)
vm.runInContext(["forgetNotification", "runForget", "close"].map(actualFunction).join("\n") +
"\nvar finishForget=" + callback, c)
return {
c,
drain() { while (later.length) later.shift()() },
finish(code, text) {
c.forgetProc.running = false
c.forgetResult.text = text
c.finishForget(code)
},
refreshes: () => refreshes
}
}
let count = 0
function test(name, fn) { fn(); count++; console.log("PASS " + name) }

test("request uses a literal IPC argument and preserves pending identity", () => {
const s = fixture()
assert(s.c.forgetNotification(first))
s.drain()
assert.equal(s.c.pendingForget.key, first.key)
assert.deepEqual([...s.c.forgetProc.command], ["qs", "ipc", "-p", "/owned-shell",
"call", "notifications", "forget", first.file])
assert.equal(s.c.notifications.length, 1)
})

test("two queued rows receive separate acknowledgments in order", () => {
const s = fixture()
s.c.forgetNotification(first); s.drain()
s.c.forgetNotification(second); s.drain()
assert.equal(s.c.pendingForget.key, first.key)
assert.equal(s.c.forgetQueue.length, 1)
s.finish(0, "ok\n")
assert.equal(s.c.pendingForget.key, second.key)
assert.equal(s.c.forgetQueue.length, 0)
s.finish(0, "ok")
assert.equal(s.c.pendingForget, null)
assert.equal(s.refreshes(), 2)
})

test("failed IPC restores visibility on refresh and reports an error", () => {
const s = fixture()
s.c.forgetNotification(first); s.drain(); s.finish(1, "")
assert(!Object.hasOwn(s.c.hiddenNotifications, first.key))
assert.equal(s.c.notificationDeleteError, "Couldn't dismiss notification")
const raw = JSON.stringify({ timestamp: 1000, originalId: 1, summary: "Fixture one" })
assert.equal(Model.shown(raw, s.c.hiddenNotifications, Date.now()).entries.length, 1)
})

test("a successful process without acceptance restores the row", () => {
for (const reply of ["none", "busy", "unexpected", ""]) {
const s = fixture()
s.c.forgetNotification(first); s.drain(); s.finish(0, reply)
assert(!Object.hasOwn(s.c.hiddenNotifications, first.key))
assert(s.c.notificationDeleteError)
}
})

test("accepted request stays hidden during the pending file write", () => {
const s = fixture()
s.c.forgetNotification(first); s.drain(); s.finish(0, "ok")
assert(Object.hasOwn(s.c.hiddenNotifications, first.key))
const raw = JSON.stringify({ timestamp: 1000, originalId: 1, summary: "Fixture one" })
assert.equal(Model.shown(raw, s.c.hiddenNotifications, Date.now()).entries.length, 0)
assert.equal(s.c.notificationDeleteError, "")
})

test("failure of one row does not abort the next queued delete", () => {
const s = fixture()
s.c.forgetNotification(first); s.drain()
s.c.forgetNotification(second); s.drain()
s.finish(1, "")
assert.equal(s.c.pendingForget.key, second.key)
s.finish(0, "ok")
assert(!Object.hasOwn(s.c.hiddenNotifications, first.key))
assert(Object.hasOwn(s.c.hiddenNotifications, second.key))
})

test("an invalid entry cannot start a process or hide any row", () => {
for (const entry of [null, {}, { key: "key-only" }, { file: "file-only" }]) {
const s = fixture()
assert.equal(s.c.forgetNotification(entry), false)
s.drain()
assert.equal(s.c.forgetProc.running, false)
assert.equal(s.c.notifications.length, 2)
}
})

// Closing the shade clears presentation state without touching pending requests.
test("closing shade clears an old error while preserving the queue", () => {
const s = fixture()
s.c.notificationDeleteError = "Couldn't dismiss notification"
s.c.forgetNotification(first)
s.drain()
const pending = s.c.pendingForget
s.c.close()
assert.equal(s.c.notificationDeleteError, "")
assert.equal(s.c.opened, false)
assert.strictEqual(s.c.pendingForget, pending)
})

console.log("PASS " + count + " actual notification dismissal cases")