@@ -44,33 +44,81 @@ define(function (require, exports, module) {
4444 function showProUpgradeDialog ( trialDays ) {
4545 const title = StringUtils . format ( Strings . PROMO_UPGRADE_TITLE , proTitle ) ;
4646 const message = StringUtils . format ( Strings . PROMO_UPGRADE_MESSAGE , trialDays ) ;
47- const $template = $ ( Mustache . render ( proUpgradeHTML , { title, message, Strings} ) ) ;
47+ const $template = $ ( Mustache . render ( proUpgradeHTML , {
48+ title, message, Strings,
49+ secondaryButton : Strings . PROMO_LEARN_MORE ,
50+ primaryButton : Strings . OK
51+ } ) ) ;
4852 Dialogs . showModalDialogUsingTemplate ( $template ) . done ( function ( id ) {
4953 console . log ( "Dialog closed with id: " + id ) ;
50- if ( id === 'learn_more ' ) {
54+ if ( id === 'secondaryButton ' ) {
5155 // todo add metrics
5256 Phoenix . app . openURLInDefaultBrowser ( brackets . config . purchase_url ) ;
5357 }
5458 } ) ;
5559 }
5660
57- function showProEndedDialog ( currentVersion ) {
58- currentVersion = currentVersion || window . AppConfig . apiVersion ;
61+ function _showLocalProEndedDialog ( ) {
62+ const title = StringUtils . format ( Strings . PROMO_PRO_ENDED_TITLE , proTitle ) ;
63+ const buttonGetPro = StringUtils . format ( Strings . PROMO_GET_APP_UPSELL_BUTTON , proTitlePlain ) ;
64+ const $template = $ ( Mustache . render ( proUpgradeHTML , {
65+ title, Strings,
66+ message : Strings . PROMO_ENDED_MESSAGE ,
67+ secondaryButton : Strings . CANCEL ,
68+ primaryButton : buttonGetPro
69+ } ) ) ;
70+ Dialogs . showModalDialogUsingTemplate ( $template ) . done ( function ( id ) {
71+ console . log ( "Dialog closed with id: " + id ) ;
72+ if ( id === 'ok' ) {
73+ // todo add metrics
74+ Phoenix . app . openURLInDefaultBrowser ( brackets . config . purchase_url ) ;
75+ }
76+ } ) ;
77+ }
78+
79+ function _showRemoteProEndedDialog ( currentVersion , promoHtmlURL , upsellPurchaseURL ) {
5980 const buttonGetPro = StringUtils . format ( Strings . PROMO_GET_APP_UPSELL_BUTTON , proTitlePlain ) ;
6081 const title = StringUtils . format ( Strings . PROMO_PRO_ENDED_TITLE , proTitle ) ;
6182 const currentTheme = ThemeManager . getCurrentTheme ( ) ;
6283 const theme = currentTheme && currentTheme . dark ? "dark" : "light" ;
63- const promoURL = `${ brackets . config . promotions_url } app/upsell_after_trial.html?lang=${ brackets . getLocale ( ) } &theme=${ theme } &version=${ currentVersion } ` ;
84+ const promoURL = `${ promoHtmlURL } ?lang=${
85+ brackets . getLocale ( ) } &theme=${ theme } &version=${ currentVersion } `;
6486 const $template = $ ( Mustache . render ( proEndedHTML , { Strings, title, buttonGetPro, promoURL} ) ) ;
6587 Dialogs . showModalDialogUsingTemplate ( $template ) . done ( function ( id ) {
6688 console . log ( "Dialog closed with id: " + id ) ;
6789 if ( id === 'get_pro' ) {
68- // todo add metrics
69- Phoenix . app . openURLInDefaultBrowser ( brackets . config . purchase_url ) ;
90+ Phoenix . app . openURLInDefaultBrowser ( upsellPurchaseURL || brackets . config . purchase_url ) ;
7091 }
7192 } ) ;
7293 }
7394
95+ async function showProEndedDialog ( ) {
96+ const currentVersion = window . AppConfig . apiVersion ;
97+
98+ if ( ! navigator . onLine ) {
99+ _showLocalProEndedDialog ( ) ;
100+ return ;
101+ }
102+
103+ try {
104+ const configURL = `${ brackets . config . promotions_url } app/config.json` ;
105+ const response = await fetch ( configURL ) ;
106+ if ( ! response . ok ) {
107+ _showLocalProEndedDialog ( ) ;
108+ return ;
109+ }
110+
111+ const config = await response . json ( ) ;
112+ if ( config . upsell_after_trial_url ) {
113+ _showRemoteProEndedDialog ( currentVersion , config . upsell_after_trial_url , config . upsell_purchase_url ) ;
114+ } else {
115+ _showLocalProEndedDialog ( ) ;
116+ }
117+ } catch ( error ) {
118+ _showLocalProEndedDialog ( ) ;
119+ }
120+ }
121+
74122 exports . showProUpgradeDialog = showProUpgradeDialog ;
75123 exports . showProEndedDialog = showProEndedDialog ;
76124} ) ;
0 commit comments