detectPlatform.js 2.3 KB

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