mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-24 04:48:03 +00:00
prefers-color-scheme detection
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user