fix: themes randomly disabling after quick succesive page loads

This commit is contained in:
SethBurkart123
2025-03-29 21:56:46 +11:00
parent 9542cb13f5
commit 09855c9ef5
+16 -5
View File
@@ -116,7 +116,7 @@ export class ThemeManager {
console.debug('[ThemeManager] Cleaning up resources'); console.debug('[ThemeManager] Cleaning up resources');
try { try {
if (this.currentTheme) { if (this.currentTheme) {
await this.removeTheme(this.currentTheme); await this.removeTheme(this.currentTheme, false);
} }
} catch (error) { } catch (error) {
console.error('[ThemeManager] Error during cleanup:', error); console.error('[ThemeManager] Error during cleanup:', error);
@@ -203,7 +203,7 @@ export class ThemeManager {
/** /**
* Remove theme and restore original settings * Remove theme and restore original settings
*/ */
private async removeTheme(theme: CustomTheme): Promise<void> { private async removeTheme(theme: CustomTheme, clearSelectedTheme: boolean = true): Promise<void> {
console.debug('[ThemeManager] Removing theme:', theme.name); console.debug('[ThemeManager] Removing theme:', theme.name);
try { try {
// Remove custom CSS // Remove custom CSS
@@ -246,7 +246,9 @@ export class ThemeManager {
} }
this.currentTheme = null; this.currentTheme = null;
if (clearSelectedTheme) {
settingsState.selectedTheme = ''; settingsState.selectedTheme = '';
}
} catch (error) { } catch (error) {
console.error('[ThemeManager] Error removing theme:', error); console.error('[ThemeManager] Error removing theme:', error);
@@ -433,7 +435,16 @@ export class ThemeManager {
return; return;
} }
const { CustomImages = [], coverImage, ...themeWithoutImages } = theme; // Extract only the fields we want to share
const {
CustomImages = [],
coverImage,
webURL,
isEditable,
selectedColor,
allowBackgrounds,
...themeBasics
} = theme;
// Convert images to base64 // Convert images to base64
const finalImages = await Promise.all(CustomImages.map(async (image) => ({ const finalImages = await Promise.all(CustomImages.map(async (image) => ({
@@ -445,9 +456,9 @@ export class ThemeManager {
// Convert cover image to base64 // Convert cover image to base64
const coverImageBase64 = coverImage ? await this.blobToBase64(coverImage) : null; const coverImageBase64 = coverImage ? await this.blobToBase64(coverImage) : null;
// Create shareable theme data // Create shareable theme data with only necessary fields
const shareableTheme = { const shareableTheme = {
...themeWithoutImages, ...themeBasics,
images: finalImages, images: finalImages,
coverImage: coverImageBase64 coverImage: coverImageBase64
}; };