From a5f7d1b2badceb9845aba035e4ee464678485dd9 Mon Sep 17 00:00:00 2001 From: Enem Date: Fri, 31 Jan 2025 18:47:43 +0100 Subject: [PATCH 1/3] Update spotify-player extension - added the option to hide artist\'s name in the Menu Bar Player - Initial commit --- extensions/spotify-player/CHANGELOG.md | 4 ++++ extensions/spotify-player/package-lock.json | 9 +++++---- extensions/spotify-player/package.json | 14 ++++++++++++-- .../spotify-player/src/helpers/formatTitle.ts | 14 +++++++++++++- .../spotify-player/src/nowPlayingMenuBar.tsx | 6 +++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/extensions/spotify-player/CHANGELOG.md b/extensions/spotify-player/CHANGELOG.md index f97fdf4d3e81c..dd975aabe8d64 100644 --- a/extensions/spotify-player/CHANGELOG.md +++ b/extensions/spotify-player/CHANGELOG.md @@ -1,5 +1,9 @@ # Spotify Player Changelog +## [Artist Name Visibility Option] - {PR_MERGE_DATE} + +- Added the option to hide the artist's name in the Menu Bar Player. + ## [Fix Your Library] - 2025-02-04 - Fix a possibly null issue from `getMeAlbums` API. diff --git a/extensions/spotify-player/package-lock.json b/extensions/spotify-player/package-lock.json index 7d2f52bdac9fe..de86e11649d07 100644 --- a/extensions/spotify-player/package-lock.json +++ b/extensions/spotify-player/package-lock.json @@ -17,7 +17,7 @@ "@types/node": "20.14.10", "@types/react": "^18.3.3", "eslint": "^8.53.0", - "prettier": "^3.3.3", + "prettier": "^3.4.2", "typescript": "^5.5.3" } }, @@ -2018,10 +2018,11 @@ } }, "node_modules/prettier": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", - "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, diff --git a/extensions/spotify-player/package.json b/extensions/spotify-player/package.json index eeea5f78e4a57..ff6c1702e7fad 100644 --- a/extensions/spotify-player/package.json +++ b/extensions/spotify-player/package.json @@ -30,7 +30,8 @@ "thomaslombart", "rhesamu", "themitpatel", - "litomore" + "litomore", + "enneemme" ], "pastContributors": [ "bkeys818" @@ -181,6 +182,15 @@ "default": "20", "required": false }, + { + "name": "showArtist", + "title": "Show artists namer", + "description": "Show the artist name in the Menu Bar", + "type": "checkbox", + "label": "Enabled", + "default": true, + "required": false + }, { "name": "iconType", "title": "Icon type", @@ -449,7 +459,7 @@ "@types/node": "20.14.10", "@types/react": "^18.3.3", "eslint": "^8.53.0", - "prettier": "^3.3.3", + "prettier": "^3.4.2", "typescript": "^5.5.3" }, "scripts": { diff --git a/extensions/spotify-player/src/helpers/formatTitle.ts b/extensions/spotify-player/src/helpers/formatTitle.ts index 2ff375aaf9aa1..53e585461e742 100644 --- a/extensions/spotify-player/src/helpers/formatTitle.ts +++ b/extensions/spotify-player/src/helpers/formatTitle.ts @@ -1,8 +1,20 @@ -export function formatTitle(title: string, max: number, showEllipsis = true) { +export function formatTitle( + name: string | undefined, + artist: string | undefined, + max: number, + showArtist: boolean, + showEllipsis = true, +) { if (max === 0) { return ""; } + if (!name || !artist) { + return ""; + } + + const title = showArtist ? `${name} - ${artist}` : name; + if (title.length <= max) { return title; } diff --git a/extensions/spotify-player/src/nowPlayingMenuBar.tsx b/extensions/spotify-player/src/nowPlayingMenuBar.tsx index b1fb674cac647..c37c440c0c39d 100644 --- a/extensions/spotify-player/src/nowPlayingMenuBar.tsx +++ b/extensions/spotify-player/src/nowPlayingMenuBar.tsx @@ -102,7 +102,7 @@ function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { const { artists, id: trackId, album } = item as TrackObject; const artistName = artists?.[0]?.name; const artistId = artists?.[0]?.id; - title = `${name} · ${artistName}`; + title = formatTitle(name, artistName, Number(preferences.maxTextLength), Boolean(preferences.showArtist)); // Get the image with the lowest resolution coverImageUrl = album?.images.slice(-1)[0]?.url || ""; @@ -188,7 +188,7 @@ function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { } else { const { show } = item as EpisodeObject; const showName = show.name; - title = `${name} · ${showName}`; + title = formatTitle(name, showName, Number(preferences.maxTextLength), Boolean(preferences.showArtist)); coverImageUrl = show.images.slice(-1)[0]?.url || ""; } @@ -203,7 +203,7 @@ function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { } : { source: { dark: "menu-icon-dark.svg", light: "menu-icon-light.svg" } } } - title={formatTitle(title, Number(preferences.maxTextLength))} + title={title} tooltip={title} > {isPlaying && ( From 90e1412789758c082cfa3349af70f588f19497f7 Mon Sep 17 00:00:00 2001 From: Thomas Lombart Date: Fri, 7 Feb 2025 13:43:42 +0100 Subject: [PATCH 2/3] Review --- extensions/spotify-player/package.json | 47 +++++++++---------- .../spotify-player/src/helpers/formatTitle.ts | 23 +++++---- .../spotify-player/src/nowPlayingMenuBar.tsx | 13 ++--- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/extensions/spotify-player/package.json b/extensions/spotify-player/package.json index ff6c1702e7fad..91c8df48e682a 100644 --- a/extensions/spotify-player/package.json +++ b/extensions/spotify-player/package.json @@ -49,10 +49,9 @@ "preferences": [ { "name": "closeWindowOnAction", - "title": "Close window on action", - "description": "Close the Raycast window after performing an action", + "description": "If enabled, the Raycast window will be closed after performing an action", "type": "checkbox", - "label": "Enabled", + "label": "Close window on action", "default": false, "required": false } @@ -175,28 +174,35 @@ "interval": "10s", "preferences": [ { - "name": "maxTextLength", - "title": "Maximum text length", - "description": "Maximum number of characters to show. If left empty, it defaults to 30", - "type": "textfield", - "default": "20", + "name": "hideIconWhenIdle", + "description": "If enabled, the icon in the Menu Bar will be hidden when Spotify is not running or when nothing is playing", + "type": "checkbox", + "label": "Hide icon when idle", + "default": false, "required": false }, { - "name": "showArtist", - "title": "Show artists namer", - "description": "Show the artist name in the Menu Bar", + "name": "hideArtistName", + "description": "If enabled, the artist's name will be hidden in the Menu Bar", "type": "checkbox", - "label": "Enabled", - "default": true, + "label": "Hide artist's name", + "default": false, + "required": false + }, + { + "name": "maxTextLength", + "title": "Now Playing Text Length", + "description": "Maximum number of characters to show for the currently playing track in the menu bar. Leave empty to use default (30 characters)", + "type": "textfield", + "default": "30", "required": false }, { "name": "iconType", - "title": "Icon type", - "description": "Choose between the default Spotify icon, or the cover image of the current track or episode", + "title": "Menu Bar Icon", + "description": "Choose between the default Spotify icon, or the cover image of the current track or episode.", "type": "dropdown", - "default": "spotify", + "default": "spotify-icon", "data": [ { "title": "Spotify Icon", @@ -208,15 +214,6 @@ } ], "required": false - }, - { - "name": "hideIconWhenIdle", - "title": "Hide icon when idle", - "description": "Hide the icon in the Menu Bar when Spotify is not running or when nothing is playing", - "type": "checkbox", - "label": "Enabled", - "default": false, - "required": false } ] }, diff --git a/extensions/spotify-player/src/helpers/formatTitle.ts b/extensions/spotify-player/src/helpers/formatTitle.ts index 53e585461e742..1e3593cfa72ec 100644 --- a/extensions/spotify-player/src/helpers/formatTitle.ts +++ b/extensions/spotify-player/src/helpers/formatTitle.ts @@ -1,23 +1,26 @@ -export function formatTitle( - name: string | undefined, - artist: string | undefined, - max: number, - showArtist: boolean, - showEllipsis = true, -) { +type FormatTitleParams = { + name?: string; + artistName?: string; + hideArtistName?: boolean; + maxTextLength?: string; +}; + +export function formatTitle({ name, artistName, hideArtistName, maxTextLength }: FormatTitleParams) { + const max = maxTextLength ? Number(maxTextLength) : 30; + if (max === 0) { return ""; } - if (!name || !artist) { + if (!name || !artistName) { return ""; } - const title = showArtist ? `${name} - ${artist}` : name; + const title = hideArtistName ? name : `${name} · ${artistName}`; if (title.length <= max) { return title; } - return title.substring(0, max).trim() + (showEllipsis ? "…" : ""); + return title.substring(0, max).trim() + "…"; } diff --git a/extensions/spotify-player/src/nowPlayingMenuBar.tsx b/extensions/spotify-player/src/nowPlayingMenuBar.tsx index c37c440c0c39d..975c34d396a4b 100644 --- a/extensions/spotify-player/src/nowPlayingMenuBar.tsx +++ b/extensions/spotify-player/src/nowPlayingMenuBar.tsx @@ -37,7 +37,7 @@ import { getErrorMessage } from "./helpers/getError"; import { useSpotifyAppData } from "./hooks/useSpotifyAppData"; function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { - const preferences = getPreferenceValues(); + const { hideArtistName, maxTextLength, iconType } = getPreferenceValues(); const [uriFromSpotify, setUriFromSpotify] = useCachedState("currentlyPlayingUri", undefined); const shouldExecute = React.useRef(false); @@ -102,7 +102,7 @@ function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { const { artists, id: trackId, album } = item as TrackObject; const artistName = artists?.[0]?.name; const artistId = artists?.[0]?.id; - title = formatTitle(name, artistName, Number(preferences.maxTextLength), Boolean(preferences.showArtist)); + title = formatTitle({ name, artistName, hideArtistName, maxTextLength }); // Get the image with the lowest resolution coverImageUrl = album?.images.slice(-1)[0]?.url || ""; @@ -188,7 +188,7 @@ function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { } else { const { show } = item as EpisodeObject; const showName = show.name; - title = formatTitle(name, showName, Number(preferences.maxTextLength), Boolean(preferences.showArtist)); + title = formatTitle({ name, artistName: showName, hideArtistName, maxTextLength }); coverImageUrl = show.images.slice(-1)[0]?.url || ""; } @@ -196,11 +196,8 @@ function NowPlayingMenuBarCommand({ launchType }: LaunchProps) { Date: Fri, 7 Feb 2025 12:56:26 +0000 Subject: [PATCH 3/3] Update CHANGELOG.md and optimise images --- extensions/spotify-player/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/spotify-player/CHANGELOG.md b/extensions/spotify-player/CHANGELOG.md index dd975aabe8d64..43b8d14fcaf0c 100644 --- a/extensions/spotify-player/CHANGELOG.md +++ b/extensions/spotify-player/CHANGELOG.md @@ -1,6 +1,6 @@ # Spotify Player Changelog -## [Artist Name Visibility Option] - {PR_MERGE_DATE} +## [Artist Name Visibility Option] - 2025-02-07 - Added the option to hide the artist's name in the Menu Bar Player.