aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/userAgent-helpers.js
blob: be61624642f5a2cea5400eeb933277fb6234b999 (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
46
47
48
49
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, addFerdiVersion = false) {
  let platformString = '';

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

  let chromeVersion = 'Chrome';
  if (!removeChromeVersion) {
    chromeVersion = `Chrome/${process.versions.chrome}`;
  }

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

  // Chrome is pinned to WebKit 537.36, the latest version before hard forking to Blink.
  return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) ${chromeVersion} Safari/537.36${applicationString}`;
  // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36 Ferdi/5.5.1-nightly.13 Electron/8.2.3
}