auto load custom theme when saving

This commit is contained in:
SethBurkart123
2024-04-04 10:28:46 +11:00
parent 3cca05535a
commit dc08934eeb
2 changed files with 15 additions and 9 deletions
+6 -2
View File
@@ -76,7 +76,9 @@ export const saveTheme = async (theme: CustomThemeBase64) => {
),
};
console.log('Theme to save:', updatedTheme)
disableTheme();
console.debug('Theme to save:', updatedTheme)
await localforage.setItem(updatedTheme.id, updatedTheme);
await localforage.getItem('customThemes').then((themes: unknown) => {
@@ -90,7 +92,7 @@ export const saveTheme = async (theme: CustomThemeBase64) => {
localforage.setItem('customThemes', [updatedTheme.id]);
}
});
console.log('Theme saved successfully!');
console.debug('Theme saved successfully!');
} catch (error) {
console.error('Error saving theme:', error);
}
@@ -256,6 +258,8 @@ export const setTheme = async (themeId: string) => {
const enabledTheme = await browser.storage.local.get('selectedTheme') as { selectedTheme: string };
const theme = await localforage.getItem(themeId) as CustomTheme;
console.debug('Loading theme', theme)
// Remove the currently enabled theme
if (enabledTheme.selectedTheme) {
const currentTheme = await localforage.getItem(enabledTheme.selectedTheme) as CustomTheme;
+9 -7
View File
@@ -1,7 +1,7 @@
import browser from 'webextension-polyfill'
import { MenuOptionsOpen, OpenMenuOptions, OpenWhatsNewPopup, closeSettings } from '../../../SEQTA';
import { UpdateImageData, UpdateThemePreview, deleteTheme, disableTheme, getAvailableThemes, getTheme, saveTheme, setTheme } from '../../ui/Themes';
import { UpdateThemePreview, deleteTheme, disableTheme, getAvailableThemes, getTheme, saveTheme, setTheme } from '../../ui/Themes';
import { CloseThemeCreator, OpenThemeCreator } from '../../ui/ThemeCreator';
export class MessageHandler {
@@ -18,16 +18,18 @@ export class MessageHandler {
case 'UpdateThemePreview':
if (request?.save == true) {
saveTheme(request.body).then(() => {
setTheme(request.body.themeID).then(() => {
sendResponse({ status: 'success' });
});
});
const save = async () => {
console.log('Saving theme:', request.body)
await saveTheme(request.body)
await setTheme(request.body.id)
sendResponse({ status: 'success' });
}
save()
} else {
UpdateThemePreview(request.body);
sendResponse({ status: 'success' });
}
break;
return true;
case 'GetTheme':
getTheme(request.body.themeID).then((theme) => {