aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/userAgent-helpers.js
blob: 15edc1054db97cef3d5655ba22606f16c420ddea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { remote, app } from 'electron';
import os from 'os';
import macosVersion from 'macos-version';
import { isMac, isWindows } from '../environment';

// This helper gets included from the backend and frontend but we only need to use "remote"
// if we are in the frontend
const ferdiVersion = remote && remote.app ? remote.app.getVersion() : app.getVersion();

function macOS() {
  const version = macosVersion();

  return `Macintosh; Intel Mac OS X ${version.replace(/\./g, '_')}`;
}

function windows() {
  const version = os.release();
  const [majorVersion, minorVersion] = version.split('.');
  return `Windows NT ${majorVersion}.${minorVersion}; Win64; x64`;
}

function linux() {
  return 'X11; Ubuntu; Linux x86_64';
}

export default function userAgent(removeChromeVersion = false) {
  let platformString = '';

  if (isMac) {
    platformString = macOS();
  } else if (isWindows) {
    platformString = windows();
  } else {
    platformString = linux();
  }

  let applicationString = '';
  if (!removeChromeVersion) {
    applicationString = ` Ferdi/${ferdiVersion} (Electron ${process.versions.electron})`;
  }

  // TODO: Update AppleWebKit and Safari version after electron update
  return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome${!removeChromeVersion ? `/${process.versions.chrome}` : ''} Safari/537.36${applicationString}`;
  // 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
}