fix mpris service references (#568)

This commit is contained in:
Jas Singh
2024-12-20 23:13:40 -08:00
committed by GitHub
parent e4a5e8060e
commit 3be15068c0
6 changed files with 28 additions and 22 deletions

View File

@@ -5,8 +5,8 @@ import { isPrimaryClick } from 'src/lib/utils';
import { getNextPlayer, getPreviousPlayer } from './helpers';
export const PreviousPlayer = (): JSX.Element => {
const className = bind(mprisService, 'players').as(() => {
const isDisabled = mprisService.players.length <= 1 ? 'disabled' : 'enabled';
const className = bind(mprisService, 'players').as((players) => {
const isDisabled = players.length <= 1 ? 'disabled' : 'enabled';
return `media-indicator-control-button ${isDisabled}`;
});
@@ -16,7 +16,7 @@ export const PreviousPlayer = (): JSX.Element => {
return;
}
const isDisabled = mprisService.players.length <= 1;
const isDisabled = mprisService.get_players().length <= 1;
if (!isDisabled) {
getPreviousPlayer();
@@ -37,8 +37,8 @@ export const PreviousPlayer = (): JSX.Element => {
};
export const NextPlayer = (): JSX.Element => {
const className = bind(mprisService, 'players').as(() => {
const isDisabled = mprisService.players.length <= 1 ? 'disabled' : 'enabled';
const className = bind(mprisService, 'players').as((players) => {
const isDisabled = players.length <= 1 ? 'disabled' : 'enabled';
return `media-indicator-control-button ${isDisabled}`;
});
const onClick = (_: Widget.Button, event: Astal.ClickEvent): void => {
@@ -46,7 +46,7 @@ export const NextPlayer = (): JSX.Element => {
return;
}
const isDisabled = mprisService.players.length <= 1;
const isDisabled = mprisService.get_players().length <= 1;
if (!isDisabled) {
getNextPlayer();

View File

@@ -86,14 +86,16 @@ export const getNextPlayer = (): void => {
return;
}
const currentPlayerIndex = mprisService.players.findIndex((player) => player.busName === currentPlayer.busName);
const totalPlayers = mprisService.players.length;
const currentPlayerIndex = mprisService
.get_players()
.findIndex((player) => player.busName === currentPlayer.busName);
const totalPlayers = mprisService.get_players().length;
if (totalPlayers === 1) {
return activePlayer.set(mprisService.players[0]);
return activePlayer.set(mprisService.get_players()[0]);
}
return activePlayer.set(mprisService.players[(currentPlayerIndex + 1) % totalPlayers]);
return activePlayer.set(mprisService.get_players()[(currentPlayerIndex + 1) % totalPlayers]);
};
/**
@@ -111,12 +113,14 @@ export const getPreviousPlayer = (): void => {
return;
}
const currentPlayerIndex = mprisService.players.findIndex((player) => player.busName === currentPlayer.busName);
const totalPlayers = mprisService.players.length;
const currentPlayerIndex = mprisService
.get_players()
.findIndex((player) => player.busName === currentPlayer.busName);
const totalPlayers = mprisService.get_players().length;
if (totalPlayers === 1) {
return activePlayer.set(mprisService.players[0]);
return activePlayer.set(mprisService.get_players()[0]);
}
return activePlayer.set(mprisService.players[(currentPlayerIndex - 1 + totalPlayers) % totalPlayers]);
return activePlayer.set(mprisService.get_players()[(currentPlayerIndex - 1 + totalPlayers) % totalPlayers]);
};

View File

@@ -52,13 +52,15 @@ export const initializeActivePlayerHook = (): void => {
[AstalMpris.PlaybackStatus.STOPPED]: 3,
};
const isPlaying = mprisService.players.find((p) => p['playbackStatus'] === AstalMpris.PlaybackStatus.PLAYING);
const isPlaying = mprisService
.get_players()
.find((p) => p['playbackStatus'] === AstalMpris.PlaybackStatus.PLAYING);
const playerStillExists = mprisService.players.some((player) => curPlayer.set(player.busName));
const playerStillExists = mprisService.get_players().some((player) => curPlayer.set(player.busName));
const nextPlayerUp = mprisService.players.sort(
(a, b) => statusOrder[a.playbackStatus] - statusOrder[b.playbackStatus],
)[0].bus_name;
const nextPlayerUp = mprisService
.get_players()
.sort((a, b) => statusOrder[a.playbackStatus] - statusOrder[b.playbackStatus])[0].bus_name;
if (isPlaying || !playerStillExists) {
curPlayer.set(nextPlayerUp);

View File

@@ -20,7 +20,7 @@ export const ClearNotificationsButton = (): JSX.Element => {
return;
}
clearNotifications(notifdService.notifications, clearDelay.get());
clearNotifications(notifdService.get_notifications(), clearDelay.get());
}}
>
<label