2023-10-31 08:32:40 -04:00
|
|
|
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
import { Button, Icon, Label, Stack, Slider, CenterBox, Box } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-01 14:33:06 -04:00
|
|
|
import { execAsync, lookUpIcon, readFileAsync } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
import Separator from '../misc/separator.js';
|
2023-11-16 15:02:00 -05:00
|
|
|
import EventBox from '../misc/cursorbox.js';
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
const ICON_SIZE = 32;
|
|
|
|
|
2023-09-15 23:22:16 -04:00
|
|
|
const icons = {
|
2023-10-20 23:11:21 -04:00
|
|
|
mpris: {
|
|
|
|
fallback: 'audio-x-generic-symbolic',
|
|
|
|
shuffle: {
|
|
|
|
enabled: '',
|
|
|
|
disabled: '',
|
|
|
|
},
|
|
|
|
loop: {
|
|
|
|
none: '',
|
|
|
|
track: '',
|
|
|
|
playlist: '',
|
|
|
|
},
|
|
|
|
playing: ' ',
|
|
|
|
paused: ' ',
|
|
|
|
stopped: ' ',
|
|
|
|
prev: '',
|
|
|
|
next: '',
|
2023-09-15 23:22:16 -04:00
|
|
|
},
|
2023-10-20 23:11:21 -04:00
|
|
|
};
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export const CoverArt = (player, props) => CenterBox({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
|
|
|
vertical: true,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
properties: [
|
|
|
|
['bgStyle', ''],
|
|
|
|
['player', player],
|
|
|
|
],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
setup: (self) => {
|
2023-11-01 13:13:30 -04:00
|
|
|
// Give temp cover art
|
2023-10-31 12:27:59 -04:00
|
|
|
readFileAsync(player.coverPath).catch(() => {
|
2023-11-01 13:13:30 -04:00
|
|
|
if (!player.colors.value && !player.trackCoverUrl) {
|
|
|
|
player.colors.value = {
|
2023-11-21 01:29:46 -05:00
|
|
|
imageAccent: '#6b4fa2',
|
|
|
|
buttonAccent: '#ecdcff',
|
|
|
|
buttonText: '#25005a',
|
|
|
|
hoverAccent: '#d4baff',
|
2023-11-01 13:13:30 -04:00
|
|
|
};
|
2023-10-31 12:27:59 -04:00
|
|
|
|
2023-11-01 13:13:30 -04:00
|
|
|
self._bgStyle = `
|
|
|
|
background: radial-gradient(circle,
|
|
|
|
rgba(0, 0, 0, 0.4) 30%,
|
|
|
|
${player.colors.value.imageAccent}),
|
|
|
|
rgb(0, 0, 0);
|
|
|
|
background-size: cover;
|
|
|
|
background-position: center;
|
|
|
|
`;
|
2023-11-06 18:37:23 -05:00
|
|
|
self.setCss(self._bgStyle);
|
2023-11-01 13:13:30 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
connections: [[player, (self) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
execAsync(['bash', '-c', `[[ -f "${player.coverPath}" ]] &&
|
2023-10-17 13:47:02 -04:00
|
|
|
coloryou "${player.coverPath}" | grep -v Warning`])
|
2023-11-21 01:29:46 -05:00
|
|
|
.then((out) => {
|
|
|
|
if (!Mpris.players.find((p) => player === p)) {
|
2023-10-20 23:11:21 -04:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-09-26 14:17:13 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
player.colors.value = JSON.parse(out);
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-11-01 14:33:06 -04:00
|
|
|
self._bgStyle = `
|
|
|
|
background: radial-gradient(circle,
|
|
|
|
rgba(0, 0, 0, 0.4) 30%,
|
|
|
|
${player.colors.value.imageAccent}),
|
|
|
|
url("${player.coverPath}");
|
|
|
|
background-size: cover;
|
|
|
|
background-position: center;
|
|
|
|
`;
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
if (!self.get_parent()._dragging) {
|
2023-11-06 18:37:23 -05:00
|
|
|
self.setCss(self._bgStyle);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
|
|
|
}).catch((err) => {
|
|
|
|
if (err !== '') {
|
2023-10-20 23:11:21 -04:00
|
|
|
print(err);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
|
|
|
}]],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export const TitleLabel = (player, props) => Label({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
|
|
|
xalign: 0,
|
|
|
|
maxWidthChars: 40,
|
|
|
|
truncate: 'end',
|
|
|
|
justification: 'left',
|
|
|
|
className: 'title',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
binds: [['label', player, 'track-title']],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export const ArtistLabel = (player, props) => Label({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
|
|
|
xalign: 0,
|
|
|
|
maxWidthChars: 40,
|
|
|
|
truncate: 'end',
|
|
|
|
justification: 'left',
|
|
|
|
className: 'artist',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
binds: [['label', player, 'track-artists', (a) => a.join(', ') || '']],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
export const PlayerIcon = (player, overlay, props) => {
|
|
|
|
const playerIcon = (p, widget, over) => EventBox({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
2023-11-28 12:24:58 -05:00
|
|
|
tooltipText: p.identity || '',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
onPrimaryClickRelease: () => {
|
|
|
|
widget?.moveToTop(over);
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
child: Icon({
|
|
|
|
className: widget ? 'position-indicator' : 'player-icon',
|
|
|
|
size: widget ? '' : ICON_SIZE,
|
|
|
|
|
|
|
|
connections: [[p, (self) => {
|
|
|
|
self.icon = lookUpIcon(p.entry) ?
|
|
|
|
p.entry :
|
|
|
|
icons.mpris.fallback;
|
|
|
|
}]],
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-01 14:33:06 -04:00
|
|
|
return Box({
|
2023-11-21 01:29:46 -05:00
|
|
|
connections: [[Mpris, (self) => {
|
2023-11-28 12:24:58 -05:00
|
|
|
const thisIndex = overlay.list()
|
|
|
|
.indexOf(self.get_parent().get_parent());
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
self.children = overlay.list().map((over, i) => {
|
|
|
|
self.children.push(Separator(2));
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
return i === thisIndex ?
|
|
|
|
playerIcon(player) :
|
|
|
|
playerIcon(over._player, overlay, over);
|
|
|
|
}).reverse();
|
2023-11-01 14:33:06 -04:00
|
|
|
}]],
|
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
};
|
2023-09-15 23:22:16 -04:00
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
export const PositionSlider = (player, props) => Slider({
|
|
|
|
...props,
|
|
|
|
className: 'position-slider',
|
|
|
|
cursor: 'pointer',
|
|
|
|
vpack: 'center',
|
|
|
|
hexpand: true,
|
|
|
|
drawValue: false,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
onChange: ({ value }) => {
|
|
|
|
player.position = player.length * value;
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
properties: [['update', (slider) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
if (!slider.dragging) {
|
|
|
|
slider.visible = player.length > 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
if (player.length > 0) {
|
2023-11-16 15:02:00 -05:00
|
|
|
slider.value = player.position / player.length;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-16 15:02:00 -05:00
|
|
|
}
|
|
|
|
}]],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
connections: [
|
2023-11-21 01:29:46 -05:00
|
|
|
[1000, (s) => s._update(s)],
|
|
|
|
[player, (s) => s._update(s), 'position'],
|
|
|
|
[player.colors, (s) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
if (player.colors.value) {
|
2023-11-21 01:29:46 -05:00
|
|
|
const c = player.colors.value;
|
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
s.setCss(`
|
|
|
|
highlight { background-color: ${c.buttonAccent}; }
|
|
|
|
slider { background-color: ${c.buttonAccent}; }
|
|
|
|
slider:hover { background-color: ${c.hoverAccent}; }
|
|
|
|
trough { background-color: ${c.buttonText}; }
|
|
|
|
`);
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
2023-11-16 15:02:00 -05:00
|
|
|
}],
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
['button-press-event', (s) => {
|
|
|
|
s.cursor = 'grabbing';
|
|
|
|
}],
|
|
|
|
['button-release-event', (s) => {
|
|
|
|
s.cursor = 'pointer';
|
|
|
|
}],
|
2023-11-16 15:02:00 -05:00
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
const PlayerButton = ({ player, items, onClick, prop }) => EventBox({
|
|
|
|
child: Button({
|
2023-11-21 01:29:46 -05:00
|
|
|
properties: [['hovered', false]],
|
2023-11-16 15:02:00 -05:00
|
|
|
child: Stack({ items }),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
onPrimaryClickRelease: () => player[onClick](),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
onHover: (self) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
self._hovered = true;
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-28 12:24:58 -05:00
|
|
|
if (prop === 'playBackStatus' && player.colors.value) {
|
|
|
|
const c = player.colors.value;
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
items.forEach((item) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
item[1].setCss(`
|
2023-11-28 12:24:58 -05:00
|
|
|
background-color: ${c.hoverAccent};
|
|
|
|
color: ${c.buttonText};
|
2023-11-01 14:33:06 -04:00
|
|
|
min-height: 40px;
|
|
|
|
min-width: 36px;
|
|
|
|
margin-bottom: 1px;
|
|
|
|
margin-right: 1px;
|
|
|
|
`);
|
2023-11-16 15:02:00 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
onHoverLost: (self) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
self._hovered = false;
|
2023-11-28 12:24:58 -05:00
|
|
|
if (prop === 'playBackStatus' && player.colors.value) {
|
|
|
|
const c = player.colors.value;
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
items.forEach((item) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
item[1].setCss(`
|
2023-11-28 12:24:58 -05:00
|
|
|
background-color: ${c.buttonAccent};
|
|
|
|
color: ${c.buttonText};
|
2023-11-01 14:33:06 -04:00
|
|
|
min-height: 42px;
|
|
|
|
min-width: 38px;
|
|
|
|
`);
|
2023-11-16 15:02:00 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
connections: [
|
2023-11-21 01:29:46 -05:00
|
|
|
[player, (button) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
button.child.shown = `${player[prop]}`;
|
|
|
|
}],
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
[player.colors, (button) => {
|
|
|
|
if (!Mpris.players.find((p) => player === p)) {
|
2023-11-16 15:02:00 -05:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-16 15:02:00 -05:00
|
|
|
if (player.colors.value) {
|
2023-11-21 01:29:46 -05:00
|
|
|
const c = player.colors.value;
|
|
|
|
|
|
|
|
if (prop === 'playBackStatus') {
|
2023-11-16 15:02:00 -05:00
|
|
|
if (button._hovered) {
|
2023-11-21 01:29:46 -05:00
|
|
|
items.forEach((item) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
item[1].setCss(`
|
2023-11-21 01:29:46 -05:00
|
|
|
background-color: ${c.hoverAccent};
|
|
|
|
color: ${c.buttonText};
|
2023-11-01 14:33:06 -04:00
|
|
|
min-height: 40px;
|
|
|
|
min-width: 36px;
|
|
|
|
margin-bottom: 1px;
|
|
|
|
margin-right: 1px;
|
|
|
|
`);
|
2023-11-16 15:02:00 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2023-11-21 01:29:46 -05:00
|
|
|
items.forEach((item) => {
|
2023-11-16 15:02:00 -05:00
|
|
|
item[1].setCss(`
|
2023-11-21 01:29:46 -05:00
|
|
|
background-color: ${c.buttonAccent};
|
|
|
|
color: ${c.buttonText};
|
2023-11-01 14:33:06 -04:00
|
|
|
min-height: 42px;
|
|
|
|
min-width: 38px;`);
|
2023-11-16 15:02:00 -05:00
|
|
|
});
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
2023-11-16 15:02:00 -05:00
|
|
|
else {
|
|
|
|
button.setCss(`
|
2023-11-21 01:29:46 -05:00
|
|
|
* { color: ${c.buttonAccent}; }
|
|
|
|
*:hover { color: ${c.hoverAccent}; }
|
2023-11-01 14:33:06 -04:00
|
|
|
`);
|
2023-11-16 15:02:00 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
2023-11-16 15:02:00 -05:00
|
|
|
}],
|
|
|
|
],
|
|
|
|
}),
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const ShuffleButton = (player) => PlayerButton({
|
2023-10-20 23:11:21 -04:00
|
|
|
player,
|
|
|
|
items: [
|
|
|
|
['true', Label({
|
|
|
|
className: 'shuffle enabled',
|
|
|
|
label: icons.mpris.shuffle.enabled,
|
|
|
|
})],
|
|
|
|
['false', Label({
|
|
|
|
className: 'shuffle disabled',
|
|
|
|
label: icons.mpris.shuffle.disabled,
|
|
|
|
})],
|
|
|
|
],
|
|
|
|
onClick: 'shuffle',
|
|
|
|
prop: 'shuffleStatus',
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const LoopButton = (player) => PlayerButton({
|
2023-10-20 23:11:21 -04:00
|
|
|
player,
|
|
|
|
items: [
|
|
|
|
['None', Label({
|
|
|
|
className: 'loop none',
|
|
|
|
label: icons.mpris.loop.none,
|
|
|
|
})],
|
|
|
|
['Track', Label({
|
|
|
|
className: 'loop track',
|
|
|
|
label: icons.mpris.loop.track,
|
|
|
|
})],
|
|
|
|
['Playlist', Label({
|
|
|
|
className: 'loop playlist',
|
|
|
|
label: icons.mpris.loop.playlist,
|
|
|
|
})],
|
|
|
|
],
|
|
|
|
onClick: 'loop',
|
|
|
|
prop: 'loopStatus',
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const PlayPauseButton = (player) => PlayerButton({
|
2023-10-20 23:11:21 -04:00
|
|
|
player,
|
|
|
|
items: [
|
|
|
|
['Playing', Label({
|
|
|
|
className: 'pausebutton playing',
|
|
|
|
label: icons.mpris.playing,
|
|
|
|
})],
|
|
|
|
['Paused', Label({
|
|
|
|
className: 'pausebutton paused',
|
|
|
|
label: icons.mpris.paused,
|
|
|
|
})],
|
|
|
|
['Stopped', Label({
|
|
|
|
className: 'pausebutton stopped paused',
|
|
|
|
label: icons.mpris.stopped,
|
|
|
|
})],
|
|
|
|
],
|
|
|
|
onClick: 'playPause',
|
|
|
|
prop: 'playBackStatus',
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const PreviousButton = (player) => PlayerButton({
|
2023-10-20 23:11:21 -04:00
|
|
|
player,
|
|
|
|
items: [
|
|
|
|
['true', Label({
|
|
|
|
className: 'previous',
|
|
|
|
label: icons.mpris.prev,
|
|
|
|
})],
|
|
|
|
['false', Label({
|
|
|
|
className: 'previous',
|
|
|
|
label: icons.mpris.prev,
|
|
|
|
})],
|
|
|
|
],
|
|
|
|
onClick: 'previous',
|
|
|
|
prop: 'canGoPrev',
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const NextButton = (player) => PlayerButton({
|
2023-10-20 23:11:21 -04:00
|
|
|
player,
|
|
|
|
items: [
|
|
|
|
['true', Label({
|
|
|
|
className: 'next',
|
|
|
|
label: icons.mpris.next,
|
|
|
|
})],
|
|
|
|
['false', Label({
|
|
|
|
className: 'next',
|
|
|
|
label: icons.mpris.next,
|
|
|
|
})],
|
|
|
|
],
|
|
|
|
onClick: 'next',
|
|
|
|
prop: 'canGoNext',
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|