-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option for automatically enabling firefox's dark theme
- Loading branch information
1 parent
699e04a
commit 9f0e3dd
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ import ( | |
"time" | ||
) | ||
|
||
const darkThemeConfig = ` | ||
user_pref("lightweightThemes.selectedThemeID", "[email protected]"); | ||
user_pref("devtools.theme", "dark");` | ||
|
||
func uninstall(profile string) (string, error) { | ||
err := os.RemoveAll(filepath.Join(profile, "chrome", "ShadowFox_customization")) | ||
if err != nil { | ||
|
@@ -102,7 +106,7 @@ func addColorOverrides(source, colors string) string { | |
return source[:startI] + colors + source[endI:] | ||
} | ||
|
||
func install(profilePath string, generateUUIDs bool) (string, error) { | ||
func install(profilePath string, generateUUIDs bool, setTheme bool) (string, error) { | ||
// Helper variables to keep things DRY | ||
chromePath := filepath.Join(profilePath, "chrome") | ||
customPath := filepath.Join(chromePath, "ShadowFox_customization") | ||
|
@@ -215,6 +219,33 @@ func install(profilePath string, generateUUIDs bool) (string, error) { | |
} | ||
} | ||
|
||
// Set dark theme | ||
if setTheme { | ||
userJs := filepath.Join(profilePath, "user.js") | ||
err = backUp(userJs) | ||
if err != nil { | ||
return "Couldn't backup user.js", err | ||
} | ||
|
||
err = createFile(userJs) | ||
if err != nil { | ||
return "Couldn't create user.js", err | ||
} | ||
|
||
userJsContent, err := ioutil.ReadFile(userJs) | ||
if err != nil { | ||
return "Couldn't read user.js", err | ||
} | ||
|
||
if !strings.Contains(string(userJsContent), darkThemeConfig) { | ||
userJsContent = append(userJsContent, []byte(darkThemeConfig)...) | ||
|
||
if err := ioutil.WriteFile(userJs, userJsContent, 0644); err != nil { | ||
return "Couldn't write user.js", err | ||
} | ||
} | ||
} | ||
|
||
// Write new files | ||
if err := ioutil.WriteFile(userChromePath, []byte(userChrome), 0644); err != nil { | ||
return "Couldn't write userChrome.css to file", err | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters