2023-09-19 23:22:53 -04:00
|
|
|
const { execAsync, lookUpIcon } = ags.Utils;
|
|
|
|
const { Button, Icon, Label, Stack, Slider, CenterBox } = ags.Widget;
|
|
|
|
const { Gdk } = imports.gi;
|
2023-09-18 10:22:12 -04:00
|
|
|
const display = Gdk.Display.get_default();
|
|
|
|
|
|
|
|
import { EventBox } from '../misc/cursorbox.js';
|
2023-09-15 23:22:16 -04:00
|
|
|
|
|
|
|
const icons = {
|
|
|
|
mpris: {
|
|
|
|
fallback: 'audio-x-generic-symbolic',
|
|
|
|
shuffle: {
|
2023-09-17 17:27:23 -04:00
|
|
|
enabled: '',
|
|
|
|
disabled: '',
|
2023-09-15 23:22:16 -04:00
|
|
|
},
|
|
|
|
loop: {
|
2023-09-17 17:27:23 -04:00
|
|
|
none: '',
|
|
|
|
track: '',
|
|
|
|
playlist: '',
|
2023-09-15 23:22:16 -04:00
|
|
|
},
|
2023-09-17 17:27:23 -04:00
|
|
|
playing: ' ',
|
|
|
|
paused: ' ',
|
|
|
|
stopped: ' ',
|
2023-09-15 23:22:16 -04:00
|
|
|
prev: '',
|
|
|
|
next: '',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
export const CoverArt = (player, params) => CenterBox({
|
|
|
|
...params,
|
|
|
|
className: 'player',
|
|
|
|
vertical: true,
|
|
|
|
connections: [
|
|
|
|
[player, box => {
|
2023-09-18 08:39:00 -04:00
|
|
|
execAsync(['bash', '-c', `[[ -f "${player.coverPath}" ]] && coloryou "${player.coverPath}"`])
|
2023-09-17 17:27:23 -04:00
|
|
|
.then(out => {
|
2023-09-19 23:22:53 -04:00
|
|
|
if (box) {
|
|
|
|
player.colors.value = JSON.parse(out);
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-09-19 23:22:53 -04:00
|
|
|
box.setStyle(`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-09-17 17:27:23 -04:00
|
|
|
}).catch(err => { if (err !== "") print(err) });
|
|
|
|
}],
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
export const TitleLabel = (player, params) => Label({
|
2023-09-18 14:31:08 -04:00
|
|
|
...params,
|
2023-09-17 17:27:23 -04:00
|
|
|
xalign: 0,
|
|
|
|
maxWidthChars: 40,
|
|
|
|
truncate: 'end',
|
|
|
|
justification: 'left',
|
|
|
|
className: 'title',
|
|
|
|
binds: [['label', player, 'trackTitle']],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
export const ArtistLabel = (player, params) => Label({
|
|
|
|
...params,
|
|
|
|
xalign: 0,
|
|
|
|
maxWidthChars: 40,
|
|
|
|
truncate: 'end',
|
|
|
|
justification: 'left',
|
|
|
|
className: 'artist',
|
|
|
|
connections: [[player, label => {
|
|
|
|
label.label = player.trackArtists.join(', ') || '';
|
|
|
|
}]],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:27:23 -04:00
|
|
|
export const PlayerIcon = (player, { symbolic = true, ...params } = {}) => Icon({
|
|
|
|
...params,
|
|
|
|
className: 'player-icon',
|
2023-09-18 10:22:12 -04:00
|
|
|
size: 32,
|
|
|
|
tooltipText: player.identity || '',
|
2023-09-17 17:27:23 -04:00
|
|
|
connections: [[player, icon => {
|
|
|
|
const name = `${player.entry}${symbolic ? '-symbolic' : ''}`;
|
|
|
|
lookUpIcon(name) ? icon.icon = name
|
|
|
|
: icon.icon = icons.mpris.fallback;
|
|
|
|
}]],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-18 10:22:12 -04:00
|
|
|
export const PositionSlider = (player, params) => EventBox({
|
|
|
|
child: Slider({
|
|
|
|
...params,
|
|
|
|
className: 'position-slider',
|
|
|
|
hexpand: true,
|
|
|
|
drawValue: false,
|
|
|
|
onChange: ({ value }) => {
|
|
|
|
player.position = player.length * value;
|
|
|
|
},
|
|
|
|
properties: [
|
|
|
|
['update', slider => {
|
|
|
|
if (slider.dragging) {
|
|
|
|
slider.get_parent().window.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (slider.get_parent() && slider.get_parent().window) {
|
|
|
|
slider.get_parent().window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
|
|
|
|
}
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-09-18 10:22:12 -04:00
|
|
|
slider.sensitive = player.length > 0;
|
|
|
|
if (player.length > 0) {
|
|
|
|
slider.value = player.position / player.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[player, s => s._update(s), 'position'],
|
|
|
|
[1000, s => s._update(s)],
|
|
|
|
[player.colors, s => {
|
|
|
|
if (player.colors.value)
|
|
|
|
s.setCss(`highlight { background-color: ${player.colors.value.buttonAccent}; }
|
|
|
|
slider { background-color: ${player.colors.value.buttonAccent}; }
|
2023-09-18 13:36:50 -04:00
|
|
|
slider:hover { background-color: ${player.colors.value.hoverAccent}; }
|
2023-09-18 10:22:12 -04:00
|
|
|
trough { background-color: ${player.colors.value.buttonAccent}; }`);
|
|
|
|
}],
|
|
|
|
],
|
|
|
|
}),
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
function lengthStr(length) {
|
2023-09-17 17:27:23 -04:00
|
|
|
const min = Math.floor(length / 60);
|
|
|
|
const sec0 = Math.floor(length % 60) < 10 ? '0' : '';
|
|
|
|
const sec = Math.floor(length % 60);
|
|
|
|
return `${min}:${sec0}${sec}`;
|
2023-09-15 23:22:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const PositionLabel = player => Label({
|
2023-09-17 17:27:23 -04:00
|
|
|
properties: [['update', label => {
|
|
|
|
player.length > 0 ? label.label = lengthStr(player.position)
|
|
|
|
: label.visible = !!player;
|
|
|
|
}]],
|
|
|
|
connections: [
|
|
|
|
[player, l => l._update(l), 'position'],
|
|
|
|
[1000, l => l._update(l)],
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export const LengthLabel = player => Label({
|
2023-09-17 17:27:23 -04:00
|
|
|
connections: [[player, label => {
|
|
|
|
player.length > 0 ? label.label = lengthStr(player.length)
|
|
|
|
: label.visible = !!player;
|
|
|
|
}]],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export const Slash = player => Label({
|
2023-09-17 17:27:23 -04:00
|
|
|
label: '/',
|
|
|
|
connections: [[player, label => {
|
|
|
|
label.visible = player.length > 0;
|
|
|
|
}]],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
2023-09-18 13:36:50 -04:00
|
|
|
// TODO: use label instead of stack to fix UI issues
|
2023-09-17 17:27:23 -04:00
|
|
|
const PlayerButton = ({ player, items, onClick, prop }) => Button({
|
|
|
|
child: Stack({ items }),
|
|
|
|
onPrimaryClickRelease: () => player[onClick](),
|
2023-09-18 14:56:57 -04:00
|
|
|
properties: [['hovered', false]],
|
2023-09-18 13:36:50 -04:00
|
|
|
onHover: box => {
|
2023-09-18 14:56:57 -04:00
|
|
|
box._hovered = true;
|
2023-09-18 13:36:50 -04:00
|
|
|
if (! box.child.sensitive || ! box.sensitive) {
|
|
|
|
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'not-allowed'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop == 'playBackStatus') {
|
|
|
|
items.forEach(item => {
|
|
|
|
item[1].setStyle(`background-color: ${player.colors.value.hoverAccent};
|
2023-09-18 14:31:08 -04:00
|
|
|
color: ${player.colors.value.buttonText};
|
|
|
|
min-height: 40px; min-width: 36px;
|
|
|
|
margin-bottom: 1px; margin-right: 1px;`);
|
2023-09-18 13:36:50 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onHoverLost: box => {
|
2023-09-18 14:56:57 -04:00
|
|
|
box._hovered = false;
|
2023-09-18 13:36:50 -04:00
|
|
|
box.window.set_cursor(null);
|
|
|
|
if (prop == 'playBackStatus') {
|
|
|
|
items.forEach(item => {
|
|
|
|
item[1].setStyle(`background-color: ${player.colors.value.buttonAccent};
|
2023-09-18 14:31:08 -04:00
|
|
|
color: ${player.colors.value.buttonText};
|
|
|
|
min-height: 42px; min-width: 38px;`);
|
2023-09-18 13:36:50 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2023-09-17 17:27:23 -04:00
|
|
|
connections: [
|
|
|
|
[player, button => {
|
|
|
|
button.child.shown = `${player[prop]}`;
|
2023-09-18 08:39:00 -04:00
|
|
|
}],
|
2023-09-17 17:27:23 -04:00
|
|
|
|
2023-09-18 08:39:00 -04:00
|
|
|
[player.colors, button => {
|
|
|
|
if (player.colors.value) {
|
2023-09-17 17:27:23 -04:00
|
|
|
if (prop == 'playBackStatus') {
|
2023-09-18 14:56:57 -04:00
|
|
|
if (button._hovered) {
|
|
|
|
items.forEach(item => {
|
|
|
|
item[1].setStyle(`background-color: ${player.colors.value.hoverAccent};
|
|
|
|
color: ${player.colors.value.buttonText};
|
|
|
|
min-height: 40px; min-width: 36px;
|
|
|
|
margin-bottom: 1px; margin-right: 1px;`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
items.forEach(item => {
|
|
|
|
item[1].setStyle(`background-color: ${player.colors.value.buttonAccent};
|
|
|
|
color: ${player.colors.value.buttonText};
|
|
|
|
min-height: 42px; min-width: 38px;`);
|
|
|
|
});
|
|
|
|
}
|
2023-09-17 17:27:23 -04:00
|
|
|
}
|
|
|
|
else {
|
2023-09-18 13:36:50 -04:00
|
|
|
button.setCss(`* { color: ${player.colors.value.buttonAccent}; }
|
|
|
|
*:hover { color: ${player.colors.value.hoverAccent}; }`);
|
2023-09-17 17:27:23 -04:00
|
|
|
}
|
2023-09-18 08:39:00 -04:00
|
|
|
}
|
2023-09-17 17:27:23 -04:00
|
|
|
}],
|
|
|
|
],
|
2023-09-15 23:22:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export const ShuffleButton = player => PlayerButton({
|
2023-09-17 17:27:23 -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
|
|
|
});
|
|
|
|
|
|
|
|
export const LoopButton = player => PlayerButton({
|
2023-09-17 17:27:23 -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
|
|
|
});
|
|
|
|
|
|
|
|
export const PlayPauseButton = player => PlayerButton({
|
2023-09-17 17:27:23 -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
|
|
|
});
|
|
|
|
|
|
|
|
export const PreviousButton = player => PlayerButton({
|
2023-09-17 17:27:23 -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
|
|
|
});
|
|
|
|
|
|
|
|
export const NextButton = player => PlayerButton({
|
2023-09-17 17:27:23 -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
|
|
|
});
|