mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 17:19:58 +02:00
Merge pull request #21 from JosueGalRe/main
fix(zenThemes): themes not being updated in other windows
This commit is contained in:
commit
7858a6f93e
2 changed files with 23 additions and 20 deletions
|
@ -12,6 +12,14 @@ var ZenThemesCommon = {
|
||||||
return this.kZenOSToSmallName[os];
|
return this.kZenOSToSmallName[os];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get browsers() {
|
||||||
|
return Services.wm.getEnumerator('navigator:browser');
|
||||||
|
},
|
||||||
|
|
||||||
|
get currentBrowser() {
|
||||||
|
return Services.wm.getMostRecentWindow('navigator:browser');
|
||||||
|
},
|
||||||
|
|
||||||
get themesRootPath() {
|
get themesRootPath() {
|
||||||
return PathUtils.join(PathUtils.profileDir, 'chrome', 'zen-themes');
|
return PathUtils.join(PathUtils.profileDir, 'chrome', 'zen-themes');
|
||||||
},
|
},
|
||||||
|
@ -24,22 +32,15 @@ var ZenThemesCommon = {
|
||||||
return PathUtils.join(this.themesRootPath, themeId);
|
return PathUtils.join(this.themesRootPath, themeId);
|
||||||
},
|
},
|
||||||
|
|
||||||
getBrowser() {
|
|
||||||
if (!this.__browser) {
|
|
||||||
this.__browser = Services.wm.getMostRecentWindow('navigator:browser');
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.__browser;
|
|
||||||
},
|
|
||||||
|
|
||||||
async getThemes() {
|
async getThemes() {
|
||||||
if (!this._themes) {
|
if (!this.themes) {
|
||||||
if (!(await IOUtils.exists(this.themesDataFile))) {
|
if (!(await IOUtils.exists(this.themesDataFile))) {
|
||||||
await IOUtils.writeJSON(this.themesDataFile, {});
|
await IOUtils.writeJSON(this.themesDataFile, {});
|
||||||
}
|
}
|
||||||
this._themes = await IOUtils.readJSON(this.themesDataFile);
|
|
||||||
|
this.themes = await IOUtils.readJSON(this.themesDataFile);
|
||||||
}
|
}
|
||||||
return this._themes;
|
return this.themes;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getThemePreferences(theme) {
|
async getThemePreferences(theme) {
|
||||||
|
|
|
@ -12,14 +12,18 @@ const kenStylesheetFooter = `
|
||||||
var gZenStylesheetManager = {
|
var gZenStylesheetManager = {
|
||||||
async writeStylesheet(path, themes) {
|
async writeStylesheet(path, themes) {
|
||||||
let content = kZenStylesheetThemeHeader;
|
let content = kZenStylesheetThemeHeader;
|
||||||
|
|
||||||
for (let theme of themes) {
|
for (let theme of themes) {
|
||||||
if (theme.enabled !== undefined && !theme.enabled) {
|
if (theme.enabled !== undefined && !theme.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
content += this.getThemeCSS(theme);
|
content += this.getThemeCSS(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
content += kenStylesheetFooter;
|
content += kenStylesheetFooter;
|
||||||
let buffer = new TextEncoder().encode(content);
|
|
||||||
|
const buffer = new TextEncoder().encode(content);
|
||||||
|
|
||||||
await IOUtils.write(path, buffer);
|
await IOUtils.write(path, buffer);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ var gZenThemeImporter = new (class {
|
||||||
}
|
}
|
||||||
|
|
||||||
async rebuildThemeStylesheet() {
|
async rebuildThemeStylesheet() {
|
||||||
this._themes = null;
|
ZenThemesCommon.themes = null;
|
||||||
await this.updateStylesheet();
|
await this.updateStylesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +172,7 @@ var gZenThemeImporter = new (class {
|
||||||
}
|
}
|
||||||
|
|
||||||
writeToDom(themesWithPreferences) {
|
writeToDom(themesWithPreferences) {
|
||||||
const browser = ZenThemesCommon.getBrowser();
|
const browser = ZenThemesCommon.currentBrowser;
|
||||||
|
|
||||||
for (const { enabled, preferences, name } of themesWithPreferences) {
|
for (const { enabled, preferences, name } of themesWithPreferences) {
|
||||||
const sanitizedName = `theme-${name?.replaceAll(/\s/g, '-')?.replaceAll(/[^A-z_-]+/g, '')}`;
|
const sanitizedName = `theme-${name?.replaceAll(/\s/g, '-')?.replaceAll(/[^A-z_-]+/g, '')}`;
|
||||||
|
@ -183,9 +187,7 @@ var gZenThemeImporter = new (class {
|
||||||
for (const { property } of preferences.filter(({ type }) => type !== 'checkbox')) {
|
for (const { property } of preferences.filter(({ type }) => type !== 'checkbox')) {
|
||||||
const sanitizedProperty = property?.replaceAll(/\./g, '-');
|
const sanitizedProperty = property?.replaceAll(/\./g, '-');
|
||||||
|
|
||||||
if (document.querySelector(':root').style.hasProperty(`--${sanitizedProperty}`)) {
|
browser.document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`);
|
||||||
document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -216,9 +218,9 @@ var gZenThemeImporter = new (class {
|
||||||
|
|
||||||
case 'string': {
|
case 'string': {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`);
|
browser.document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`);
|
||||||
} else {
|
} else {
|
||||||
document.querySelector(':root').style.setProperty(`--${sanitizedProperty}`, value);
|
browser.document.querySelector(':root').style.setProperty(`--${sanitizedProperty}`, value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +234,7 @@ var gZenThemeImporter = new (class {
|
||||||
|
|
||||||
async writeStylesheet(themeList) {
|
async writeStylesheet(themeList) {
|
||||||
const themes = [];
|
const themes = [];
|
||||||
this._themes = null;
|
ZenThemesCommon.themes = null;
|
||||||
|
|
||||||
for (let theme of themeList) {
|
for (let theme of themeList) {
|
||||||
theme._chromeURL = this.getStylesheetURIForTheme(theme).spec;
|
theme._chromeURL = this.getStylesheetURIForTheme(theme).spec;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue