From 83a612c6e504ebd1fe2e7e09b08b42f41fe27d9b Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Tue, 15 Oct 2024 16:10:25 +0200 Subject: [PATCH] Fix issue with corrupted themes data file --- src/ZenThemesCommon.mjs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ZenThemesCommon.mjs b/src/ZenThemesCommon.mjs index b514b92..5da3ce4 100644 --- a/src/ZenThemesCommon.mjs +++ b/src/ZenThemesCommon.mjs @@ -31,7 +31,22 @@ var ZenThemesCommon = { await IOUtils.writeJSON(this.themesDataFile, {}); } - this.themes = await IOUtils.readJSON(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_INFO_MEDIUM, + }, + [] + ); + } } return this.themes; },