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

View File

@@ -86,14 +86,16 @@ export const getNextPlayer = (): void => {
return; return;
} }
const currentPlayerIndex = mprisService.players.findIndex((player) => player.busName === currentPlayer.busName); const currentPlayerIndex = mprisService
const totalPlayers = mprisService.players.length; .get_players()
.findIndex((player) => player.busName === currentPlayer.busName);
const totalPlayers = mprisService.get_players().length;
if (totalPlayers === 1) { 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; return;
} }
const currentPlayerIndex = mprisService.players.findIndex((player) => player.busName === currentPlayer.busName); const currentPlayerIndex = mprisService
const totalPlayers = mprisService.players.length; .get_players()
.findIndex((player) => player.busName === currentPlayer.busName);
const totalPlayers = mprisService.get_players().length;
if (totalPlayers === 1) { 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, [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( const nextPlayerUp = mprisService
(a, b) => statusOrder[a.playbackStatus] - statusOrder[b.playbackStatus], .get_players()
)[0].bus_name; .sort((a, b) => statusOrder[a.playbackStatus] - statusOrder[b.playbackStatus])[0].bus_name;
if (isPlaying || !playerStillExists) { if (isPlaying || !playerStillExists) {
curPlayer.set(nextPlayerUp); curPlayer.set(nextPlayerUp);

View File

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

View File

@@ -16,7 +16,7 @@ mprisService.connect('player-closed', (_, closedPlayer) => {
} }
if (closedPlayer.busName === activePlayer.get()?.busName) { if (closedPlayer.busName === activePlayer.get()?.busName) {
const nextPlayer = mprisService.players.find((player) => player.busName !== closedPlayer.busName); const nextPlayer = mprisService.get_players().find((player) => player.busName !== closedPlayer.busName);
activePlayer.set(nextPlayer); activePlayer.set(nextPlayer);
} }
}); });

View File

@@ -38,7 +38,7 @@ export const clearNotifications = async (notifications: AstalNotifd.Notification
const clearAllNotifications = async (): Promise<void> => { const clearAllNotifications = async (): Promise<void> => {
try { try {
clearNotifications(notifdService.notifications, clearDelay.get()); clearNotifications(notifdService.get_notifications(), clearDelay.get());
} catch (error) { } catch (error) {
errorHandler(error); errorHandler(error);
} }