Merge branch 'dev' into Fix-#7701

This commit is contained in:
mr. m 2025-05-12 17:45:40 +02:00 committed by GitHub
commit 80dfcf5eaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 37 deletions

View file

@ -108,7 +108,6 @@ var gZenMarketplaceManager = {
}, },
async observe() { async observe() {
ZenThemesCommon.resetThemesCache();
await this._buildThemesList(); await this._buildThemesList();
}, },

View file

@ -36,35 +36,27 @@ var ZenThemesCommon = {
return PathUtils.join(this.themesRootPath, themeId); return PathUtils.join(this.themesRootPath, themeId);
}, },
resetThemesCache() {
this.themes = null;
},
async getThemes() { async getThemes() {
if (!this.themes) {
if (!(await IOUtils.exists(this.themesDataFile))) { if (!(await IOUtils.exists(this.themesDataFile))) {
await IOUtils.writeJSON(this.themesDataFile, {}); await IOUtils.writeJSON(this.themesDataFile, {});
} }
let themes = {};
try { try {
this.themes = await IOUtils.readJSON(this.themesDataFile); themes = await IOUtils.readJSON(this.themesDataFile);
if (themes === null || typeof themes !== 'object') {
throw new Error('Themes data file is null');
}
} catch (e) { } catch (e) {
// If we have a corrupted file, reset it // If we have a corrupted file, reset it
await IOUtils.writeJSON(this.themesDataFile, {}); await IOUtils.writeJSON(this.themesDataFile, {});
this.themes = {}; Services.wm
gNotificationBox.appendNotification( .getMostRecentWindow('navigator:browser')
'zen-themes-corrupted', .gZenUIManager.showToast('zen-themes-corrupted', {
{ timeout: 8000,
label: { 'l10n-id': 'zen-themes-corrupted' }, });
image: 'chrome://browser/skin/notification-icons/persistent-storage-blocked.svg',
priority: gNotificationBox.PRIORITY_WARNING_HIGH,
},
[]
);
} }
} return themes;
return this.themes;
}, },
async getThemePreferences(theme) { async getThemePreferences(theme) {

View file

@ -63,6 +63,7 @@ var gZenThemesImporter = new (class {
return; return;
} }
await ZenThemesCommon.getThemes(); // Check for any errors in the themes data file
const themes = await this.getEnabledThemes(); const themes = await this.getEnabledThemes();
const themesWithPreferences = await Promise.all( const themesWithPreferences = await Promise.all(
@ -159,8 +160,6 @@ var gZenThemesImporter = new (class {
} }
async rebuildThemeStylesheet() { async rebuildThemeStylesheet() {
ZenThemesCommon.themes = null;
await this.removeStylesheet(); await this.removeStylesheet();
const themes = await this.getEnabledThemes(); const themes = await this.getEnabledThemes();
@ -316,7 +315,6 @@ var gZenThemesImporter = new (class {
async writeStylesheet(themeList = []) { async writeStylesheet(themeList = []) {
const themes = []; const themes = [];
ZenThemesCommon.themes = null;
for (let theme of themeList) { for (let theme of themeList) {
theme._chromeURL = this.getStylesheetURIForTheme(theme).spec; theme._chromeURL = this.getStylesheetURIForTheme(theme).spec;

View file

@ -75,8 +75,7 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
console.info('ZenThemeMarketplaceParent: Checking for theme updates'); console.info('ZenThemeMarketplaceParent: Checking for theme updates');
let updates = []; let updates = [];
this._themes = null; const themes = await this.getThemes();
for (const theme of Object.values(await this.getThemes())) { for (const theme of Object.values(await this.getThemes())) {
try { try {
const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', { const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', {
@ -102,15 +101,14 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
updates.push(themeInfo); updates.push(themeInfo);
await this.removeTheme(theme.id, false); await this.removeTheme(theme.id, false);
themes[themeInfo.id] = themeInfo;
this._themes[themeInfo.id] = themeInfo;
} }
} catch (e) { } catch (e) {
console.error('ZenThemeMarketplaceParent: Error checking for theme updates', e); console.error('ZenThemeMarketplaceParent: Error checking for theme updates', e);
} }
} }
await this.updateThemes(this._themes); await this.updateThemes(themes);
this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates }); this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates });
} }
@ -123,8 +121,10 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
return await IOUtils.readJSON(this.themesDataFile); return await IOUtils.readJSON(this.themesDataFile);
} }
async updateThemes(themes) { async updateThemes(themes = undefined) {
this._themes = themes; if (!themes) {
themes = await this.getThemes();
}
await IOUtils.writeJSON(this.themesDataFile, themes); await IOUtils.writeJSON(this.themesDataFile, themes);
await this.checkForThemeChanges(); await this.checkForThemeChanges();
} }