detectPlatform.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright 2023 Google Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import os from 'os';
  17. import { BrowserPlatform } from './browser-data/browser-data.js';
  18. /**
  19. * @public
  20. */
  21. export function detectBrowserPlatform() {
  22. const platform = os.platform();
  23. switch (platform) {
  24. case 'darwin':
  25. return os.arch() === 'arm64'
  26. ? BrowserPlatform.MAC_ARM
  27. : BrowserPlatform.MAC;
  28. case 'linux':
  29. return BrowserPlatform.LINUX;
  30. case 'win32':
  31. return os.arch() === 'x64' ||
  32. // Windows 11 for ARM supports x64 emulation
  33. (os.arch() === 'arm64' && isWindows11(os.release()))
  34. ? BrowserPlatform.WIN64
  35. : BrowserPlatform.WIN32;
  36. default:
  37. return undefined;
  38. }
  39. }
  40. /**
  41. * Windows 11 is identified by the version 10.0.22000 or greater
  42. * @internal
  43. */
  44. function isWindows11(version) {
  45. const parts = version.split('.');
  46. if (parts.length > 2) {
  47. const major = parseInt(parts[0], 10);
  48. const minor = parseInt(parts[1], 10);
  49. const patch = parseInt(parts[2], 10);
  50. return (major > 10 ||
  51. (major === 10 && minor > 0) ||
  52. (major === 10 && minor === 0 && patch >= 22000));
  53. }
  54. return false;
  55. }
  56. //# sourceMappingURL=detectPlatform.js.map