feat: show unseen count in macos dock

Resolves #93
This commit is contained in:
talksik
2026-03-30 13:53:50 -07:00
parent 65ea901626
commit a5e1ea1acf
5 changed files with 46 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import { useEffect, useMemo } from "react";
import type { Particle, StreamProperties } from "@/api/types";
type StreamParticle = Particle & { type: "stream"; properties: StreamProperties };
/**
* Syncs the macOS dock badge with the count of unseen streams.
* Both last_child_created_at and playback_markers store the child particle's
* created_at, so they're directly comparable.
*/
export function useDockBadge(streams: StreamParticle[], userId: string | undefined) {
const unseenCount = useMemo(() => {
if (!userId) return 0;
return streams.filter((s) => {
const lastActivity = s.last_child_created_at?.getTime();
if (!lastActivity) return false;
const marker = s.playback_markers?.[userId]?.getTime();
if (marker === undefined) return false;
return lastActivity > marker;
}).length;
}, [streams, userId]);
useEffect(() => {
window.electronApp.setDockBadge(unseenCount);
return () => window.electronApp.setDockBadge(0);
}, [unseenCount]);
}