added auto updating of themes

This commit is contained in:
SethBurkart123
2024-04-07 17:19:14 +10:00
parent 801e97e6ff
commit 438f52f29c
4 changed files with 44 additions and 12 deletions
+32 -11
View File
@@ -31,19 +31,40 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
}));
useEffect(() => {
const fetchThemes = async () => {
try {
const { themes, selectedTheme } = await listThemes();
setThemes(themes);
setSelectedTheme(selectedTheme ? selectedTheme : '');
} catch (error) {
console.error('Error fetching themes:', error);
} finally {
setIsLoading(false);
}
const handleThemeChange = async () => {
await new Promise((resolve) => setTimeout(resolve, 500));
fetchThemes();
};
Browser.runtime.onMessage.addListener((message) => {
if (message.info === 'themeChanged') {
handleThemeChange();
}
});
return () => {
Browser.runtime.onMessage.removeListener((message) => {
if (message.info === 'themeChanged') {
handleThemeChange();
}
});
};
}, []);
const fetchThemes = async () => {
try {
const { themes, selectedTheme } = await listThemes();
setThemes(themes);
setSelectedTheme(selectedTheme ? selectedTheme : '');
} catch (error) {
console.error('Error fetching themes:', error);
} finally {
setIsLoading(false);
}
};
useEffect(() => {
fetchThemes();
}, []);