2525 * Provides loginless pro trials
2626 *
2727 * - First install: 30-day trial on first usage
28- * - Subsequent versions: 3 -day trial (or remaining from 30-day if still valid)
28+ * - Subsequent versions: 7 -day trial (or remaining from 30-day if still valid)
2929 * - Older versions: No new trial, but existing 30-day trial remains valid
3030 */
3131
@@ -36,6 +36,7 @@ define(function (require, exports, module) {
3636 semver = require ( "thirdparty/semver.browser" ) ,
3737 ProDialogs = require ( "./pro-dialogs" ) ;
3838
39+ let dateNowFn = Date . now ;
3940 const KernalModeTrust = window . KernalModeTrust ;
4041 if ( ! KernalModeTrust ) {
4142 throw new Error ( "Promotions service requires access to KernalModeTrust. Cannot boot without trust ring" ) ;
@@ -47,7 +48,7 @@ define(function (require, exports, module) {
4748 const EVENT_PRO_UPGRADE_ON_INSTALL = "pro_upgrade_on_install" ;
4849 const TRIAL_POLL_MS = 10 * 1000 ; // 10 seconds after start, we assign a free trial if possible
4950 const FIRST_INSTALL_TRIAL_DAYS = 30 ;
50- const SUBSEQUENT_TRIAL_DAYS = 3 ;
51+ const SUBSEQUENT_TRIAL_DAYS = 7 ;
5152 const MS_PER_DAY = 24 * 60 * 60 * 1000 ;
5253
5354 /**
@@ -151,7 +152,7 @@ define(function (require, exports, module) {
151152 * Calculate remaining trial days from end date
152153 */
153154 function _calculateRemainingTrialDays ( existingTrialData ) {
154- const now = Date . now ( ) ;
155+ const now = dateNowFn ( ) ;
155156 const trialEndDate = existingTrialData . endDate ;
156157
157158 // Calculate days remaining until trial ends
@@ -209,7 +210,7 @@ define(function (require, exports, module) {
209210
210211 let trialDays = FIRST_INSTALL_TRIAL_DAYS ;
211212 let endDate ;
212- const now = Date . now ( ) ;
213+ const now = dateNowFn ( ) ;
213214 let metricString = `${ currentVersion . replaceAll ( "." , "_" ) } ` ; // 3.1.0 -> 3_1_0
214215
215216 if ( existingTrialData ) {
@@ -250,7 +251,7 @@ define(function (require, exports, module) {
250251 endDate = existingTrialData . endDate ;
251252 metricString = `nD_${ metricString } _upgrade` ;
252253 } else {
253- // Newer version with shorter existing trial - give 3 days
254+ // Newer version with shorter existing trial - give 7 days
254255 console . log ( `Newer version - granting ${ SUBSEQUENT_TRIAL_DAYS } days trial` ) ;
255256 trialDays = SUBSEQUENT_TRIAL_DAYS ;
256257 endDate = now + ( trialDays * MS_PER_DAY ) ;
@@ -328,5 +329,44 @@ define(function (require, exports, module) {
328329 LoginService . getProTrialDaysRemaining = getProTrialDaysRemaining ;
329330 LoginService . EVENT_PRO_UPGRADE_ON_INSTALL = EVENT_PRO_UPGRADE_ON_INSTALL ;
330331
332+ // Test-only exports for integration testing
333+ if ( Phoenix . isTestWindow ) {
334+ window . _test_login_exports = {
335+ LoginService : LoginService ,
336+ ProDialogs : ProDialogs ,
337+ _getTrialData : _getTrialData ,
338+ _setTrialData : _setTrialData ,
339+ _cleanTrialData : async function ( ) {
340+ try {
341+ if ( Phoenix . isNativeApp ) {
342+ await KernalModeTrust . removeCredential ( KernalModeTrust . CRED_KEY_ENTITLEMENTS ) ;
343+ } else {
344+ const filePath = Phoenix . app . getApplicationSupportDirectory ( ) + "entitlements_granted.json" ;
345+ return new Promise ( ( resolve ) => {
346+ window . fs . unlink ( filePath , ( ) => {
347+ // Always resolve, ignore errors since file might not exist
348+ resolve ( ) ;
349+ } ) ;
350+ } ) ;
351+ }
352+ } catch ( error ) {
353+ // Ignore cleanup errors
354+ console . log ( "Trial data cleanup completed (ignoring errors)" ) ;
355+ }
356+ } ,
357+ activateProTrial : activateProTrial ,
358+ getProTrialDaysRemaining : getProTrialDaysRemaining ,
359+ setDateNowFn : function _setDdateNowFn ( fn ) {
360+ dateNowFn = fn ;
361+ } ,
362+ EVENT_PRO_UPGRADE_ON_INSTALL : EVENT_PRO_UPGRADE_ON_INSTALL ,
363+ TRIAL_CONSTANTS : {
364+ FIRST_INSTALL_TRIAL_DAYS ,
365+ SUBSEQUENT_TRIAL_DAYS ,
366+ MS_PER_DAY
367+ }
368+ } ;
369+ }
370+
331371 // no public exports to prevent extension tampering
332372} ) ;
0 commit comments