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],
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[Mpris, (overlay, busName) => {
|
|
|
|
if (overlay._players.has(busName))
|
|
|
|
return;
|
|
|
|
|
2023-11-01 13:13:30 -04:00
|
|
|
// Sometimes the signal doesn't give the busName
|
2023-10-20 23:11:21 -04:00
|
|
|
if (!busName) {
|
|
|
|
const player = Mpris.players.find(p => !overlay._players.has(p.busName));
|
|
|
|
if (player)
|
|
|
|
busName = player.busName;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-01 13:13:30 -04:00
|
|
|
// Get the one on top so it stays there
|
|
|
|
var previousFirst = overlay.get_children().at(-1);
|
|
|
|
for (const [key, value] of overlay._players.entries()) {
|
|
|
|
if (value === previousFirst) {
|
|
|
|
previousFirst = key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const player = Mpris.getPlayer(busName);
|
|
|
|
player.colors = Variable();
|
2023-10-31 12:27:59 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
overlay._players.set(busName, PlayerBox(player));
|
|
|
|
|
|
|
|
const result = [];
|
|
|
|
overlay._players.forEach(widget => {
|
|
|
|
result.push(widget);
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay.overlays = result;
|
|
|
|
|
|
|
|
// Select favorite player at startup
|
2023-11-01 23:11:39 -04:00
|
|
|
if (!overlay._setup && overlay._players.has(FAVE_PLAYER)) {
|
|
|
|
overlay.reorder_overlay(overlay._players.get(FAVE_PLAYER), -1);
|
2023-10-20 23:11:21 -04:00
|
|
|
overlay._setup = true;
|
|
|
|
}
|
2023-11-01 23:11:39 -04:00
|
|
|
else if (overlay._players.get(previousFirst)) {
|
2023-11-01 13:13:30 -04:00
|
|
|
overlay.reorder_overlay(overlay._players.get(previousFirst), -1);
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}, 'player-added'],
|
|
|
|
|
|
|
|
|
|
|
|
[Mpris, (overlay, busName) => {
|
|
|
|
if (!busName || !overlay._players.has(busName))
|
|
|
|
return;
|
|
|
|
|
2023-11-01 13:13:30 -04:00
|
|
|
// Get the one on top so it stays there
|
|
|
|
var previousFirst = overlay.get_children().at(-1);
|
|
|
|
for (const [key, value] of overlay._players.entries()) {
|
|
|
|
if (value === previousFirst) {
|
|
|
|
previousFirst = key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
overlay._players.delete(busName);
|
|
|
|
|
|
|
|
const result = [];
|
|
|
|
overlay._players.forEach(widget => {
|
|
|
|
result.push(widget);
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay.overlays = result;
|
2023-11-01 13:13:30 -04:00
|
|
|
|
|
|
|
if (overlay._players.has(previousFirst))
|
|
|
|
overlay.reorder_overlay(overlay._players.get(previousFirst), -1);
|
2023-10-20 23:11:21 -04:00
|
|
|
}, 'player-closed'],
|
|
|
|
],
|
|
|
|
}),
|
2023-09-26 10:47:36 -04:00
|
|
|
});
|