mirror of
https://github.com/zen-browser/desktop.git
synced 2026-08-26 08:21:34 +00:00
Merge pull request #4167 from JosueGalRe/dev
This commit is contained in:
@@ -14,14 +14,18 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
||||
|
||||
initalizeZenAPI(event) {
|
||||
const verifier = this.contentWindow.document.querySelector('meta[name="zen-content-verified"]');
|
||||
|
||||
if (verifier) {
|
||||
verifier.setAttribute('content', 'verified');
|
||||
}
|
||||
|
||||
const possibleRicePage = this.collectRiceMetadata();
|
||||
|
||||
if (possibleRicePage?.id) {
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:RicePage', possibleRicePage);
|
||||
return;
|
||||
}
|
||||
|
||||
this.initiateThemeMarketplace();
|
||||
this.contentWindow.document.addEventListener('ZenCheckForThemeUpdates', this.checkForThemeUpdates.bind(this));
|
||||
}
|
||||
@@ -55,7 +59,7 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
||||
return this.contentWindow.document.getElementById('install-theme');
|
||||
}
|
||||
|
||||
get actionButtonUnnstall() {
|
||||
get actionButtonUninstall() {
|
||||
return this.contentWindow.document.getElementById('install-theme-uninstall');
|
||||
}
|
||||
|
||||
@@ -64,10 +68,12 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
||||
case 'ZenThemeMarketplace:ThemeChanged': {
|
||||
const themeId = message.data.themeId;
|
||||
const actionButton = this.actionButton;
|
||||
const actionButtonInstalled = this.actionButtonUnnstall;
|
||||
const actionButtonInstalled = this.actionButtonUninstall;
|
||||
|
||||
if (actionButton && actionButtonInstalled) {
|
||||
actionButton.disabled = false;
|
||||
actionButtonInstalled.disabled = false;
|
||||
|
||||
if (await this.isThemeInstalled(themeId)) {
|
||||
actionButton.classList.add('hidden');
|
||||
actionButtonInstalled.classList.remove('hidden');
|
||||
@@ -76,18 +82,24 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
||||
actionButtonInstalled.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'ZenThemeMarketplace:CheckForUpdatesFinished': {
|
||||
const updates = message.data.updates;
|
||||
|
||||
this.contentWindow.document.dispatchEvent(
|
||||
new CustomEvent('ZenThemeMarketplace:CheckForUpdatesFinished', { detail: { updates } })
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'ZenThemeMarketplace:GetThemeInfo': {
|
||||
const themeId = message.data.themeId;
|
||||
const theme = await this.getThemeInfo(themeId);
|
||||
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +113,7 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
|
||||
|
||||
async addIntallButtons() {
|
||||
const actionButton = this.actionButton;
|
||||
const actionButtonUnnstall = this.actionButtonUnnstall;
|
||||
const actionButtonUnnstall = this.actionButtonUninstall;
|
||||
const errorMessage = this.contentWindow.document.getElementById('install-theme-error');
|
||||
if (!actionButton || !actionButtonUnnstall) {
|
||||
return;
|
||||
|
||||
@@ -45,7 +45,7 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
||||
window.gZenThemePicker.riceManager.openRicePage(data);
|
||||
}
|
||||
|
||||
compareversion(version1, version2) {
|
||||
compareVersions(version1, version2) {
|
||||
var result = false;
|
||||
if (typeof version1 !== 'object') {
|
||||
version1 = version1.toString().split('.');
|
||||
@@ -73,22 +73,31 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
||||
|
||||
async checkForThemeUpdates() {
|
||||
console.info('ZenThemeMarketplaceParent: Checking for theme updates');
|
||||
|
||||
let updates = [];
|
||||
this._themes = null;
|
||||
|
||||
for (const theme of Object.values(await this.getThemes())) {
|
||||
const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', { themeId: theme.id });
|
||||
|
||||
if (!themeInfo) {
|
||||
continue;
|
||||
}
|
||||
if (!this.compareversion(themeInfo.version, theme.version || '0.0.0') && themeInfo.version != theme.version) {
|
||||
|
||||
if (!this.compareVersions(themeInfo.version, theme.version || '0.0.0') && themeInfo.version != theme.version) {
|
||||
console.info('ZenThemeMarketplaceParent: Theme update found', theme.id, theme.version, themeInfo.version);
|
||||
|
||||
themeInfo.enabled = theme.enabled;
|
||||
updates.push(themeInfo);
|
||||
|
||||
await this.removeTheme(theme.id, false);
|
||||
|
||||
this._themes[themeInfo.id] = themeInfo;
|
||||
}
|
||||
}
|
||||
|
||||
await this.updateThemes(this._themes);
|
||||
|
||||
this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates });
|
||||
}
|
||||
|
||||
@@ -166,27 +175,30 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
|
||||
|
||||
async checkForThemeChanges() {
|
||||
const themes = await this.getThemes();
|
||||
|
||||
const themeIds = Object.keys(themes);
|
||||
let changed = false;
|
||||
|
||||
for (const themeId of themeIds) {
|
||||
const theme = themes[themeId];
|
||||
|
||||
if (!theme) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const themePath = PathUtils.join(this.themesRootPath, themeId);
|
||||
|
||||
if (!(await IOUtils.exists(themePath))) {
|
||||
await this.installTheme(theme);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
this.triggerThemeUpdate();
|
||||
}
|
||||
|
||||
this.triggerThemeUpdate();
|
||||
}
|
||||
|
||||
async removeTheme(themeId, triggerUpdate = true) {
|
||||
const themePath = PathUtils.join(this.themesRootPath, themeId);
|
||||
await IOUtils.remove(themePath, { recursive: true, ignoreAbsent: true });
|
||||
|
||||
if (triggerUpdate) {
|
||||
this.triggerThemeUpdate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user