Files
custum-hyprpanel/src/lib/shared/media.ts
Jas Singh 2bb1449fb6 Fix: An issue that would cause Matugen colors to not apply. (#929)
* Eslint updates

* linter fixes

* Type fixes

* More type fixes

* Fix isvis

* More type fixes

* Type Fixes

* Consolidate logic to manage options

* Linter fixes

* Package lock update

* Update configs

* Version checker

* Debug pipeline

* Package lock update

* Update ci

* Strict check

* Revert ci

* Eslint

* Remove rule since it causes issues in CI

* Actual matugen fix
2025-05-11 23:01:55 -07:00

36 lines
1.0 KiB
TypeScript

import AstalMpris from 'gi://AstalMpris?version=0.1';
const mprisService = AstalMpris.get_default();
export const getCurrentPlayer = (
activePlayer: AstalMpris.Player = mprisService.get_players()[0],
): AstalMpris.Player => {
const statusOrder = {
[AstalMpris.PlaybackStatus.PLAYING]: 1,
[AstalMpris.PlaybackStatus.PAUSED]: 2,
[AstalMpris.PlaybackStatus.STOPPED]: 3,
};
const mprisPlayers = mprisService.get_players();
if (mprisPlayers.length === 0) {
return mprisPlayers[0];
}
const isPlaying = mprisPlayers.some(
(p: AstalMpris.Player) => p.playbackStatus === AstalMpris.PlaybackStatus.PLAYING,
);
const playerStillExists = mprisPlayers.some((p) => activePlayer.bus_name === p.bus_name);
const nextPlayerUp = mprisPlayers.sort(
(a: AstalMpris.Player, b: AstalMpris.Player) =>
statusOrder[a.playbackStatus] - statusOrder[b.playbackStatus],
)[0];
if (isPlaying || !playerStillExists) {
return nextPlayerUp;
}
return activePlayer;
};