@@ -45,7 +45,11 @@ define(function (require, exports, module) {
4545 // save a copy of window.fetch so that extensions wont tamper with it.
4646 let fetchFn = window . fetch ;
4747
48- function showProUpgradeDialog ( trialDays ) {
48+ const UPSELL_TYPE_LIVE_EDIT = "live_edit" ;
49+ const UPSELL_TYPE_PRO_TRIAL_ENDED = "pro_trial_ended" ;
50+ const UPSELL_TYPE_GET_PRO = "get_pro" ;
51+
52+ function showProTrialStartDialog ( trialDays ) {
4953 const title = StringUtils . format ( Strings . PROMO_UPGRADE_TITLE , proTitle ) ;
5054 const message = StringUtils . format ( Strings . PROMO_UPGRADE_MESSAGE , trialDays ) ;
5155 const $template = $ ( Mustache . render ( proUpgradeHTML , {
@@ -65,12 +69,38 @@ define(function (require, exports, module) {
6569 } ) ;
6670 }
6771
68- function _showLocalProEndedDialog ( ) {
69- const title = StringUtils . format ( Strings . PROMO_PRO_ENDED_TITLE , proTitle ) ;
70- const buttonGetPro = StringUtils . format ( Strings . PROMO_GET_APP_UPSELL_BUTTON , proTitlePlain ) ;
72+ function _getUpsellDialogText ( upsellType ) {
73+ // our pro dialog has 2 flavors. Local which is shipped with the release for showing if user is offline
74+ // and remote which is fetched from the server if we have a remote offer to show. This fn will be called
75+ // by both of these flavors and we need to return the appropriate text for each.
76+ const buttonGetProText = StringUtils . format ( Strings . PROMO_GET_APP_UPSELL_BUTTON , proTitlePlain ) ;
77+ switch ( upsellType ) {
78+ case UPSELL_TYPE_PRO_TRIAL_ENDED : return {
79+ title : StringUtils . format ( Strings . PROMO_PRO_ENDED_TITLE , proTitle ) ,
80+ localDialogMessage : Strings . PROMO_ENDED_MESSAGE , // this will be shown in the local dialog
81+ buttonGetProText
82+ } ;
83+ case UPSELL_TYPE_LIVE_EDIT : return {
84+ title : StringUtils . format ( Strings . PROMO_PRO_UNLOCK_LIVE_EDIT_TITLE , proTitle ) ,
85+ localDialogMessage : Strings . PROMO_PRO_UNLOCK_MESSAGE ,
86+ buttonGetProText
87+ } ;
88+ case UPSELL_TYPE_GET_PRO :
89+ default : return {
90+ title : StringUtils . format ( Strings . PROMO_PRO_UNLOCK_PRO_TITLE , proTitle ) ,
91+ localDialogMessage : Strings . PROMO_PRO_UNLOCK_MESSAGE ,
92+ buttonGetProText
93+ } ;
94+ }
95+ }
96+
97+ function _showLocalProEndedDialog ( upsellType ) {
98+ const dlgText = _getUpsellDialogText ( upsellType ) ;
99+ const title = dlgText . title ;
100+ const buttonGetPro = dlgText . buttonGetProText ;
71101 const $template = $ ( Mustache . render ( proUpgradeHTML , {
72102 title, Strings,
73- message : Strings . PROMO_ENDED_MESSAGE ,
103+ message : dlgText . localDialogMessage ,
74104 secondaryButton : Strings . CANCEL ,
75105 primaryButton : buttonGetPro
76106 } ) ) ;
@@ -86,13 +116,14 @@ define(function (require, exports, module) {
86116 } ) ;
87117 }
88118
89- function _showRemoteProEndedDialog ( currentVersion , promoHtmlURL , upsellPurchaseURL ) {
90- const buttonGetPro = StringUtils . format ( Strings . PROMO_GET_APP_UPSELL_BUTTON , proTitlePlain ) ;
91- const title = StringUtils . format ( Strings . PROMO_PRO_ENDED_TITLE , proTitle ) ;
119+ function _showRemoteProEndedDialog ( upsellType , currentVersion , promoHtmlURL , upsellPurchaseURL ) {
120+ const dlgText = _getUpsellDialogText ( upsellType ) ;
121+ const title = dlgText . title ;
122+ const buttonGetPro = dlgText . buttonGetProText ;
92123 const currentTheme = ThemeManager . getCurrentTheme ( ) ;
93124 const theme = currentTheme && currentTheme . dark ? "dark" : "light" ;
94125 const promoURL = `${ promoHtmlURL } ?lang=${
95- brackets . getLocale ( ) } &theme=${ theme } &version=${ currentVersion } `;
126+ brackets . getLocale ( ) } &theme=${ theme } &version=${ currentVersion } &upsellType= ${ upsellType } `;
96127 const $template = $ ( Mustache . render ( proEndedHTML , { Strings, title, buttonGetPro, promoURL} ) ) ;
97128 Dialogs . showModalDialogUsingTemplate ( $template ) . done ( function ( id ) {
98129 console . log ( "Dialog closed with id: " + id ) ;
@@ -106,30 +137,31 @@ define(function (require, exports, module) {
106137 } ) ;
107138 }
108139
109- async function showProEndedDialog ( ) {
140+ async function showProUpsellDialog ( upsellType ) {
110141 const currentVersion = window . AppConfig . apiVersion ;
111142
112143 if ( ! navigator . onLine ) {
113- _showLocalProEndedDialog ( ) ;
144+ _showLocalProEndedDialog ( upsellType ) ;
114145 return ;
115146 }
116147
117148 try {
118149 const configURL = `${ brackets . config . promotions_url } app/config.json` ;
119150 const response = await fetchFn ( configURL ) ;
120151 if ( ! response . ok ) {
121- _showLocalProEndedDialog ( ) ;
152+ _showLocalProEndedDialog ( upsellType ) ;
122153 return ;
123154 }
124155
125156 const config = await response . json ( ) ;
126157 if ( config . upsell_after_trial_url ) {
127- _showRemoteProEndedDialog ( currentVersion , config . upsell_after_trial_url , config . upsell_purchase_url ) ;
158+ _showRemoteProEndedDialog ( upsellType , currentVersion ,
159+ config . upsell_after_trial_url , config . upsell_purchase_url ) ;
128160 } else {
129- _showLocalProEndedDialog ( ) ;
161+ _showLocalProEndedDialog ( upsellType ) ;
130162 }
131163 } catch ( error ) {
132- _showLocalProEndedDialog ( ) ;
164+ _showLocalProEndedDialog ( upsellType ) ;
133165 }
134166 }
135167
@@ -141,6 +173,9 @@ define(function (require, exports, module) {
141173 } ;
142174 }
143175
144- exports . showProUpgradeDialog = showProUpgradeDialog ;
145- exports . showProEndedDialog = showProEndedDialog ;
176+ exports . showProTrialStartDialog = showProTrialStartDialog ;
177+ exports . showProUpsellDialog = showProUpsellDialog ;
178+ exports . UPSELL_TYPE_PRO_TRIAL_ENDED = UPSELL_TYPE_PRO_TRIAL_ENDED ;
179+ exports . UPSELL_TYPE_GET_PRO = UPSELL_TYPE_GET_PRO ;
180+ exports . UPSELL_TYPE_LIVE_EDIT = UPSELL_TYPE_LIVE_EDIT ;
146181} ) ;
0 commit comments