Skip to content

Commit

Permalink
ags/music: rework connections/binds
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Dec 17, 2023
1 parent bb9742c commit dd5e9ee
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 79 deletions.
16 changes: 6 additions & 10 deletions home/programs/ags/windows/music/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ export default (player) =>
centerWidget: Widget.Button({
onClicked: () => player.playPause(),

child: Widget.Icon({
binds: [
[
"icon",
player,
"play-back-status",
mprisStateIcon,
],
],
}),
child: Widget.Icon().bind(
"icon",
player,
"play-back-status",
mprisStateIcon,
),
}),

endWidget: Widget.Button({
Expand Down
8 changes: 3 additions & 5 deletions home/programs/ags/windows/music/cover.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Widget } from "../../imports.js";

export default (player) =>
Widget.Box({
className: "cover",
binds: [[
Widget.Box({ className: "cover" })
.bind(
"css",
player,
"cover-path",
(cover) => `background-image: url('${cover ?? ""}')`,
]],
});
);
40 changes: 17 additions & 23 deletions home/programs/ags/windows/music/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,27 @@ const MusicBox = (player) =>
Cover(player),
Info(player),
],

binds: [
[
"css",
player,
"cover-path",
generateBackground,
],
],
});
})
.bind(
"css",
player,
"cover-path",
generateBackground,
);

export default PopupWindow({
monitor: 0,
layer: "overlay",
anchor: ["top"],
name: "music",
child: Widget.Box(),

binds: [
[
"child",
Mpris,
"players",
(players) => {
if (players.length == 0) return Widget.Box();
return MusicBox(players[0]);
},
],
],
});
})
.bind(
"child",
Mpris,
"players",
(players) => {
if (players.length == 0) return Widget.Box();
return MusicBox(players[0]);
},
);
7 changes: 3 additions & 4 deletions home/programs/ags/windows/music/player_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default (player) =>
hpack: "end",
className: "player-icon",
tooltipText: player.identity ?? "",

binds: [[
})
.bind(
"icon",
player,
"entry",
Expand All @@ -22,7 +22,6 @@ export default (player) =>
if (entry == "spotify") entry = "spotify-client";
return Utils.lookUpIcon(entry ?? "") ? entry : Icons.media.player;
},
]],
}),
),
],
});
32 changes: 11 additions & 21 deletions home/programs/ags/windows/music/time_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,25 @@ export const PositionLabel = (player) =>
? label.label = lengthStr(time || player.position)
: label.visible = !!player;
}]],

connections: [
[player, (l, time) => l._update(l, time), "position"],
[1000, (l) => l._update(l)],
],
});
})
.hook(player, (l, time) => l._update(l, time), "position")
.poll(1000, (l) => l._update(l));

export const LengthLabel = (player) =>
Widget.Label({
className: "length",
hexpand: true,
xalign: 1,

connections: [[player, (label) => {
player.length > 0
? label.label = lengthStr(player.length)
: label.visible = !!player;
}]],
});
})
.bind("visible", player, "length", (length) => length > 0)
.bind("label", player, "length", (length) => lengthStr(length));

export const Position = (player) =>
Widget.Slider({
className: "position",
draw_value: false,

on_change: ({ value }) => {
onChange: ({ value }) => {
player.position = player.length * value;
},

Expand All @@ -51,13 +44,10 @@ export const Position = (player) =>
slider.value = player.position / player.length;
}
}]],

connections: [
[player, (self) => self._update(self)],
[player, (self) => self._update(self), "position"],
[1000, (self) => self._update(self)],
],
});
})
.hook(player, (self) => self._update(self))
.hook(player, (self) => self._update(self), "position")
.poll(1000, (self) => self._update(self));

export default (player) =>
Widget.Box({
Expand Down
26 changes: 10 additions & 16 deletions home/programs/ags/windows/music/title_artists.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ export const Title = (player) =>
child: Widget.Label({
className: "title",
label: "Nothing playing",

binds: [
[
"label",
player,
"track-title",
(title) => title ?? "Nothing playing",
],
],
}),
})
.bind(
"label",
player,
"track-title",
(title) => title ?? "Nothing playing",
),
});

export const Artists = (player) =>
Expand All @@ -27,14 +24,11 @@ export const Artists = (player) =>
vscroll: "never",
hscroll: "automatic",

child: Widget.Label({
className: "artists",

binds: [[
child: Widget.Label({ className: "artists" })
.bind(
"label",
player,
"track-artists",
(artists) => artists.join(", ") ?? "",
]],
}),
),
});

0 comments on commit dd5e9ee

Please sign in to comment.