Skip to content

Commit

Permalink
feat(devtools): devtools report (Tencent#2556)
Browse files Browse the repository at this point in the history
* feat(devtools): add devtools update context

* fix(ios): add TDFRuntime.updateContextInfo devtools method

* fix(devtools): update ios context

* fix(devtools): update copywrite

Co-authored-by: jonasluo <jonasluo@tencent.com>
  • Loading branch information
lavnFan and luoyibu authored Oct 19, 2022
1 parent 314e2ac commit edfca67
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
/* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2018-2022 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tencent.mtt.hippy.devsupport.inspector;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import com.tencent.mtt.hippy.BuildConfig;
import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.devsupport.DebugWebSocketClient;
import com.tencent.mtt.hippy.devsupport.inspector.domain.CSSDomain;
Expand Down Expand Up @@ -146,8 +166,21 @@ public void updateContextName(String name) {
try {
JSONObject contextObj = new JSONObject();
contextObj.put("contextName", name);

Context context = mContextRef.get().getGlobalConfigs().getContext();
String packageName = "";
String versionName = "";
if (context != null) {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
packageName = packageInfo.packageName;
versionName = packageInfo.versionName;
}
contextObj.put("bundleId", packageName);
contextObj.put("hostVersion", versionName);
contextObj.put("sdkVersion", BuildConfig.LIBRARY_VERSION);
sendEventToFrontend(new InspectEvent("TDFRuntime.updateContextInfo", contextObj));
} catch (JSONException e) {
} catch (Exception e) {
LogUtils.e(TAG, "updateContextName, exception:", e);
}
}
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/debug/devtools/HippyDevManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef NS_ENUM(NSInteger, HippyDevCloseType) {
- (void)closeWebSocket:(HippyDevCloseType)type;

@property(nonatomic, weak) HippyBridge *bridge;
@property(nonatomic, readwrite) NSString *contextName;

@end

Expand Down
23 changes: 23 additions & 0 deletions ios/sdk/debug/devtools/HippyDevManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#import "HippyUIManager.h"
#import "HippyInspector.h"

NSString *const HippyRuntimeDomainName = @"TDFRuntime";
NSString *const HippyRuntimeMethodUpdateContextInfo = @"updateContextInfo";

@interface HippyDevManager ()<HippyDevClientProtocol> {
HippyDevWebSocketClient *_devWSClient;
HippyInspector *_inspector;
Expand All @@ -49,10 +52,30 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge devInfo:(HippyDevInfo *)dev
clientId:clientId];
_devWSClient.delegate = self;
_inspector = [[HippyInspector alloc] initWithDevManager:self];
self.contextName = contextName;
}
return self;
}

- (void)devClientDidConnect:(HippyDevWebSocketClient *)devClient {
[self updateContextInfoWithName:self.contextName];
}

- (void)updateContextInfoWithName:(NSString *)contextName {
NSString *methodName = [NSString stringWithFormat:@"%@.%@", HippyRuntimeDomainName, HippyRuntimeMethodUpdateContextInfo];
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
NSString *hostVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

NSDictionary *params = @{
@"contextName": contextName ? : @"",
@"bundleId": bundleId ? : @"Unknown",
@"hostVersion": hostVersion ? : @"",
@"sdkVersion": _HippySDKVersion
};
[_inspector sendDataToFrontendWithMethod:methodName
params:params];
}

- (void)sendDataToFrontendWithData:(NSString *)dataString {
if (DevWebSocketState_OPEN == _devWSClient.state) {
[_devWSClient sendData:dataString];
Expand Down

0 comments on commit edfca67

Please sign in to comment.