oak-frontend-base/es/utils/env/env.native.js

31 lines
957 B
JavaScript

import { Platform, NativeModules } from 'react-native';
import { getLocales } from 'react-native-localize';
import { getDeviceId } from 'react-native-device-info';
const isRemoteDebugging = () => {
if (!__DEV__) {
return false;
}
const debuggerModule = NativeModules?.Debugger;
return typeof debuggerModule !== 'undefined';
};
export async function getEnv() {
const isDebuggingEnabled = isRemoteDebugging();
const language = isDebuggingEnabled ? navigator.language : getLocales()[0].languageTag;
const deviceId = getDeviceId();
const fullEnv = {
...Platform,
visitorId: deviceId,
language,
type: 'native',
};
const briefEnv = {
brand: fullEnv.constants.Brand,
model: fullEnv.constants.Model,
system: `${fullEnv.OS}/${fullEnv.constants.Version || fullEnv.constants.osVersion}/${language}`,
};
return {
fullEnv,
briefEnv,
};
}