refactor: Update ZenThemeImporter and ZenThemeMarketplaceParent

Improve page load performance by adding lazy loading for images in the ZenThemeImporter and ZenThemeMarketplaceParent files. In ZenThemeImporter, the observer method has been updated to call the rebuildThemeStylesheet function instead of updateStylesheet. Additionally, the sss.loadAndRegisterSheet method has been modified to use the AGENT_SHEET parameter instead of USER_SHEET. In ZenThemeMarketplaceParent, the console.info statement for downloading files has been removed and replaced with a console.error statement for error handling. These changes optimize the loading of images and enhance the overall user experience.
This commit is contained in:
Mauro Balades 2024-08-17 15:27:49 +02:00
parent cd1de4db6f
commit ae03ba527a
2 changed files with 5 additions and 7 deletions

View file

@ -41,7 +41,7 @@ var gZenThemeImporter = new class {
} catch (e) {
console.error("ZenThemeImporter: Error importing Zen theme: ", e);
}
Services.prefs.addObserver("zen.themes.updated-value-observer", this.updateStylesheet.bind(this), false);
Services.prefs.addObserver("zen.themes.updated-value-observer", this.rebuildThemeStylesheet.bind(this), false);
}
get sss() {
@ -106,12 +106,12 @@ var gZenThemeImporter = new class {
insertStylesheet() {
if (IOUtils.exists(this.styleSheetPath)) {
this.sss.loadAndRegisterSheet(this.styleSheetURI, this.sss.USER_SHEET);
this.sss.loadAndRegisterSheet(this.styleSheetURI, this.sss.AGENT_SHEET);
}
}
removeStylesheet() {
this.sss.unregisterSheet(this.styleSheetURI, this.sss.USER_SHEET);
this.sss.unregisterSheet(this.styleSheetURI, this.sss.AGENT_SHEET);
}
async updateStylesheet() {
@ -125,9 +125,8 @@ var gZenThemeImporter = new class {
this._themes = null;
for (let theme of Object.values(await this.getThemes())) {
theme._chromeURL = this.getStylesheetURIForTheme(theme).spec;
console.info("ZenThemeImporter: Writing theme: ", theme._chromeURL);
themes.push(theme);
}
gZenStylesheetManager.writeStylesheet(this.styleSheetPath, themes);
await gZenStylesheetManager.writeStylesheet(this.styleSheetPath, themes);
}
};

View file

@ -55,14 +55,13 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
async downloadUrlToFile(url, path) {
try {
console.info("ZenThemeMarketplaceParent: Downloading file from ", url);
const response = await fetch(url);
const data = await response.text();
// convert the data into a Uint8Array
let buffer = new TextEncoder().encode(data);
await IOUtils.write(path, buffer);
} catch (e) {
console.error("ZenThemeMarketplaceParent: Error downloading file", e);
console.error("ZenThemeMarketplaceParent: Error downloading file", url, e);
}
}