From 01cc267ab1fdd97586bea35f60117aee45fc550e Mon Sep 17 00:00:00 2001 From: Cryolitia PukNgae Date: Tue, 17 Sep 2024 00:17:33 +0800 Subject: [PATCH] fix(colorScheme): systemPreferScheme not initialized on start up --- assets/ts/colorScheme.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/ts/colorScheme.ts b/assets/ts/colorScheme.ts index 8cb8a20..978e98e 100644 --- a/assets/ts/colorScheme.ts +++ b/assets/ts/colorScheme.ts @@ -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);