Clean up media module logic and code. (#380)
* Organized media menu code * More consolidation
This commit is contained in:
27
modules/menus/media/components/title/album/index.ts
Normal file
27
modules/menus/media/components/title/album/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
const media = await Service.import('mpris');
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { getPlayerInfo } from '../../helpers';
|
||||
|
||||
export const songAlbum = (): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: 'media-indicator-current-song-album',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: 'end',
|
||||
wrap: true,
|
||||
max_width_chars: 40,
|
||||
class_name: 'media-indicator-current-song-album-label',
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const curPlayer = getPlayerInfo();
|
||||
return (self.label =
|
||||
curPlayer !== undefined && curPlayer['track_album'].length
|
||||
? curPlayer['track_album']
|
||||
: '---');
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
};
|
||||
36
modules/menus/media/components/title/author/index.ts
Normal file
36
modules/menus/media/components/title/author/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
const media = await Service.import('mpris');
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { getPlayerInfo } from '../../helpers';
|
||||
|
||||
export const songAuthor = (): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: 'media-indicator-current-song-author',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: 'end',
|
||||
wrap: true,
|
||||
max_width_chars: 35,
|
||||
class_name: 'media-indicator-current-song-author-label',
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const curPlayer = getPlayerInfo();
|
||||
|
||||
const makeArtistList = (trackArtists: string[]): string => {
|
||||
if (trackArtists.length === 1 && !trackArtists[0].length) {
|
||||
return '-----';
|
||||
}
|
||||
|
||||
return trackArtists.join(', ');
|
||||
};
|
||||
|
||||
return (self.label =
|
||||
curPlayer !== undefined && curPlayer['track_artists'].length
|
||||
? makeArtistList(curPlayer['track_artists'])
|
||||
: '-----');
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
};
|
||||
14
modules/menus/media/components/title/index.ts
Normal file
14
modules/menus/media/components/title/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { songName } from './name/index';
|
||||
import { songAuthor } from './author/index';
|
||||
import { songAlbum } from './album/index';
|
||||
|
||||
export const MediaInfo = (): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: 'media-indicator-current-media-info',
|
||||
hpack: 'center',
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [songName(), songAuthor(), songAlbum()],
|
||||
});
|
||||
};
|
||||
28
modules/menus/media/components/title/name/index.ts
Normal file
28
modules/menus/media/components/title/name/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { getPlayerInfo } from '../../helpers';
|
||||
|
||||
const media = await Service.import('mpris');
|
||||
|
||||
export const songName = (): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: 'media-indicator-current-song-name',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: 'end',
|
||||
max_width_chars: 31,
|
||||
wrap: true,
|
||||
class_name: 'media-indicator-current-song-name-label',
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const curPlayer = getPlayerInfo();
|
||||
return (self.label =
|
||||
curPlayer !== undefined && curPlayer['track_title'].length
|
||||
? curPlayer['track_title']
|
||||
: 'No Media Currently Playing');
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user