Send and receive current debugger mode
Summary: Make sure mobile client and sonar desktop app keep debugger mode in sync Desktop client listens to available modes and currently selected mode which is what we use here. Later we can tweak the logic to try to restore last mode if desktop or mobile clients crash / disconnect etc Reviewed By: lblasa Differential Revision: D49384358 fbshipit-source-id: 5bc1f4240253b68a746dfa5feba4b352f4e261a2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
60364eadca
commit
3f0e1f76d5
@@ -8,6 +8,7 @@
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "UIDTraversalMode.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -16,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface UIDInitEvent : NSObject
|
||||
|
||||
@property(nonatomic) NSUInteger rootId;
|
||||
@property(nonatomic) UIDTraversalMode currentTraversalMode;
|
||||
@property(nonatomic, strong)
|
||||
NSArray<UIDFrameworkEventMetadata*>* frameworkEventMetadata;
|
||||
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import "FlipperKitUIDebuggerPlugin.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <FlipperKit/FlipperClient.h>
|
||||
#import <FlipperKit/FlipperConnection.h>
|
||||
#import <FlipperKit/FlipperResponder.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "Core/UIDContext.h"
|
||||
|
||||
@@ -20,6 +19,8 @@
|
||||
#import "Observer/UIDTreeObserverFactory.h"
|
||||
#import "Observer/UIDTreeObserverManager.h"
|
||||
|
||||
#import "UIDTraversalMode.h"
|
||||
|
||||
@implementation FlipperKitUIDebuggerPlugin {
|
||||
UIDContext* _context;
|
||||
}
|
||||
@@ -49,7 +50,6 @@
|
||||
}
|
||||
|
||||
_context.connection = connection;
|
||||
|
||||
[[UIDTreeObserverManager shared] startWithContext:_context];
|
||||
|
||||
NSSet<id<UIDConnectionListener>>* connectionListeners =
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_CLOSED_ENUM(NSInteger, UIDTraversalMode) {
|
||||
UIDTraversalModeViewHierarchy,
|
||||
UIDTraversalModeAccessibilityHierarchy,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
UIDTraversalMode UIDTraversalModeFromString(NSString* string);
|
||||
NSString* NSStringFromUIDTraversalMode(UIDTraversalMode mode);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import "UIDTraversalMode.h"
|
||||
|
||||
static NSString* kUIDTraversalModeViewHierarchyValue = @"view-hierarchy";
|
||||
|
||||
static NSString* kUIDTraversalModeAccessibilityHierarchyValue =
|
||||
@"accessibility-hierarchy";
|
||||
|
||||
UIDTraversalMode UIDTraversalModeFromString(NSString* string) {
|
||||
if ([string isEqualToString:kUIDTraversalModeAccessibilityHierarchyValue]) {
|
||||
return UIDTraversalModeAccessibilityHierarchy;
|
||||
}
|
||||
return UIDTraversalModeViewHierarchy;
|
||||
}
|
||||
|
||||
NSString* NSStringFromUIDTraversalMode(UIDTraversalMode mode) {
|
||||
switch (mode) {
|
||||
case UIDTraversalModeViewHierarchy:
|
||||
return kUIDTraversalModeViewHierarchyValue;
|
||||
case UIDTraversalModeAccessibilityHierarchy:
|
||||
return kUIDTraversalModeAccessibilityHierarchyValue;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import <FlipperKitUIDebuggerPlugin/UIDTraversalMode.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@@ -17,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
+ (instancetype)shared;
|
||||
|
||||
@property(nonatomic, assign) UIDTraversalMode traversalMode;
|
||||
|
||||
- (void)startWithContext:(UIDContext*)context;
|
||||
- (void)stop;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
_queue =
|
||||
dispatch_queue_create("ui-debugger.background", DISPATCH_QUEUE_SERIAL);
|
||||
_context = nil;
|
||||
_traversalMode = UIDTraversalModeViewHierarchy;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -54,6 +55,19 @@
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (void)setTraversalMode:(UIDTraversalMode)traversalMode {
|
||||
if (_traversalMode == traversalMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// trigger another pass
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self->_rootObserver processNode:self->_context.application
|
||||
withSnapshot:YES
|
||||
withContext:self->_context];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)startWithContext:(UIDContext*)context {
|
||||
_context = context;
|
||||
_context.updateDigester = self;
|
||||
@@ -69,6 +83,18 @@
|
||||
[_rootObserver subscribe:_context.application];
|
||||
|
||||
[_context.frameworkEventManager enable];
|
||||
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
[_context.connection
|
||||
receive:@"onTraversalModeChange"
|
||||
withBlock:^(NSDictionary* data, id<FlipperResponder> responder) {
|
||||
NSString* _Nullable maybeMode =
|
||||
[data[@"mode"] isKindOfClass:NSString.class] ? data[@"mode"] : nil;
|
||||
if (maybeMode == nil) {
|
||||
return;
|
||||
}
|
||||
weakSelf.traversalMode = UIDTraversalModeFromString(maybeMode);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)stop {
|
||||
@@ -86,6 +112,7 @@
|
||||
UIDInitEvent* init = [UIDInitEvent new];
|
||||
init.rootId = [descriptor identifierForNode:_context.application];
|
||||
init.frameworkEventMetadata = [_context.frameworkEventManager eventsMetadata];
|
||||
init.currentTraversalMode = _traversalMode;
|
||||
|
||||
[_context.connection send:[UIDInitEvent name] withRawParams:UID_toJSON(init)];
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#import "NSArray+Foundation.h"
|
||||
#import "UIDInitEvent+Foundation.h"
|
||||
#import "UIDTraversalMode.h"
|
||||
|
||||
FB_LINKABLE(UIDInitEvent_Foundation)
|
||||
@implementation UIDInitEvent (Foundation)
|
||||
@@ -19,6 +20,12 @@ FB_LINKABLE(UIDInitEvent_Foundation)
|
||||
@"frameworkEventMetadata" : self.frameworkEventMetadata
|
||||
? [self.frameworkEventMetadata toFoundation]
|
||||
: @[],
|
||||
@"supportedTraversalModes" : @[
|
||||
NSStringFromUIDTraversalMode(UIDTraversalModeViewHierarchy),
|
||||
NSStringFromUIDTraversalMode(UIDTraversalModeAccessibilityHierarchy),
|
||||
],
|
||||
@"currentTraversalMode" :
|
||||
NSStringFromUIDTraversalMode(self.currentTraversalMode),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user