-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dark/white theme controls. Fix #56
- Loading branch information
Showing
4 changed files
with
45 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { store } from "../extensionPreferences"; | ||
import { waitForElement } from "../utility/waitForElement"; | ||
import { OLFeature, SettingToggle } from "./base"; | ||
|
||
const systemThemeKey = "systemTheme" | ||
const whiteThemeKey = "whiteTheme" | ||
|
||
export default class WhiteTheme extends OLFeature { | ||
moduleId: string = "whiteTheme"; | ||
moduleName: string = "Theme controls"; | ||
async init () { | ||
this.settingOptions.push( | ||
new SettingToggle("White theme", "Enables white theme instead of dark.", whiteThemeKey, async (theme) => { | ||
const { systemTheme } = await store.get(systemThemeKey) | ||
if (systemTheme !== undefined && systemTheme) { | ||
console.log("Systemtheme key is set, not enabling white theme") | ||
return | ||
} | ||
waitForElement("body", () => { | ||
document.body.classList.toggle("whiteTheme", theme) | ||
}) | ||
}) | ||
) | ||
this.settingOptions.push( | ||
new SettingToggle("System theme", "Makes oldlander follow system theme. Overrides white theme option", systemThemeKey, (followSystemTheme) => { | ||
if (followSystemTheme) { | ||
this.followSystemTheme() | ||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', this.followSystemTheme) | ||
} | ||
}) | ||
) | ||
} | ||
followSystemTheme() { | ||
const darkTheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches | ||
console.log("Dark theme?", darkTheme) | ||
waitForElement("body", () => { | ||
document.body.classList.toggle("whiteTheme", !darkTheme) | ||
}) | ||
} | ||
} |
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