Forward VM version to inspector

Reviewed By: bnham

Differential Revision: D6938018

fbshipit-source-id: c79853ddf835acab86a16ebd539874d29d3aa60a
This commit is contained in:
Paco Estevez Garcia 2018-02-13 08:06:43 -08:00 committed by Facebook Github Bot
parent b1d8af48ae
commit ad2d9e7fab
9 changed files with 30 additions and 14 deletions

View File

@ -15,6 +15,7 @@
@interface RCTInspectorPage : NSObject @interface RCTInspectorPage : NSObject
@property (nonatomic, readonly) NSInteger id; @property (nonatomic, readonly) NSInteger id;
@property (nonatomic, readonly) NSString *title; @property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) NSString *vm;
@end @end
@interface RCTInspector : NSObject @interface RCTInspector : NSObject

View File

@ -38,9 +38,11 @@ private:
@interface RCTInspectorPage () { @interface RCTInspectorPage () {
NSInteger _id; NSInteger _id;
NSString *_title; NSString *_title;
NSString *_vm;
} }
- (instancetype)initWithId:(NSInteger)id - (instancetype)initWithId:(NSInteger)id
title:(NSString *)title; title:(NSString *)title
vm:(NSString *)vm;
@end @end
@interface RCTInspectorLocalConnection () { @interface RCTInspectorLocalConnection () {
@ -64,7 +66,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
NSMutableArray<RCTInspectorPage *> *array = [NSMutableArray arrayWithCapacity:pages.size()]; NSMutableArray<RCTInspectorPage *> *array = [NSMutableArray arrayWithCapacity:pages.size()];
for (size_t i = 0; i < pages.size(); i++) { for (size_t i = 0; i < pages.size(); i++) {
RCTInspectorPage *pageWrapper = [[RCTInspectorPage alloc] initWithId:pages[i].id RCTInspectorPage *pageWrapper = [[RCTInspectorPage alloc] initWithId:pages[i].id
title:@(pages[i].title.c_str())]; title:@(pages[i].title.c_str())
vm:@(pages[i].vm.c_str())];
[array addObject:pageWrapper]; [array addObject:pageWrapper];
} }
@ -86,10 +89,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (instancetype)initWithId:(NSInteger)id - (instancetype)initWithId:(NSInteger)id
title:(NSString *)title title:(NSString *)title
vm:(NSString *)vm
{ {
if (self = [super init]) { if (self = [super init]) {
_id = id; _id = id;
_title = title; _title = title;
_vm = vm;
} }
return self; return self;
} }

View File

@ -155,6 +155,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
@"id": [@(page.id) stringValue], @"id": [@(page.id) stringValue],
@"title": page.title, @"title": page.title,
@"app": [[NSBundle mainBundle] bundleIdentifier], @"app": [[NSBundle mainBundle] bundleIdentifier],
@"vm": page.vm,
@"isLastBundleDownloadSuccess": bundleStatus == nil @"isLastBundleDownloadSuccess": bundleStatus == nil
? [NSNull null] ? [NSNull null]
: @(bundleStatus.isLastBundleDownloadSuccess), : @(bundleStatus.isLastBundleDownloadSuccess),

View File

@ -51,6 +51,7 @@ public class Inspector {
public static class Page { public static class Page {
private final int mId; private final int mId;
private final String mTitle; private final String mTitle;
private final String mVM;
public int getId() { public int getId() {
return mId; return mId;
@ -60,6 +61,10 @@ public class Inspector {
return mTitle; return mTitle;
} }
public String getVM() {
return mVM;
}
@Override @Override
public String toString() { public String toString() {
return "Page{" + return "Page{" +
@ -69,9 +74,10 @@ public class Inspector {
} }
@DoNotStrip @DoNotStrip
private Page(int id, String title) { private Page(int id, String title, String vm) {
mId = id; mId = id;
mTitle = title; mTitle = title;
mVM = vm;
} }
} }

View File

@ -154,6 +154,7 @@ public class InspectorPackagerConnection {
jsonPage.put("id", String.valueOf(page.getId())); jsonPage.put("id", String.valueOf(page.getId()));
jsonPage.put("title", page.getTitle()); jsonPage.put("title", page.getTitle());
jsonPage.put("app", mPackageName); jsonPage.put("app", mPackageName);
jsonPage.put("vm", page.getVM());
jsonPage.put("isLastBundleDownloadSuccess", bundleStatus.isLastDownloadSucess); jsonPage.put("isLastBundleDownloadSuccess", bundleStatus.isLastDownloadSucess);
jsonPage.put("bundleUpdateTimestamp", bundleStatus.updateTimestamp); jsonPage.put("bundleUpdateTimestamp", bundleStatus.updateTimestamp);
array.put(jsonPage); array.put(jsonPage);

View File

@ -28,9 +28,9 @@ private:
} }
jni::local_ref<JPage::javaobject> JPage::create(int id, const std::string& title) { jni::local_ref<JPage::javaobject> JPage::create(int id, const std::string& title, const std::string& vm) {
static auto constructor = javaClassStatic()->getConstructor<JPage::javaobject(jint, jni::local_ref<jni::JString>)>(); static auto constructor = javaClassStatic()->getConstructor<JPage::javaobject(jint, jni::local_ref<jni::JString>, jni::local_ref<jni::JString>)>();
return javaClassStatic()->newObject(constructor, id, jni::make_jstring(title)); return javaClassStatic()->newObject(constructor, id, jni::make_jstring(title), jni::make_jstring(vm));
} }
void JRemoteConnection::onMessage(const std::string& message) const { void JRemoteConnection::onMessage(const std::string& message) const {
@ -70,7 +70,7 @@ jni::local_ref<jni::JArrayClass<JPage::javaobject>> JInspector::getPages() {
std::vector<InspectorPage> pages = inspector_->getPages(); std::vector<InspectorPage> pages = inspector_->getPages();
auto array = jni::JArrayClass<JPage::javaobject>::newArray(pages.size()); auto array = jni::JArrayClass<JPage::javaobject>::newArray(pages.size());
for (size_t i = 0; i < pages.size(); i++) { for (size_t i = 0; i < pages.size(); i++) {
(*array)[i] = JPage::create(pages[i].id, pages[i].title); (*array)[i] = JPage::create(pages[i].id, pages[i].title, pages[i].vm);
} }
return array; return array;
} }

View File

@ -16,7 +16,7 @@ class JPage : public jni::JavaClass<JPage> {
public: public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/Inspector$Page;"; static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/Inspector$Page;";
static jni::local_ref<JPage::javaobject> create(int id, const std::string& title); static jni::local_ref<JPage::javaobject> create(int id, const std::string& title, const std::string& vm);
}; };
class JRemoteConnection : public jni::JavaClass<JRemoteConnection> { class JRemoteConnection : public jni::JavaClass<JRemoteConnection> {

View File

@ -11,6 +11,7 @@
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include <tuple>
namespace facebook { namespace facebook {
namespace react { namespace react {
@ -27,7 +28,7 @@ namespace {
class InspectorImpl : public IInspector { class InspectorImpl : public IInspector {
public: public:
int addPage(const std::string& title, ConnectFunc connectFunc) override; int addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) override;
void removePage(int pageId) override; void removePage(int pageId) override;
std::vector<InspectorPage> getPages() const override; std::vector<InspectorPage> getPages() const override;
@ -38,15 +39,15 @@ class InspectorImpl : public IInspector {
private: private:
mutable std::mutex mutex_; mutable std::mutex mutex_;
int nextPageId_{1}; int nextPageId_{1};
std::unordered_map<int, std::string> titles_; std::unordered_map<int, std::tuple<std::string, std::string>> titles_;
std::unordered_map<int, ConnectFunc> connectFuncs_; std::unordered_map<int, ConnectFunc> connectFuncs_;
}; };
int InspectorImpl::addPage(const std::string& title, ConnectFunc connectFunc) { int InspectorImpl::addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
int pageId = nextPageId_++; int pageId = nextPageId_++;
titles_[pageId] = title; titles_[pageId] = std::make_tuple(title, vm);
connectFuncs_[pageId] = std::move(connectFunc); connectFuncs_[pageId] = std::move(connectFunc);
return pageId; return pageId;
@ -64,7 +65,7 @@ std::vector<InspectorPage> InspectorImpl::getPages() const {
std::vector<InspectorPage> inspectorPages; std::vector<InspectorPage> inspectorPages;
for (auto& it : titles_) { for (auto& it : titles_) {
inspectorPages.push_back(InspectorPage{it.first, it.second}); inspectorPages.push_back(InspectorPage{it.first, std::get<0>(it.second), std::get<1>(it.second)});
} }
return inspectorPages; return inspectorPages;

View File

@ -25,6 +25,7 @@ class IDestructible {
struct InspectorPage { struct InspectorPage {
const int id; const int id;
const std::string title; const std::string title;
const std::string vm;
}; };
/// IRemoteConnection allows the VM to send debugger messages to the client. /// IRemoteConnection allows the VM to send debugger messages to the client.
@ -52,7 +53,7 @@ class IInspector : public IDestructible {
virtual ~IInspector() = 0; virtual ~IInspector() = 0;
/// addPage is called by the VM to add a page to the list of debuggable pages. /// addPage is called by the VM to add a page to the list of debuggable pages.
virtual int addPage(const std::string& title, ConnectFunc connectFunc) = 0; virtual int addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) = 0;
/// removePage is called by the VM to remove a page from the list of /// removePage is called by the VM to remove a page from the list of
/// debuggable pages. /// debuggable pages.