From 6b0c9af07c6c8a08ac11522e2a8c7af60c210deb Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Thu, 27 Mar 2025 16:45:25 +1100
Subject: sidebar: streams module
---
src/modules/sidebar/audio.tsx | 2 +
src/modules/sidebar/modules/streams.tsx | 111 ++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
create mode 100644 src/modules/sidebar/modules/streams.tsx
(limited to 'src')
diff --git a/src/modules/sidebar/audio.tsx b/src/modules/sidebar/audio.tsx
index 2b4c6e9..a5c1651 100644
--- a/src/modules/sidebar/audio.tsx
+++ b/src/modules/sidebar/audio.tsx
@@ -1,8 +1,10 @@
import Media from "./modules/media";
+import Streams from "./modules/streams";
export default () => (
+
);
diff --git a/src/modules/sidebar/modules/streams.tsx b/src/modules/sidebar/modules/streams.tsx
new file mode 100644
index 0000000..a7b27cb
--- /dev/null
+++ b/src/modules/sidebar/modules/streams.tsx
@@ -0,0 +1,111 @@
+import { bind, execAsync, Variable } from "astal";
+import { Gtk } from "astal/gtk3";
+import AstalWp from "gi://AstalWp";
+
+interface IStream {
+ stream: AstalWp.Endpoint;
+ playing: boolean;
+}
+
+const header = (audio: AstalWp.Audio, key: "streams" | "speakers" | "recorders") =>
+ `${audio[key].length} ${audio[key].length === 1 ? key.slice(0, -1) : key}`;
+
+const sortStreams = (a: IStream, b: IStream) => {
+ if (a.playing || b.playing) return a.playing ? -1 : 1;
+ return 0;
+};
+
+const Stream = ({ stream, playing }: IStream) => (
+
+
+
+
+
+
+
+);
+
+const List = ({ audio }: { audio: AstalWp.Audio }) => {
+ const streams = Variable([]);
+
+ const update = async () => {
+ const paStreams = JSON.parse(await execAsync("pactl -f json list sink-inputs"));
+ streams.set(
+ audio.streams.map(s => ({
+ stream: s,
+ playing: paStreams.find((p: any) => p.properties["object.serial"] == s.serial)?.corked === false,
+ }))
+ );
+ };
+
+ streams.watch("pactl -f json subscribe", out => {
+ if (JSON.parse(out).on === "sink-input") update().catch(console.error);
+ return streams.get();
+ });
+ audio.connect("notify::streams", () => update().catch(console.error));
+
+ return (
+ streams.drop()}>
+ {bind(streams).as(ps => ps.sort(sortStreams).map(s => ))}
+
+ );
+};
+
+const NoSources = ({ icon, label }: { icon: string; label: string }) => (
+
+
+
+
+
+
+);
+
+const NoWp = () => (
+
+
+
+
+
+
+);
+
+export default () => {
+ const audio = AstalWp.get_default()?.get_audio();
+
+ if (!audio) return ;
+
+ const label = Variable("");
+
+ label.observe(
+ ["streams", "speakers", "recorders"].map(k => [audio, `notify::${k}`]),
+ () => `${header(audio, "streams")} • ${header(audio, "speakers")} • ${header(audio, "recorders")}`
+ );
+
+ return (
+ label.drop()}>
+
+
+
+ (s.length > 0 ? "list" : "empty"))}
+ >
+
+
+
+
+
+
+ );
+};
--
cgit v1.2.3-freya