diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/plan-helpers.js | 12 | ||||
-rw-r--r-- | src/helpers/userAgent-helpers.js | 45 |
2 files changed, 55 insertions, 2 deletions
diff --git a/src/helpers/plan-helpers.js b/src/helpers/plan-helpers.js index ee22e4471..b474f8bbd 100644 --- a/src/helpers/plan-helpers.js +++ b/src/helpers/plan-helpers.js | |||
@@ -20,6 +20,10 @@ const messages = defineMessages({ | |||
20 | }, | 20 | }, |
21 | }); | 21 | }); |
22 | 22 | ||
23 | export function cleanupPlanId(id) { | ||
24 | return id.replace(/(.*)-x[0-9]/, '$1'); | ||
25 | } | ||
26 | |||
23 | export function i18nPlanName(planId, intl) { | 27 | export function i18nPlanName(planId, intl) { |
24 | if (!planId) { | 28 | if (!planId) { |
25 | throw new Error('planId is required'); | 29 | throw new Error('planId is required'); |
@@ -29,7 +33,9 @@ export function i18nPlanName(planId, intl) { | |||
29 | throw new Error('intl context is required'); | 33 | throw new Error('intl context is required'); |
30 | } | 34 | } |
31 | 35 | ||
32 | const plan = PLANS_MAPPING[planId]; | 36 | const id = cleanupPlanId(planId); |
37 | |||
38 | const plan = PLANS_MAPPING[id]; | ||
33 | 39 | ||
34 | return intl.formatMessage(messages[plan]); | 40 | return intl.formatMessage(messages[plan]); |
35 | } | 41 | } |
@@ -39,7 +45,9 @@ export function getPlan(planId) { | |||
39 | throw new Error('planId is required'); | 45 | throw new Error('planId is required'); |
40 | } | 46 | } |
41 | 47 | ||
42 | const plan = PLANS_MAPPING[planId]; | 48 | const id = cleanupPlanId(planId); |
49 | |||
50 | const plan = PLANS_MAPPING[id]; | ||
43 | 51 | ||
44 | return plan; | 52 | return plan; |
45 | } | 53 | } |
diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.js new file mode 100644 index 000000000..15edc1054 --- /dev/null +++ b/src/helpers/userAgent-helpers.js | |||
@@ -0,0 +1,45 @@ | |||
1 | import { remote, app } from 'electron'; | ||
2 | import os from 'os'; | ||
3 | import macosVersion from 'macos-version'; | ||
4 | import { isMac, isWindows } from '../environment'; | ||
5 | |||
6 | // This helper gets included from the backend and frontend but we only need to use "remote" | ||
7 | // if we are in the frontend | ||
8 | const ferdiVersion = remote && remote.app ? remote.app.getVersion() : app.getVersion(); | ||
9 | |||
10 | function macOS() { | ||
11 | const version = macosVersion(); | ||
12 | |||
13 | return `Macintosh; Intel Mac OS X ${version.replace(/\./g, '_')}`; | ||
14 | } | ||
15 | |||
16 | function windows() { | ||
17 | const version = os.release(); | ||
18 | const [majorVersion, minorVersion] = version.split('.'); | ||
19 | return `Windows NT ${majorVersion}.${minorVersion}; Win64; x64`; | ||
20 | } | ||
21 | |||
22 | function linux() { | ||
23 | return 'X11; Ubuntu; Linux x86_64'; | ||
24 | } | ||
25 | |||
26 | export default function userAgent(removeChromeVersion = false) { | ||
27 | let platformString = ''; | ||
28 | |||
29 | if (isMac) { | ||
30 | platformString = macOS(); | ||
31 | } else if (isWindows) { | ||
32 | platformString = windows(); | ||
33 | } else { | ||
34 | platformString = linux(); | ||
35 | } | ||
36 | |||
37 | let applicationString = ''; | ||
38 | if (!removeChromeVersion) { | ||
39 | applicationString = ` Ferdi/${ferdiVersion} (Electron ${process.versions.electron})`; | ||
40 | } | ||
41 | |||
42 | // TODO: Update AppleWebKit and Safari version after electron update | ||
43 | return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome${!removeChromeVersion ? `/${process.versions.chrome}` : ''} Safari/537.36${applicationString}`; | ||
44 | // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) old-airport-include/1.0.0 Chrome Electron/7.1.7 Safari/537.36 | ||
45 | } | ||