Clean up media module logic and code. (#380)

* Organized media menu code

* More consolidation
This commit is contained in:
Jas Singh
2024-10-27 00:17:51 -07:00
committed by GitHub
parent 86ff27fd3e
commit 14654998ea
23 changed files with 511 additions and 427 deletions

View File

@@ -0,0 +1,27 @@
const media = await Service.import('mpris');
import icons from 'lib/icons';
import { Attribute } from 'lib/types/widget';
import { getPlayerInfo } from '../../helpers';
import Button from 'types/widgets/button';
import Icon from 'types/widgets/icon';
export const previousTrack = (): Button<Icon<Attribute>, Attribute> => {
return Widget.Button({
hpack: 'center',
child: Widget.Icon(icons.mpris.prev),
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name = 'media-indicator-control-button prev disabled';
return;
}
self.on_primary_click = (): void => {
foundPlayer.previous();
};
self.class_name = `media-indicator-control-button prev ${foundPlayer.can_go_prev !== null && foundPlayer.can_go_prev ? 'enabled' : 'disabled'}`;
});
},
});
};