fix: add test notification button (closes #930) (#948)

Adds a "Send test notification" button to the notification settings page to allow users to immediately verify their configuration. The button uses the existing notifyAgentCompletion API.
This commit is contained in:
ricautomation
2026-04-21 22:52:07 +03:00
committed by GitHub
parent a8719f0a8e
commit 3509a5f98b
@@ -385,6 +385,31 @@ export const NotificationSettings: React.FC = () => {
}; };
}; };
const handleTestNotification = async () => {
const apis = getRegisteredRuntimeAPIs();
if (!apis?.notifications) {
toast.error('Notifications API not available');
return;
}
try {
const success = await apis.notifications.notifyAgentCompletion({
title: 'Test Notification',
body: 'This is a test notification from OpenChamber.',
tag: 'openchamber-test',
});
if (success) {
toast.success('Test notification sent successfully');
} else {
toast.error('Failed to send test notification');
}
} catch (error) {
console.error('Test notification failed:', error);
toast.error('Failed to send test notification');
}
};
const handleEnableBackgroundNotifications = async () => { const handleEnableBackgroundNotifications = async () => {
if (!pushSupported) { if (!pushSupported) {
toast.error('Push notifications not supported'); toast.error('Push notifications not supported');
@@ -547,26 +572,39 @@ export const NotificationSettings: React.FC = () => {
</div> </div>
{nativeNotificationsEnabled && canShowNotifications && ( {nativeNotificationsEnabled && canShowNotifications && (
<div <>
className="group flex cursor-pointer items-center gap-2 py-1.5" <div
role="button" className="group flex cursor-pointer items-center gap-2 py-1.5"
tabIndex={0} role="button"
aria-pressed={notificationMode === 'always'} tabIndex={0}
onClick={() => setNotificationMode(notificationMode === 'always' ? 'hidden-only' : 'always')} aria-pressed={notificationMode === 'always'}
onKeyDown={(event) => { onClick={() => setNotificationMode(notificationMode === 'always' ? 'hidden-only' : 'always')}
if (event.key === ' ' || event.key === 'Enter') { onKeyDown={(event) => {
event.preventDefault(); if (event.key === ' ' || event.key === 'Enter') {
setNotificationMode(notificationMode === 'always' ? 'hidden-only' : 'always'); event.preventDefault();
} setNotificationMode(notificationMode === 'always' ? 'hidden-only' : 'always');
}} }
> }}
<Checkbox >
checked={notificationMode === 'always'} <Checkbox
onChange={(checked) => setNotificationMode(checked ? 'always' : 'hidden-only')} checked={notificationMode === 'always'}
ariaLabel="Notify while app is focused" onChange={(checked) => setNotificationMode(checked ? 'always' : 'hidden-only')}
/> ariaLabel="Notify while app is focused"
<span className="typography-ui-label text-foreground">Notify While App is Focused</span> />
</div> <span className="typography-ui-label text-foreground">Notify While App is Focused</span>
</div>
<div className="py-2">
<Button
type="button"
variant="outline"
size="sm"
onClick={() => void handleTestNotification()}
>
Send test notification
</Button>
</div>
</>
)} )}
</section> </section>