quick fix to regex, and added trunc indicator (#104)

This commit is contained in:
matavach
2024-08-10 23:37:07 -05:00
committed by GitHub
parent 0898c98f9c
commit a3178678dd

View File

@@ -2,7 +2,6 @@ import Gdk from 'gi://Gdk?version=3.0';
const mpris = await Service.import("mpris"); const mpris = await Service.import("mpris");
import { openMenu } from "../utils.js"; import { openMenu } from "../utils.js";
import options from "options"; import options from "options";
import { Mpris } from 'types/service/mpris.js';
import { getCurrentPlayer } from 'lib/shared/media.js'; import { getCurrentPlayer } from 'lib/shared/media.js';
const { show_artist, truncation, truncation_size } = options.bar.media; const { show_artist, truncation, truncation_size } = options.bar.media;
@@ -17,18 +16,16 @@ const Media = () => {
const getIconForPlayer = (playerName: string): string => { const getIconForPlayer = (playerName: string): string => {
const windowTitleMap = [ const windowTitleMap = [
["Mozilla Firefox", "󰈹 "], ["Firefox", "󰈹 "],
["Microsoft Edge", "󰇩 "], ["Microsoft Edge", "󰇩 "],
["(.*)Discord(.*)", " "], ["Discord", " "],
["Plex", "󰚺 "], ["Plex", "󰚺 "],
["(.*) Spotify Free", "󰓇 "],
["(.*)Spotify Premium", "󰓇 "],
["Spotify", "󰓇 "], ["Spotify", "󰓇 "],
["(.*)", "󰝚 "], ["(.*)", "󰝚 "],
]; ];
const foundMatch = windowTitleMap.find((wt) => const foundMatch = windowTitleMap.find((wt) =>
RegExp(wt[0]).test(playerName), RegExp(wt[0], "i").test(playerName),
); );
return foundMatch ? foundMatch[1] : "󰝚"; return foundMatch ? foundMatch[1] : "󰝚";
@@ -39,15 +36,19 @@ const Media = () => {
const mediaLabel = Utils.watch("󰎇 Media 󰎇", [mpris, show_artist, truncation, truncation_size], () => { const mediaLabel = Utils.watch("󰎇 Media 󰎇", [mpris, show_artist, truncation, truncation_size], () => {
if (activePlayer.value) { if (activePlayer.value) {
const { track_title, identity, track_artists } = activePlayer.value; const { track_title, identity, track_artists } = activePlayer.value;
songIcon.value = getIconForPlayer(identity);
const trackArtist = show_artist.value const trackArtist = show_artist.value
? ` - ${track_artists.join(', ')}` ? ` - ${track_artists.join(', ')}`
: ``; : ``;
songIcon.value = getIconForPlayer(identity); const truncatedLabel = truncation.value
return track_title.length === 0
? `No media playing...`
: truncation.value
? `${track_title + trackArtist}`.substring(0, truncation_size.value) ? `${track_title + trackArtist}`.substring(0, truncation_size.value)
: `${track_title + trackArtist}`; : `${track_title + trackArtist}`;
return track_title.length === 0
? `No media playing...`
: ((truncatedLabel.length < truncation_size.value) || !truncation.value)
? `${truncatedLabel}`
: `${truncatedLabel.substring(0, truncatedLabel.length - 3)}...`;
} else { } else {
songIcon.value = ""; songIcon.value = "";
return "󰎇 Media 󰎇"; return "󰎇 Media 󰎇";