136 lines
4.3 KiB
JavaScript
Raw Permalink Normal View History

2025-06-21 23:30:33 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.envUtils = exports.getJWSPublicKey = exports.getEnvironment = exports.isNative = exports.isDesktop = exports.isWeb = void 0;
const tslib_1 = require("tslib");
const ua_parser_js_1 = tslib_1.__importDefault(require("ua-parser-js"));
const jws_1 = require("./jws");
const isWeb = () => process.env.SUITE_TYPE === 'web';
exports.isWeb = isWeb;
const isDesktop = () => process.env.SUITE_TYPE === 'desktop';
exports.isDesktop = isDesktop;
const isNative = () => false;
exports.isNative = isNative;
const getEnvironment = () => {
if ((0, exports.isWeb)())
return 'web';
return 'desktop';
};
exports.getEnvironment = getEnvironment;
let userAgentParser;
const getUserAgent = () => window.navigator.userAgent;
const getUserAgentParser = () => {
if (!userAgentParser) {
const ua = getUserAgent();
userAgentParser = new ua_parser_js_1.default(ua);
}
return userAgentParser;
};
const isAndroid = () => /Android/.test(getUserAgent());
const isChromeOs = () => /CrOS/.test(getUserAgent());
const getBrowserVersion = () => getUserAgentParser().getBrowser().version || '';
const getCommitHash = () => process.env.COMMITHASH || '';
const getOsVersion = () => getUserAgentParser().getOS().version || '';
const getSuiteVersion = () => process.env.VERSION || '';
const getBrowserName = () => {
const browserName = getUserAgentParser().getBrowser().name;
return browserName?.toLowerCase() || '';
};
const isFirefox = () => getBrowserName() === 'firefox';
const getPlatform = () => window.navigator.platform;
const getPlatformLanguages = () => window.navigator.languages;
const getScreenWidth = () => window.screen.width;
const getScreenHeight = () => window.screen.height;
const getWindowWidth = () => window.innerWidth;
const getWindowHeight = () => window.innerHeight;
const getLocationOrigin = () => window.location.origin;
const getLocationHostname = () => window.location.hostname;
const getProcessPlatform = () => (typeof process !== 'undefined' ? process.platform : '');
const isMacOs = () => {
if (getProcessPlatform() === 'darwin')
return true;
if (typeof window === 'undefined')
return;
return getPlatform().startsWith('Mac');
};
const isWindows = () => {
if (getProcessPlatform() === 'win32')
return true;
if (typeof window === 'undefined')
return;
return getPlatform().startsWith('Win');
};
const isIOs = () => ['iPhone', 'iPad', 'iPod'].includes(getPlatform());
const isLinux = () => {
if (getProcessPlatform() === 'linux')
return true;
if (typeof window === 'undefined')
return;
if (isAndroid() || isChromeOs())
return false;
return getPlatform().startsWith('Linux');
};
const isCodesignBuild = () => process.env.IS_CODESIGN_BUILD === 'true';
const getOsName = () => {
if (isWindows())
return 'windows';
if (isMacOs())
return 'macos';
if (isAndroid())
return 'android';
if (isChromeOs())
return 'chromeos';
if (isLinux())
return 'linux';
if (isIOs())
return 'ios';
return '';
};
const getOsNameWeb = () => getUserAgentParser().getOS().name;
const getOsFamily = () => {
const osName = getUserAgentParser().getOS().name;
if (osName === 'Windows') {
return 'Windows';
}
if (osName === 'Mac OS') {
return 'MacOS';
}
return 'Linux';
};
const getDeviceType = () => getUserAgentParser().getDevice().type;
const getJWSPublicKey = () => (isCodesignBuild() ? jws_1.publicKey.codesign : jws_1.publicKey.dev);
exports.getJWSPublicKey = getJWSPublicKey;
exports.envUtils = {
isWeb: exports.isWeb,
isDesktop: exports.isDesktop,
isNative: exports.isNative,
getEnvironment: exports.getEnvironment,
getUserAgent,
isAndroid,
isChromeOs,
getOsVersion,
getBrowserName,
getBrowserVersion,
getCommitHash,
getDeviceType,
getSuiteVersion,
isFirefox,
getPlatform,
getPlatformLanguages,
getScreenWidth,
getScreenHeight,
getWindowWidth,
getWindowHeight,
getLocationOrigin,
getLocationHostname,
getProcessPlatform,
isMacOs,
isWindows,
isIOs,
isLinux,
isCodesignBuild,
getOsName,
getOsNameWeb,
getOsFamily,
getJWSPublicKey: exports.getJWSPublicKey,
};
//# sourceMappingURL=envUtils.js.map