Skip to content

Commit 1ba6ef0

Browse files
authored
fix(config): check for duplicates when adding multiple values (#2963)
1 parent d31784f commit 1ba6ef0

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

jsHelper/spicetifyWrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ Spicetify.Playbar = (() => {
23902390
const prNumber = match[3];
23912391
const prLink = match[4];
23922392
let text = "<li>";
2393-
if (feature) text += `<strong>${feature}</strong>: `;
2393+
if (feature) text += `<strong>${feature}</strong>${!feature.endsWith(":") ? ": " : " "}`;
23942394
text += `${description} (<a href="${prLink}">${prNumber}</a>)</li>`;
23952395
return text;
23962396
})

src/apply/apply.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func insertCustomApp(jsPath string, flags Flag) {
233233

234234
if (len(reactSymbs) < 2) || (len(eleSymbs) == 0) {
235235
utils.PrintError("Spotify version mismatch with Spicetify. Please report it on our github repository.")
236+
utils.PrintInfo("Spicetify might have been updated for this version already. Please run `spicetify update` to check for a new version. If one isn't available yet, please wait for the update to be released.")
236237
return content
237238
}
238239

src/cmd/config.go

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67
"strings"
@@ -121,41 +122,64 @@ func arrayType(section *ini.Section, field, value string) {
121122
utils.Fatal(err)
122123
}
123124

124-
allExts := key.Strings("|")
125+
allExts := make(map[string]bool)
126+
for _, v := range key.Strings("|") {
127+
allExts[v] = true
128+
}
125129

126-
isSubstract := value[len(value)-1] == '-'
127-
if isSubstract {
128-
value = value[0 : len(value)-1]
129-
found := false
130-
newList := []string{}
131-
for _, v := range allExts {
132-
if value == v {
133-
found = true
134-
} else {
135-
newList = append(newList, v)
136-
}
137-
}
130+
values := strings.Split(value, "|")
131+
duplicates := []string{}
132+
inputValues := make(map[string]bool)
133+
modifiedValues := 0
138134

139-
if !found {
140-
unchangeWarning(field, value+" is not on the list.")
141-
return
135+
for _, value := range values {
136+
isSubstract := strings.HasSuffix(value, "-")
137+
if isSubstract {
138+
value = value[:len(value)-1]
142139
}
143140

144-
allExts = newList
145-
} else {
146-
for _, ext := range allExts {
147-
if value == ext {
148-
unchangeWarning(field, value+" is already in the list.")
141+
if isSubstract {
142+
if _, found := allExts[value]; !found {
143+
unchangeWarning(field, fmt.Sprintf("%s is not on the list.", value))
149144
return
150145
}
146+
147+
modifiedValues++
148+
delete(allExts, value)
149+
} else {
150+
if _, found := allExts[value]; found && !inputValues[value] {
151+
duplicates = append(duplicates, value)
152+
} else if _, found := allExts[value]; !found {
153+
allExts[value] = true
154+
modifiedValues++
155+
}
156+
157+
inputValues[value] = true
151158
}
159+
}
152160

153-
allExts = append(allExts, value)
161+
if len(duplicates) > 0 {
162+
unchangeWarning(field, fmt.Sprintf("%s %s already in the list.", strings.Join(duplicates, ", "), pluralize(len(duplicates), "is", "are")))
154163
}
155164

156-
newList := strings.Join(allExts, "|")
157-
key.SetValue(newList)
158-
changeSuccess(field, newList)
165+
if modifiedValues == 0 {
166+
return
167+
}
168+
169+
newList := make([]string, 0, len(allExts))
170+
for k := range allExts {
171+
newList = append(newList, k)
172+
}
173+
174+
key.SetValue(strings.Join(newList, "|"))
175+
changeSuccess(field, strings.Join(newList, "|"))
176+
}
177+
178+
func pluralize(count int, singular, plural string) string {
179+
if count == 1 {
180+
return singular
181+
}
182+
return plural
159183
}
160184

161185
func stringType(section *ini.Section, field, value string) {

0 commit comments

Comments
 (0)