UNPKG

@itwin/core-bentley

Version:

Bentley JavaScript core components

72 lines 5.32 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module ProcessDetector */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ProcessDetector = void 0; /** Functions to determine the type of JavaScript process currently executing. * @public */ class ProcessDetector { /** Is this a browser process? * @note this method will also return `true` for the frontend of Electron or Mobile apps. They *are* browser processes. */ static get isBrowserProcess() { return typeof window === "object" && typeof window.navigator === "object"; } /** Is this a Node process? * @note this means "is this a backend process"? It will return `true` for all backend process, including Electron and mobile apps. */ static get isNodeProcess() { return typeof process === "object" && undefined !== process.platform; } /** Is this process the frontend of an Electron app? */ static get isElectronAppFrontend() { return typeof navigator === "object" && navigator.userAgent.toLowerCase().indexOf("electron") >= 0; } /** Is this process the backend of an Electron app? */ static get isElectronAppBackend() { return typeof process === "object" && process.versions.hasOwnProperty("electron"); } /** Is this process running in a browser on an iPad? * @note This method will return `true` for any frontend running on an iPad, whether it is a user-launched web browser (e.g. Safari) or the frontend of a mobile app. */ static get isIPadBrowser() { return this.isBrowserProcess && window.navigator.platform === "iPad" || (window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 0 && !("MSStream" in window)); /* eslint-disable-line @typescript-eslint/no-deprecated */ } /** Is this process running in a browser on an iPhone? * @note This method will return `true` for any frontend running on an iPhone, whether it is a user-launched web browser (e.g. Safari) or the frontend of a mobile app. */ static get isIPhoneBrowser() { return this.isBrowserProcess && (/(iphone|ipod)/i.test(window.navigator.userAgent)); } /** Is this process running in a browser on an iOS device? * @note This method will return `true` for any frontend running on an iOS device, whether it is a user-launched web browser (e.g. Safari) or the frontend of a mobile app. */ static get isIOSBrowser() { return this.isIPadBrowser || this.isIPhoneBrowser; } /** Is this process running in a browser on an Android device? * @note This method will return `true` for any frontend running on an Android device, whether it is a user-launched web browser (e.g. Chrome) or the frontend of a mobile app. */ static get isAndroidBrowser() { return this.isBrowserProcess && /android/i.test(window.navigator.userAgent); } /** Is this process running in a browser on a mobile device? * @note This method will return `true` for any frontend running on a mobile device, whether it is a user-launched web browser or the frontend of a mobile app. */ static get isMobileBrowser() { return this.isIOSBrowser || this.isAndroidBrowser; } /** Is this process running in a Chromium based browser (Chrome / new Edge / Electron front end)? */ static get isChromium() { return (this.isBrowserProcess && window.navigator.userAgent.indexOf("Chrome") > -1 && window.navigator.userAgent.indexOf("OP") === -1) || this.isElectronAppFrontend; } /** Is this process the frontend of an iTwin mobile application? * @note this indicates that this is a browser process started by an iTwin mobile application. * It will return `false` when running user-launched web browsers on a mobile device. */ static get isMobileAppFrontend() { return this.isAndroidAppFrontend || this.isIOSAppFrontend; } /** Is this process the frontend of an iOS mobile application? */ static get isIOSAppFrontend() { return this.isBrowserProcess && window.location.hash.indexOf("platform=ios") !== -1; } /** Is this process the frontend of an Android mobile application? */ static get isAndroidAppFrontend() { return this.isBrowserProcess && window.location.hash.indexOf("platform=android") !== -1; } /** Is this process the backend of an iOS mobile application? */ static get isIOSAppBackend() { return this.isNodeProcess && process.platform === "ios"; } /** Is this process the backend of an Android mobile application? */ static get isAndroidAppBackend() { return this.isNodeProcess && process.platform === "android"; } /** Is this process a mobile app backend? */ static get isMobileAppBackend() { return this.isIOSAppBackend || this.isAndroidAppBackend; } /** Is this process the frontend of a native (Electron or Mobile) app? */ static get isNativeAppFrontend() { return this.isElectronAppFrontend || this.isMobileAppFrontend; } } exports.ProcessDetector = ProcessDetector; //# sourceMappingURL=ProcessDetector.js.map