bar: unread -> notif count

There technically is no unread cause they only disappear when swiped, also notif count makes more sense
This commit is contained in:
2 * r + 2 * t 2025-01-16 22:34:10 +11:00
parent 9e32cd4b61
commit c0a05f48b0
2 changed files with 27 additions and 54 deletions

View file

@ -92,7 +92,7 @@
color: scheme.$blue; color: scheme.$blue;
} }
.unread { .notif-count {
color: scheme.$mauve; color: scheme.$mauve;
} }

View file

@ -389,59 +389,32 @@ const PkgUpdates = () => (
</button> </button>
); );
const Unread = () => { const NotifCount = () => (
const unreadCount = Variable(0); <button
return ( onClick={(self, event) => {
<button if (event.button === Astal.MouseButton.PRIMARY) {
onClick={(self, event) => { const popup = App.get_window("notifications") as PopupWindow | null;
if (event.button === Astal.MouseButton.PRIMARY) { if (popup) {
const popup = App.get_window("notifications") as PopupWindow | null; if (popup.visible) popup.hide();
if (popup) { else popup.popup_at_widget(self, event);
if (popup.visible) popup.hide(); }
else popup.popup_at_widget(self, event);
}
} else if (event.button === Astal.MouseButton.SECONDARY) unreadCount.set(0);
}}
setup={self =>
setupCustomTooltip(
self,
bind(unreadCount).as(n => `${n} unread notification${n === 1 ? "" : "s"}`)
)
} }
> }}
<box className="module unread"> setup={self =>
<label className="icon" label="info" /> setupCustomTooltip(
<label self,
label={bind(unreadCount).as(String)} bind(AstalNotifd.get_default(), "notifications").as(
setup={self => { n => `${n.length} notification${n.length === 1 ? "" : "s"}`
const notifd = AstalNotifd.get_default(); )
let notifsOpen = false; )
let unread = new Set<number>(); }
self.hook(unreadCount, (_, u) => u === 0 && unread.clear()); >
<box className="module notif-count">
self.hook(notifd, "notified", (_, id, replaced) => { <label className="icon" label="info" />
if (!notifsOpen && !replaced) { <label label={bind(AstalNotifd.get_default(), "notifications").as(n => String(n.length))} />
unread.add(id); </box>
unreadCount.set(unread.size); </button>
} );
});
self.hook(notifd, "resolved", (_, id) => {
if (unread.delete(id)) {
unreadCount.set(unread.size);
}
});
self.hook(App, "window-toggled", (_, window) => {
if (window.name === "notifications") {
notifsOpen = window.visible;
if (notifsOpen) unreadCount.set(0);
}
});
}}
/>
</box>
</button>
);
};
const DateTime = () => ( const DateTime = () => (
<box className="module date-time"> <box className="module date-time">
@ -501,7 +474,7 @@ export default ({ monitor }: { monitor: Monitor }) => (
<Tray /> <Tray />
<StatusIcons /> <StatusIcons />
<PkgUpdates /> <PkgUpdates />
<Unread /> <NotifCount />
<DateTime /> <DateTime />
<Power /> <Power />
</box> </box>