tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

detectPlatform.ts (1342B)


      1 /**
      2 * @license
      3 * Copyright 2023 Google Inc.
      4 * SPDX-License-Identifier: Apache-2.0
      5 */
      6 
      7 import os from 'node:os';
      8 
      9 import {BrowserPlatform} from './browser-data/browser-data.js';
     10 
     11 /**
     12 * @public
     13 */
     14 export function detectBrowserPlatform(): BrowserPlatform | undefined {
     15  const platform = os.platform();
     16  const arch = os.arch();
     17  switch (platform) {
     18    case 'darwin':
     19      return arch === 'arm64' ? BrowserPlatform.MAC_ARM : BrowserPlatform.MAC;
     20    case 'linux':
     21      return arch === 'arm64'
     22        ? BrowserPlatform.LINUX_ARM
     23        : BrowserPlatform.LINUX;
     24    case 'win32':
     25      return arch === 'x64' ||
     26        // Windows 11 for ARM supports x64 emulation
     27        (arch === 'arm64' && isWindows11(os.release()))
     28        ? BrowserPlatform.WIN64
     29        : BrowserPlatform.WIN32;
     30    default:
     31      return undefined;
     32  }
     33 }
     34 
     35 /**
     36 * Windows 11 is identified by the version 10.0.22000 or greater
     37 * @internal
     38 */
     39 function isWindows11(version: string): boolean {
     40  const parts = version.split('.');
     41  if (parts.length > 2) {
     42    const major = parseInt(parts[0] as string, 10);
     43    const minor = parseInt(parts[1] as string, 10);
     44    const patch = parseInt(parts[2] as string, 10);
     45    return (
     46      major > 10 ||
     47      (major === 10 && minor > 0) ||
     48      (major === 10 && minor === 0 && patch >= 22000)
     49    );
     50  }
     51  return false;
     52 }