From ae03ba527a70be70b7652758b7aa9eab925ef387 Mon Sep 17 00:00:00 2001 From: Mauro Balades Date: Sat, 17 Aug 2024 15:27:49 +0200 Subject: [PATCH] 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. --- src/ZenThemesImporter.mjs | 9 ++++----- src/actors/ZenThemeMarketplaceParent.sys.mjs | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ZenThemesImporter.mjs b/src/ZenThemesImporter.mjs index b23c1e6..e9ebd50 100644 --- a/src/ZenThemesImporter.mjs +++ b/src/ZenThemesImporter.mjs @@ -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); } }; diff --git a/src/actors/ZenThemeMarketplaceParent.sys.mjs b/src/actors/ZenThemeMarketplaceParent.sys.mjs index 1958c0b..30d3133 100644 --- a/src/actors/ZenThemeMarketplaceParent.sys.mjs +++ b/src/actors/ZenThemeMarketplaceParent.sys.mjs @@ -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); } }