mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 04:09:59 +02:00
feature(zenThemesImporter): add compatibility mode with legacy preferences
This commit is contained in:
parent
1dcfec3d5a
commit
c5619a7dc9
1 changed files with 16 additions and 3 deletions
|
@ -125,17 +125,30 @@ var gZenThemeImporter = new (class {
|
||||||
const themePath = PathUtils.join(this.getThemeFolder(theme), 'preferences.json');
|
const themePath = PathUtils.join(this.getThemeFolder(theme), 'preferences.json');
|
||||||
|
|
||||||
if (!(await IOUtils.exists(themePath)) || !theme.preferences) {
|
if (!(await IOUtils.exists(themePath)) || !theme.preferences) {
|
||||||
return [];
|
return { preferences: [], isLegacyMode: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
return IOUtils.readJSON(themePath);
|
let preferences = await IOUtils.readJSON(themePath);
|
||||||
|
|
||||||
|
// skip transformation, we won't be writing old preferences to dom, all of them can only be checkboxes
|
||||||
|
if (typeof preferences === "object" && !Array.isArray(preferences)) {
|
||||||
|
return { preferences: [], areOldPreferences: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { preferences, areOldPreferences: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
async writeToDom() {
|
async writeToDom() {
|
||||||
const browser = this._getBrowser()
|
const browser = this._getBrowser()
|
||||||
|
|
||||||
for (const theme of Object.values(await this.getThemes())) {
|
for (const theme of Object.values(await this.getThemes())) {
|
||||||
const themePreferences = (await this._getThemePreferences(theme)).filter(({ type }) => type === "dropdown")
|
const { preferences, areOldPreferences } = await this._getThemePreferences(theme);
|
||||||
|
|
||||||
|
if (areOldPreferences) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const themePreferences = preferences.filter(({ type }) => type === "dropdown")
|
||||||
|
|
||||||
for (const { property } of themePreferences) {
|
for (const { property } of themePreferences) {
|
||||||
const value = Services.prefs.getStringPref(property, "")
|
const value = Services.prefs.getStringPref(property, "")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue