Update the media menu - move time stamp to tooltip

This commit is contained in:
Jas Singh
2024-06-28 01:20:16 -07:00
parent 5d9be96cca
commit 9a2a9d4ec5
8 changed files with 57 additions and 118 deletions

View File

@@ -107,6 +107,7 @@ export default () => {
children: [
Widget.Label({
truncate: "end",
max_width_chars: 21,
wrap: true,
class_name:
"media-indicator-current-song-name-label",
@@ -249,45 +250,11 @@ export default () => {
class_name: "media-indicator-current-progress-bar",
hexpand: true,
children: [
Widget.Label({
class_name: "media-indicator-time current",
vpack: "center",
setup: (self) => {
function update() {
const curHour = Math.floor(
curPlayer.position / 3600,
);
const curMin = Math.floor(
(curPlayer.position % 3600) / 60,
);
const curSec = Math.floor(
curPlayer.position % 60,
);
if (
typeof curPlayer.position === "number" &&
curPlayer.position >= 0
) {
// WARN: These nested ternaries are absolutely disgusting lol
self.label = `${
curHour > 0
? (curHour < 10
? "0" + curHour
: curHour) + ":"
: ""
}${curMin < 10 ? "0" + curMin : curMin}:${curSec < 10 ? "0" + curSec : curSec}`;
} else {
self.label = `00:00`;
}
}
self.poll(1000, update);
self.hook(curPlayer, update);
},
}),
Widget.Box({
hexpand: true,
child: Widget.Slider({
hexpand: true,
tooltip_text: "yoyo",
class_name: "menu-slider media progress",
draw_value: false,
on_change: ({ value }) =>
@@ -312,38 +279,40 @@ export default () => {
self.hook(curPlayer, update);
self.hook(curPlayer, update, "position");
self.poll(1000, update);
function updateTooltip() {
const curHour = Math.floor(
curPlayer.position / 3600,
);
const curMin = Math.floor(
(curPlayer.position % 3600) / 60,
);
const curSec = Math.floor(
curPlayer.position % 60,
);
if (
typeof curPlayer.position ===
"number" &&
curPlayer.position >= 0
) {
// WARN: These nested ternaries are absolutely disgusting lol
self.tooltip_text = `${
curHour > 0
? (curHour < 10
? "0" + curHour
: curHour) + ":"
: ""
}${curMin < 10 ? "0" + curMin : curMin}:${curSec < 10 ? "0" + curSec : curSec}`;
} else {
self.tooltip_text = `00:00`;
}
}
self.poll(1000, updateTooltip);
self.hook(curPlayer, updateTooltip);
},
}),
}),
Widget.Label({
class_name: "media-indicator-time total",
setup: (self) => {
const update = () => {
const totalSeconds = curPlayer.length;
const curHour = Math.floor(
totalSeconds / 3600,
);
const curMin = Math.floor(
(totalSeconds % 3600) / 60,
);
const curSec = Math.floor(
totalSeconds % 60,
);
self.label = `${
curHour > 0
? (curHour < 10
? "0" + curHour
: curHour) + ":"
: ""
}${curMin < 10 ? "0" + curMin : curMin}:${
curSec < 10 ? "0" + curSec : curSec
}`;
};
self.hook(curPlayer, update);
},
}),
],
}),
],