mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
added auto updating of themes
This commit is contained in:
@@ -93,6 +93,16 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse:
|
||||
reloadSeqtaPages();
|
||||
break;
|
||||
|
||||
case 'extensionPages':
|
||||
browser.tabs.query({}).then(function (tabs) {
|
||||
for (let tab of tabs) {
|
||||
if (tab.url?.includes('chrome-extension://')) {
|
||||
browser.tabs.sendMessage(tab.id!, request);
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'currentTab':
|
||||
browser.tabs.query({ active: true, currentWindow: true }).then(function (tabs) {
|
||||
browser.tabs.sendMessage(tabs[0].id!, request).then(function (response) {
|
||||
|
||||
@@ -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();
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ export const sendThemeUpdate = (updatedTheme: CustomTheme, saveTheme?: boolean,
|
||||
|
||||
if (saveTheme) {
|
||||
browser.runtime.sendMessage({ type: 'currentTab', info: 'CloseThemeCreator' });
|
||||
browser.runtime.sendMessage({ type: 'extensionPages', info: 'themeChanged' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ export class MessageHandler {
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Unknown request info:', request.info);
|
||||
console.debug('Unknown request info:', request.info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user