Skip to content

Commit 7d6546f

Browse files
committed
chore: null checks/fensing
1 parent de8e1ec commit 7d6546f

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,17 @@ define(function (require, exports, module) {
162162
let connectingOverlayTimer = null; // this is needed as we show the connecting overlay after 3s
163163
let connectingOverlayTimeDuration = 3000;
164164

165+
function _getLiveEditEntitlement() {
166+
// in community edition, this may not be present;
167+
return KernalModeTrust.EntitlementsManager && KernalModeTrust.EntitlementsManager.getLiveEditEntitlement();
168+
}
169+
165170
let isProEditUser = false;
166171
// this is called everytime there is a change in entitlements
167172
async function _entitlementsChanged() {
168173
try {
169-
const entitlement = await KernalModeTrust.EntitlementsManager.getLiveEditEntitlement();
170-
isProEditUser = entitlement.activated;
174+
const entitlement = await _getLiveEditEntitlement();
175+
isProEditUser = entitlement && entitlement.activated;
171176
} catch (error) {
172177
console.error("Error updating pro user status:", error);
173178
isProEditUser = false;
@@ -1317,7 +1322,8 @@ define(function (require, exports, module) {
13171322
_projectOpened();
13181323
if(!Phoenix.isSpecRunnerWindow){
13191324
_entitlementsChanged();
1320-
KernalModeTrust.EntitlementsManager.on(
1325+
// in community edition EntitlementsManager may be null
1326+
KernalModeTrust.EntitlementsManager && KernalModeTrust.EntitlementsManager.on(
13211327
KernalModeTrust.EntitlementsManager.EVENT_ENTITLEMENTS_CHANGED,
13221328
_entitlementsChanged
13231329
);

src/extensionsIntegrated/Phoenix/guided-tour.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,23 @@ define(function (require, exports, module) {
235235
PhStore.setItem(GUIDED_TOUR_LOCAL_STORAGE_KEY, JSON.stringify(userAlreadyDidAction));
236236
}
237237

238+
function _isLoggedIn() {
239+
// in community edition entitlements for pro is null
240+
return KernalModeTrust.EntitlementsManager && KernalModeTrust.EntitlementsManager.isLoggedIn();
241+
}
242+
243+
function _isPaidSubscriber() {
244+
// in community edition entitlements for pro is null
245+
return KernalModeTrust.EntitlementsManager && KernalModeTrust.EntitlementsManager.isPaidSubscriber();
246+
}
247+
238248
async function _resolvePowerUserSurveyURL(surveyJson) {
239249
try {
240-
const isLoggedIn = KernalModeTrust.EntitlementsManager.isLoggedIn();
250+
const isLoggedIn = _isLoggedIn();
241251
if(!isLoggedIn) {
242252
return surveyJson.powerUser;
243253
}
244-
const paidSubscriber = await KernalModeTrust.EntitlementsManager.isPaidSubscriber();
254+
const paidSubscriber = await _isPaidSubscriber();
245255
if(paidSubscriber && surveyJson.powerUserPaid) {
246256
return surveyJson.powerUserPaid;
247257
}

src/utils/Metrics.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ define(function (require, exports, module) {
268268

269269
async function _setPowerUserPrefix() {
270270
powerUserPrefix = null;
271-
const EntitlementsManager = KernalModeTrust.EntitlementsManager;
271+
const EntitlementsManager = KernalModeTrust.EntitlementsManager; // can be null in free builds
272272
if(cachedIsPowerUser){
273273
// A power user is someone who used Phoenix at least 3 days/8 hours in the last two weeks
274274
powerUserPrefix = "P";
275275
} else if(!isFirstUseDay){
276276
// A repeat user is a user who has used phoenix at least one other day before
277277
powerUserPrefix = "R";
278278
}
279-
if(EntitlementsManager.isLoggedIn()){
279+
if(EntitlementsManager && EntitlementsManager.isLoggedIn()){
280280
if(await EntitlementsManager.isPaidSubscriber()){
281281
powerUserPrefix = "S"; // subscriber
282282
return;
@@ -306,8 +306,8 @@ define(function (require, exports, module) {
306306
_setPowerUserPrefix();
307307
}, ONE_DAY);
308308
}
309-
KernalModeTrust.EntitlementsManager.on(KernalModeTrust.EntitlementsManager.EVENT_ENTITLEMENTS_CHANGED,
310-
_setPowerUserPrefix);
309+
KernalModeTrust.EntitlementsManager && KernalModeTrust.EntitlementsManager.on(
310+
KernalModeTrust.EntitlementsManager.EVENT_ENTITLEMENTS_CHANGED, _setPowerUserPrefix);
311311
}
312312

313313
// some events generate too many ga events that ga can't handle. ignore them.

0 commit comments

Comments
 (0)