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() {
ZenThemesCommon.resetThemesCache();
await this._buildThemesList();
},

View file

@ -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) {

View file

@ -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;

View file

@ -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();
}