fix(colorScheme): systemPreferScheme not initialized on start up

This commit is contained in:
Cryolitia PukNgae 2024-09-17 00:17:33 +08:00
parent 048a000f17
commit 01cc267ab1
No known key found for this signature in database
GPG Key ID: 63982609A2647D3C

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);