Skip to content

Commit

Permalink
Refactor Zen API integration and update match URL patterns for theme …
Browse files Browse the repository at this point in the history
…marketplace
  • Loading branch information
mauro-balades committed Dec 29, 2024
1 parent 819c818 commit 87976fc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/browser/app/profile/zen-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/browser/base/zen-components/ZenRices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/browser/base/zen-components/ZenThemesImporter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
this.checkForThemeUpdates();
break;
}
case 'ZenThemeMarketplace:RizePage': {
// TODO: Implement
break;
}
}
}

Expand Down

0 comments on commit 87976fc

Please sign in to comment.