mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 07:16:08 +08:00
修复matchMedia兼容性
This commit is contained in:
parent
2a9751e051
commit
2f4fb657e6
|
@ -47,7 +47,8 @@ export const useTheme = () => {
|
|||
const isDark =
|
||||
(media.matches && storageTheme !== 'light') || storageTheme === 'dark';
|
||||
setTheme(isDark ? 'vs-dark' : 'vs');
|
||||
media.addEventListener('change', (e) => {
|
||||
|
||||
const cb = (e: any) => {
|
||||
if (storageTheme === 'auto' || !storageTheme) {
|
||||
if (e.matches) {
|
||||
setTheme('vs-dark');
|
||||
|
@ -55,7 +56,12 @@ export const useTheme = () => {
|
|||
setTheme('vs');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
if (typeof media.addEventListener === 'function') {
|
||||
media.addEventListener('change', cb);
|
||||
} else if (typeof media.addListener === 'function') {
|
||||
media.addListener(cb);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { theme };
|
||||
|
|
Loading…
Reference in New Issue
Block a user