forked from ZenBrowserMirrors/zen-desktop
Merge branch 'dev' into Fix-#7701
This commit is contained in:
commit
80dfcf5eaa
4 changed files with 26 additions and 37 deletions
|
@ -108,7 +108,6 @@ var gZenMarketplaceManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async observe() {
|
async observe() {
|
||||||
ZenThemesCommon.resetThemesCache();
|
|
||||||
await this._buildThemesList();
|
await this._buildThemesList();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
async getThemePreferences(theme) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue