Skip to content

feat(dashboard): add auto switch theme (default off)#6405

Merged
LIghtJUNction merged 2 commits intoAstrBotDevs:devfrom
kyangconn:feat/auto-switch-theme
Mar 17, 2026
Merged

feat(dashboard): add auto switch theme (default off)#6405
LIghtJUNction merged 2 commits intoAstrBotDevs:devfrom
kyangconn:feat/auto-switch-theme

Conversation

@kyangconn
Copy link

@kyangconn kyangconn commented Mar 15, 2026

feat(dashboard): move all get theme and set theme by check current theme into stores/customizer

添加了根据浏览器主题自动切换页面主题的功能(默认不打开),打开按钮后如果页面主题和浏览器不匹配就会自动切换,无需刷新,可通过在其他地方手动切换主题关闭,也可直接关闭按钮。

Modifications / 改动点

在Settings页添加了一个按钮用于控制是否自动切换(默认关)
在VerticalHeader里添加了自动切换的逻辑以及监听器。
在stores/customizer里添加了判断当前是否是深色背景的getter和用于打开自动切换,自动切换,手动切换的actions。

添加了这个按钮相关的中英文翻译,改动了其他页面独立切换主题的逻辑(如果有),改动了其他页面判断主题的方式。
改动了ConversationSideBar中的中文描述(从夜间/日间改为深色/浅色,和其他地方统一)

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

按钮位置
图片

图片

未打开自动切换

图片

打开之后


Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
    / If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.

  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”
    / My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.

  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。
    / I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.

  • 😮 我的更改没有引入恶意代码。
    / My changes do not introduce malicious code.

  • ⚠️ 我已认真阅读并理解以上所有内容,确保本次提交符合规范。
    / I have read and understood all the above and confirm this PR follows the rules.

  • 🚀 我确保本次开发基于 dev 分支,并将代码合并至开发分支(除非极其紧急,才允许合并到主分支)。
    / I confirm that this development is based on the dev branch and will be merged into the development branch, unless it is extremely urgent to merge into the main branch.

  • ⚠️没有认真阅读以上内容,直接提交。
    / I did not read the above carefully before submitting.

Summary by Sourcery

Add optional automatic theme synchronization with the system appearance and centralize theme management in the customizer store.

New Features:

  • Introduce an auto-switch theme option that follows the browser/system color scheme when enabled, defaulting to off.
  • Expose a settings toggle to control automatic theme synchronization and immediately apply the system theme when turned on.

Enhancements:

  • Centralize theme toggling logic and dark-mode detection in the customizer store via a new isDarkTheme getter and theme-related actions, and update all callers to use them.
  • Add a media-query listener in the vertical header to react to system theme changes when auto-switch is enabled and clean it up on unmount.
  • Align theme-related UI text and translations, including renaming the conversation sidebar theme labels from day/night to light/dark.

feat(dashboard): move all get theme and set theme by check current theme into stores/customizer
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 15, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过引入一个基于用户系统偏好自动切换主题的功能,来提升用户体验。核心改动在于将主题管理逻辑集中到 Pinia store 中,实现了更清晰、更易维护的代码结构。用户现在可以灵活选择是否启用自动同步主题,并且手动切换主题时会自动禁用自动同步,确保了主题设置的灵活性和用户控制权。

Highlights

  • 自动主题切换功能: 新增了根据浏览器系统主题自动切换页面主题的功能,默认关闭。开启后,页面主题将与系统主题保持同步,无需刷新。手动切换主题将自动关闭此功能。
  • 主题逻辑集中管理: 所有获取和设置主题的逻辑已统一迁移至 stores/customizer Pinia 状态管理模块,提高了代码的可维护性和一致性。
  • 自定义器 Store 增强: 在 customizer store 中添加了 isDarkTheme getter 用于判断当前是否为深色主题,并新增了 SET_AUTO_SYNCTOGGLE_DARK_MODEAPPLY_SYSTEM_THEME 等 action,以支持自动和手动主题切换。
  • 用户界面更新: 在设置页面添加了一个新的开关按钮,用于控制自动主题切换功能。同时,多个组件中判断深色主题的逻辑已更新为使用新的 isDarkTheme getter。
  • 国际化支持: 为自动主题切换功能添加了中英文翻译。此外,将聊天侧边栏中的主题描述从“夜间/日间模式”统一更新为“深色/浅色模式”,以保持一致性。
Changelog
  • dashboard/src/components/chat/Chat.vue
    • 更新了 isDark 计算属性以使用 customizer.isDarkTheme
    • 修改了 toggleTheme 函数以使用 customizer.TOGGLE_DARK_MODE()
  • dashboard/src/components/chat/ChatInput.vue
    • 更新了 isDark 计算属性以使用 customizer.isDarkTheme
  • dashboard/src/components/chat/StandaloneChat.vue
    • 更新了 isDark 计算属性以使用 customizer.isDarkTheme
  • dashboard/src/components/shared/ExtensionCard.vue
    • 更新了背景色和文字颜色样式以使用 !useCustomizerStore().isDarkTheme
  • dashboard/src/i18n/locales/en-US/features/settings.json
    • 添加了自动同步主题功能的新翻译键
  • dashboard/src/i18n/locales/zh-CN/features/chat.json
    • 将“夜间模式”和“日间模式”的翻译更新为“深色模式”和“浅色模式”
  • dashboard/src/i18n/locales/zh-CN/features/settings.json
    • 添加了自动同步主题功能的新翻译键
  • dashboard/src/layouts/full/vertical-header/VerticalHeader.vue
    • 导入了 onBeforeUnmount 生命周期钩子
    • toggleDarkMode 替换为使用 customizer.TOGGLE_DARK_MODE()toggleTheme
    • 新增了 autoSwitchTheme 函数以应用系统主题
    • 新增了 autoSwitchThemeListener 以监听系统主题变化
    • onMountedonBeforeUnmount 中实现了系统主题变化监听器的管理
    • 更新了主题切换按钮以使用新的 toggleTheme()customizer.isDarkTheme
  • dashboard/src/stores/customizer.ts
    • 新增了 autoSwitchTheme 状态属性,并从 localStorage 初始化
    • 新增了 isDarkTheme getter 以判断当前是否为深色主题
    • 新增了 SET_AUTO_SYNC action 以更新 autoSwitchTheme 状态和 localStorage
    • 新增了 TOGGLE_DARK_MODE action 以手动切换主题并禁用自动同步
    • 新增了 APPLY_SYSTEM_THEME action 以根据系统偏好设置主题
  • dashboard/src/views/ConversationPage.vue
    • 更新了 isDark 计算属性以使用 customizerStore.isDarkTheme
  • dashboard/src/views/Settings.vue
    • 添加了一个新的 v-list-item 包含 v-switch 用于控制 autoThemeSwitcher
    • 实现了 autoThemeSwitcher 计算属性以管理 customizer.autoSwitchTheme 并在启用时应用系统主题
  • dashboard/src/views/authentication/auth/LoginPage.vue
    • 修改了 toggleTheme 函数以使用 customizer.TOGGLE_DARK_MODE()
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the area:webui The bug / feature is about webui(dashboard) of astrbot. label Mar 15, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The auto theme sync only registers the matchMedia listener in VerticalHeader on mount when autoSwitchTheme is already true, so enabling the toggle later in Settings won’t start listening to system changes; consider watching autoSwitchTheme or centralizing the listener setup in the store so it activates/deactivates dynamically.
  • The logic in autoSwitchThemeListener duplicates what APPLY_SYSTEM_THEME does; you could simplify and avoid divergence by delegating to APPLY_SYSTEM_THEME() instead of recalculating and setting the theme separately.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The auto theme sync only registers the `matchMedia` listener in `VerticalHeader` on mount when `autoSwitchTheme` is already true, so enabling the toggle later in Settings won’t start listening to system changes; consider watching `autoSwitchTheme` or centralizing the listener setup in the store so it activates/deactivates dynamically.
- The logic in `autoSwitchThemeListener` duplicates what `APPLY_SYSTEM_THEME` does; you could simplify and avoid divergence by delegating to `APPLY_SYSTEM_THEME()` instead of recalculating and setting the theme separately.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 引入了根据系统颜色方案自动切换主题的功能,并将主题管理逻辑重构到 customizer store 中。总体实现很好,集中了状态和操作。但在代码重复和响应式方面还有一些改进空间。具体来说,主题更新的逻辑散布在多个组件中,并且系统主题变化的监听器不是完全响应式的。我还发现了一个中文翻译中的小错误。我的建议旨在使代码更健壮、更易于维护。

根据Gemini的意见更改了一些地方。
将原本的状态更新挪到了App.vue里,可以去除很多地方更新theme所需要的theme依赖。
将翻译修改了
将监听器改为了watch
@LIghtJUNction
Copy link
Member

可以

@LIghtJUNction LIghtJUNction merged commit 7aae048 into AstrBotDevs:dev Mar 17, 2026
2 checks passed
@LIghtJUNction
Copy link
Member

4c0fb31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants