mpris working!
This commit is contained in:
parent
c05f5904cc
commit
788df7773c
1 changed files with 34 additions and 25 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { bind, Variable } from "astal";
|
import { bind, derive, Variable } from "astal";
|
||||||
import AstalMpris from "gi://AstalMpris";
|
import AstalMpris from "gi://AstalMpris";
|
||||||
|
|
||||||
function IntegerToMinuteSeconds(value: number) {
|
function IntegerToMinuteSeconds(value: number) {
|
||||||
|
|
@ -7,40 +7,49 @@ function IntegerToMinuteSeconds(value: number) {
|
||||||
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function FormatLabel(player: AstalMpris.Player) {
|
function FormatLabel(player: {
|
||||||
|
title: string;
|
||||||
|
artist: string;
|
||||||
|
position: number;
|
||||||
|
length: number;
|
||||||
|
}) {
|
||||||
return `${player.title} - ${player.artist} [${IntegerToMinuteSeconds(player.position)}/${IntegerToMinuteSeconds(player.length)}]`;
|
return `${player.title} - ${player.artist} [${IntegerToMinuteSeconds(player.position)}/${IntegerToMinuteSeconds(player.length)}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Mpris = function () {
|
const Mpris = function () {
|
||||||
const mpris = AstalMpris.get_default();
|
const mpris = AstalMpris.get_default();
|
||||||
|
|
||||||
mpris.connect("player-added", () => {
|
const players = bind(mpris, "players");
|
||||||
players.set(mpris.players);
|
const activeIndex = Variable(0);
|
||||||
});
|
|
||||||
mpris.connect("player-closed", () => {
|
|
||||||
players.set(mpris.players);
|
|
||||||
});
|
|
||||||
|
|
||||||
const players = Variable<Array<AstalMpris.Player>>(mpris.players);
|
bind(
|
||||||
|
derive([players, activeIndex], (players, index) => players[index]),
|
||||||
const label = Variable.derive([players], (players) => {
|
).subscribe((value) => print(value.title));
|
||||||
const player = players[0];
|
|
||||||
if (!player.title || !player.artist || !player.position || !player.length) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return FormatLabel(player);
|
|
||||||
});
|
|
||||||
|
|
||||||
label.subscribe((value) => print(value));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<box>
|
<box>
|
||||||
<label
|
{bind(
|
||||||
label={bind(label)}
|
derive([players, activeIndex], (players, index) => {
|
||||||
onScroll={(self, dx, dy) => {
|
const activePlayer = players[index];
|
||||||
dy > 0 ? print("BLING!") : print("BANG!");
|
|
||||||
}}
|
return (
|
||||||
/>
|
<label
|
||||||
|
label={bind(
|
||||||
|
derive(
|
||||||
|
[
|
||||||
|
bind(activePlayer, "title"),
|
||||||
|
bind(activePlayer, "artist"),
|
||||||
|
bind(activePlayer, "position"),
|
||||||
|
bind(activePlayer, "length"),
|
||||||
|
],
|
||||||
|
(title, artist, position, length) =>
|
||||||
|
FormatLabel({ title, artist, position, length }),
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)}
|
||||||
</box>
|
</box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue