-
Notifications
You must be signed in to change notification settings - Fork 625
fix: theme change issue #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,15 +39,19 @@ const devicePresenter = usePresenter('devicePresenter') | |
| watch( | ||
| [() => themeStore.themeMode, () => settingsStore.fontSizeClass], | ||
| ([newTheme, newFontSizeClass], [oldTheme, oldFontSizeClass]) => { | ||
| let newThemeName = newTheme | ||
| if (newTheme === 'system') { | ||
| newThemeName = themeStore.isDark ? 'dark' : 'light' | ||
| } | ||
| if (oldTheme) { | ||
|
Comment on lines
+42
to
46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix stale CSS classes when switching to/from 'system' theme and align target element Bug: removing oldTheme (which can be 'system') won’t remove the actually applied 'dark'/'light' class, causing class accumulation and theme flicker. Also, elsewhere you add classes to body, but here you mutate documentElement, leading to inconsistency. Replace removal with explicit removal of 'dark' and 'light', then add the effective theme. Keep logs in English and prefer debug level. - let newThemeName = newTheme
- if (newTheme === 'system') {
- newThemeName = themeStore.isDark ? 'dark' : 'light'
- }
- if (oldTheme) {
- document.documentElement.classList.remove(oldTheme)
- }
+ const effectiveTheme =
+ newTheme === 'system' ? (themeStore.isDark ? 'dark' : 'light') : newTheme
+ // Always normalize classes before applying the new one
+ document.documentElement.classList.remove('dark')
+ document.documentElement.classList.remove('light')
@@
- document.documentElement.classList.add(newThemeName)
+ document.documentElement.classList.add(effectiveTheme)
@@
- console.log('newTheme', newThemeName)
+ console.debug('[theme] applied', { themeMode: newTheme, effectiveTheme })Additionally, align initial mount with the same element and effective theme (outside the changed range): // onMounted initial classes
const initialEffectiveTheme =
themeStore.themeMode === 'system' ? (themeStore.isDark ? 'dark' : 'light') : themeStore.themeMode
document.documentElement.classList.add(initialEffectiveTheme)
document.documentElement.classList.add(settingsStore.fontSizeClass)Also applies to: 52-55 |
||
| document.documentElement.classList.remove(oldTheme) | ||
| } | ||
| if (oldFontSizeClass) { | ||
| document.documentElement.classList.remove(oldFontSizeClass) | ||
| } | ||
| document.documentElement.classList.add(newTheme) | ||
| document.documentElement.classList.add(newThemeName) | ||
| document.documentElement.classList.add(newFontSizeClass) | ||
| console.log('newTheme', themeStore.themeMode) | ||
| console.log('newTheme', newThemeName) | ||
| }, | ||
| { immediate: false } // 初始化在 onMounted 中处理 | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { useDark, useToggle } from '@vueuse/core' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { defineStore } from 'pinia' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ref, onMounted, onUnmounted } from 'vue' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { IpcRendererEvent } from 'electron' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CONFIG_EVENTS, SYSTEM_EVENTS } from '@/events' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type ThemeMode = 'dark' | 'light' | 'system' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,67 +20,68 @@ export const useThemeStore = defineStore('theme', () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentTheme = (await configPresenter.getTheme()) as ThemeMode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| themeMode.value = currentTheme | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 如果是系统主题模式,则根据系统实际深色/浅色设置来设置界面 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentTheme === 'system') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const systemIsDark = await configPresenter.toggleTheme('system') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('initTheme', systemIsDark) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark(systemIsDark) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark(currentTheme === 'dark') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 获取当前实际的深色模式状态 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isDarkMode = await configPresenter.getCurrentThemeIsDark() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('initTheme - theme:', currentTheme, 'isDark:', isDarkMode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark(isDarkMode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initTheme() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 监听系统主题变化事件 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleSystemThemeChange = (_event: IpcRendererEvent, isDarkMode: boolean) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('handleSystemThemeChange', isDarkMode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 只有在系统模式下才跟随系统主题变化 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (themeMode.value === 'system') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark(isDarkMode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 监听用户主题变化事件 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleUserThemeChange = (_event: IpcRendererEvent, theme: ThemeMode) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (themeMode.value !== theme) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| configPresenter.getCurrentThemeIsDark().then((isDark) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('handleUserThemeChange', theme, isDark) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| themeMode.value = theme | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark(isDark) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid unnecessary IPC and add try/catch in handleUserThemeChange() Compute isDark locally for 'dark'/'light' and only query main for 'system'. Also switch to await + try/catch for clearer flow and required error handling. - const handleUserThemeChange = (_event: IpcRendererEvent, theme: ThemeMode) => {
- if (themeMode.value !== theme) {
- configPresenter.getCurrentThemeIsDark().then((isDark) => {
- console.log('handleUserThemeChange', theme, isDark)
- themeMode.value = theme
- toggleDark(isDark)
- })
- }
- }
+ const handleUserThemeChange = async (_event: IpcRendererEvent, theme: ThemeMode) => {
+ if (themeMode.value === theme) return
+ try {
+ const isDark =
+ theme === 'system'
+ ? await configPresenter.getCurrentThemeIsDark()
+ : theme === 'dark'
+ log('INFO', 'handleUserThemeChange', { theme, isDark })
+ themeMode.value = theme
+ toggleDark(isDark)
+ } catch (err) {
+ log('ERROR', 'handleUserThemeChange failed', { theme, err })
+ }
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 注册和清理主题变化监听器 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onMounted(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.on('system-theme-updated', handleSystemThemeChange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.on(SYSTEM_EVENTS.SYSTEM_THEME_UPDATED, handleSystemThemeChange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.on(CONFIG_EVENTS.THEME_CHANGED, handleUserThemeChange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUnmounted(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.removeListener('system-theme-updated', handleSystemThemeChange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.removeListener( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SYSTEM_EVENTS.SYSTEM_THEME_UPDATED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleSystemThemeChange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.removeListener(CONFIG_EVENTS.THEME_CHANGED, handleUserThemeChange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
51
to
62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Vue lifecycle hooks don’t run inside Pinia stores — IPC listeners won’t register onMounted/onUnmounted are component hooks; in a Pinia store they are no-ops, so your handlers never get attached. Register listeners once at store creation with an idempotent guard and clean up on HMR. - // 注册和清理主题变化监听器
- onMounted(() => {
- window.electron.ipcRenderer.on(SYSTEM_EVENTS.SYSTEM_THEME_UPDATED, handleSystemThemeChange)
- window.electron.ipcRenderer.on(CONFIG_EVENTS.THEME_CHANGED, handleUserThemeChange)
- })
-
- onUnmounted(() => {
- window.electron.ipcRenderer.removeListener(
- SYSTEM_EVENTS.SYSTEM_THEME_UPDATED,
- handleSystemThemeChange
- )
- window.electron.ipcRenderer.removeListener(CONFIG_EVENTS.THEME_CHANGED, handleUserThemeChange)
- })
+ // Register/unregister IPC listeners once per store instance (no component lifecycle here)
+ let listenersRegistered = false
+ const registerIpcListeners = () => {
+ if (listenersRegistered) return
+ try {
+ window.electron.ipcRenderer.on(
+ SYSTEM_EVENTS.SYSTEM_THEME_UPDATED,
+ handleSystemThemeChange
+ )
+ window.electron.ipcRenderer.on(
+ CONFIG_EVENTS.THEME_CHANGED,
+ handleUserThemeChange
+ )
+ listenersRegistered = true
+ log('INFO', 'IPC listeners registered')
+ } catch (err) {
+ log('ERROR', 'Failed to register IPC listeners', { err })
+ }
+ }
+ const unregisterIpcListeners = () => {
+ if (!listenersRegistered) return
+ try {
+ window.electron.ipcRenderer.removeListener(
+ SYSTEM_EVENTS.SYSTEM_THEME_UPDATED,
+ handleSystemThemeChange
+ )
+ window.electron.ipcRenderer.removeListener(
+ CONFIG_EVENTS.THEME_CHANGED,
+ handleUserThemeChange
+ )
+ } finally {
+ listenersRegistered = false
+ log('INFO', 'IPC listeners unregistered')
+ }
+ }
+ registerIpcListeners()
+ // Ensure cleanup during HMR
+ if (import.meta.hot) {
+ import.meta.hot.dispose(unregisterIpcListeners)
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 监听深色模式变化 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // watch(isDark, (value) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // // 只有在非系统模式下,才直接切换主题 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // if (themeMode.value !== 'system') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // windowPresenter.toggleTheme(value ? 'dark' : 'light') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // themeMode.value = value ? 'dark' : 'light' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 设置主题模式 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setThemeMode = async (mode: ThemeMode) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| themeMode.value = mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isDarkMode = await configPresenter.toggleTheme(mode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isDarkMode = await configPresenter.setTheme(mode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 如果不是系统模式,直接设置深色/浅色状态 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 如果是系统模式,toggleTheme 会返回系统当前的深色状态 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 设置界面深色/浅色状态 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark(isDarkMode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
65
to
71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Set theme atomically with error handling; update state only on success Currently themeMode is set before setTheme() resolves. If IPC fails, UI and persisted setting diverge. Move assignment after success and add required structured logging. - const setThemeMode = async (mode: ThemeMode) => {
- themeMode.value = mode
- const isDarkMode = await configPresenter.setTheme(mode)
-
- // 设置界面深色/浅色状态
- toggleDark(isDarkMode)
- }
+ const setThemeMode = async (mode: ThemeMode) => {
+ try {
+ const isDarkMode = await configPresenter.setTheme(mode)
+ themeMode.value = mode
+ log('INFO', 'setThemeMode', { mode, isDark: isDarkMode })
+ toggleDark(isDarkMode)
+ } catch (err) {
+ log('ERROR', 'setThemeMode failed', { mode, err })
+ }
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 循环切换主题:light -> dark -> system -> light | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cycleTheme = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cycleTheme = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('cycleTheme', themeMode.value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (themeMode.value === 'light') setThemeMode('dark') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (themeMode.value === 'dark') setThemeMode('system') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else setThemeMode('light') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (themeMode.value === 'light') await setThemeMode('dark') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (themeMode.value === 'dark') await setThemeMode('system') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else await setThemeMode('light') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isDark, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toggleDark, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| themeMode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setThemeMode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cycleTheme | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
81
to
86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainDon’t export toggleDark; expose setThemeMode to keep renderer and main in sync Exporting toggleDark enables “local-only” toggles that bypass configPresenter and events, causing desync across windows and restarts. Surface setThemeMode instead and keep toggleDark private. return {
isDark,
- toggleDark,
themeMode,
- cycleTheme
+ cycleTheme,
+ setThemeMode
}Run to find any direct usages of toggleDark you’ll need to migrate: 🏁 Script executed: #!/bin/bash
rg -nP -C2 --type=ts --type=tsx --type=vue '\b(useThemeStore\(\)|themeStore)\.toggleDark\b|toggleDark\s*\('Length of output: 137 🏁 Script executed: #!/bin/bash
# Re-run search for direct usages of toggleDark across .ts, .tsx, and .vue files
rg -nP -C2 '\b(useThemeStore\(\)|themeStore)\.toggleDark\b|toggleDark\s*\(' --glob '*.ts' --glob '*.tsx' --glob '*.vue'Length of output: 1750 Action Required: Remove Based on the grep search,
After you remove • In return {
isDark,
- toggleDark,
themeMode,
cycleTheme,
+ setThemeMode
}• In - @click="themeStore.toggleDark()"
+ @click="themeStore.setThemeMode(themeStore.isDark ? 'light' : 'dark')"—or, if you prefer cycling through modes (including - @click="themeStore.toggleDark()"
+ @click="themeStore.cycleTheme()"No other external usages of 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
System theme update is sent to main instead of renderer
You intend to notify renderers on OS theme changes when themeSource === 'system', but eventBus.sendToMain delivers only within main. Use sendToRenderer and broadcast to all windows.
📝 Committable suggestion
🤖 Prompt for AI Agents