Implemented strict linting standards and prettier formatting config. (#248)
* Implemented strict linting standards and prettier formatting config. * More linter fixes and type updates. * More linter updates and type fixes * Remove noisy comments * Linter and type updates * Linter, formatting and type updates. * Linter updates * Type updates * Type updates * fixed all linter errors * Fixed all linting, formatting and type issues. * Resolve merge conflicts.
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
const media = await Service.import("mpris");
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { Mpris, MprisPlayer } from 'types/service/mpris';
|
||||
|
||||
const Bar = (getPlayerInfo: Function) => {
|
||||
const media = await Service.import('mpris');
|
||||
|
||||
const Bar = (getPlayerInfo: (media: Mpris) => MprisPlayer): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: "media-indicator-current-progress-bar",
|
||||
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",
|
||||
tooltip_text: '--',
|
||||
class_name: 'menu-slider media progress',
|
||||
draw_value: false,
|
||||
on_change: ({ value }) => {
|
||||
const foundPlayer = getPlayerInfo(media);
|
||||
@@ -20,7 +23,7 @@ const Bar = (getPlayerInfo: Function) => {
|
||||
return (foundPlayer.position = value * foundPlayer.length);
|
||||
},
|
||||
setup: (self) => {
|
||||
const update = () => {
|
||||
const update = (): void => {
|
||||
const foundPlayer = getPlayerInfo(media);
|
||||
if (foundPlayer !== undefined) {
|
||||
const value = foundPlayer.length ? foundPlayer.position / foundPlayer.length : 0;
|
||||
@@ -32,28 +35,25 @@ const Bar = (getPlayerInfo: Function) => {
|
||||
self.hook(media, update);
|
||||
self.poll(1000, update);
|
||||
|
||||
function updateTooltip() {
|
||||
const updateTooltip = (): void => {
|
||||
const foundPlayer = getPlayerInfo(media);
|
||||
if (foundPlayer === undefined) {
|
||||
return self.tooltip_text = '00:00'
|
||||
self.tooltip_text = '00:00';
|
||||
return;
|
||||
}
|
||||
const curHour = Math.floor(foundPlayer.position / 3600);
|
||||
const curMin = Math.floor((foundPlayer.position % 3600) / 60);
|
||||
const curSec = Math.floor(foundPlayer.position % 60);
|
||||
|
||||
if (
|
||||
typeof foundPlayer.position === "number" &&
|
||||
foundPlayer.position >= 0
|
||||
) {
|
||||
if (typeof foundPlayer.position === 'number' && foundPlayer.position >= 0) {
|
||||
// WARN: These nested ternaries are absolutely disgusting lol
|
||||
self.tooltip_text = `${curHour > 0
|
||||
? (curHour < 10 ? "0" + curHour : curHour) + ":"
|
||||
: ""
|
||||
}${curMin < 10 ? "0" + curMin : curMin}:${curSec < 10 ? "0" + curSec : curSec}`;
|
||||
self.tooltip_text = `${
|
||||
curHour > 0 ? (curHour < 10 ? '0' + curHour : curHour) + ':' : ''
|
||||
}${curMin < 10 ? '0' + curMin : curMin}:${curSec < 10 ? '0' + curSec : curSec}`;
|
||||
} else {
|
||||
self.tooltip_text = `00:00`;
|
||||
}
|
||||
}
|
||||
};
|
||||
self.poll(1000, updateTooltip);
|
||||
self.hook(media, updateTooltip);
|
||||
},
|
||||
|
||||
@@ -1,82 +1,81 @@
|
||||
import { MprisPlayer } from "types/service/mpris.js";
|
||||
import icons from "../../../icons/index.js";
|
||||
import { LoopStatus, PlaybackStatus } from "lib/types/mpris.js";
|
||||
const media = await Service.import("mpris");
|
||||
import { MprisPlayer } from 'types/service/mpris.js';
|
||||
import icons from '../../../icons/index.js';
|
||||
import { LoopStatus, PlaybackStatus } from 'lib/types/mpris.js';
|
||||
import { BoxWidget } from 'lib/types/widget.js';
|
||||
const media = await Service.import('mpris');
|
||||
|
||||
const Controls = (getPlayerInfo: Function) => {
|
||||
const isValidLoopStatus = (status: string): status is LoopStatus =>
|
||||
["none", "track", "playlist"].includes(status);
|
||||
const Controls = (getPlayerInfo: () => MprisPlayer): BoxWidget => {
|
||||
const isValidLoopStatus = (status: string): status is LoopStatus => ['none', 'track', 'playlist'].includes(status);
|
||||
|
||||
const isValidPlaybackStatus = (status: string): status is PlaybackStatus =>
|
||||
["playing", "paused", "stopped"].includes(status);
|
||||
['playing', 'paused', 'stopped'].includes(status);
|
||||
|
||||
const isLoopActive = (player: MprisPlayer) => {
|
||||
return player["loop_status"] !== null &&
|
||||
["track", "playlist"].includes(player["loop_status"].toLowerCase())
|
||||
? "active"
|
||||
: "";
|
||||
const isLoopActive = (player: MprisPlayer): string => {
|
||||
return player['loop_status'] !== null && ['track', 'playlist'].includes(player['loop_status'].toLowerCase())
|
||||
? 'active'
|
||||
: '';
|
||||
};
|
||||
|
||||
const isShuffleActive = (player: MprisPlayer) => {
|
||||
return player["shuffle_status"] !== null && player["shuffle_status"]
|
||||
? "active"
|
||||
: "";
|
||||
const isShuffleActive = (player: MprisPlayer): string => {
|
||||
return player['shuffle_status'] !== null && player['shuffle_status'] ? 'active' : '';
|
||||
};
|
||||
|
||||
return Widget.Box({
|
||||
class_name: "media-indicator-current-player-controls",
|
||||
class_name: 'media-indicator-current-player-controls',
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-controls",
|
||||
hpack: "center",
|
||||
class_name: 'media-indicator-current-controls',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-control shuffle",
|
||||
class_name: 'media-indicator-control shuffle',
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
hasTooltip: true,
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const foundPlayer = getPlayerInfo();
|
||||
if (foundPlayer === undefined) {
|
||||
self.tooltip_text = "Unavailable";
|
||||
self.class_name =
|
||||
"media-indicator-control-button shuffle disabled";
|
||||
self.tooltip_text = 'Unavailable';
|
||||
self.class_name = 'media-indicator-control-button shuffle disabled';
|
||||
return;
|
||||
}
|
||||
|
||||
self.tooltip_text =
|
||||
foundPlayer.shuffle_status !== null
|
||||
? foundPlayer.shuffle_status
|
||||
? "Shuffling"
|
||||
: "Not Shuffling"
|
||||
? 'Shuffling'
|
||||
: 'Not Shuffling'
|
||||
: null;
|
||||
self.on_primary_click = () => foundPlayer.shuffle();
|
||||
self.class_name = `media-indicator-control-button shuffle ${isShuffleActive(foundPlayer)} ${foundPlayer.shuffle_status !== null ? "enabled" : "disabled"}`;
|
||||
self.on_primary_click = (): void => {
|
||||
foundPlayer.shuffle();
|
||||
};
|
||||
self.class_name = `media-indicator-control-button shuffle ${isShuffleActive(foundPlayer)} ${foundPlayer.shuffle_status !== null ? 'enabled' : 'disabled'}`;
|
||||
});
|
||||
},
|
||||
child: Widget.Icon(icons.mpris.shuffle["enabled"]),
|
||||
child: Widget.Icon(icons.mpris.shuffle['enabled']),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
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";
|
||||
self.class_name = 'media-indicator-control-button prev disabled';
|
||||
return;
|
||||
}
|
||||
|
||||
self.on_primary_click = () => foundPlayer.previous();
|
||||
self.class_name = `media-indicator-control-button prev ${foundPlayer.can_go_prev !== null && foundPlayer.can_go_prev ? "enabled" : "disabled"}`;
|
||||
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'}`;
|
||||
});
|
||||
},
|
||||
}),
|
||||
@@ -85,40 +84,35 @@ const Controls = (getPlayerInfo: Function) => {
|
||||
Widget.Box({
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const foundPlayer = getPlayerInfo();
|
||||
if (foundPlayer === undefined) {
|
||||
self.class_name =
|
||||
"media-indicator-control-button play disabled";
|
||||
self.class_name = 'media-indicator-control-button play disabled';
|
||||
return;
|
||||
}
|
||||
|
||||
self.on_primary_click = () => foundPlayer.playPause();
|
||||
self.class_name = `media-indicator-control-button play ${foundPlayer.can_play !== null ? "enabled" : "disabled"}`;
|
||||
self.on_primary_click = (): void => {
|
||||
foundPlayer.playPause();
|
||||
};
|
||||
self.class_name = `media-indicator-control-button play ${foundPlayer.can_play !== null ? 'enabled' : 'disabled'}`;
|
||||
});
|
||||
},
|
||||
child: Widget.Icon({
|
||||
icon: Utils.watch(
|
||||
icons.mpris.paused,
|
||||
media,
|
||||
"changed",
|
||||
() => {
|
||||
const foundPlayer: MprisPlayer = getPlayerInfo();
|
||||
if (foundPlayer === undefined) {
|
||||
return icons.mpris["paused"];
|
||||
}
|
||||
const playbackStatus = foundPlayer.play_back_status?.toLowerCase();
|
||||
icon: Utils.watch(icons.mpris.paused, media, 'changed', () => {
|
||||
const foundPlayer: MprisPlayer = getPlayerInfo();
|
||||
if (foundPlayer === undefined) {
|
||||
return icons.mpris['paused'];
|
||||
}
|
||||
const playbackStatus = foundPlayer.play_back_status?.toLowerCase();
|
||||
|
||||
if (playbackStatus && isValidPlaybackStatus(playbackStatus)) {
|
||||
return icons.mpris[playbackStatus];
|
||||
}
|
||||
else {
|
||||
return icons.mpris["paused"];
|
||||
}
|
||||
},
|
||||
),
|
||||
if (playbackStatus && isValidPlaybackStatus(playbackStatus)) {
|
||||
return icons.mpris[playbackStatus];
|
||||
} else {
|
||||
return icons.mpris['paused'];
|
||||
}
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
@@ -127,47 +121,49 @@ const Controls = (getPlayerInfo: Function) => {
|
||||
class_name: `media-indicator-control next`,
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
child: Widget.Icon(icons.mpris.next),
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const foundPlayer = getPlayerInfo();
|
||||
if (foundPlayer === undefined) {
|
||||
self.class_name =
|
||||
"media-indicator-control-button next disabled";
|
||||
self.class_name = 'media-indicator-control-button next disabled';
|
||||
return;
|
||||
}
|
||||
|
||||
self.on_primary_click = () => foundPlayer.next();
|
||||
self.class_name = `media-indicator-control-button next ${foundPlayer.can_go_next !== null && foundPlayer.can_go_next ? "enabled" : "disabled"}`;
|
||||
self.on_primary_click = (): void => {
|
||||
foundPlayer.next();
|
||||
};
|
||||
self.class_name = `media-indicator-control-button next ${foundPlayer.can_go_next !== null && foundPlayer.can_go_next ? 'enabled' : 'disabled'}`;
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-control loop",
|
||||
class_name: 'media-indicator-control loop',
|
||||
children: [
|
||||
Widget.Button({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const foundPlayer = getPlayerInfo();
|
||||
if (foundPlayer === undefined) {
|
||||
self.tooltip_text = "Unavailable";
|
||||
self.class_name =
|
||||
"media-indicator-control-button shuffle disabled";
|
||||
self.tooltip_text = 'Unavailable';
|
||||
self.class_name = 'media-indicator-control-button shuffle disabled';
|
||||
return;
|
||||
}
|
||||
|
||||
self.tooltip_text =
|
||||
foundPlayer.loop_status !== null
|
||||
? foundPlayer.loop_status
|
||||
? "Shuffling"
|
||||
: "Not Shuffling"
|
||||
? 'Shuffling'
|
||||
: 'Not Shuffling'
|
||||
: null;
|
||||
self.on_primary_click = () => foundPlayer.loop();
|
||||
self.class_name = `media-indicator-control-button loop ${isLoopActive(foundPlayer)} ${foundPlayer.loop_status !== null ? "enabled" : "disabled"}`;
|
||||
self.on_primary_click = (): void => {
|
||||
foundPlayer.loop();
|
||||
};
|
||||
self.class_name = `media-indicator-control-button loop ${isLoopActive(foundPlayer)} ${foundPlayer.loop_status !== null ? 'enabled' : 'disabled'}`;
|
||||
});
|
||||
},
|
||||
child: Widget.Icon({
|
||||
@@ -176,7 +172,7 @@ const Controls = (getPlayerInfo: Function) => {
|
||||
const foundPlayer: MprisPlayer = getPlayerInfo();
|
||||
|
||||
if (foundPlayer === undefined) {
|
||||
self.icon = icons.mpris.loop["none"];
|
||||
self.icon = icons.mpris.loop['none'];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -184,9 +180,8 @@ const Controls = (getPlayerInfo: Function) => {
|
||||
|
||||
if (loopStatus && isValidLoopStatus(loopStatus)) {
|
||||
self.icon = icons.mpris.loop[loopStatus];
|
||||
}
|
||||
else {
|
||||
self.icon = icons.mpris.loop["none"];
|
||||
} else {
|
||||
self.icon = icons.mpris.loop['none'];
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,78 +1,82 @@
|
||||
const media = await Service.import("mpris");
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { MprisPlayer } from 'types/service/mpris';
|
||||
|
||||
const MediaInfo = (getPlayerInfo: Function) => {
|
||||
const media = await Service.import('mpris');
|
||||
|
||||
const MediaInfo = (getPlayerInfo: () => MprisPlayer): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: "media-indicator-current-media-info",
|
||||
hpack: "center",
|
||||
class_name: 'media-indicator-current-media-info',
|
||||
hpack: 'center',
|
||||
hexpand: true,
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-song-name",
|
||||
hpack: "center",
|
||||
class_name: 'media-indicator-current-song-name',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
truncate: 'end',
|
||||
max_width_chars: 31,
|
||||
wrap: true,
|
||||
class_name: "media-indicator-current-song-name-label",
|
||||
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");
|
||||
curPlayer !== undefined && curPlayer['track_title'].length
|
||||
? curPlayer['track_title']
|
||||
: 'No Media Currently Playing');
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-song-author",
|
||||
hpack: "center",
|
||||
class_name: 'media-indicator-current-song-author',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
truncate: 'end',
|
||||
wrap: true,
|
||||
max_width_chars: 35,
|
||||
class_name: "media-indicator-current-song-author-label",
|
||||
class_name: 'media-indicator-current-song-author-label',
|
||||
setup: (self) => {
|
||||
self.hook(media, () => {
|
||||
const curPlayer = getPlayerInfo();
|
||||
|
||||
const makeArtistList = (trackArtists: string[]) => {
|
||||
const makeArtistList = (trackArtists: string[]): string => {
|
||||
if (trackArtists.length === 1 && !trackArtists[0].length) {
|
||||
return "-----";
|
||||
return '-----';
|
||||
}
|
||||
|
||||
return trackArtists.join(", ");
|
||||
return trackArtists.join(', ');
|
||||
};
|
||||
|
||||
return (self.label =
|
||||
curPlayer !== undefined && curPlayer["track-artists"].length
|
||||
? makeArtistList(curPlayer["track-artists"])
|
||||
: "-----");
|
||||
curPlayer !== undefined && curPlayer['track_artists'].length
|
||||
? makeArtistList(curPlayer['track_artists'])
|
||||
: '-----');
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "media-indicator-current-song-album",
|
||||
hpack: "center",
|
||||
class_name: 'media-indicator-current-song-album',
|
||||
hpack: 'center',
|
||||
children: [
|
||||
Widget.Label({
|
||||
truncate: "end",
|
||||
truncate: 'end',
|
||||
wrap: true,
|
||||
max_width_chars: 40,
|
||||
class_name: "media-indicator-current-song-album-label",
|
||||
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"]
|
||||
: "---");
|
||||
curPlayer !== undefined && curPlayer['track_album'].length
|
||||
? curPlayer['track_album']
|
||||
: '---');
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user