Refactor Zen API integration and update match URL patterns for theme marketplace

This commit is contained in:
mr. M
2024-12-30 00:13:10 +01:00
parent 819c818976
commit 87976fc845
5 changed files with 35 additions and 6 deletions

View File

@@ -94,8 +94,8 @@ pref('zen.view.show-newtab-button-top', false);
pref('zen.rice.api.url', 'https://share.zen-browser.app', locked);
pref('zen.injections.match-urls', 'https://zen-browser.app/*,https://share.zen-browser.app/*', locked);
#else
pref('zen.rice.api.url', "http://localhost:3000", locked);
pref('zen.injections.match-urls', 'http://localhost:3000/*', locked);
pref('zen.rice.api.url', "http://localhost", locked);
pref('zen.injections.match-urls', 'http://localhost/*', locked);
#endif
pref('zen.rice.share.notice.accepted', false);

View File

@@ -381,7 +381,7 @@
document.getElementById("zen-rice-share-second-form").setAttribute("fade-out", "true");
successBox.removeAttribute("hidden");
const link = document.getElementById("zen-rice-share-success-link");
link.value = `${ZEN_RICE_API}/${slug}`;
link.value = `${ZEN_RICE_API}/rices/${slug}`;
this.showConffetti();
}, 2000);
}

View File

@@ -313,5 +313,5 @@ gZenActorsManager.addJSWindowActor("ZenThemeMarketplace", {
DOMContentLoaded: {},
},
},
matches: [Services.prefs.getStringPref("zen.injections.match-urls").split(","), "about:preferences"],
matches: [...Services.prefs.getStringPref("zen.injections.match-urls").split(","), "about:preferences"],
});

View File

@@ -6,13 +6,38 @@ export class ZenThemeMarketplaceChild extends JSWindowActorChild {
handleEvent(event) {
switch (event.type) {
case 'DOMContentLoaded':
this.initiateThemeMarketplace();
this.contentWindow.document.addEventListener('ZenCheckForThemeUpdates', this.checkForThemeUpdates.bind(this));
this.initalizeZenAPI(event);
break;
default:
}
}
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) {
this.sendAsyncMessage('ZenThemeMarketplace:RizePage', { data: possibleRicePage });
return;
}
this.initiateThemeMarketplace();
this.contentWindow.document.addEventListener('ZenCheckForThemeUpdates', this.checkForThemeUpdates.bind(this));
}
collectRiceMetadata() {
const meta = this.contentWindow.document.querySelector('meta[name="rize-metadata"]');
if (meta) {
return {
id: meta.getAttribute('data-id'),
name: meta.getAttribute('data-title'),
author: meta.getAttribute('data-author'),
}
}
return null;
}
// This function will be caleld from about:preferences
checkForThemeUpdates(event) {
event.preventDefault();

View File

@@ -34,6 +34,10 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
this.checkForThemeUpdates();
break;
}
case 'ZenThemeMarketplace:RizePage': {
// TODO: Implement
break;
}
}
}