diff --git a/src/browser/components/preferences/zen-settings.js b/src/browser/components/preferences/zen-settings.js index bd5385f5..d871e169 100644 --- a/src/browser/components/preferences/zen-settings.js +++ b/src/browser/components/preferences/zen-settings.js @@ -108,7 +108,6 @@ var gZenMarketplaceManager = { }, async observe() { - ZenThemesCommon.resetThemesCache(); await this._buildThemesList(); }, diff --git a/src/zen/mods/ZenThemesCommon.mjs b/src/zen/mods/ZenThemesCommon.mjs index f8bda8cf..82632939 100644 --- a/src/zen/mods/ZenThemesCommon.mjs +++ b/src/zen/mods/ZenThemesCommon.mjs @@ -36,35 +36,27 @@ var ZenThemesCommon = { return PathUtils.join(this.themesRootPath, themeId); }, - resetThemesCache() { - this.themes = null; - }, - async getThemes() { - if (!this.themes) { - if (!(await IOUtils.exists(this.themesDataFile))) { - await IOUtils.writeJSON(this.themesDataFile, {}); - } - - try { - this.themes = await IOUtils.readJSON(this.themesDataFile); - } catch (e) { - // If we have a corrupted file, reset it - await IOUtils.writeJSON(this.themesDataFile, {}); - this.themes = {}; - gNotificationBox.appendNotification( - 'zen-themes-corrupted', - { - label: { 'l10n-id': 'zen-themes-corrupted' }, - image: 'chrome://browser/skin/notification-icons/persistent-storage-blocked.svg', - priority: gNotificationBox.PRIORITY_WARNING_HIGH, - }, - [] - ); - } + if (!(await IOUtils.exists(this.themesDataFile))) { + await IOUtils.writeJSON(this.themesDataFile, {}); } - return this.themes; + let themes = {}; + try { + themes = await IOUtils.readJSON(this.themesDataFile); + if (themes === null || typeof themes !== 'object') { + throw new Error('Themes data file is null'); + } + } catch (e) { + // If we have a corrupted file, reset it + await IOUtils.writeJSON(this.themesDataFile, {}); + Services.wm + .getMostRecentWindow('navigator:browser') + .gZenUIManager.showToast('zen-themes-corrupted', { + timeout: 8000, + }); + } + return themes; }, async getThemePreferences(theme) { diff --git a/src/zen/mods/ZenThemesImporter.mjs b/src/zen/mods/ZenThemesImporter.mjs index 1303db5f..e1378a56 100644 --- a/src/zen/mods/ZenThemesImporter.mjs +++ b/src/zen/mods/ZenThemesImporter.mjs @@ -63,6 +63,7 @@ var gZenThemesImporter = new (class { return; } + await ZenThemesCommon.getThemes(); // Check for any errors in the themes data file const themes = await this.getEnabledThemes(); const themesWithPreferences = await Promise.all( @@ -159,8 +160,6 @@ var gZenThemesImporter = new (class { } async rebuildThemeStylesheet() { - ZenThemesCommon.themes = null; - await this.removeStylesheet(); const themes = await this.getEnabledThemes(); @@ -316,7 +315,6 @@ var gZenThemesImporter = new (class { async writeStylesheet(themeList = []) { const themes = []; - ZenThemesCommon.themes = null; for (let theme of themeList) { theme._chromeURL = this.getStylesheetURIForTheme(theme).spec; diff --git a/src/zen/mods/actors/ZenThemeMarketplaceParent.sys.mjs b/src/zen/mods/actors/ZenThemeMarketplaceParent.sys.mjs index c26f4446..1a6efa5a 100644 --- a/src/zen/mods/actors/ZenThemeMarketplaceParent.sys.mjs +++ b/src/zen/mods/actors/ZenThemeMarketplaceParent.sys.mjs @@ -75,8 +75,7 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent { console.info('ZenThemeMarketplaceParent: Checking for theme updates'); let updates = []; - this._themes = null; - + const themes = await this.getThemes(); for (const theme of Object.values(await this.getThemes())) { try { const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', { @@ -102,15 +101,14 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent { updates.push(themeInfo); await this.removeTheme(theme.id, false); - - this._themes[themeInfo.id] = themeInfo; + themes[themeInfo.id] = themeInfo; } } catch (e) { console.error('ZenThemeMarketplaceParent: Error checking for theme updates', e); } } - await this.updateThemes(this._themes); + await this.updateThemes(themes); this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates }); } @@ -123,8 +121,10 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent { return await IOUtils.readJSON(this.themesDataFile); } - async updateThemes(themes) { - this._themes = themes; + async updateThemes(themes = undefined) { + if (!themes) { + themes = await this.getThemes(); + } await IOUtils.writeJSON(this.themesDataFile, themes); await this.checkForThemeChanges(); }