mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
implemented new Util function isSimulatorOrEmulator
This commit is contained in:
3
packages/core/index.d.ts
vendored
3
packages/core/index.d.ts
vendored
@ -93,7 +93,7 @@ export type { InstrumentationMode, TimerInfo } from './profiling';
|
|||||||
export { encoding } from './text';
|
export { encoding } from './text';
|
||||||
export * from './trace';
|
export * from './trace';
|
||||||
export * from './ui';
|
export * from './ui';
|
||||||
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils';
|
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, isSimulatorOrEmulator, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils';
|
||||||
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
|
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
|
||||||
export declare const Utils: {
|
export declare const Utils: {
|
||||||
GC: typeof GC;
|
GC: typeof GC;
|
||||||
@ -111,6 +111,7 @@ export declare const Utils: {
|
|||||||
openFile: typeof openFile;
|
openFile: typeof openFile;
|
||||||
openUrl: typeof openUrl;
|
openUrl: typeof openUrl;
|
||||||
isRealDevice: typeof isRealDevice;
|
isRealDevice: typeof isRealDevice;
|
||||||
|
isSimulatorOrEmulator: typeof isSimulatorOrEmulator;
|
||||||
layout: typeof layout;
|
layout: typeof layout;
|
||||||
android: typeof androidUtils;
|
android: typeof androidUtils;
|
||||||
ad: typeof androidUtils;
|
ad: typeof androidUtils;
|
||||||
|
@ -110,7 +110,7 @@ export * from './trace';
|
|||||||
|
|
||||||
export * from './ui';
|
export * from './ui';
|
||||||
|
|
||||||
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX } from './utils';
|
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, isSimulatorOrEmulator, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX } from './utils';
|
||||||
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
|
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
|
||||||
|
|
||||||
export const Utils = {
|
export const Utils = {
|
||||||
@ -131,6 +131,7 @@ export const Utils = {
|
|||||||
openFile,
|
openFile,
|
||||||
openUrl,
|
openUrl,
|
||||||
isRealDevice,
|
isRealDevice,
|
||||||
|
isSimulatorOrEmulator,
|
||||||
|
|
||||||
layout,
|
layout,
|
||||||
android: androidUtils,
|
android: androidUtils,
|
||||||
|
@ -167,3 +167,7 @@ Please ensure you have your manifest correctly configured with the FileProvider.
|
|||||||
export function isRealDevice(): boolean {
|
export function isRealDevice(): boolean {
|
||||||
return ad.isRealDevice();
|
return ad.isRealDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean {
|
||||||
|
return ad.isSimulatorOrEmulator();
|
||||||
|
}
|
||||||
|
2
packages/core/utils/index.d.ts
vendored
2
packages/core/utils/index.d.ts
vendored
@ -286,3 +286,5 @@ export function eliminateDuplicates(arr: Array<any>): Array<any>;
|
|||||||
* Checks whether the application is running on real device and not on simulator/emulator.
|
* Checks whether the application is running on real device and not on simulator/emulator.
|
||||||
*/
|
*/
|
||||||
export function isRealDevice(): boolean;
|
export function isRealDevice(): boolean;
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean;
|
||||||
|
@ -47,4 +47,8 @@ export function isRealDevice(): boolean {
|
|||||||
return iOSNativeHelper.isRealDevice();
|
return iOSNativeHelper.isRealDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean {
|
||||||
|
return iOSNativeHelper.isSimulatorOrEmulator();
|
||||||
|
}
|
||||||
|
|
||||||
export const ad = 0;
|
export const ad = 0;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { getNativeApplication, android as androidApp } from '../application';
|
import { getNativeApplication, android as androidApp } from '../application';
|
||||||
import { Trace } from '../trace';
|
import { Trace } from '../trace';
|
||||||
|
import { isNullOrUndefined } from './types';
|
||||||
|
|
||||||
// We are using "ad" here to avoid namespace collision with the global android object
|
// We are using "ad" here to avoid namespace collision with the global android object
|
||||||
export namespace ad {
|
export namespace ad {
|
||||||
@ -153,9 +154,17 @@ export namespace ad {
|
|||||||
|
|
||||||
export function isRealDevice(): boolean {
|
export function isRealDevice(): boolean {
|
||||||
const fingerprint = android.os.Build.FINGERPRINT;
|
const fingerprint = android.os.Build.FINGERPRINT;
|
||||||
|
|
||||||
return fingerprint != null && (fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1);
|
return fingerprint != null && (fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean {
|
||||||
|
const fingerprint = android.os.Build.FINGERPRINT;
|
||||||
|
if (isNullOrUndefined(fingerprint)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return fingerprint.includes('vbox') || fingerprint.includes('generic');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const iOSNativeHelper = 0;
|
export const iOSNativeHelper = 0;
|
||||||
|
4
packages/core/utils/native-helper.d.ts
vendored
4
packages/core/utils/native-helper.d.ts
vendored
@ -88,6 +88,8 @@ export namespace ad {
|
|||||||
* Checks whether the application is running on real device and not on emulator.
|
* Checks whether the application is running on real device and not on emulator.
|
||||||
*/
|
*/
|
||||||
export function isRealDevice(): boolean;
|
export function isRealDevice(): boolean;
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Module with ios specific utilities.
|
* Module with ios specific utilities.
|
||||||
@ -177,4 +179,6 @@ export namespace iOSNativeHelper {
|
|||||||
* Checks whether the application is running on real device and not on simulator.
|
* Checks whether the application is running on real device and not on simulator.
|
||||||
*/
|
*/
|
||||||
export function isRealDevice(): boolean;
|
export function isRealDevice(): boolean;
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Trace } from '../trace';
|
import { Trace } from '../trace';
|
||||||
|
import { isNullOrUndefined } from './types';
|
||||||
|
|
||||||
declare let UIImagePickerControllerSourceType: any;
|
declare let UIImagePickerControllerSourceType: any;
|
||||||
|
|
||||||
@ -164,4 +165,9 @@ export namespace iOSNativeHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isSimulatorOrEmulator(): boolean {
|
||||||
|
const realDevice = isRealDevice();
|
||||||
|
return isNullOrUndefined(realDevice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user