From bb37c8e2adb4310298761cf79cd7409bc11423ab Mon Sep 17 00:00:00 2001 From: partisan Date: Sun, 8 Dec 2024 18:22:32 +0100 Subject: [PATCH] fixed type pref --- patches/homepage.patch | 2 +- patches/peskyfox.patch | 2 +- pref.go | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/patches/homepage.patch b/patches/homepage.patch index 794142a..9e95191 100644 --- a/patches/homepage.patch +++ b/patches/homepage.patch @@ -1,4 +1,4 @@ -t:pref +t: pref i: /browser/app/profile/firefox.js o: /browser/app/profile/firefox.js diff --git a/patches/peskyfox.patch b/patches/peskyfox.patch index 20f6e79..80505b8 100644 --- a/patches/peskyfox.patch +++ b/patches/peskyfox.patch @@ -1,4 +1,4 @@ -t:pref +t: pref i: /browser/app/profile/firefox.js o: /browser/app/profile/firefox.js diff --git a/pref.go b/pref.go index 8c719fd..b5a4648 100644 --- a/pref.go +++ b/pref.go @@ -29,10 +29,12 @@ func applyPrefModifications(targetFilePath string, modifications []string) error // Prepare the modification map for _, mod := range modifications { if strings.HasPrefix(mod, "+pref") { - parts := strings.SplitN(mod, "(", 2) - if len(parts) > 1 { - key := strings.TrimSpace(parts[0][1:]) - modMap[key] = strings.TrimSpace(mod) + // Strip the `+` and extract the key within parentheses + start := strings.Index(mod, "(") + end := strings.LastIndex(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 lineModified := false 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) if _, err := tempFile.WriteString(replacement + "\n"); err != nil { 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) for key, replacement := range modMap { 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) } }