-
-
Notifications
You must be signed in to change notification settings - Fork 825
Refactor trashbin.js for readability and safer artist skipping #3660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,7 +54,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| function settingsContent() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Options | ||||||||||||||||||||||||||||||||||||||||||||||||
| header = document.createElement("h2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| const header = document.createElement("h2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| header.innerText = "Options"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| content.appendChild(header); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -152,7 +152,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const value = JSON.parse(Spicetify.LocalStorage.get(item)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return value ?? defaultValue; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(`Failed to parse ${item} from LocalStorage`, e); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return defaultValue; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -261,17 +262,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| let uriIndex = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
| let artistUri = data.item.metadata.artist_uri; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| while (artistUri) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (trashArtistList[artistUri]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Spicetify.Player.next(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| uriIndex++; | ||||||||||||||||||||||||||||||||||||||||||||||||
| artistUri = data.item.metadata[`artist_uri:${uriIndex}`]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| const artistUris = [data.item.metadata.artist_uri]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| let i = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| while (data.item.metadata[`artist_uri:${i}`]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| artistUris.push(data.item.metadata[`artist_uri:${i}`]); | ||||||||||||||||||||||||||||||||||||||||||||||||
| i++; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (artistUris.some(uri => trashArtistList[uri])) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Spicetify.Player.next(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+265
to
274
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle undefined Two concerns:
🔎 Suggested fix to handle undefined and address formatting:- const artistUris = [data.item.metadata.artist_uri];
- let i = 1;
- while (data.item.metadata[`artist_uri:${i}`]) {
- artistUris.push(data.item.metadata[`artist_uri:${i}`]);
- i++;
- }
-
- if (artistUris.some(uri => trashArtistList[uri])) {
- Spicetify.Player.next();
- }
+ const artistUris = [];
+ if (data.item.metadata.artist_uri) {
+ artistUris.push(data.item.metadata.artist_uri);
+ }
+ let i = 1;
+ while (data.item.metadata[`artist_uri:${i}`]) {
+ artistUris.push(data.item.metadata[`artist_uri:${i}`]);
+ i++;
+ }
+
+ if (artistUris.some((uri) => trashArtistList[uri])) {
+ Spicetify.Player.next();
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -342,13 +341,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| const uri = uris[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| const uriObj = Spicetify.URI.fromString(uri); | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (uriObj.type === Spicetify.URI.Type.TRACK) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.name = trashSongList[uri] ? UNTHROW_TEXT : THROW_TEXT; | ||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||
| return { name: trashSongList[uri] ? UNTHROW_TEXT : THROW_TEXT }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find and examine trashbin.js to see lines 344 and 348
find . -name "trashbin.js" -type f | head -5Repository: spicetify/cli Length of output: 81 🏁 Script executed: #!/bin/bash
# Read trashbin.js around lines 344 and 348
sed -n '330,360p' ./Extensions/trashbin.js | cat -nRepository: spicetify/cli Length of output: 1143 Fix shouldAddContextMenu to return a boolean, not an object with a name property. Lines 344 and 348 return Also applies to: 348-348 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (uriObj.type === Spicetify.URI.Type.ARTIST) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.name = trashArtistList[uri] ? UNTHROW_TEXT : THROW_TEXT; | ||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||
| return { name: trashArtistList[uri] ? UNTHROW_TEXT : THROW_TEXT }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -391,7 +388,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const writable = await handle.createWritable(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| await writable.write(JSON.stringify(data)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| await writable.write(JSON.stringify(data, null, 2)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| await writable.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Spicetify.showNotification("Backup saved succesfully."); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical:
constdeclaration breaks subsequent reassignment.Declaring
headerasconstat line 57 causes a runtime error at line 70, whereheaderis reassigned. This is confirmed by the pipeline failure: "Can't assign header because it's a constant."🔎 Apply this fix to use `let` instead of `const`:
📝 Committable suggestion
🤖 Prompt for AI Agents