diff options
author | 2021-08-15 17:15:09 +0530 | |
---|---|---|
committer | 2021-08-15 13:54:00 +0000 | |
commit | bc76d19c6f5687dd18c96db249e0abe7ad79a673 (patch) | |
tree | d4e977f99be77d723ce93bb3866468d8b63ec038 /src/helpers/userAgent-helpers.ts | |
parent | chore: npm upgrades (diff) | |
download | ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.gz ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.zst ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.zip |
chore: typescript conversion of some minor utilities
Also removed 'targz' unused package from runtime.
Diffstat (limited to 'src/helpers/userAgent-helpers.ts')
-rw-r--r-- | src/helpers/userAgent-helpers.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/helpers/userAgent-helpers.ts b/src/helpers/userAgent-helpers.ts new file mode 100644 index 000000000..73c8bfd03 --- /dev/null +++ b/src/helpers/userAgent-helpers.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import os from 'os'; | ||
2 | import macosVersion from 'macos-version'; | ||
3 | import { chrome } from 'useragent-generator'; | ||
4 | import { | ||
5 | chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease, | ||
6 | } from '../environment'; | ||
7 | |||
8 | function macOS() { | ||
9 | const version = macosVersion() || ''; | ||
10 | let cpuName = os.cpus()[0].model.split(' ')[0]; | ||
11 | if (cpuName && cpuName.match(/\(/)) { | ||
12 | cpuName = cpuName.split('(')[0]; | ||
13 | } | ||
14 | return `Macintosh; ${cpuName} Mac OS X ${version.replace(/\./g, '_')}`; | ||
15 | } | ||
16 | |||
17 | function windows() { | ||
18 | const version = osRelease; | ||
19 | const [majorVersion, minorVersion] = version.split('.'); | ||
20 | const archString = is64Bit ? 'Win64' : 'Win32'; | ||
21 | return `Windows NT ${majorVersion}.${minorVersion}; ${archString}; ${osArch}`; | ||
22 | } | ||
23 | |||
24 | function linux() { | ||
25 | const archString = is64Bit ? 'x86_64' : osArch; | ||
26 | return `X11; Ubuntu; Linux ${archString}`; | ||
27 | } | ||
28 | |||
29 | export default function userAgent() { | ||
30 | let platformString = ''; | ||
31 | |||
32 | if (isMac) { | ||
33 | platformString = macOS(); | ||
34 | } else if (isWindows) { | ||
35 | platformString = windows(); | ||
36 | } else { | ||
37 | platformString = linux(); | ||
38 | } | ||
39 | |||
40 | return chrome({ os: platformString, version: chromeVersion }); | ||
41 | } | ||