|
16 | 16 | * |
17 | 17 | */ |
18 | 18 |
|
19 | | -/*global logger*/ |
| 19 | +/*global logger, path*/ |
20 | 20 |
|
21 | 21 | /** |
22 | 22 | * Promotions Service |
@@ -46,7 +46,7 @@ define(function (require, exports, module) { |
46 | 46 |
|
47 | 47 | // Constants |
48 | 48 | const EVENT_PRO_UPGRADE_ON_INSTALL = "pro_upgrade_on_install"; |
49 | | - const PROMO_LOCAL_FILE = "entitlements_promo.json"; |
| 49 | + const PROMO_LOCAL_FILE = path.join(Phoenix.app.getApplicationSupportDirectory(), "entitlements_promo.json"); |
50 | 50 | const TRIAL_POLL_MS = 10 * 1000; // 10 seconds after start, we assign a free trial if possible |
51 | 51 | const FIRST_INSTALL_TRIAL_DAYS = 30; |
52 | 52 | const SUBSEQUENT_TRIAL_DAYS = 7; |
@@ -94,9 +94,8 @@ define(function (require, exports, module) { |
94 | 94 | if (Phoenix.isNativeApp) { |
95 | 95 | await KernalModeTrust.removeCredential(KernalModeTrust.CRED_KEY_PROMO); |
96 | 96 | } else { |
97 | | - const filePath = Phoenix.app.getApplicationSupportDirectory() + PROMO_LOCAL_FILE; |
98 | 97 | await new Promise((resolve) => { |
99 | | - window.fs.unlink(filePath, () => resolve()); // Always resolve, ignore errors |
| 98 | + window.fs.unlink(PROMO_LOCAL_FILE, () => resolve()); // Always resolve, ignore errors |
100 | 99 | }); |
101 | 100 | } |
102 | 101 | } catch (error) { |
@@ -183,8 +182,7 @@ define(function (require, exports, module) { |
183 | 182 | } else { |
184 | 183 | // Browser app: use virtual filesystem. in future we need to always fetch from remote about trial |
185 | 184 | // entitlements for browser app. |
186 | | - const filePath = Phoenix.app.getApplicationSupportDirectory() + PROMO_LOCAL_FILE; |
187 | | - const fileData = await _readFileAsync(filePath); |
| 185 | + const fileData = await _readFileAsync(PROMO_LOCAL_FILE); |
188 | 186 |
|
189 | 187 | if (!fileData) { |
190 | 188 | return null; // No data exists - genuine first install |
@@ -219,8 +217,7 @@ define(function (require, exports, module) { |
219 | 217 | await KernalModeTrust.setCredential(KernalModeTrust.CRED_KEY_PROMO, JSON.stringify(trialData)); |
220 | 218 | } else { |
221 | 219 | // Browser app: use virtual filesystem |
222 | | - const filePath = Phoenix.app.getApplicationSupportDirectory() + PROMO_LOCAL_FILE; |
223 | | - await _writeFileAsync(filePath, JSON.stringify(trialData)); |
| 220 | + await _writeFileAsync(PROMO_LOCAL_FILE, JSON.stringify(trialData)); |
224 | 221 | } |
225 | 222 | } catch (error) { |
226 | 223 | console.error("Error setting trial data:", error); |
@@ -475,6 +472,14 @@ define(function (require, exports, module) { |
475 | 472 | console.log("Salt data cleanup completed (ignoring errors)"); |
476 | 473 | } |
477 | 474 | }, |
| 475 | + // Test-only functions for manipulating credentials directly (bypassing validation) |
| 476 | + _testSetRawCredential: async function(data) { |
| 477 | + if (Phoenix.isNativeApp) { |
| 478 | + await KernalModeTrust.setCredential(KernalModeTrust.CRED_KEY_PROMO, JSON.stringify(data)); |
| 479 | + } else { |
| 480 | + await _writeFileAsync(PROMO_LOCAL_FILE, JSON.stringify(data)); |
| 481 | + } |
| 482 | + }, |
478 | 483 | activateProTrial: activateProTrial, |
479 | 484 | getProTrialDaysRemaining: getProTrialDaysRemaining, |
480 | 485 | setDateNowFn: function _setDdateNowFn(fn) { |
|
0 commit comments