Skip to content

Commit 854617c

Browse files
committed
fix: detect vitepress theme key
1 parent ebd49d4 commit 854617c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

packages/client/src/App.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import type { Ref } from 'vue'
33
import { useDevToolsBridge, useDevToolsBridgeRpc, useDevToolsState } from '@vue/devtools-core'
44
import { isInChromePanel } from '@vue/devtools-shared'
55
import { Pane, Splitpanes } from 'splitpanes'
6+
import { getThemeKey } from './utils'
67
78
import('./setup/unocss-runtime')
89
910
// @TODO: fix browser extension cross-origin localStorage issue
10-
useColorMode()
11+
12+
useColorMode({
13+
storageKey: getThemeKey(),
14+
})
1115
const router = useRouter()
1216
const route = useRoute()
1317
const { connected, clientConnected } = useDevToolsState()

packages/client/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './color'
22
export * from './time'
3+
export * from './theme'

packages/client/src/utils/theme.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const ThemeStorageKeys = {
2+
default: 'vueuse-color-scheme',
3+
vitepress: 'vitepress-theme-appearance',
4+
}
5+
6+
export function getThemeKey() {
7+
let themeKey = ThemeStorageKeys.default
8+
9+
const nonDefaultKeys = Object
10+
.values(ThemeStorageKeys)
11+
.filter(key => key !== ThemeStorageKeys.default)
12+
13+
const resultKey = nonDefaultKeys.find(key => useLocalStorage(key, undefined).value)
14+
15+
if (resultKey)
16+
themeKey = resultKey
17+
18+
return themeKey
19+
}

0 commit comments

Comments
 (0)