Skip to content

Commit 4ff986f

Browse files
authored
Merge pull request #1986 from 3clyp50/notification-plugin-hooks
Expose notification arrivals and modal actions to plugins
2 parents 0ca2d48 + c9d61ed commit 4ff986f

5 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎tests/test_notification_copy.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ def serve(route):
3939
route.fulfill(content_type="text/html", body=html)
4040
elif path == "/js/modals.js":
4141
route.fulfill(content_type="text/javascript", body="export async function openModal() { window.modalOpens++; }")
42+
elif path == "/js/extensions.js":
43+
route.fulfill(content_type="text/javascript", body="""
44+
export async function callJsExtensions(point, data) {
45+
(window.notificationEvents ??= []).push({ point, ...structuredClone(data) });
46+
data.notification.title = 'Extension-owned copy';
47+
}
48+
""")
4249
else:
4350
asset = WEBUI / path.lstrip("/")
4451
route.fulfill(path=asset, content_type=mimetypes.guess_type(asset)[0])
@@ -68,6 +75,10 @@ def serve(route):
6875
playwright.expect(copy).to_be_visible()
6976
expected = "Error title\nFailure & details\n" + "Long traceback line\n" * 40 + "x" * 500 + "\nLAST LINE"
7077
assert content.inner_text() == expected
78+
events = page.evaluate("window.notificationEvents")
79+
assert [event["source"] for event in events] == ["frontend", "frontend"]
80+
assert all(event["point"] == "notification_received" for event in events)
81+
assert events[0]["notification"]["title"] == "Error title"
7182
before = copy.bounding_box()
7283
text_box = content.bounding_box()
7384
assert copy.inner_text().endswith("Copy")
@@ -121,5 +132,10 @@ def serve(route):
121132
dismiss.click()
122133
playwright.expect(toast).to_have_count(0)
123134
playwright.expect(page.locator(".toast-item")).to_have_count(1)
135+
page.evaluate("""() => {
136+
store.addOrUpdateNotification({ id: 'backend-test', title: 'Backend error', message: 'Details' });
137+
}""")
138+
assert page.evaluate("window.notificationEvents.at(-1).source") == "backend"
139+
assert page.evaluate("store.notifications[0].title") == "Backend error"
124140
finally:
125141
browser.close()

‎tests/test_webui_extension_surfaces.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def get(context_id):
2929

3030

3131
SURFACE_SCENARIOS: list[tuple[str, str]] = [
32+
("notification-header-actions-start", "webui/components/notifications/notification-modal.html"),
3233
("sidebar-start", "webui/components/sidebar/left-sidebar.html"),
3334
("sidebar-end", "webui/components/sidebar/left-sidebar.html"),
3435
("sidebar-top-wrapper-start", "webui/components/sidebar/top-section/sidebar-top.html"),

‎webui/components/notifications/AGENTS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
- Use the notification system for user-facing success, warning, info, and error feedback.
1717
- Keep public helper names stable for core and plugin callers.
18+
- `notification_received` JS extensions receive `{ notification, source }` for backend arrivals/updates and frontend-only toasts before dismissal. `notification` is a shallow copy, `source` is `backend` or `frontend`, and dispatch does not delay rendering; consumers must deduplicate replayed snapshots and handle their own persistence failures.
19+
- `notification-header-actions-start` hosts plugin actions before Clear All, including when the notification list is empty.
1820
- Keep the toast stack visible above normal and legacy modal overlays while staying below confirmation dialogs.
1921
- Toasts keep the shared copy icon with a visible `Copy` label below the scrolling content, aligned with the text; Dismiss stays at the top right. Copy the full rendered title and message as plain text without opening the modal or dismissing the toast; pause dismissal while hovered or keyboard-focused.
2022
- Reload actions must persist their notification as read before refreshing the page.

‎webui/components/notifications/notification-modal.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<!-- Modal Header Actions -->
1515
<div class="modal-subheader">
1616
<div class="notification-header-actions">
17+
<x-extension id="notification-header-actions-start"></x-extension>
1718
<button class="notification-action" @click="$store.notificationStore?.clearAll()"
1819
:disabled="!$store.notificationStore || $store.notificationStore.getDisplayNotifications().length === 0"
1920
title="Clear All">

‎webui/components/notifications/notification-store.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createStore } from "/js/AlpineStore.js";
22
import * as API from "/js/api.js";
33
import { openModal } from "/js/modals.js";
4+
import { callJsExtensions } from "/js/extensions.js";
45
import { formatDateTime, getCurrentUserISOString } from "/js/time-utils.js";
56
import { createActionButton, copyToClipboard } from "/components/messages/action-buttons/simple-action-buttons.js";
67

@@ -298,6 +299,10 @@ const model = {
298299

299300
// Add or update a notification
300301
addOrUpdateNotification(notification) {
302+
void callJsExtensions("notification_received", {
303+
notification: { ...notification },
304+
source: "backend",
305+
});
301306
const existingIndex = this.notifications.findIndex(
302307
(n) => n.id === notification.id
303308
);
@@ -671,6 +676,11 @@ const model = {
671676
//adjust data before using
672677
this.adjustNotificationData(notification);
673678

679+
void callJsExtensions("notification_received", {
680+
notification: { ...notification },
681+
source: "frontend",
682+
});
683+
674684
// If notification has a group, remove any existing toasts with the same group
675685
if (group && String(group).trim() !== "") {
676686
const existingToastIndex = this.toastStack.findIndex(

0 commit comments

Comments
 (0)