2023-10-31 08:32:40 -04:00
|
|
|
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
|
|
|
|
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
|
|
|
import { Box, CenterBox } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
import * as mpris from './mpris.js';
|
2023-09-26 10:43:37 -04:00
|
|
|
import PlayerGesture from './gesture.js';
|
2023-10-17 13:47:02 -04:00
|
|
|
import Separator from '../misc/separator.js';
|
|
|
|
|
|
|
|
const FAVE_PLAYER = 'org.mpris.MediaPlayer2.spotify';
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
const Top = player => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
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({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'center',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
CenterBox({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Box({
|
|
|
|
className: 'metadata',
|
|
|
|
vertical: true,
|
|
|
|
halign: 'start',
|
|
|
|
valign: 'center',
|
|
|
|
hexpand: true,
|
|
|
|
children: [
|
|
|
|
mpris.TitleLabel(player),
|
|
|
|
mpris.ArtistLabel(player),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
}),
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
CenterBox({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
null,
|
|
|
|
mpris.PlayPauseButton(player),
|
|
|
|
null,
|
|
|
|
],
|
|
|
|
}),
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
const Bottom = player => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'bottom',
|
|
|
|
children: [
|
|
|
|
mpris.PreviousButton(player, {
|
|
|
|
valign: 'end',
|
|
|
|
halign: 'start',
|
|
|
|
}),
|
|
|
|
Separator(8),
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
mpris.PositionSlider(player),
|
|
|
|
Separator(8),
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
mpris.NextButton(player),
|
|
|
|
Separator(8),
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
mpris.ShuffleButton(player),
|
|
|
|
Separator(8),
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
mpris.LoopButton(player),
|
|
|
|
],
|
2023-09-17 17:27:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const PlayerBox = player => mpris.CoverArt(player, {
|
2023-10-20 23:11:21 -04:00
|
|
|
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-10-20 23:11:21 -04:00
|
|
|
className: 'media',
|
|
|
|
child: PlayerGesture({
|
|
|
|
properties: [
|
|
|
|
['players', new Map()],
|
|
|
|
['setup', false],
|
|
|
|
['selected'],
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[Mpris, (overlay, busName) => {
|
|
|
|
if (overlay._players.has(busName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!busName) {
|
|
|
|
const player = Mpris.players.find(p => !overlay._players.has(p.busName));
|
|
|
|
if (player)
|
|
|
|
busName = player.busName;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const player = Mpris.getPlayer(busName);
|
|
|
|
player.colors = Variable();
|
|
|
|
overlay._players.set(busName, PlayerBox(player));
|
|
|
|
|
|
|
|
const result = [];
|
|
|
|
overlay._players.forEach(widget => {
|
|
|
|
result.push(widget);
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay.overlays = result;
|
|
|
|
|
|
|
|
// Select favorite player at startup
|
|
|
|
if (!overlay._setup) {
|
|
|
|
if (overlay._players.has(FAVE_PLAYER))
|
|
|
|
overlay._selected = overlay._players.get(FAVE_PLAYER);
|
|
|
|
|
|
|
|
overlay._setup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (overlay._selected)
|
|
|
|
overlay.reorder_overlay(overlay._selected, -1);
|
|
|
|
}, 'player-added'],
|
|
|
|
|
|
|
|
|
|
|
|
[Mpris, (overlay, busName) => {
|
|
|
|
if (!busName || !overlay._players.has(busName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
overlay._players.delete(busName);
|
|
|
|
|
|
|
|
const result = [];
|
|
|
|
overlay._players.forEach(widget => {
|
|
|
|
result.push(widget);
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay.overlays = result;
|
|
|
|
if (overlay._selected)
|
|
|
|
overlay.reorder_overlay(overlay._selected, -1);
|
|
|
|
}, 'player-closed'],
|
|
|
|
],
|
|
|
|
}),
|
2023-09-26 10:47:36 -04:00
|
|
|
});
|