-
-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathpro-dialogs.js
More file actions
146 lines (133 loc) · 6.28 KB
/
pro-dialogs.js
File metadata and controls
146 lines (133 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*global logger*/
/**
* Phoenix pro pre and post promo dialogs
* shows dialog where we give Phoenix pro to all users on app install
* and dialogs on pro trial ends.
*
*/
define(function (require, exports, module) {
const proTitle = `<span class="phoenix-pro-title">
<span class="pro-plan-name">${brackets.config.main_pro_plan}</span>
<i class="fa-solid fa-feather orange-gold" style="margin-left: 3px;"></i>
</span>`,
proTitlePlain = `<span class="pro-plan-name">${brackets.config.main_pro_plan}</span>
<i class="fa-solid fa-feather" style="margin-left: 2px;"></i>`;
require("./setup-login-service"); // this adds loginService to KernalModeTrust
const Dialogs = require("widgets/Dialogs"),
Mustache = require("thirdparty/mustache/mustache"),
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
ThemeManager = require("view/ThemeManager"),
Metrics = require("utils/Metrics"),
proUpgradeHTML = require("text!./html/pro-upgrade.html"),
proEndedHTML = require("text!./html/promo-ended.html");
// save a copy of window.fetch so that extensions wont tamper with it.
let fetchFn = window.fetch;
function showProUpgradeDialog(trialDays) {
const title = StringUtils.format(Strings.PROMO_UPGRADE_TITLE, proTitle);
const message = StringUtils.format(Strings.PROMO_UPGRADE_MESSAGE, trialDays);
const $template = $(Mustache.render(proUpgradeHTML, {
title, message, Strings,
secondaryButton: Strings.PROMO_LEARN_MORE,
primaryButton: Strings.OK
}));
Dialogs.showModalDialogUsingTemplate($template).done(function (id) {
console.log("Dialog closed with id: " + id);
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgShow", "promo");
if(id === 'secondaryButton') {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgAct", "promoLearn");
Phoenix.app.openURLInDefaultBrowser(brackets.config.purchase_url);
} else {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgAct", "promoCancel");
}
});
}
function _showLocalProEndedDialog() {
const title = StringUtils.format(Strings.PROMO_PRO_ENDED_TITLE, proTitle);
const buttonGetPro = StringUtils.format(Strings.PROMO_GET_APP_UPSELL_BUTTON, proTitlePlain);
const $template = $(Mustache.render(proUpgradeHTML, {
title, Strings,
message: Strings.PROMO_ENDED_MESSAGE,
secondaryButton: Strings.CANCEL,
primaryButton: buttonGetPro
}));
Dialogs.showModalDialogUsingTemplate($template).done(function (id) {
console.log("Dialog closed with id: " + id);
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgShow", "localUpgrade");
if(id === 'ok') {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgAct", "localGetPro");
Phoenix.app.openURLInDefaultBrowser(brackets.config.purchase_url);
} else {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgAct", "localCancel");
}
});
}
function _showRemoteProEndedDialog(currentVersion, promoHtmlURL, upsellPurchaseURL) {
const buttonGetPro = StringUtils.format(Strings.PROMO_GET_APP_UPSELL_BUTTON, proTitlePlain);
const title = StringUtils.format(Strings.PROMO_PRO_ENDED_TITLE, proTitle);
const currentTheme = ThemeManager.getCurrentTheme();
const theme = currentTheme && currentTheme.dark ? "dark" : "light";
const promoURL = `${promoHtmlURL}?lang=${
brackets.getLocale()}&theme=${theme}&version=${currentVersion}`;
const $template = $(Mustache.render(proEndedHTML, {Strings, title, buttonGetPro, promoURL}));
Dialogs.showModalDialogUsingTemplate($template).done(function (id) {
console.log("Dialog closed with id: " + id);
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgShow", "remoteUpgrade");
if(id === 'get_pro') {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgAct", "remoteGetPro");
Phoenix.app.openURLInDefaultBrowser(upsellPurchaseURL || brackets.config.purchase_url);
} else {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "dlgAct", "remoteCancel");
}
});
}
async function showProEndedDialog() {
const currentVersion = window.AppConfig.apiVersion;
if (!navigator.onLine) {
_showLocalProEndedDialog();
return;
}
try {
const configURL = `${brackets.config.promotions_url}app/config.json`;
const response = await fetchFn(configURL);
if (!response.ok) {
_showLocalProEndedDialog();
return;
}
const config = await response.json();
if (config.upsell_after_trial_url) {
_showRemoteProEndedDialog(currentVersion, config.upsell_after_trial_url, config.upsell_purchase_url);
} else {
_showLocalProEndedDialog();
}
} catch (error) {
_showLocalProEndedDialog();
}
}
if (Phoenix.isTestWindow) {
window._test_pro_dlg_login_exports = {
setFetchFn: function _setDdateNowFn(fn) {
fetchFn = fn;
}
};
}
exports.showProUpgradeDialog = showProUpgradeDialog;
exports.showProEndedDialog = showProEndedDialog;
});