Skip to content

Commit

Permalink
set dark theme in prefs.js
Browse files Browse the repository at this point in the history
  • Loading branch information
arguablykomodo committed Oct 18, 2018
1 parent 91d2626 commit 9b5aa16
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"time"
)

const darkThemeConfig = `
user_pref("lightweightThemes.selectedThemeID", "[email protected]");
user_pref("devtools.theme", "dark");`
var darkThemeConfig = map[string]string{
"lightweightThemes.selectedThemeID": "\"[email protected]\"",
"browser.uidensity": "1",
"devtools.theme": "\"dark\"",
}

func uninstall(profile string) (string, error) {
err := os.RemoveAll(filepath.Join(profile, "chrome", "ShadowFox_customization"))
Expand Down Expand Up @@ -221,33 +223,34 @@ func install(profilePath string, generateUUIDs bool, setTheme bool) (string, err

// Set dark theme
if setTheme {
userJs := filepath.Join(profilePath, "user.js")
userJsContent := []byte{}
prefs := filepath.Join(profilePath, "prefs.js")
prefsContent := []byte{}

exists, _, err := pathExists(userJs)
exists, _, err := pathExists(prefs)
if exists {
userJsContent, err = ioutil.ReadFile(userJs)
prefsContent, err = ioutil.ReadFile(prefs)
if err != nil {
return "Couldn't read user.js", err
return "Couldn't read prefs.js", err
}
} else {
err = createFile(userJs)
err = createFile(prefs)
if err != nil {
return "Couldn't create user.js", err
return "Couldn't create prefs.js", err
}
}

if !strings.Contains(string(userJsContent), darkThemeConfig) {
err = backUp(userJs)
if err != nil {
return "Couldn't backup user.js", err
for key, value := range darkThemeConfig {
regex := regexp.MustCompile("user_pref(\"" + key + "\", .+);")
replace := []byte("user_pref(\"" + key + "\", " + value + ");")
if regex.Match(prefsContent) {
prefsContent = regex.ReplaceAll(prefsContent, replace)
} else {
prefsContent = append(append(prefsContent, replace...), '\n')
}
}

userJsContent = append(userJsContent, []byte(darkThemeConfig)...)

if err := ioutil.WriteFile(userJs, userJsContent, 0644); err != nil {
return "Couldn't write user.js", err
}
if err := ioutil.WriteFile(prefs, prefsContent, 0644); err != nil {
return "Couldn't write prefs.js", err
}
}

Expand Down

0 comments on commit 9b5aa16

Please sign in to comment.