* fix: display media total length on bar * fix: add option to display custom nomedia text * feat: add dedicated label too * fix: media add more window names for playables * fix: add option to control display time * Consolidate code and make tooltip timestamp for media bar opt-in. --------- Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
const media = await Service.import('mpris');
|
|
import options from 'options';
|
|
import { BoxWidget } from 'lib/types/widget';
|
|
import { getPlayerInfo } from '../helpers';
|
|
import { update, updateTooltip } from './helpers';
|
|
|
|
const { displayTimeTooltip } = options.menus.media;
|
|
|
|
const Bar = (): BoxWidget => {
|
|
return Widget.Box({
|
|
class_name: 'media-indicator-current-progress-bar',
|
|
hexpand: true,
|
|
children: [
|
|
Widget.Box({
|
|
hexpand: true,
|
|
child: Widget.Slider({
|
|
hexpand: true,
|
|
tooltip_text: '--',
|
|
class_name: 'menu-slider media progress',
|
|
draw_value: false,
|
|
on_change: ({ value }) => {
|
|
const foundPlayer = getPlayerInfo();
|
|
if (foundPlayer === undefined) {
|
|
return;
|
|
}
|
|
return (foundPlayer.position = value * foundPlayer.length);
|
|
},
|
|
setup: (self) => {
|
|
self.poll(1000, () => {
|
|
const foundPlayer = getPlayerInfo();
|
|
|
|
if (foundPlayer?.play_back_status !== 'Playing') return;
|
|
|
|
update(self, foundPlayer);
|
|
|
|
if (!displayTimeTooltip.value) {
|
|
self.tooltip_text = '';
|
|
return;
|
|
}
|
|
|
|
updateTooltip(self, foundPlayer);
|
|
});
|
|
|
|
self.hook(media, () => {
|
|
const foundPlayer = getPlayerInfo();
|
|
update(self, foundPlayer);
|
|
|
|
if (!displayTimeTooltip.value) return;
|
|
|
|
updateTooltip(self, foundPlayer);
|
|
});
|
|
},
|
|
}),
|
|
}),
|
|
],
|
|
});
|
|
};
|
|
|
|
export { Bar };
|