fixed type pref
This commit is contained in:
parent
6c9c66bd7a
commit
bb37c8e2ad
3 changed files with 12 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
t:pref
|
t: pref
|
||||||
i: /browser/app/profile/firefox.js
|
i: /browser/app/profile/firefox.js
|
||||||
o: /browser/app/profile/firefox.js
|
o: /browser/app/profile/firefox.js
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
t:pref
|
t: pref
|
||||||
i: /browser/app/profile/firefox.js
|
i: /browser/app/profile/firefox.js
|
||||||
o: /browser/app/profile/firefox.js
|
o: /browser/app/profile/firefox.js
|
||||||
|
|
||||||
|
|
16
pref.go
16
pref.go
|
@ -29,10 +29,12 @@ func applyPrefModifications(targetFilePath string, modifications []string) error
|
||||||
// Prepare the modification map
|
// Prepare the modification map
|
||||||
for _, mod := range modifications {
|
for _, mod := range modifications {
|
||||||
if strings.HasPrefix(mod, "+pref") {
|
if strings.HasPrefix(mod, "+pref") {
|
||||||
parts := strings.SplitN(mod, "(", 2)
|
// Strip the `+` and extract the key within parentheses
|
||||||
if len(parts) > 1 {
|
start := strings.Index(mod, "(")
|
||||||
key := strings.TrimSpace(parts[0][1:])
|
end := strings.LastIndex(mod, ")")
|
||||||
modMap[key] = strings.TrimSpace(mod)
|
if start > 0 && end > start {
|
||||||
|
key := strings.TrimSpace(mod[start+1 : end])
|
||||||
|
modMap[key] = strings.TrimPrefix(mod, "+") // Remove the `+` prefix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +46,7 @@ func applyPrefModifications(targetFilePath string, modifications []string) error
|
||||||
// Check if the line matches any modification key
|
// Check if the line matches any modification key
|
||||||
lineModified := false
|
lineModified := false
|
||||||
for key, replacement := range modMap {
|
for key, replacement := range modMap {
|
||||||
if strings.HasPrefix(line, key) && !modifiedLines[key] {
|
if strings.Contains(line, key) && !modifiedLines[key] {
|
||||||
fmt.Printf("Replacing line: %s\n", line)
|
fmt.Printf("Replacing line: %s\n", line)
|
||||||
if _, err := tempFile.WriteString(replacement + "\n"); err != nil {
|
if _, err := tempFile.WriteString(replacement + "\n"); err != nil {
|
||||||
return fmt.Errorf("failed to write to temp file: %v", err)
|
return fmt.Errorf("failed to write to temp file: %v", err)
|
||||||
|
@ -70,7 +72,9 @@ func applyPrefModifications(targetFilePath string, modifications []string) error
|
||||||
// Write remaining modifications (new preferences)
|
// Write remaining modifications (new preferences)
|
||||||
for key, replacement := range modMap {
|
for key, replacement := range modMap {
|
||||||
if !modifiedLines[key] {
|
if !modifiedLines[key] {
|
||||||
if _, err := tempFile.WriteString(replacement + "\n"); err != nil {
|
// Remove the `+` prefix before writing
|
||||||
|
cleanReplacement := strings.TrimPrefix(replacement, "+")
|
||||||
|
if _, err := tempFile.WriteString(cleanReplacement + "\n"); err != nil {
|
||||||
return fmt.Errorf("failed to write new preference to temp file: %v", err)
|
return fmt.Errorf("failed to write new preference to temp file: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue