WIP - Refactor media menu
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
const AlbumCover = (curPlayer) => {
|
||||
if (
|
||||
typeof curPlayer.track_cover_url === "string" &&
|
||||
curPlayer.track_cover_url.length > 0
|
||||
) {
|
||||
return Widget.Box({
|
||||
vexpand: false,
|
||||
vpack: "center",
|
||||
class_name: "media-indicator-current-album-cover",
|
||||
css: `background-image: url("${curPlayer.track_cover_url}")`,
|
||||
});
|
||||
}
|
||||
return Widget.Box();
|
||||
};
|
||||
|
||||
export { AlbumCover };
|
||||
@@ -1,4 +1,26 @@
|
||||
const Bar = (curPlayer) => {
|
||||
const media = await Service.import("mpris");
|
||||
|
||||
const Bar = (getPlayerInfo) => {
|
||||
media.connect("changed", () => {
|
||||
const statusOrder = {
|
||||
Playing: 1,
|
||||
Paused: 2,
|
||||
Stopped: 3,
|
||||
};
|
||||
|
||||
const isPlaying = media.players.find(
|
||||
(p) => p["play-back-status"] === "Playing",
|
||||
);
|
||||
|
||||
if (isPlaying) {
|
||||
curPlayer.value = media.players.sort(
|
||||
(a, b) =>
|
||||
statusOrder[a["play-back-status"]] -
|
||||
statusOrder[b["play-back-status"]],
|
||||
)[0];
|
||||
}
|
||||
});
|
||||
|
||||
return Widget.Box({
|
||||
class_name: "media-indicator-current-progress-bar",
|
||||
hexpand: true,
|
||||
@@ -11,34 +33,34 @@ const Bar = (curPlayer) => {
|
||||
class_name: "menu-slider media progress",
|
||||
draw_value: false,
|
||||
on_change: ({ value }) => {
|
||||
return (curPlayer.position = value * curPlayer.length);
|
||||
const foundPlayer = getPlayerInfo(media);
|
||||
return (foundPlayer.position = value * foundPlayer.length);
|
||||
},
|
||||
setup: (self) => {
|
||||
const update = () => {
|
||||
if (
|
||||
typeof curPlayer.position === "number" &&
|
||||
curPlayer.position > 0 &&
|
||||
typeof curPlayer.length === "number" &&
|
||||
curPlayer.length > 0
|
||||
) {
|
||||
const value = curPlayer.position / curPlayer.length;
|
||||
const foundPlayer = getPlayerInfo(media);
|
||||
if (foundPlayer !== undefined) {
|
||||
const value = foundPlayer.position / foundPlayer.length;
|
||||
self.value = value > 0 ? value : 0;
|
||||
} else {
|
||||
self.value = 0;
|
||||
}
|
||||
};
|
||||
self.hook(curPlayer, update);
|
||||
self.hook(curPlayer, update, "position");
|
||||
self.hook(media, update);
|
||||
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);
|
||||
const foundPlayer = getPlayerInfo(media);
|
||||
if (foundPlayer === undefined) {
|
||||
return self.tooltip_text = '0:0'
|
||||
}
|
||||
const curHour = Math.floor(foundPlayer.position / 3600);
|
||||
const curMin = Math.floor((foundPlayer.position % 3600) / 60);
|
||||
const curSec = Math.floor(foundPlayer.position % 60);
|
||||
|
||||
if (
|
||||
typeof curPlayer.position === "number" &&
|
||||
curPlayer.position >= 0
|
||||
typeof foundPlayer.position === "number" &&
|
||||
foundPlayer.position >= 0
|
||||
) {
|
||||
// WARN: These nested ternaries are absolutely disgusting lol
|
||||
self.tooltip_text = `${
|
||||
@@ -51,7 +73,7 @@ const Bar = (curPlayer) => {
|
||||
}
|
||||
}
|
||||
self.poll(1000, updateTooltip);
|
||||
self.hook(curPlayer, updateTooltip);
|
||||
self.hook(media, updateTooltip);
|
||||
},
|
||||
}),
|
||||
}),
|
||||
|
||||
63
modules/menus/media/components/controls.js
vendored
63
modules/menus/media/components/controls.js
vendored
@@ -1,6 +1,31 @@
|
||||
import icons from "../../../icons/index.js";
|
||||
const media = await Service.import("mpris");
|
||||
|
||||
const Controls = (curPlayer) => {
|
||||
const Controls = () => {
|
||||
const curPlayer = Variable(media.players[0]);
|
||||
|
||||
media.connect("changed", () => {
|
||||
const statusOrder = {
|
||||
Playing: 1,
|
||||
Paused: 2,
|
||||
Stopped: 3,
|
||||
};
|
||||
|
||||
const isPlaying = media.players.find(
|
||||
(p) => p["play-back-status"] === "Playing",
|
||||
);
|
||||
|
||||
if (isPlaying) {
|
||||
curPlayer.value = media.players.sort(
|
||||
(a, b) =>
|
||||
statusOrder[a["play-back-status"]] -
|
||||
statusOrder[b["play-back-status"]],
|
||||
)[0];
|
||||
}
|
||||
});
|
||||
if (curPlayer.value === undefined) {
|
||||
return Widget.Box();
|
||||
}
|
||||
const isLoopActive = (player) => {
|
||||
return player["loop-status"] !== null &&
|
||||
["track", "playlist"].includes(player["loop-status"].toLowerCase())
|
||||
@@ -28,25 +53,25 @@ const Controls = (curPlayer) => {
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
tooltip_text:
|
||||
curPlayer.shuffle_status !== null
|
||||
? curPlayer.shuffle_status
|
||||
curPlayer.value.shuffle_status !== null
|
||||
? curPlayer.value.shuffle_status
|
||||
? "Shuffling"
|
||||
: "Not Shuffling"
|
||||
: null,
|
||||
hasTooltip: true,
|
||||
on_primary_click: () => curPlayer.shuffle(),
|
||||
class_name: `media-indicator-control-button shuffle ${isShuffleActive(curPlayer)} ${curPlayer.shuffle_status !== null ? "enabled" : "disabled"}`,
|
||||
on_primary_click: () => curPlayer.value.shuffle(),
|
||||
class_name: `media-indicator-control-button shuffle ${isShuffleActive(curPlayer.value)} ${curPlayer.value.shuffle_status !== null ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(icons.mpris.shuffle["enabled"]),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: `media-indicator-control prev ${curPlayer.can_go_prev}`,
|
||||
class_name: `media-indicator-control prev ${curPlayer.value.can_go_prev}`,
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
on_primary_click: () => curPlayer.previous(),
|
||||
class_name: `media-indicator-control-button prev ${curPlayer.can_go_prev ? "enabled" : "disabled"}`,
|
||||
on_primary_click: () => curPlayer.value.previous(),
|
||||
class_name: `media-indicator-control-button prev ${curPlayer.value.can_go_prev ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(icons.mpris.prev),
|
||||
}),
|
||||
],
|
||||
@@ -56,10 +81,10 @@ const Controls = (curPlayer) => {
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
on_primary_click: () => curPlayer.playPause(),
|
||||
class_name: `media-indicator-control-button play ${curPlayer.can_play ? "enabled" : "disabled"}`,
|
||||
on_primary_click: () => curPlayer.value.playPause(),
|
||||
class_name: `media-indicator-control-button play ${curPlayer.value.can_play ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(
|
||||
icons.mpris[curPlayer.play_back_status.toLowerCase()],
|
||||
icons.mpris[curPlayer.value.play_back_status.toLowerCase()],
|
||||
),
|
||||
}),
|
||||
],
|
||||
@@ -69,8 +94,8 @@ const Controls = (curPlayer) => {
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
on_primary_click: () => curPlayer.next(),
|
||||
class_name: `media-indicator-control-button next ${curPlayer.can_go_next ? "enabled" : "disabled"}`,
|
||||
on_primary_click: () => curPlayer.value.next(),
|
||||
class_name: `media-indicator-control-button next ${curPlayer.value.can_go_next ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(icons.mpris.next),
|
||||
}),
|
||||
],
|
||||
@@ -81,16 +106,16 @@ const Controls = (curPlayer) => {
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
tooltip_text:
|
||||
curPlayer.loop_status !== null
|
||||
? `Looping: ${curPlayer.loop_status}`
|
||||
curPlayer.value.loop_status !== null
|
||||
? `Looping: ${curPlayer.value.loop_status}`
|
||||
: null,
|
||||
hasTooltip: true,
|
||||
on_primary_click: () => curPlayer.loop(),
|
||||
class_name: `media-indicator-control-button loop ${isLoopActive(curPlayer)} ${curPlayer.loop_status !== null ? "enabled" : "disabled"}`,
|
||||
on_primary_click: () => curPlayer.value.loop(),
|
||||
class_name: `media-indicator-control-button loop ${isLoopActive(curPlayer.value)} ${curPlayer.value.loop_status !== null ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(
|
||||
curPlayer.loop_status === null
|
||||
curPlayer.value.loop_status === null
|
||||
? icons.mpris.loop["none"]
|
||||
: icons.mpris.loop[curPlayer.loop_status?.toLowerCase()],
|
||||
: icons.mpris.loop[curPlayer.value.loop_status?.toLowerCase()],
|
||||
),
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
const MediaInfo = (curPlayer) => {
|
||||
const media = await Service.import("mpris");
|
||||
|
||||
const MediaInfo = () => {
|
||||
const curPlayer = Variable(media.players[0]);
|
||||
|
||||
media.connect("changed", () => {
|
||||
const statusOrder = {
|
||||
Playing: 1,
|
||||
Paused: 2,
|
||||
Stopped: 3,
|
||||
};
|
||||
|
||||
const isPlaying = media.players.find(
|
||||
(p) => p["play-back-status"] === "Playing",
|
||||
);
|
||||
|
||||
if (isPlaying) {
|
||||
curPlayer.value = media.players.sort(
|
||||
(a, b) =>
|
||||
statusOrder[a["play-back-status"]] -
|
||||
statusOrder[b["play-back-status"]],
|
||||
)[0];
|
||||
}
|
||||
console.log('changed');
|
||||
});
|
||||
return Widget.Box({
|
||||
class_name: "media-indicator-current-media-info",
|
||||
hpack: "center",
|
||||
@@ -11,10 +35,15 @@ const MediaInfo = (curPlayer) => {
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
max_width_chars: 21,
|
||||
max_width_chars: 35,
|
||||
wrap: true,
|
||||
class_name: "media-indicator-current-song-name-label",
|
||||
label: curPlayer["track-title"],
|
||||
setup: (self) => {
|
||||
self.hook(curPlayer, () => {
|
||||
console.log('did change')
|
||||
return (self.label = curPlayer.value["track-title"]);
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -25,9 +54,14 @@ const MediaInfo = (curPlayer) => {
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
max_width_chars: 25,
|
||||
max_width_chars: 35,
|
||||
class_name: "media-indicator-current-song-author-label",
|
||||
label: curPlayer["track-artists"].join(", "),
|
||||
setup: (self) => {
|
||||
self.hook(curPlayer, () => {
|
||||
console.log(JSON.stringify(curPlayer, null, 2));
|
||||
return (self.label = curPlayer.value["track-title"]);
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -38,9 +72,13 @@ const MediaInfo = (curPlayer) => {
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
max_width_chars: 25,
|
||||
max_width_chars: 40,
|
||||
class_name: "media-indicator-current-song-album-label",
|
||||
label: curPlayer["track-album"],
|
||||
setup: (self) => {
|
||||
self.hook(curPlayer, () => {
|
||||
return (self.label = curPlayer.value["track-album"]);
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
||||
@@ -1,343 +0,0 @@
|
||||
const media = await Service.import("mpris");
|
||||
import DropdownMenu from "../DropdownMenu.js";
|
||||
import icons from "../../icons/index.js";
|
||||
|
||||
media.cacheCoverArt = false;
|
||||
|
||||
export default () => {
|
||||
const activePlayer = Variable(media.players[0]);
|
||||
|
||||
media.connect("changed", (value) => {
|
||||
const statusOrder = {
|
||||
Playing: 1,
|
||||
Paused: 2,
|
||||
Stopped: 3,
|
||||
};
|
||||
|
||||
if (value.players.length === 0) {
|
||||
activePlayer.value = media.players[0];
|
||||
return;
|
||||
}
|
||||
|
||||
const isPlaying = value.players.find(
|
||||
(p) => p["play-back-status"] === "Playing",
|
||||
);
|
||||
|
||||
if (isPlaying) {
|
||||
activePlayer.value = value.players.sort(
|
||||
(a, b) =>
|
||||
statusOrder[a["play-back-status"]] -
|
||||
statusOrder[b["play-back-status"]],
|
||||
)[0];
|
||||
}
|
||||
});
|
||||
|
||||
const isLoopActive = (player) => {
|
||||
return player["loop-status"] !== null &&
|
||||
["track", "playlist"].includes(player["loop-status"].toLowerCase())
|
||||
? "active"
|
||||
: "";
|
||||
};
|
||||
|
||||
const isShuffleActive = (player) => {
|
||||
return player["shuffle-status"] !== null && player["shuffle-status"]
|
||||
? "active"
|
||||
: "";
|
||||
};
|
||||
|
||||
return DropdownMenu({
|
||||
name: "mediamenu",
|
||||
transition: "crossfade",
|
||||
fixed: true,
|
||||
minWidth: 550,
|
||||
child: Widget.Box({
|
||||
class_name: "media-indicator-container",
|
||||
vertical: true,
|
||||
hexpand: true,
|
||||
vexpand: true,
|
||||
child: Widget.Box({
|
||||
class_name: "media-indicator-items",
|
||||
vexpand: true,
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-player-info",
|
||||
vpack: "center",
|
||||
hexpand: true,
|
||||
setup: (self) => {
|
||||
self.hook(activePlayer, () => {
|
||||
self.hook(media, () => {
|
||||
const curPlayer = activePlayer.value;
|
||||
|
||||
const albumCover = (player) => {
|
||||
if (
|
||||
typeof player.track_cover_url === "string" &&
|
||||
player.track_cover_url.length > 0
|
||||
) {
|
||||
return [
|
||||
Widget.Box({
|
||||
vexpand: false,
|
||||
vpack: "center",
|
||||
class_name: "media-indicator-current-album-cover",
|
||||
css: `background-image: url("${curPlayer.track_cover_url}")`,
|
||||
}),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
if (curPlayer && curPlayer.play_back_status !== "Stopped") {
|
||||
return (self.children = [
|
||||
...albumCover(curPlayer),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-right-section",
|
||||
hpack: "center",
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-media-info",
|
||||
hpack: "center",
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-song-name",
|
||||
hpack: "center",
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
max_width_chars: 21,
|
||||
wrap: true,
|
||||
class_name:
|
||||
"media-indicator-current-song-name-label",
|
||||
label: curPlayer["track-title"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name:
|
||||
"media-indicator-current-song-author",
|
||||
hpack: "center",
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
max_width_chars: 25,
|
||||
class_name:
|
||||
"media-indicator-current-song-author-label",
|
||||
label:
|
||||
curPlayer["track-artists"].join(", "),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name:
|
||||
"media-indicator-current-song-album",
|
||||
hpack: "center",
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
max_width_chars: 25,
|
||||
class_name:
|
||||
"media-indicator-current-song-album-label",
|
||||
label: curPlayer["track-album"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name:
|
||||
"media-indicator-current-player-controls",
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-controls",
|
||||
hpack: "center",
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name:
|
||||
"media-indicator-control shuffle",
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
tooltip_text:
|
||||
curPlayer.shuffle_status !== null
|
||||
? curPlayer.shuffle_status
|
||||
? "Shuffling"
|
||||
: "Not Shuffling"
|
||||
: null,
|
||||
hasTooltip: true,
|
||||
on_primary_click: () =>
|
||||
curPlayer.shuffle(),
|
||||
class_name: `media-indicator-control-button shuffle ${isShuffleActive(curPlayer)} ${curPlayer.shuffle_status !== null ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(
|
||||
icons.mpris.shuffle["enabled"],
|
||||
),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: `media-indicator-control prev ${curPlayer.can_go_prev}`,
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
on_primary_click: () =>
|
||||
curPlayer.previous(),
|
||||
class_name: `media-indicator-control-button prev ${curPlayer.can_go_prev ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(icons.mpris.prev),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-control play",
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
on_primary_click: () =>
|
||||
curPlayer.playPause(),
|
||||
class_name: `media-indicator-control-button play ${curPlayer.can_play ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(
|
||||
icons.mpris[
|
||||
curPlayer.play_back_status.toLowerCase()
|
||||
],
|
||||
),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: `media-indicator-control next`,
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
on_primary_click: () =>
|
||||
curPlayer.next(),
|
||||
class_name: `media-indicator-control-button next ${curPlayer.can_go_next ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(icons.mpris.next),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-control loop",
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
tooltip_text:
|
||||
curPlayer.loop_status !== null
|
||||
? `Looping: ${curPlayer.loop_status}`
|
||||
: null,
|
||||
hasTooltip: true,
|
||||
on_primary_click: () =>
|
||||
curPlayer.loop(),
|
||||
class_name: `media-indicator-control-button loop ${isLoopActive(curPlayer)} ${curPlayer.loop_status !== null ? "enabled" : "disabled"}`,
|
||||
child: Widget.Icon(
|
||||
curPlayer.loop_status === null
|
||||
? icons.mpris.loop["none"]
|
||||
: icons.mpris.loop[
|
||||
curPlayer.loop_status?.toLowerCase()
|
||||
],
|
||||
),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-progress-bar",
|
||||
hexpand: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
hexpand: true,
|
||||
child: Widget.Slider({
|
||||
hexpand: true,
|
||||
tooltip_text: "yoyo",
|
||||
class_name: "menu-slider media progress",
|
||||
draw_value: false,
|
||||
on_change: ({ value }) =>
|
||||
(curPlayer.position =
|
||||
value * curPlayer.length),
|
||||
visible: curPlayer
|
||||
.bind("length")
|
||||
.as((l) => l > 0),
|
||||
setup: (self) => {
|
||||
const update = () => {
|
||||
if (
|
||||
typeof curPlayer.position ===
|
||||
"number" &&
|
||||
curPlayer.position > 0
|
||||
) {
|
||||
const value =
|
||||
curPlayer.position / curPlayer.length;
|
||||
self.value = value > 0 ? value : 0;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
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);
|
||||
},
|
||||
}),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
return (self.children = [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-none",
|
||||
hpack: "center",
|
||||
vpack: "center",
|
||||
expand: true,
|
||||
child: Widget.Label({
|
||||
class_name: "media-indicator-none-label dim",
|
||||
label: "No Media Is Currently Playing",
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
};
|
||||
@@ -1,10 +1,35 @@
|
||||
const media = await Service.import("mpris");
|
||||
import { AlbumCover } from "./components/albumcover.js";
|
||||
import { MediaInfo } from "./components/mediainfo.js";
|
||||
import { Controls } from "./components/controls.js";
|
||||
import { Bar } from "./components/bar.js";
|
||||
|
||||
const Media = () => {
|
||||
const curPlayer = Variable("");
|
||||
|
||||
media.connect("changed", () => {
|
||||
const statusOrder = {
|
||||
Playing: 1,
|
||||
Paused: 2,
|
||||
Stopped: 3,
|
||||
};
|
||||
|
||||
const isPlaying = media.players.find(
|
||||
(p) => p["play-back-status"] === "Playing",
|
||||
);
|
||||
|
||||
if (isPlaying) {
|
||||
curPlayer.value = media.players.sort(
|
||||
(a, b) =>
|
||||
statusOrder[a["play-back-status"]] -
|
||||
statusOrder[b["play-back-status"]],
|
||||
)[0].name;
|
||||
}
|
||||
});
|
||||
|
||||
const getPlayerInfo = (plyr) => {
|
||||
return plyr.players.find(p => p.name === curPlayer.value)
|
||||
}
|
||||
|
||||
return Widget.Box({
|
||||
class_name: "menu-section-container",
|
||||
children: [
|
||||
@@ -13,60 +38,38 @@ const Media = () => {
|
||||
vertical: false,
|
||||
child: Widget.Box({
|
||||
class_name: "menu-content",
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-content",
|
||||
child: Widget.Box({
|
||||
class_name: "media-indicator-right-section",
|
||||
hpack: "fill",
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [MediaInfo(), Controls(), Bar(getPlayerInfo)],
|
||||
}),
|
||||
}),
|
||||
],
|
||||
setup: (self) => {
|
||||
let curPlayer = media.players[0];
|
||||
self.hook(media, () => {
|
||||
const statusOrder = {
|
||||
Playing: 1,
|
||||
Paused: 2,
|
||||
Stopped: 3,
|
||||
};
|
||||
self.css = `background-image: linear-gradient(
|
||||
rgba(30, 30, 46, 0.85),
|
||||
rgba(30, 30, 46, 0.9),
|
||||
#1e1e2e 40em), url("${getPlayerInfo(media).track_cover_url}");
|
||||
`;
|
||||
|
||||
const isPlaying = media.players.find(
|
||||
(p) => p["play-back-status"] === "Playing",
|
||||
);
|
||||
|
||||
if (isPlaying) {
|
||||
curPlayer = media.players.sort(
|
||||
(a, b) =>
|
||||
statusOrder[a["play-back-status"]] -
|
||||
statusOrder[b["play-back-status"]],
|
||||
)[0];
|
||||
}
|
||||
|
||||
if (
|
||||
media.players.length &&
|
||||
curPlayer &&
|
||||
curPlayer.play_back_status !== "Stopped"
|
||||
) {
|
||||
return (self.children = [
|
||||
AlbumCover(curPlayer),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-right-section",
|
||||
hpack: "fill",
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [
|
||||
MediaInfo(curPlayer),
|
||||
Controls(curPlayer),
|
||||
Bar(curPlayer),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
return (self.children = [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-none",
|
||||
hpack: "center",
|
||||
hexpand: true,
|
||||
vpack: "center",
|
||||
child: Widget.Label({
|
||||
class_name: "media-indicator-none-label dim",
|
||||
label: "No Media Is Currently Playing",
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
// return (self.children = [
|
||||
// Widget.Box({
|
||||
// class_name: "media-indicator-none",
|
||||
// hpack: "center",
|
||||
// hexpand: true,
|
||||
// vpack: "center",
|
||||
// child: Widget.Label({
|
||||
// class_name: "media-indicator-none-label dim",
|
||||
// label: "No Media Is Currently Playing",
|
||||
// }),
|
||||
// }),
|
||||
// ]);
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user