Skip to content

Commit 9b9d6c8

Browse files
committed
fix: pro trial upgrade working for most cases
1 parent 87311a0 commit 9b9d6c8

File tree

5 files changed

+76
-30
lines changed

5 files changed

+76
-30
lines changed

src/nls/root/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,6 @@ define({
16781678
"PROMO_CARD_4_MESSAGE": "Edit headings, buttons, and copy directly in the preview.",
16791679
"PROMO_LEARN_MORE": "Learn More\u2026",
16801680
"PROMO_GET_APP_UPSELL_BUTTON": "Get {0}",
1681-
"PROMO_PRO_ENDED_TITLE": "Your {0} upgrade has ended",
1681+
"PROMO_PRO_ENDED_TITLE": "Your {0} Trial has ended",
16821682
"PROMO_PRO_TRIAL_DAYS_LEFT": "Phoenix Pro Trial ({0} days left)"
16831683
});

src/services/login-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ define(function (require, exports, module) {
393393

394394
// Only set exports for browser apps to avoid conflict with desktop login
395395
if (!Phoenix.isNativeApp) {
396-
init();
397396
// kernal exports
398397
// Add to existing KernalModeTrust.loginService from login-service.js
399398
LoginService.isLoggedIn = isLoggedIn;
@@ -402,6 +401,7 @@ define(function (require, exports, module) {
402401
LoginService.getProfile = getProfile;
403402
LoginService.verifyLoginStatus = () => _verifyBrowserLogin(false);
404403
LoginService.getAccountBaseURL = _getAccountBaseURL;
404+
init();
405405
}
406406

407407
// public exports

src/services/login-desktop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ define(function (require, exports, module) {
407407

408408
// Only set exports for native apps to avoid conflict with browser login
409409
if (Phoenix.isNativeApp) {
410-
init();
411410
// kernal exports - add to existing KernalModeTrust.loginService from login-service.js
412411
LoginService.isLoggedIn = isLoggedIn;
413412
LoginService.signInToAccount = signInToAccount;
414413
LoginService.signOutAccount = signOutAccount;
415414
LoginService.getProfile = getProfile;
416415
LoginService.verifyLoginStatus = () => _verifyLogin(false);
417416
LoginService.getAccountBaseURL = getAccountBaseURL;
417+
init();
418418
}
419419

420420
// public exports

src/services/profile-menu.js

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ define(function (require, exports, module) {
140140
/**
141141
* Shows the sign-in popup when the user is not logged in
142142
*/
143-
async function showLoginPopup() {
143+
function showLoginPopup() {
144144
// If popup is already visible, just close it
145145
if (isPopupVisible) {
146146
closePopup();
@@ -150,26 +150,34 @@ define(function (require, exports, module) {
150150
// create the popup element
151151
closePopup(); // close any existing popup first
152152

153-
// Check if non-logged-in user has trial entitlements
154-
const effectiveEntitlements = await KernalModeTrust.loginService.getEffectiveEntitlements();
155-
let templateData = {Strings};
156-
157-
if (effectiveEntitlements && effectiveEntitlements.isInProTrial) {
158-
// Add trial information to template data
159-
const planName = StringUtils.format(Strings.PROMO_PRO_TRIAL_DAYS_LEFT,
160-
effectiveEntitlements.trialDaysRemaining);
161-
templateData.trialInfo = {planName};
162-
}
163-
164-
// Render template with data
165-
const renderedTemplate = Mustache.render(loginTemplate, templateData);
153+
// Render template with basic data first for instant response
154+
const renderedTemplate = Mustache.render(loginTemplate, {Strings});
166155
$popup = $(renderedTemplate);
167156

168157
$("body").append($popup);
169158
isPopupVisible = true;
170159

171160
positionPopup();
172161

162+
// Check for trial info asynchronously and update popup
163+
KernalModeTrust.loginService.getEffectiveEntitlements().then(effectiveEntitlements => {
164+
if (effectiveEntitlements && effectiveEntitlements.isInProTrial && isPopupVisible && $popup) {
165+
// Add trial info to the existing popup
166+
const planName = StringUtils.format(Strings.PROMO_PRO_TRIAL_DAYS_LEFT,
167+
effectiveEntitlements.trialDaysRemaining);
168+
const trialInfoHtml = `<div class="trial-plan-info">
169+
<span class="phoenix-pro-title-plain">
170+
<span class="pro-plan-name">${planName}</span>
171+
<i class="fa-solid fa-feather" style="margin-left: 3px;"></i>
172+
</span>
173+
</div>`;
174+
$popup.find('.popup-title').after(trialInfoHtml);
175+
positionPopup(); // Reposition after adding content
176+
}
177+
}).catch(error => {
178+
console.error('Failed to check trial info for login popup:', error);
179+
});
180+
173181
PopUpManager.addPopUp($popup, function() {
174182
$popup.remove();
175183
$popup = null;
@@ -365,7 +373,7 @@ define(function (require, exports, module) {
365373
$planName.addClass('user-plan-paid').html(proTitle);
366374
} else {
367375
// For paid users: regular plan name with icon
368-
const proTitle = `<span class="phoenix-pro-title-plain">
376+
const proTitle = `<span class="phoenix-pro-title">
369377
<span class="pro-plan-name">${entitlements.plan.name}</span>
370378
<i class="fa-solid fa-feather" style="margin-left: 3px;"></i>
371379
</span>`;
@@ -550,20 +558,33 @@ define(function (require, exports, module) {
550558
});
551559
}
552560

561+
/**
562+
* Check if user has an active trial (works for both logged-in and non-logged-in users)
563+
*/
564+
async function _hasActiveTrial() {
565+
try {
566+
const effectiveEntitlements = await KernalModeTrust.loginService.getEffectiveEntitlements();
567+
return effectiveEntitlements && effectiveEntitlements.isInProTrial;
568+
} catch (error) {
569+
console.error('Failed to check trial status:', error);
570+
return false;
571+
}
572+
}
573+
553574
/**
554575
* Initialize branding for non-logged-in trial users on startup
555576
*/
556577
async function _initializeBrandingForTrialUsers() {
557-
// Only check if user is not logged in
558-
if (!KernalModeTrust.loginService.isLoggedIn()) {
559-
try {
560-
const effectiveEntitlements = await KernalModeTrust.loginService.getEffectiveEntitlements();
561-
if (effectiveEntitlements && effectiveEntitlements.isInProTrial) {
562-
_updateBranding(effectiveEntitlements);
563-
}
564-
} catch (error) {
565-
console.error('Failed to initialize branding for trial users:', error);
578+
try {
579+
const effectiveEntitlements = await KernalModeTrust.loginService.getEffectiveEntitlements();
580+
if (effectiveEntitlements && effectiveEntitlements.isInProTrial) {
581+
console.log('Profile Menu: Found active trial, updating branding...');
582+
_updateBranding(effectiveEntitlements);
583+
} else {
584+
console.log('Profile Menu: No active trial found');
566585
}
586+
} catch (error) {
587+
console.error('Failed to initialize branding for trial users:', error);
567588
}
568589
}
569590

@@ -583,6 +604,14 @@ define(function (require, exports, module) {
583604

584605
// Initialize branding for non-logged-in trial users
585606
_initializeBrandingForTrialUsers();
607+
608+
// Listen for entitlements changes to update branding for non-logged-in trial users
609+
KernalModeTrust.loginService.on(KernalModeTrust.loginService.EVENT_ENTITLEMENTS_CHANGED, () => {
610+
// When entitlements change (including trial activation) for non-logged-in users, update branding
611+
if (!KernalModeTrust.loginService.isLoggedIn()) {
612+
_initializeBrandingForTrialUsers();
613+
}
614+
});
586615
}
587616

588617
function setNotLoggedIn() {
@@ -592,11 +621,24 @@ define(function (require, exports, module) {
592621
}
593622
_removeProfileIcon();
594623

624+
// Reset branding, but preserve trial branding if user has active trial
625+
_hasActiveTrial().then(hasActiveTrial => {
626+
if (!hasActiveTrial) {
627+
// Only reset branding if no trial exists
628+
console.log('Profile Menu: No trial, resetting branding to free');
629+
_updateBranding(null);
630+
} else {
631+
// User has trial, maintain pro branding
632+
console.log('Profile Menu: Trial exists, maintaining pro branding');
633+
_initializeBrandingForTrialUsers();
634+
}
635+
}).catch(error => {
636+
console.error('Failed to check trial status during logout:', error);
637+
// Fallback to resetting branding
638+
_updateBranding(null);
639+
});
595640
// Clear cached entitlements when user logs out
596641
KernalModeTrust.loginService.clearEntitlements();
597-
598-
// Reset branding to free mode
599-
_updateBranding(null);
600642
}
601643

602644
function setLoggedIn(initial, color) {

src/services/promotions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ define(function (require, exports, module) {
289289
trialDays: trialDays,
290290
isFirstInstall: !existingTrialData
291291
});
292+
293+
// Also trigger entitlements changed event since effective entitlements have changed
294+
// This allows UI components to update based on the new trial status
295+
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED, null);
292296
}
293297

294298
function _isAnyDialogsVisible() {

0 commit comments

Comments
 (0)