1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-24 12:58:34 +00:00

prefers-color-scheme detection

This commit is contained in:
zhouwenxuan
2025-07-15 14:32:22 +08:00
parent 9d8aad861e
commit c9346d1b6b

View File

@@ -95,8 +95,20 @@ class App extends Component {
this.navigateClientUrlToLib();
this.initCurrentTabByLocation();
this.colorSchemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
this.colorSchemeQuery.addEventListener('change', this.handleColorSchemeChange);
}
componentWillUnmount() {
this.colorSchemeQuery.removeEventListener('change', this.handleColorSchemeChange);
}
handleColorSchemeChange = (e) => {
const isDark = e.matches;
document.body.setAttribute('data-bs-theme', isDark ? 'dark' : 'light');
this.forceUpdate();
};
initCurrentTabByLocation = () => {
// when visit the siteRoot page, highlight the 'Files' tab in the side nav.
if (location.pathname == siteRoot) {