2023-09-15 23:22:16 -04:00
|
|
|
const { Mpris } = ags.Service;
|
2023-09-17 17:27:23 -04:00
|
|
|
const { Box, CenterBox, Label } = ags.Widget;
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
import * as mpris from './mpris.js';
|
|
|
|
import { Separator } from '../misc/separator.js';
|
|
|
|
|
|
|
|
const Top = player => Box({
|
|
|
|
className: 'top',
|
|
|
|
halign: 'start',
|
|
|
|
valign: 'start',
|
|
|
|
children: [
|
|
|
|
mpris.PlayerIcon(player, {
|
|
|
|
symbolic: false,
|
|
|
|
}),
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
const Center = player => Box({
|
|
|
|
className: 'center',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
CenterBox({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
|
2023-09-15 23:22:16 -04:00
|
|
|
Box({
|
2023-09-17 17:27:23 -04:00
|
|
|
className: 'metadata',
|
|
|
|
vertical: true,
|
|
|
|
halign: 'start',
|
|
|
|
valign: 'center',
|
|
|
|
hexpand: true,
|
|
|
|
children: [
|
|
|
|
mpris.TitleLabel(player),
|
|
|
|
mpris.ArtistLabel(player),
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
}),
|
2023-09-17 17:27:23 -04:00
|
|
|
|
|
|
|
Label(),
|
|
|
|
Label(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
|
|
|
|
CenterBox({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Label(),
|
|
|
|
mpris.PlayPauseButton(player),
|
|
|
|
Label(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
const Bottom = player => Box({
|
|
|
|
className: 'bottom',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
mpris.PreviousButton(player, {
|
|
|
|
valign: 'end',
|
|
|
|
halign: 'start',
|
|
|
|
}),
|
|
|
|
Separator(8),
|
|
|
|
mpris.PositionSlider(player),
|
|
|
|
Separator(8),
|
|
|
|
mpris.NextButton(player),
|
|
|
|
Separator(8),
|
|
|
|
mpris.ShuffleButton(player),
|
|
|
|
Separator(8),
|
|
|
|
mpris.LoopButton(player),
|
|
|
|
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const PlayerBox = player => mpris.CoverArt(player, {
|
|
|
|
className: `player ${player.name}`,
|
|
|
|
hexpand: true,
|
|
|
|
children: [
|
|
|
|
Top(player),
|
|
|
|
Center(player),
|
|
|
|
Bottom(player),
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-22 14:47:37 -04:00
|
|
|
// TODO: Make this a stack with animations and gestures
|
2023-09-15 23:22:16 -04:00
|
|
|
export default () => Box({
|
2023-09-18 08:39:00 -04:00
|
|
|
vertical: true,
|
|
|
|
className: 'media',
|
|
|
|
properties: [['players', new Map()]],
|
|
|
|
connections: [
|
|
|
|
[Mpris, (box, busName) => {
|
|
|
|
if (!busName || box._players.has(busName))
|
|
|
|
return;
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-09-18 08:39:00 -04:00
|
|
|
const player = Mpris.getPlayer(busName);
|
|
|
|
player.colors = ags.Variable();
|
|
|
|
box._players.set(busName, PlayerBox(player));
|
|
|
|
box.children = Array.from(box._players.values());
|
|
|
|
}, 'player-added'],
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-09-18 08:39:00 -04:00
|
|
|
[Mpris, (box, busName) => {
|
|
|
|
if (!busName || !box._players.has(busName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
box._players.delete(busName);
|
|
|
|
box.children = Array.from(box._players.values());
|
|
|
|
}, 'player-closed'],
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|