detectPlatform.js 1.3 KB

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