@@ -3,6 +3,7 @@ define(function (require, exports, module) {
33 PopUpManager = require ( "widgets/PopUpManager" ) ,
44 ThemeManager = require ( "view/ThemeManager" ) ,
55 Strings = require ( "strings" ) ,
6+ StringUtils = require ( "utils/StringUtils" ) ,
67 LoginService = require ( "./login-service" ) ;
78
89 const KernalModeTrust = window . KernalModeTrust ;
@@ -139,7 +140,7 @@ define(function (require, exports, module) {
139140 /**
140141 * Shows the sign-in popup when the user is not logged in
141142 */
142- function showLoginPopup ( ) {
143+ async function showLoginPopup ( ) {
143144 // If popup is already visible, just close it
144145 if ( isPopupVisible ) {
145146 closePopup ( ) ;
@@ -149,8 +150,19 @@ define(function (require, exports, module) {
149150 // create the popup element
150151 closePopup ( ) ; // close any existing popup first
151152
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+
152164 // Render template with data
153- const renderedTemplate = Mustache . render ( loginTemplate , { Strings } ) ;
165+ const renderedTemplate = Mustache . render ( loginTemplate , templateData ) ;
154166 $popup = $ ( renderedTemplate ) ;
155167
156168 $ ( "body" ) . append ( $popup ) ;
@@ -206,12 +218,15 @@ define(function (require, exports, module) {
206218 } ;
207219 }
208220 if ( entitlements && entitlements . plan && entitlements . plan . paidSubscriber ) {
209- // Paid subscriber: show plan name with feather icon
210- const planName = entitlements . plan . name || "Phoenix Pro" ;
221+ // Pro user (paid subscriber or trial): show plan name with feather icon
222+ let displayName = entitlements . plan . name || "Phoenix Pro" ;
223+ if ( entitlements . isInProTrial ) {
224+ displayName = `Phoenix Pro` ; // Just "Phoenix Pro" for branding, not "Phoenix Pro Trial"
225+ }
211226 $brandingLink
212227 . attr ( "href" , "https://account.phcode.dev" )
213228 . addClass ( "phoenix-pro" )
214- . html ( `${ planName } <i class="fa-solid fa-feather orange-gold" style="margin-left: 3px;"></i>` ) ;
229+ . html ( `${ displayName } <i class="fa-solid fa-feather orange-gold" style="margin-left: 3px;"></i>` ) ;
215230 } else {
216231 // Free user: show phcode.io branding
217232 $brandingLink
@@ -333,17 +348,29 @@ define(function (require, exports, module) {
333348 // Update plan information
334349 if ( entitlements . plan ) {
335350 const $planName = $popup . find ( '.user-plan-name' ) ;
336-
351+
337352 // Update plan class and content based on paid subscriber status
338353 $planName . removeClass ( 'user-plan-free user-plan-paid' ) ;
339-
354+
340355 if ( entitlements . plan . paidSubscriber ) {
341- // Use pro styling with feather icon for paid subscribers
342- const proTitle = `<span class="phoenix-pro-title">
343- <span class="pro-plan-name">${ entitlements . plan . name } </span>
344- <i class="fa-solid fa-feather orange-gold" style="margin-left: 3px;"></i>
345- </span>` ;
346- $planName . addClass ( 'user-plan-paid' ) . html ( proTitle ) ;
356+ // Use pro styling with feather icon for pro users (paid or trial)
357+ if ( entitlements . isInProTrial ) {
358+ // For trial users: separate "Phoenix Pro" with icon from "(X days left)" text
359+ const planName = StringUtils . format ( Strings . PROMO_PRO_TRIAL_DAYS_LEFT ,
360+ entitlements . trialDaysRemaining ) ;
361+ const proTitle = `<span class="phoenix-pro-title-plain">
362+ <span class="pro-plan-name">${ planName } </span>
363+ <i class="fa-solid fa-feather" style="margin-left: 3px;"></i>
364+ </span>` ;
365+ $planName . addClass ( 'user-plan-paid' ) . html ( proTitle ) ;
366+ } else {
367+ // For paid users: regular plan name with icon
368+ const proTitle = `<span class="phoenix-pro-title-plain">
369+ <span class="pro-plan-name">${ entitlements . plan . name } </span>
370+ <i class="fa-solid fa-feather" style="margin-left: 3px;"></i>
371+ </span>` ;
372+ $planName . addClass ( 'user-plan-paid' ) . html ( proTitle ) ;
373+ }
347374 } else {
348375 // Use simple text for free users
349376 $planName . addClass ( 'user-plan-free' ) . text ( entitlements . plan . name ) ;
@@ -412,8 +439,8 @@ define(function (require, exports, module) {
412439
413440 positionPopup ( ) ;
414441
415- // Apply cached entitlements immediately if available (including quota/messages)
416- KernalModeTrust . loginService . getEntitlements ( false ) . then ( cachedEntitlements => {
442+ // Apply cached effective entitlements immediately if available (including quota/messages)
443+ KernalModeTrust . loginService . getEffectiveEntitlements ( false ) . then ( cachedEntitlements => {
417444 if ( cachedEntitlements && isPopupVisible ) {
418445 _updatePopupWithEntitlements ( cachedEntitlements ) ;
419446 }
@@ -462,8 +489,7 @@ define(function (require, exports, module) {
462489 */
463490 async function _refreshEntitlementsInBackground ( ) {
464491 try {
465- // Fetch fresh entitlements from API
466- const freshEntitlements = await KernalModeTrust . loginService . getEntitlements ( true ) ; // Force refresh to get latest data
492+ const freshEntitlements = await KernalModeTrust . loginService . getEffectiveEntitlements ( true ) ;
467493
468494 // Only update popup if it's still visible
469495 if ( isPopupVisible && $popup && freshEntitlements ) {
@@ -524,6 +550,23 @@ define(function (require, exports, module) {
524550 } ) ;
525551 }
526552
553+ /**
554+ * Initialize branding for non-logged-in trial users on startup
555+ */
556+ 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 ) ;
566+ }
567+ }
568+ }
569+
527570 function init ( ) {
528571 const helpButtonID = "user-profile-button" ;
529572 $icon = $ ( "<a>" )
@@ -537,6 +580,9 @@ define(function (require, exports, module) {
537580 $icon . on ( 'click' , ( ) => {
538581 togglePopup ( ) ;
539582 } ) ;
583+
584+ // Initialize branding for non-logged-in trial users
585+ _initializeBrandingForTrialUsers ( ) ;
540586 }
541587
542588 function setNotLoggedIn ( ) {
@@ -560,11 +606,11 @@ define(function (require, exports, module) {
560606 }
561607 _updateProfileIcon ( initial , color ) ;
562608
563- // Preload entitlements when user logs in
564- KernalModeTrust . loginService . getEntitlements ( )
609+ // Preload effective entitlements when user logs in
610+ KernalModeTrust . loginService . getEffectiveEntitlements ( )
565611 . then ( _updateBranding )
566612 . catch ( error => {
567- console . error ( 'Failed to preload entitlements on login:' , error ) ;
613+ console . error ( 'Failed to preload effective entitlements on login:' , error ) ;
568614 } ) ;
569615 }
570616
0 commit comments