2023-10-02 12:06:35 -04:00
|
|
|
import { Mpris, Variable, Widget } from '../../imports.js';
|
|
|
|
const { Box, CenterBox, Label } = Widget;
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
import * as mpris from './mpris.js';
|
2023-09-26 10:43:37 -04:00
|
|
|
import PlayerGesture from './gesture.js';
|
2023-09-17 17:27:23 -04:00
|
|
|
import { Separator } from '../misc/separator.js';
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
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: [
|
2023-09-26 10:43:37 -04:00
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
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-26 10:47:36 -04:00
|
|
|
export default () => Box({
|
2023-09-26 10:43:37 -04:00
|
|
|
className: 'media',
|
2023-09-26 10:47:36 -04:00
|
|
|
child: PlayerGesture({
|
|
|
|
properties: [
|
|
|
|
['players', new Map()],
|
|
|
|
['setup', false],
|
|
|
|
['selected'],
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[Mpris, (overlay, busName) => {
|
|
|
|
if (!busName || overlay._players.has(busName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const player = Mpris.getPlayer(busName);
|
2023-10-02 12:06:35 -04:00
|
|
|
player.colors = Variable();
|
2023-09-26 10:47:36 -04:00
|
|
|
overlay._players.set(busName, PlayerBox(player));
|
|
|
|
|
|
|
|
let result = [];
|
|
|
|
overlay._players.forEach(widget => {
|
|
|
|
result.push(widget);
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay.overlays = result;
|
|
|
|
|
|
|
|
// Favor spotify
|
|
|
|
if (!overlay._setup) {
|
|
|
|
if (overlay._players.has('org.mpris.MediaPlayer2.spotify')) {
|
|
|
|
overlay._selected = overlay._players.get('org.mpris.MediaPlayer2.spotify');
|
|
|
|
}
|
|
|
|
overlay._setup = true;
|
2023-09-24 01:40:41 -04:00
|
|
|
}
|
2023-09-26 10:43:37 -04:00
|
|
|
|
2023-09-26 10:47:36 -04:00
|
|
|
if (overlay._selected)
|
|
|
|
overlay.reorder_overlay(overlay._selected, -1);
|
|
|
|
}, 'player-added'],
|
2023-09-26 10:43:37 -04:00
|
|
|
|
2023-09-26 10:47:36 -04:00
|
|
|
[Mpris, (overlay, busName) => {
|
|
|
|
if (!busName || !overlay._players.has(busName))
|
|
|
|
return;
|
2023-09-26 10:43:37 -04:00
|
|
|
|
2023-09-26 10:47:36 -04:00
|
|
|
overlay._players.delete(busName);
|
2023-09-26 10:43:37 -04:00
|
|
|
|
2023-09-26 10:47:36 -04:00
|
|
|
let result = [];
|
|
|
|
overlay._players.forEach(widget => {
|
|
|
|
result.push(widget);
|
|
|
|
});
|
2023-09-26 10:43:37 -04:00
|
|
|
|
2023-09-26 10:47:36 -04:00
|
|
|
overlay.overlays = result;
|
|
|
|
if (overlay._selected)
|
|
|
|
overlay.reorder_overlay(overlay._selected, -1);
|
|
|
|
}, 'player-closed'],
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|