diff options
Diffstat (limited to 'src/helpers/userAgent-helpers.js')
-rw-r--r-- | src/helpers/userAgent-helpers.js | 45 |
1 files changed, 45 insertions, 0 deletions
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 | } | ||