feat(ags player): make player into stack and add anim
This commit is contained in:
parent
897fbc3afb
commit
26e04f9626
1 changed files with 77 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
|||
const { Mpris } = ags.Service;
|
||||
const { Box, CenterBox, Label } = ags.Widget;
|
||||
const { Box, CenterBox, Label, Stack, EventBox } = ags.Widget;
|
||||
const { Gtk } = imports.gi;
|
||||
|
||||
import * as mpris from './mpris.js';
|
||||
import { Separator } from '../misc/separator.js';
|
||||
|
@ -82,28 +83,81 @@ const PlayerBox = player => mpris.CoverArt(player, {
|
|||
],
|
||||
});
|
||||
|
||||
// TODO: Make this a stack with animations and gestures
|
||||
export default () => Box({
|
||||
vertical: true,
|
||||
export default () => {
|
||||
let widget = EventBox();
|
||||
|
||||
let gesture = Gtk.GestureDrag.new(widget)
|
||||
|
||||
widget.child = Stack({
|
||||
className: 'media',
|
||||
properties: [['players', new Map()]],
|
||||
properties: [
|
||||
['players', new Map()],
|
||||
['previous', 'spotify'],
|
||||
],
|
||||
connections: [
|
||||
[Mpris, (box, busName) => {
|
||||
if (!busName || box._players.has(busName))
|
||||
[gesture, stack => {
|
||||
const offset = gesture.get_offset()[1];
|
||||
if (Math.abs(offset) > 200) {
|
||||
let players = [];
|
||||
stack._players.forEach((_, busName) => players.push(Mpris.getPlayer(busName).name));
|
||||
let current = players.findIndex(player => player === stack.shown);
|
||||
|
||||
if (offset > 0) {
|
||||
stack.transition = 'slide_right';
|
||||
if (players[++current])
|
||||
stack.shown = `${players[current]}`;
|
||||
else
|
||||
stack.shown = `${players[0]}`;
|
||||
}
|
||||
else {
|
||||
stack.transition = 'slide_left';
|
||||
if (players[--current])
|
||||
stack.shown = `${players[current]}`;
|
||||
else
|
||||
stack.shown = `${players.at(-1)}`;
|
||||
}
|
||||
stack._previous = stack.shown;
|
||||
}
|
||||
}, 'drag-end'],
|
||||
|
||||
[Mpris, (stack, busName) => {
|
||||
if (!busName || stack._players.has(busName))
|
||||
return;
|
||||
|
||||
const player = Mpris.getPlayer(busName);
|
||||
player.colors = ags.Variable();
|
||||
box._players.set(busName, PlayerBox(player));
|
||||
box.children = Array.from(box._players.values());
|
||||
stack._players.set(busName, PlayerBox(player));
|
||||
|
||||
let result = [];
|
||||
stack._players.forEach((widget, busName) => {
|
||||
result.push([`${Mpris.getPlayer(busName).name}`, widget]);
|
||||
});
|
||||
|
||||
stack.items = result;
|
||||
if (result.find(p => p[0] === stack._previous))
|
||||
stack.shown = stack._previous;
|
||||
else if (stack._players.has('org.mpris.MediaPlayer2.spotify'))
|
||||
stack.shown = `spotify`;
|
||||
}, 'player-added'],
|
||||
|
||||
[Mpris, (box, busName) => {
|
||||
if (!busName || !box._players.has(busName))
|
||||
[Mpris, (stack, busName) => {
|
||||
if (!busName || !stack._players.has(busName))
|
||||
return;
|
||||
|
||||
box._players.delete(busName);
|
||||
box.children = Array.from(box._players.values());
|
||||
stack._players.delete(busName);
|
||||
|
||||
let result = [];
|
||||
stack._players.forEach((widget, busName) => {
|
||||
result.push([`${Mpris.getPlayer(busName).name}`, widget]);
|
||||
});
|
||||
|
||||
stack.items = result;
|
||||
if (result.find(p => p[0] === stack._previous))
|
||||
stack.shown = stack._previous;
|
||||
else if (stack._players.has('org.mpris.MediaPlayer2.spotify'))
|
||||
stack.shown = `spotify`;
|
||||
}, 'player-closed'],
|
||||
],
|
||||
});
|
||||
return widget;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue