mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-21 22:57:17 +01:00
feat(env-utils): implement new getOsVersion, deprecate old one
This commit is contained in:
committed by
Jiri Zbytovsky
parent
a0c0fa7193
commit
1973c02f62
@@ -3,8 +3,8 @@ import { storage } from '@trezor/connect-common';
|
||||
import {
|
||||
getBrowserName,
|
||||
getBrowserVersion,
|
||||
getDeprecatedOsVersion,
|
||||
getOsName,
|
||||
getOsVersion,
|
||||
getPlatformLanguages,
|
||||
getScreenHeight,
|
||||
getScreenWidth,
|
||||
@@ -64,7 +64,7 @@ export const initAnalytics = () => {
|
||||
browserName: getBrowserName(),
|
||||
browserVersion: getBrowserVersion(),
|
||||
osName: getOsName(),
|
||||
osVersion: getOsVersion(),
|
||||
osVersion: getDeprecatedOsVersion(),
|
||||
screenWidth: getScreenWidth(),
|
||||
screenHeight: getScreenHeight(),
|
||||
windowWidth: getWindowWidth(),
|
||||
|
||||
@@ -24,7 +24,9 @@ const getBrowserVersion = () => '';
|
||||
|
||||
const getDeviceType = () => '';
|
||||
|
||||
const getOsVersion = () => `${Platform.Version}`;
|
||||
// no need for async fn on native; only for the sake of consistency with Web/Desktop
|
||||
const getOsVersion = () => Promise.resolve(`${Platform.Version}`);
|
||||
const getDeprecatedOsVersion = () => `${Platform.Version}`;
|
||||
|
||||
const getSuiteVersion = () => Constants.expoConfig?.version || '';
|
||||
|
||||
@@ -91,6 +93,7 @@ export const envUtils: EnvUtils = {
|
||||
getCommitHash,
|
||||
getDeviceType,
|
||||
getOsVersion,
|
||||
getDeprecatedOsVersion,
|
||||
getSuiteVersion,
|
||||
isFirefox,
|
||||
getPlatform,
|
||||
|
||||
@@ -37,8 +37,18 @@ const getBrowserVersion = () => getUserAgentParser().getBrowser().version || '';
|
||||
|
||||
const getCommitHash = () => process.env.COMMITHASH || '';
|
||||
|
||||
/* Not correct for Linux as there is many different distributions in different versions */
|
||||
const getOsVersion = () => getUserAgentParser().getOS().version || '';
|
||||
/**
|
||||
* .getOS() without `.withClientHints()` is sync and uses only `userAgent`, which is insufficient
|
||||
* to distinguish macOS >= 11 (Big Sur and above) and Windows 10 | 11, so we need the async `.withClientHints()`.
|
||||
* FYI it uses `getHighEntropyValues` under the hood (works only on Chromium-based browsers).
|
||||
*/
|
||||
const getOsVersion = async () => {
|
||||
const { version } = await getUserAgentParser().getOS().withClientHints();
|
||||
|
||||
return version ?? '';
|
||||
};
|
||||
/** @deprecated: Use the async getOsVersion instead. */
|
||||
const getDeprecatedOsVersion = () => getUserAgentParser().getOS().version || '';
|
||||
|
||||
const getSuiteVersion = () => process.env.VERSION || '';
|
||||
|
||||
@@ -136,6 +146,7 @@ export const envUtils: EnvUtils = {
|
||||
isAndroid,
|
||||
isChromeOs,
|
||||
getOsVersion,
|
||||
getDeprecatedOsVersion,
|
||||
getBrowserName,
|
||||
getBrowserVersion,
|
||||
getCommitHash,
|
||||
|
||||
@@ -15,6 +15,7 @@ export const {
|
||||
getCommitHash,
|
||||
getDeviceType,
|
||||
getOsVersion,
|
||||
getDeprecatedOsVersion,
|
||||
getSuiteVersion,
|
||||
isFirefox,
|
||||
getPlatform,
|
||||
|
||||
@@ -12,7 +12,8 @@ export interface EnvUtils {
|
||||
getBrowserVersion: () => string;
|
||||
getCommitHash: () => string;
|
||||
getDeviceType: () => string | undefined;
|
||||
getOsVersion: () => string;
|
||||
getOsVersion: () => Promise<string>;
|
||||
getDeprecatedOsVersion: () => string;
|
||||
getSuiteVersion: () => string;
|
||||
isFirefox: () => boolean;
|
||||
getPlatform: () => string;
|
||||
|
||||
@@ -14,7 +14,9 @@ export const init: ModuleInit = () => {
|
||||
|
||||
try {
|
||||
const osVersion = os.release();
|
||||
// Possible values are 'darwin', 'freebsd', 'linux', 'sunos', 'win32', and 'android'.
|
||||
const osName = os.platform();
|
||||
// Possible values are 'arm', 'arm64', 'ia32', 'loong64', 'mips', 'mipsel', 'ppc', 'ppc64', 'riscv64', 's390', 's390x', and 'x64'.
|
||||
const osArchitecture = os.arch();
|
||||
|
||||
return { success: true, payload: { osVersion, osName, osArchitecture } };
|
||||
|
||||
@@ -7,8 +7,8 @@ import { getCustomBackends } from '@suite-common/wallet-utils';
|
||||
import {
|
||||
getBrowserName,
|
||||
getBrowserVersion,
|
||||
getDeprecatedOsVersion,
|
||||
getOsName,
|
||||
getOsVersion,
|
||||
getPlatformLanguages,
|
||||
getScreenHeight,
|
||||
getScreenWidth,
|
||||
@@ -82,7 +82,7 @@ export const getSuiteReadyPayload = async (
|
||||
browserVersion: getBrowserVersion(),
|
||||
osName: getOsName(),
|
||||
// version from UA parser, which includes only the most basic info as it runs in renderer process
|
||||
osVersion: getOsVersion(),
|
||||
osVersion: getDeprecatedOsVersion(),
|
||||
// detailed info obtained in main process, if available
|
||||
desktopOsVersion: systemInformation?.osVersion,
|
||||
desktopOsName: systemInformation?.osName,
|
||||
|
||||
@@ -20,9 +20,9 @@ import {
|
||||
getBrowserName,
|
||||
getBrowserVersion,
|
||||
getCommitHash,
|
||||
getDeprecatedOsVersion,
|
||||
getEnvironment,
|
||||
getOsName,
|
||||
getOsVersion,
|
||||
getPlatformLanguages,
|
||||
getScreenHeight,
|
||||
getScreenWidth,
|
||||
@@ -189,7 +189,7 @@ export const getApplicationInfo = (state: AppState, hideSensitiveInfo: boolean)
|
||||
browserName: getBrowserName(),
|
||||
browserVersion: getBrowserVersion(),
|
||||
osName: getOsName(),
|
||||
osVersion: getOsVersion(),
|
||||
osVersion: getDeprecatedOsVersion(),
|
||||
windowWidth: getWindowWidth(),
|
||||
windowHeight: getWindowHeight(),
|
||||
screenWidth: getScreenWidth(),
|
||||
|
||||
@@ -24,9 +24,9 @@ import {
|
||||
getBrowserName,
|
||||
getBrowserVersion,
|
||||
getCommitHash,
|
||||
getDeprecatedOsVersion,
|
||||
getEnvironment,
|
||||
getOsName,
|
||||
getOsVersion,
|
||||
getSuiteVersion,
|
||||
} from '@trezor/env-utils';
|
||||
|
||||
@@ -209,7 +209,7 @@ export const validateConditions = (condition: Condition, options: Options) => {
|
||||
const { device, transports = [], settings } = options;
|
||||
|
||||
const currentOsName = getOsName();
|
||||
const currentOsVersion = transformVersionToSemverFormat(getOsVersion());
|
||||
const currentOsVersion = transformVersionToSemverFormat(getDeprecatedOsVersion());
|
||||
|
||||
const currentBrowserName = getBrowserName();
|
||||
const currentBrowserVersion = transformVersionToSemverFormat(getBrowserVersion());
|
||||
|
||||
Reference in New Issue
Block a user