Skip to content

Commit

Permalink
Update theme on system color mode change (#3296)
Browse files Browse the repository at this point in the history
Currently, when theme `auto` is set and the system theme changes, users
need to reload the site themselves.

This PR adds an even listener which listens for such changes and reloads
the theme automatically in the background.

---------

Co-authored-by: Anbraten <anton@ju60.de>
  • Loading branch information
pat-s and anbraten authored Jan 30, 2024
1 parent 3415e2b commit da4bd8b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions web/src/compositions/useTheme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useColorMode } from '@vueuse/core';
import { watch } from 'vue';

const { store: storeTheme, state: resolvedTheme } = useColorMode({
const {
store: storeTheme,
state: resolvedTheme,
system: systemTheme,
} = useColorMode({
storageKey: 'woodpecker:theme',
});

Expand All @@ -19,9 +23,7 @@ function updateTheme() {
}
}

watch(storeTheme, updateTheme);

updateTheme();
watch([storeTheme, systemTheme], updateTheme, { immediate: true });

export function useTheme() {
return {
Expand Down

0 comments on commit da4bd8b

Please sign in to comment.