fix(colorScheme): systemPreferScheme not initialized on start up (#1061)

This commit is contained in:
PukNgae Cryolitia 2024-10-07 01:32:13 +08:00 committed by GitHub
parent 0fb25c808b
commit 245b0f2810
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,10 @@ class StackColorScheme {
constructor(toggleEl: HTMLElement) {
this.bindMatchMedia();
this.currentScheme = this.getSavedScheme();
if (window.matchMedia('(prefers-color-scheme: dark)').matches === true)
this.systemPreferScheme = 'dark'
else
this.systemPreferScheme = 'light';
this.dispatchEvent(document.documentElement.dataset.scheme as colorScheme);