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