From 245b0f2810c0e6c8dc9b887139f8e68cd9298efd Mon Sep 17 00:00:00 2001 From: PukNgae Cryolitia Date: Mon, 7 Oct 2024 01:32:13 +0800 Subject: [PATCH] fix(colorScheme): systemPreferScheme not initialized on start up (#1061) --- 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);