Skip to content

Commit 686655f

Browse files
committed
feat: pass is paid subscriber to the backend for quota reservation
1 parent 297123d commit 686655f

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/LiveDevelopment/main.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ define(function main(require, exports, module) {
5252

5353
// this will later be assigned its correct values once entitlementsManager loads
5454
let hasLiveEditCapability = false;
55+
let isPaidUser = false;
5556

5657
const PREFERENCE_LIVE_PREVIEW_MODE = CONSTANTS.PREFERENCE_LIVE_PREVIEW_MODE;
5758

@@ -95,7 +96,8 @@ define(function main(require, exports, module) {
9596
mode: LIVE_HIGHLIGHT_MODE, // will be updated when we fetch entitlements
9697
elemHighlights: CONSTANTS.HIGHLIGHT_HOVER, // default value, this will get updated when the extension loads
9798
showRulerLines: false, // default value, this will get updated when the extension loads
98-
imageGalleryState: _getImageGalleryState() // image gallery selected state
99+
imageGalleryState: _getImageGalleryState(), // image gallery selected state
100+
isPaidUser: false // will be updated when we fetch entitlements
99101
};
100102

101103
// Status labels/styles are ordered: error, not connected, progress1, progress2, connected.
@@ -241,6 +243,15 @@ define(function main(require, exports, module) {
241243
}
242244
}
243245

246+
function _isPaidUserChanged(newStatus) {
247+
if(newStatus !== isPaidUser){
248+
isPaidUser = newStatus;
249+
const config = MultiBrowserLiveDev.getConfig();
250+
config.isPaidUser = isPaidUser;
251+
MultiBrowserLiveDev.updateConfig(config);
252+
}
253+
}
254+
244255
function setMode(mode) {
245256
if (mode === LIVE_EDIT_MODE && !hasLiveEditCapability) {
246257
return false;
@@ -260,7 +271,7 @@ define(function main(require, exports, module) {
260271
/** Initialize LiveDevelopment */
261272
AppInit.appReady(function () {
262273
params.parse();
263-
const config = MultiBrowserLiveDev.getConfig() || defaultConfig;
274+
const config = Object.assign({}, defaultConfig, MultiBrowserLiveDev.getConfig());
264275
config.mode = getCurrentMode();
265276
MultiBrowserLiveDev.init(config);
266277

@@ -327,6 +338,7 @@ define(function main(require, exports, module) {
327338

328339
// private api
329340
exports._liveEditCapabilityChanged = _liveEditCapabilityChanged;
341+
exports._isPaidUserChanged = _isPaidUserChanged;
330342

331343
// public events
332344
exports.EVENT_OPEN_PREVIEW_URL = MultiBrowserLiveDev.EVENT_OPEN_PREVIEW_URL;

src/extensionsIntegrated/phoenix-pro/browser-context/image-gallery.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,10 @@ ImageRibbonGallery.prototype = {
366366
this._clearCache();
367367
}
368368

369+
const isPaidUser = config.isPaidUser || false;
370+
369371
const apiUrl = `https://images.phcode.dev/api/images/search?` +
370-
`q=${encodeURIComponent(searchQuery)}&per_page=30&page=${page}&safe=true`;
372+
`q=${encodeURIComponent(searchQuery)}&per_page=30&page=${page}&safe=true&isPaidUser=${isPaidUser}`;
371373

372374
if (!append) {
373375
this._showLoading();

src/extensionsIntegrated/phoenix-pro/pro-utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,36 @@ define(function (require, exports, module) {
1414

1515
// this will later be assigned its correct values once entitlementsManager loads
1616
let _isProEditActivated = false;
17+
let _isPaidUser = false;
1718
// called everytime there is a change in entitlements (app start/every 15 mis, explicit check/ anytime really)
1819
async function _entitlementsChanged() {
1920
try {
2021
const entitlement = await KernalModeTrust.EntitlementsManager.getLiveEditEntitlement();
2122
_isProEditActivated = entitlement.activated;
23+
_isPaidUser = await KernalModeTrust.EntitlementsManager.isPaidSubscriber();
2224
} catch (error) {
2325
console.error("Error updating pro user status:", error);
2426
_isProEditActivated = false;
27+
_isPaidUser = false;
2528
}
2629
LiveDevelopment._liveEditCapabilityChanged(_isProEditActivated);
30+
LiveDevelopment._isPaidUserChanged(_isPaidUser);
2731
}
2832

2933
function isProEditActivated() {
3034
return _isProEditActivated;
3135
}
3236

37+
function isPaidUser() {
38+
return _isPaidUser;
39+
}
40+
3341
AppInit.appReady(function () {
3442
_entitlementsChanged();
3543
KernalModeTrust.EntitlementsManager.on(
3644
KernalModeTrust.EntitlementsManager.EVENT_ENTITLEMENTS_CHANGED, _entitlementsChanged);
3745
});
3846

3947
exports.isProEditActivated = isProEditActivated;
48+
exports.isPaidUser = isPaidUser;
4049
});

0 commit comments

Comments
 (0)