-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* annual upgrade plan message * update documentation * separate into 2 messages * re-evaluate message conditions on a timer * mistype * linter * Unify 14 and 87 day upgrade messages into one * code review updates * linter * use single qtimer object for callbacks * disconnect timeout signal before creating new one * rename message * initial test * functional test * fix inspector command * unit test * linter * use production addon for testing * fix timer unit test * linter * move comment
- Loading branch information
1 parent
d24c9e1
commit 6facaf0
Showing
23 changed files
with
388 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(function(api, condition) { | ||
//Show this message after 14 days, and resurface after 87 days | ||
|
||
//This will run when TaskaGetSubscriptionDetails returns something different than what is loaded from setting | ||
//(often from signing in/out but can be any change in the subscription) | ||
api.connectSignal(api.subscriptionData, 'changed', () => computeCondition()); | ||
|
||
//This will run on app launch for signed in users when there subscription data is loaded into memory from settings | ||
api.connectSignal(api.subscriptionData, 'initialized', () => computeCondition()); | ||
|
||
//This is for already running clients that receive this addon while the client is launched and signed in | ||
//(Because these users may not see a change in subscriptionData for a long time) | ||
computeCondition() | ||
|
||
function isMonthlyWebPlan() { | ||
return api.subscriptionData.type === api.subscriptionData.SubscriptionWeb && | ||
api.subscriptionData.planBillingInterval === api.subscriptionData.BillingIntervalMonthly | ||
} | ||
|
||
function computeCondition() { | ||
//subscriptionData not initalized - return | ||
if (api.subscriptionData.createdAt <= 0) return | ||
|
||
let now = Date.now() | ||
let fourteenDaysAfterSubscriptionStarted = api.subscriptionData.createdAt + 1000 * 60 * 60 * 24 * 14 | ||
let eightySevenDaysAfterSubscriptionStarted = api.subscriptionData.createdAt + 1000 * 60 * 60 * 24 * 87 | ||
|
||
if (isMonthlyWebPlan) { | ||
//Less than 14 days into the subscription, don't show message | ||
if (now < fourteenDaysAfterSubscriptionStarted) { | ||
api.setTimedCallback(fourteenDaysAfterSubscriptionStarted - now, () => computeCondition()); | ||
condition.disable() | ||
} | ||
//Between 14 and 87 days into the subscription, show message | ||
else if (now >= fourteenDaysAfterSubscriptionStarted && now < eightySevenDaysAfterSubscriptionStarted) { | ||
api.setTimedCallback(eightySevenDaysAfterSubscriptionStarted - now, () => computeCondition()) | ||
api.addon.date = fourteenDaysAfterSubscriptionStarted / 1000 | ||
condition.enable() | ||
} | ||
// After 87 days into the subscription, re-surface the message (undimiss, unread, updating timestamp) | ||
else if (now >= eightySevenDaysAfterSubscriptionStarted) { | ||
api.addon.date = eightySevenDaysAfterSubscriptionStarted / 1000 | ||
api.addon.resetMessage() | ||
condition.enable() | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(function(api) { | ||
function versionCompare(a, b) { | ||
for (let i = 0; i < 3; ++i) { | ||
if (a[i] != b[i]) { | ||
return a[i] > b[i] ? -1 : 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
const parts = api.env.versionString.split('.'); | ||
|
||
const version = parts.map(a => parseInt(a, 10)); | ||
|
||
//Post 2.16 API | ||
if (versionCompare([2, 16, 0], version) >= 0) { | ||
api.navigator.requestScreen(api.vpn.ScreenGetHelp); | ||
return; | ||
} | ||
//Pre 2.16 API | ||
else { | ||
api.navigator.requestScreen(api.navigator.ScreenGetHelp); | ||
return; | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"api_version": "0.1", | ||
"id": "message_upgrade_to_annual_plan", | ||
"name": "Upgrade to annual plan", | ||
"type": "message", | ||
"conditions": { | ||
"javascript": "conditions.js" | ||
}, | ||
"message": { | ||
"id": "message_upgrade_to_annual_plan", | ||
"title": "Save 50% when you switch to an annual plan", | ||
"subtitle": "Get the same protection, for half the price.", | ||
"badge": "subscription", | ||
"notify": false, | ||
"blocks": [ | ||
{ | ||
"id": "c_1", | ||
"type": "text", | ||
"content": "Switch to an annual plan, and get all the same benefits at 50% less than the monthly plan:" | ||
}, | ||
{ "id": "c_2", | ||
"type": "ulist", | ||
"content": [ | ||
{ "id": "l_1", | ||
"content": "Protection for up to 5 devices" | ||
}, | ||
{ "id": "l_2", | ||
"content": "500+ servers in 30+ countries" | ||
}, | ||
{ "id": "l_3", | ||
"content": "Device-level encryption" | ||
}, | ||
{ "id": "l_4", | ||
"content": "No bandwidth restrictions" | ||
}, | ||
{ "id": "l_5", | ||
"content": "No logging of your network activity" | ||
} | ||
] | ||
}, | ||
{ "id": "c_3", | ||
"type": "button", | ||
"style": "primary", | ||
"content": "Switch to an annual plan", | ||
"javascript": "openLink.js" | ||
}, | ||
{ | ||
"id": "c_4", | ||
"type": "button", | ||
"style": "link", | ||
"content": "Get help", | ||
"javascript": "getHelp.js" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
((api) => { | ||
return api.urlOpener.openUrl( | ||
`https://www.mozilla.org/products/vpn/?utm_medium=mozillavpn&utm_source=messages#pricing`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.