From 39ba403d5979ec0233ee4e9e0e20d495ed1a9e02 Mon Sep 17 00:00:00 2001 From: sameerasw Date: Tue, 29 Apr 2025 04:12:46 +0530 Subject: pop-up layout changes and default configs upon fetching --- popup/popup.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'popup/popup.js') diff --git a/popup/popup.js b/popup/popup.js index c86a882..d87debb 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -627,10 +627,46 @@ new (class ExtensionPopup { if (!response.ok) throw new Error("Failed to fetch styles.json"); const styles = await response.json(); await browser.storage.local.set({ styles }); - await browser.storage.local.set({ lastFetchedTime: Date.now() }); + + // Check if we need to initialize default settings + const settingsData = await browser.storage.local.get( + this.BROWSER_STORAGE_KEY + ); + if (!settingsData[this.BROWSER_STORAGE_KEY]) { + // Initialize default settings if none exist + const defaultSettings = { + enableStyling: true, + autoUpdate: true, + forceStyling: false, + whitelistMode: false, + whitelistStyleMode: false, + lastFetchedTime: Date.now(), + }; + + // Save default settings + await browser.storage.local.set({ + [this.BROWSER_STORAGE_KEY]: defaultSettings, + }); + console.info("Initialized default settings during first fetch"); + + // Update our internal global settings + this.globalSettings = defaultSettings; + + // Update UI to reflect these defaults + this.enableStylingSwitch.checked = true; + this.autoUpdateSwitch.checked = false; + this.forceStylingSwitch.checked = false; + this.whitelistModeSwitch.checked = false; + this.whitelistStylingModeSwitch.checked = false; + + // Update labels + this.updateModeLabels(); + } else { + // Just update the lastFetchedTime + await browser.storage.local.set({ lastFetchedTime: Date.now() }); + } this.loadCurrentSiteFeatures(); - // this.loadWebsitesList(); this.updateActiveTabStyling(); this.refetchCSSButton.textContent = "Done!"; -- cgit v1.2.3