@@ -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]);
|
||||
}
|
||||
Reference in New Issue
Block a user