Skip to content

Commit

Permalink
Update theme on system color mode change (woodpecker-ci#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 <[email protected]>
  • Loading branch information
2 people authored and fernandrone committed Feb 1, 2024
1 parent ea40e7a commit cfb6014
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 cfb6014

Please sign in to comment.