diff --git a/src/ZenThemesImporter.mjs b/src/ZenThemesImporter.mjs index 84d1338..337ae9c 100644 --- a/src/ZenThemesImporter.mjs +++ b/src/ZenThemesImporter.mjs @@ -146,6 +146,12 @@ var gZenThemeImporter = new (class { for (const theme of Object.values(await this.getThemes())) { const { preferences, areOldPreferences } = await this._getThemePreferences(theme); + + if (areOldPreferences) { + continue; + } + + const filteredPreferences = preferences.filter(({ type }) => type !== 'checkbox'); const sanitizedName = `theme-${theme.name?.replaceAll(/\s/g, '-')?.replaceAll(/[^A-z_-]+/g, '')}`; if (!theme.enabled) { @@ -155,31 +161,51 @@ var gZenThemeImporter = new (class { element.remove(); } + for (const { property } of filteredPreferences) { + const sanitizedProperty = property?.replaceAll(/\./g, '-'); + + if (document.querySelector(':root').style.hasProperty(`--${sanitizedProperty}`)) { + document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`); + } + } + continue; } - if (areOldPreferences) { - continue; - } - - const themePreferences = preferences.filter(({ type }) => type === 'dropdown'); - - for (const { property } of themePreferences) { + for (const { property, type } of preferences) { const value = Services.prefs.getStringPref(property, ''); + const sanitizedProperty = property?.replaceAll(/\./g, '-'); - if (value !== '') { - let element = browser.document.getElementById(sanitizedName); + switch (type) { + case 'dropdown': { + if (value !== '') { + let element = browser.document.getElementById(sanitizedName); - if (!element) { - element = browser.document.createElement('div'); + if (!element) { + element = browser.document.createElement('div'); - element.style.display = 'none'; - element.setAttribute('id', sanitizedName); + element.style.display = 'none'; + element.setAttribute('id', sanitizedName); - browser.document.body.appendChild(element); + browser.document.body.appendChild(element); + } + + element.setAttribute(sanitizedProperty, value); + } + break; } - element.setAttribute(property?.replaceAll(/\./g, '-'), value); + case 'string': { + if (value === '') { + document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`); + } else { + document.querySelector(':root').style.setProperty(`--${sanitizedProperty}`, value); + } + break; + } + + default: { + } } } } diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index fca62ab..b30371c 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -495,7 +495,7 @@ var ZenWorkspaces = { for (let workspace of workspaces.workspaces) { workspace.used = workspace.uuid === window.uuid; } - this.unsafeSaveWorkspaces(workspaces); + await this.unsafeSaveWorkspaces(workspaces); console.info('ZenWorkspaces: Changing workspace to', window.uuid); for (let tab of gBrowser.tabs) { if ((tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) || !tab.hasAttribute('zen-workspace-id')) {