From 98c7d59a706bce4e9f1cdf9f9e9a27f5418f11d2 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 14 Mar 2020 10:54:13 +0800 Subject: [PATCH] Environment add device brand and model info --- .../src/main/java/pub/doric/engine/DoricJSEngine.java | 4 +++- doric-iOS/Pod/Classes/Engine/DoricJSEngine.m | 9 +++++++++ doric-js/index.d.ts | 2 ++ doric-js/lib/src/runtime/global.d.ts | 2 ++ doric-js/src/runtime/global.ts | 9 +++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java b/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java index e94624fe..bc3b0de6 100644 --- a/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java +++ b/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java @@ -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 extend = mDoricRegistry.getEnvironmentVariables(); for (String key : extend.keySet()) { diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index 536b20d5..e0c59b72 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -25,6 +25,7 @@ #import "DoricConstant.h" #import "DoricUtil.h" #import "DoricBridgeExtension.h" +#import @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]; diff --git a/doric-js/index.d.ts b/doric-js/index.d.ts index 1d4757a5..0a432819 100644 --- a/doric-js/index.d.ts +++ b/doric-js/index.d.ts @@ -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: { diff --git a/doric-js/lib/src/runtime/global.d.ts b/doric-js/lib/src/runtime/global.d.ts index 0b8d54a7..594da345 100644 --- a/doric-js/lib/src/runtime/global.d.ts +++ b/doric-js/lib/src/runtime/global.d.ts @@ -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: { diff --git a/doric-js/src/runtime/global.ts b/doric-js/src/runtime/global.ts index 8ae88ef4..97c193a7 100644 --- a/doric-js/src/runtime/global.ts +++ b/doric-js/src/runtime/global.ts @@ -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