Environment add device brand and model info

This commit is contained in:
pengfei.zhou 2020-03-14 10:54:13 +08:00 committed by osborn
parent 47cf63ef36
commit 98c7d59a70
5 changed files with 25 additions and 1 deletions

View File

@ -18,6 +18,7 @@ package pub.doric.engine;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
@ -106,7 +107,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
.put("appVersion", appVersion)
.put("screenWidth", DoricUtils.px2dp(DoricUtils.getScreenWidth()))
.put("screenHeight", DoricUtils.px2dp(DoricUtils.getScreenHeight()))
.put("statusBarHeight", DoricUtils.px2dp(DoricUtils.getStatusBarHeight(Doric.application())));
.put("deviceBrand", Build.BRAND)
.put("deviceModel", Build.MODEL);
Map<String, Object> extend = mDoricRegistry.getEnvironmentVariables();
for (String key : extend.keySet()) {

View File

@ -25,6 +25,7 @@
#import "DoricConstant.h"
#import "DoricUtil.h"
#import "DoricBridgeExtension.h"
#import <sys/utsname.h>
@interface DoricJSEngine ()
@property(nonatomic, strong) NSMutableDictionary *timers;
@ -39,6 +40,12 @@ - (instancetype)init {
_jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL);
_bridgeExtension = [[DoricBridgeExtension alloc] init];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
if (TARGET_OS_SIMULATOR == 1) {
platform = [NSProcessInfo new].environment[@"SIMULATOR_MODEL_IDENTIFIER"];
}
_innerEnvironmentDictionary = @{
@"platform": @"iOS",
@"platformVersion": [[UIDevice currentDevice] systemVersion],
@ -47,6 +54,8 @@ - (instancetype)init {
@"screenWidth": @([[UIScreen mainScreen] bounds].size.width),
@"screenHeight": @([[UIScreen mainScreen] bounds].size.height),
@"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height),
@"deviceBrand": @"Apple",
@"deviceModel": platform,
};
dispatch_async(_jsQueue, ^() {
self.timers = [[NSMutableDictionary alloc] init];

2
doric-js/index.d.ts vendored
View File

@ -51,6 +51,8 @@ declare module 'doric/lib/src/runtime/global' {
screenWidth: number;
screenHeight: number;
statusBarHeight: number;
deviceBrand: string;
deviceModel: string;
[index: string]: number | string | boolean | object | undefined;
};
function Entry(constructor: {

View File

@ -37,6 +37,8 @@ declare global {
screenWidth: number;
screenHeight: number;
statusBarHeight: number;
deviceBrand: string;
deviceModel: string;
[index: string]: number | string | boolean | object | undefined;
};
function Entry(constructor: {

View File

@ -62,6 +62,15 @@ declare global {
statusBarHeight: number,
/**
* ex:Apple or Google
*/
deviceBrand: string,
/**
* ex: iPhone12,5 or pixel 3
*/
deviceModel: string,
[index: string]: number | string | boolean | object | undefined
}
function Entry(constructor: { new(...args: any[]): {} }): any