Skip to content

Commit 71cde62

Browse files
committed
SDP profile update and minor changes
1 parent b958d25 commit 71cde62

7 files changed

Lines changed: 40 additions & 79 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ You are able to configure the behavior of some of them via their settings.
100100
Map this button to any supported Spotify URL and press it to start playing.
101101

102102
- **Add to Playlist**\
103-
Adds the currently playing song to a selected playlist. Choose your playlist from the settings and optionally display the playlist name and/or song name with automatic scrolling for long text.
103+
Adds the currently playing song to a selected playlist of yours.
104104

105105
### Dials
106106
- **Playback Control**\
8 Bytes
Binary file not shown.

com.ntanis.essentials-for-spotify.sdPlugin/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
"Name": "Add to Playlist",
233233
"UUID": "com.ntanis.essentials-for-spotify.add-to-playlist-button",
234234
"Icon": "images/actions/add-to-playlist",
235-
"Tooltip": "Adds the currently playing song to a specific playlist.",
235+
"Tooltip": "Adds the currently playing song to a selected playlist of yours.",
236236
"PropertyInspectorPath": "pi/add-to-playlist-button.html",
237237
"DisableAutomaticStates": true,
238238
"UserTitleEnabled": false,

src/actions/add-to-playlist-button.ts

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,84 +48,62 @@ export default class AddToPlaylistButton extends Button {
4848
const show = this.settings[context].show || ['playlist']
4949
const data: any = []
5050

51-
// Track if we need to restart marquee or just update entries
5251
let needsRestart = !this.marquees[context]
5352

54-
for (const item of show) {
55-
if (item === 'playlist' && this.settings[context].playlist_name) {
53+
for (const item of show)
54+
if (item === 'playlist' && this.settings[context].playlist_name)
5655
data.push({
5756
key: 'playlist',
5857
value: this.settings[context].playlist_name
5958
})
60-
} else if (item === 'name' && song?.item?.name) {
59+
else if (item === 'name' && song?.item?.name) {
6160
data.push({
6261
key: 'name',
6362
value: song.item.name
6463
})
6564

66-
// Update song marquee entry if it exists and song changed
67-
if (this.marquees[context]?.entries?.name && this.marquees[context].entries.name.original !== song.item.name) {
65+
if (this.marquees[context]?.entries?.name && this.marquees[context].entries.name.original !== song.item.name)
6866
this.updateMarqueeEntry(context, 'name', song.item.name)
69-
}
7067
}
71-
}
7268

73-
// If no data, clear the marquee and show blank
7469
if (data.length === 0) {
7570
this.clearMarquee(context)
7671
await this.setTitle(context, '')
77-
return
78-
}
79-
80-
// Only restart marquee if needed
81-
if (needsRestart || !this.marquees[context]) {
72+
} else if (needsRestart || (!this.marquees[context]))
8273
await this.marqueeTitle('add-to-playlist', data, context)
83-
}
8474
}
8575

8676
async #updatePlaylists(contexts = this.contexts) {
8777
const items: any = []
8878

89-
if (connector.set) {
79+
if (connector.set)
9080
try {
91-
// Fetch all pages of playlists
9281
let page = 1
93-
let hasMore = true
9482

95-
while (hasMore) {
83+
while (true) {
9684
const playlistsResponse = await wrapper.getUserPlaylists(page)
9785

9886
if (playlistsResponse && playlistsResponse.status === constants.WRAPPER_RESPONSE_SUCCESS) {
99-
for (const playlist of playlistsResponse.items) {
87+
for (const playlist of playlistsResponse.items)
10088
if (playlist) {
101-
// Include "Liked Songs" or playlists the user owns or collaborative playlists
102-
const canAddTracks = playlist.type === 'collection' ||
103-
playlist.owner?.id === wrapper.user?.id ||
104-
playlist.collaborative === true
89+
const canAddTracks = playlist.type === 'collection' || playlist.owner?.id === wrapper.user?.id || playlist.collaborative === true
10590

106-
if (canAddTracks) {
91+
if (canAddTracks)
10792
items.push({
10893
value: playlist.id,
10994
label: playlist.name
11095
})
111-
}
11296
}
113-
}
11497

115-
// Check if there are more pages
116-
const totalFetched = page * constants.WRAPPER_ITEMS_PER_PAGE
117-
hasMore = totalFetched < playlistsResponse.total
98+
if ((page * constants.WRAPPER_ITEMS_PER_PAGE) >= playlistsResponse.total)
99+
break
100+
118101
page++
119-
} else {
120-
hasMore = false
121-
}
102+
} else
103+
break
122104
}
123-
} catch (e) {
124-
// Silently handle error, will send empty array
125-
}
126-
}
105+
} catch (e) { }
127106

128-
// Always send response to clear loading state
129107
for (const context of contexts) {
130108
await StreamDeck.client.sendToPropertyInspector(context, {
131109
event: 'getPlaylists',
@@ -142,10 +120,8 @@ export default class AddToPlaylistButton extends Button {
142120
playlist_name: playlist.label
143121
})
144122

145-
// Update marquee entry if playlist name changed
146-
if (oldPlaylistName !== playlist.label) {
123+
if (oldPlaylistName !== playlist.label)
147124
this.updateMarqueeEntry(context, 'playlist', playlist.label)
148-
}
149125
}
150126
}
151127
}
@@ -158,11 +134,9 @@ export default class AddToPlaylistButton extends Button {
158134
if (!this.settings[context].playlist_id)
159135
return constants.WRAPPER_RESPONSE_NOT_AVAILABLE
160136

161-
// Get the current track in real-time to avoid stale cached data
162137
const currentTrack = await wrapper.getCurrentTrack()
163138

164139
if (!currentTrack?.uri) {
165-
// Fall back to cached song if getCurrentTrack fails
166140
if (!wrapper.song?.item?.id)
167141
return constants.WRAPPER_RESPONSE_NOT_AVAILABLE
168142

@@ -190,7 +164,6 @@ export default class AddToPlaylistButton extends Button {
190164
async onSettingsUpdated(context: string, oldSettings: any) {
191165
await super.onSettingsUpdated(context, oldSettings)
192166

193-
// Set default show value
194167
if (!this.settings[context].show)
195168
await this.setSettings(context, {
196169
show: ['playlist']
@@ -199,23 +172,20 @@ export default class AddToPlaylistButton extends Button {
199172
if (oldSettings.playlist_id !== this.settings[context].playlist_id)
200173
await this.#updatePlaylists([context])
201174

202-
// Update display if show settings changed
203-
const showChanged = oldSettings.show?.length !== this.settings[context].show?.length ||
204-
(oldSettings.show && this.settings[context].show &&
205-
(!oldSettings.show.every((value: any, index: number) => value === this.settings[context].show[index])))
175+
const showChanged = oldSettings.show?.length !== this.settings[context].show?.length || (oldSettings.show && this.settings[context].show && (!oldSettings.show.every((value: any, index: number) => value === this.settings[context].show[index])))
206176

207177
if (showChanged) {
208178
this.clearMarquee(context)
179+
209180
if (wrapper.song)
210181
await this.#updateDisplay(context, wrapper.song)
211182
else
212183
await this.#updateDisplay(context, null)
213-
} else if (oldSettings.playlist_id !== this.settings[context].playlist_id) {
184+
} else if (oldSettings.playlist_id !== this.settings[context].playlist_id)
214185
if (wrapper.song)
215186
await this.#onSongChanged(wrapper.song, false)
216187
else
217188
await this.#onSongChanged(null, false)
218-
}
219189
}
220190

221191
async onStateSettled(context: string) {
@@ -226,9 +196,8 @@ export default class AddToPlaylistButton extends Button {
226196
await this.setImage(context, 'images/states/add-to-playlist')
227197
this.setUnpressable(context, false)
228198
await this.#updateDisplay(context, wrapper.song)
229-
} else {
199+
} else
230200
await this.#onSongChanged(null, false)
231-
}
232201
}
233202

234203
async onStateLoss(context: string) {

src/actions/context-information-button.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,15 @@ export default class ContextInformationButton extends Button {
2929
}
3030

3131
async #onSongChanged(song: any, pending: boolean = false) {
32-
// Only update image when image_source is set to 'album'
33-
for (const context of this.contexts) {
34-
if (this.settings[context]?.image_source === 'album' && wrapper.playbackContext) {
32+
for (const context of this.contexts)
33+
if (this.settings[context]?.image_source === 'album' && wrapper.playbackContext)
3534
await this.#updateImage(context, wrapper.playbackContext, song, pending)
36-
}
37-
}
3835
}
3936

4037
async #updateImage(context: string, playbackContext: any, song: any, pending: boolean) {
4138
const imageSource = this.settings[context]?.image_source || 'context'
4239

4340
if (imageSource === 'album' && song?.item?.album) {
44-
// Use album image - leverage the song cache which already has the album cover
4541
if (!images.isSongCached(song))
4642
await this.setImage(context, 'images/states/pending')
4743

@@ -53,25 +49,22 @@ export default class ContextInformationButton extends Button {
5349
await this.setImage(context, 'images/states/local')
5450
else
5551
await this.setImage(context)
56-
} else {
57-
// Use context image (original behavior)
58-
if (playbackContext) {
59-
if (!images.isItemCached(playbackContext))
60-
await this.setImage(context, 'images/states/pending')
52+
} else if (playbackContext) {
53+
if (!images.isItemCached(playbackContext))
54+
await this.setImage(context, 'images/states/pending')
6155

62-
const image = await images.getForItem(playbackContext)
56+
const image = await images.getForItem(playbackContext)
6357

64-
if (image)
65-
await this.setImage(context, `data:image/jpeg;base64,${image}`)
66-
else if (playbackContext.type === 'local')
67-
await this.setImage(context, 'images/states/local')
68-
else
69-
await this.setImage(context)
70-
} else if (pending)
71-
await this.setImage(context, 'images/states/pending')
58+
if (image)
59+
await this.setImage(context, `data:image/jpeg;base64,${image}`)
60+
else if (playbackContext.type === 'local')
61+
await this.setImage(context, 'images/states/local')
7262
else
73-
await this.setImage(context, 'images/states/context-information-unknown')
74-
}
63+
await this.setImage(context)
64+
} else if (pending)
65+
await this.setImage(context, 'images/states/pending')
66+
else
67+
await this.setImage(context, 'images/states/context-information-unknown')
7568
}
7669

7770
async #onPlaybackContextChanged(playbackContext: any, pending: boolean = false, contexts = this.contexts, force = false) {
@@ -174,7 +167,6 @@ export default class ContextInformationButton extends Button {
174167
if (oldSettings.show?.length !== this.settings[context].show?.length || (oldSettings.show && this.settings[context].show && (!oldSettings.show.every((value: any, index: number) => value === this.settings[context].show[index]))))
175168
await this.#onPlaybackContextChanged(wrapper.playbackContext, wrapper.pendingPlaybackContext, [context], true)
176169

177-
// Update image when image_source changes
178170
if (oldSettings.image_source !== this.settings[context].image_source && wrapper.playbackContext)
179171
await this.#updateImage(context, wrapper.playbackContext, wrapper.song, wrapper.pendingPlaybackContext)
180172
}

src/library/connector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
v4
1414
} from 'uuid'
1515

16-
const proxyAgent = false ? new ProxyAgent({
16+
const proxyAgent = true ? new ProxyAgent({
1717
uri: 'http://127.0.0.1:8000',
1818

1919
requestTls: {

src/ui/pi/context-information.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</sdpi-item>
1414
<sdpi-item label="Image Source">
1515
<sdpi-select setting="image_source">
16-
<option value="context">Context (Playlist/Album/etc)</option>
16+
<option value="context">Current Context (Playlist / Album)</option>
1717
<option value="album">Current Song's Album</option>
1818
</sdpi-select>
1919
</sdpi-item>

0 commit comments

Comments
 (0)