MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / initializeThemeStore

Function initializeThemeStore

cli/src/hooks/use-theme.tsx:89–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87}
88
89export function initializeThemeStore() {
90 if (themeStoreInitialized) {
91 return
92 }
93 themeStoreInitialized = true
94
95 setThemeResolver(detectSystemTheme)
96 setupFileWatchers()
97
98 const initialThemeName = detectSystemTheme()
99 setLastDetectedTheme(initialThemeName)
100 const initialTheme = buildTheme(
101 cloneChatTheme(chatThemes[initialThemeName]),
102 initialThemeName,
103 themeConfig.customColors,
104 themeConfig.plugins,
105 )
106
107 useThemeStore = create<ThemeStore>((set, get) => ({
108 theme: initialTheme,
109
110 setThemeName: (name: ThemeName) => {
111 const currentTheme = get().theme
112
113 // Skip if theme name hasn't changed
114 if (currentTheme.name === name) {
115 return
116 }
117
118 const baseTheme = cloneChatTheme(chatThemes[name])
119 const theme = buildTheme(
120 baseTheme,
121 name,
122 themeConfig.customColors,
123 themeConfig.plugins,
124 )
125 set({ theme })
126 },
127 }))
128
129 // Set up the theme watcher for reactive updates when system theme changes
130 initializeThemeWatcher((name: ThemeName) => {
131 useThemeStore.getState().setThemeName(name)
132 })
133
134 // Note: OSC detection is done earlier in index.tsx before OpenTUI starts,
135 // so the result is already available via getOscDetectedTheme()
136}
137
138export const useTheme = (): ChatTheme => {
139 return useThemeStore((state) => state.theme)

Calls 9

setThemeResolverFunction · 0.90
setupFileWatchersFunction · 0.90
setLastDetectedThemeFunction · 0.90
buildThemeFunction · 0.90
cloneChatThemeFunction · 0.90
initializeThemeWatcherFunction · 0.90
detectSystemThemeFunction · 0.85
setFunction · 0.85
getFunction · 0.50

Tested by

no test coverage detected