Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed May 15, 2022
1 parent f844df1 commit 25b0b90
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions music-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,11 @@ async function searchAlbum(props: iTunesProps): Promise<iTunesInfos> {
* limits string to specified number limit
* will output the string with 3 chars at the end replaced by '...'
* @param s string
* @param n char number limit
* @param maxLength char number limit
* @returns {string}
*/
function limitStr(s: string, n: number): string {
let l = s;
if (l.length > n) {
l = l.substring(0, n - 3) + "...";
}

return l;
function limitStr(s: string, maxLength: number): string {
return s.length <= maxLength ? s : `${s.slice(0, maxLength - 3)}...`;
}

// Activity setter
Expand All @@ -153,7 +148,6 @@ async function setActivity(rpc: Client) {

switch (state) {
case "playing": {
// EVERYTHING must be less than or equal to 128 chars long
const props = await getProps();
console.log("props:", props);

Expand All @@ -163,13 +157,14 @@ async function setActivity(rpc: Client) {
const delta = (props.duration - props.playerPosition) * 1000;
const end = Math.ceil(Date.now() + delta);

// EVERYTHING must be less than or equal to 128 chars long
const activity: Activity = {
details: limitStr(props.name, 128),
state: limitStr(props.artist, 128),
timestamps: { end },
assets: {
large_image: infos.artwork,
large_text: `${limitStr(`${props.album}`, 120)} (${props.year})`,
large_text: limitStr(props.album, 128),
},
};
if (infos.url) {
Expand Down

0 comments on commit 25b0b90

Please sign in to comment.