Skip to content

Commit 72e0d21

Browse files
authored
Merge pull request #10 from yossizahn/main
Respect theme preference from previous selection
2 parents b0377c6 + d9a9738 commit 72e0d21

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/theme.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ type ThemeValue = "light" | "dark"
55
const theme = ref<ThemeValue>()
66

77
const initTheme = () => {
8-
9-
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
10-
setTheme('dark')
11-
}
12-
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
13-
setTheme('light')
14-
}
15-
168
let theme = localStorage.getItem('theme')
9+
1710
if (theme) {
1811
setTheme(theme as ThemeValue)
12+
} else {
13+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
14+
setTheme('dark')
15+
}
16+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
17+
setTheme('light')
18+
}
1919
}
2020
}
2121

@@ -50,4 +50,4 @@ const toggleTheme = () => {
5050

5151
export const themeHandler = {
5252
theme, toggleTheme, initTheme
53-
}
53+
}

0 commit comments

Comments
 (0)