Run CLANGFORMAT on plugins
Summary: This diff runs CLANGFORMAT lint on plugins. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT. Ran `arc lint -a --paths-cmd "find ./iOS/Plugins -type f" --verbose` Reviewed By: passy Differential Revision: D19942173 fbshipit-source-id: 8b975b0a344df073b02d69cd1f9ee5629af2799d
This commit is contained in:
committed by
Facebook Github Bot
parent
a19a430eee
commit
e8b20d5b15
@@ -10,15 +10,15 @@
|
||||
#import <FlipperKit/FlipperResponder.h>
|
||||
#import "FKUserDefaultsSwizzleUtility.h"
|
||||
|
||||
static NSString *const kStandardUserDefaultsName = @"Standard UserDefaults";
|
||||
static NSString *const kAppSuiteUserDefaultsName = @"App Suite UserDefaults";
|
||||
static NSString* const kStandardUserDefaultsName = @"Standard UserDefaults";
|
||||
static NSString* const kAppSuiteUserDefaultsName = @"App Suite UserDefaults";
|
||||
|
||||
@interface FKUserDefaultsPlugin ()
|
||||
@property (nonatomic, strong) id<FlipperConnection> flipperConnection;
|
||||
@property (nonatomic, strong) NSUserDefaults *standardUserDefaults;
|
||||
@property (nonatomic, strong) NSUserDefaults *appSuiteUserDefaults;
|
||||
@property (nonatomic, copy) NSString *key;
|
||||
@property (nonatomic, copy) NSString *suiteName;
|
||||
@property(nonatomic, strong) id<FlipperConnection> flipperConnection;
|
||||
@property(nonatomic, strong) NSUserDefaults* standardUserDefaults;
|
||||
@property(nonatomic, strong) NSUserDefaults* appSuiteUserDefaults;
|
||||
@property(nonatomic, copy) NSString* key;
|
||||
@property(nonatomic, copy) NSString* suiteName;
|
||||
@end
|
||||
|
||||
@implementation FKUserDefaultsPlugin
|
||||
@@ -27,89 +27,106 @@ static NSString *const kAppSuiteUserDefaultsName = @"App Suite UserDefaults";
|
||||
if (self = [super init]) {
|
||||
_standardUserDefaults = [NSUserDefaults standardUserDefaults];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[FKUserDefaultsSwizzleUtility swizzleSelector:@selector(setObject:forKey:) class:[NSUserDefaults class] block:^(NSInvocation * _Nonnull invocation) {
|
||||
__unsafe_unretained id firstArg = nil;
|
||||
__unsafe_unretained id secondArg = nil;
|
||||
[invocation getArgument:&firstArg atIndex:2];
|
||||
[invocation getArgument:&secondArg atIndex:3];
|
||||
[invocation invoke];
|
||||
[weakSelf userDefaults:([invocation.target isKindOfClass:[NSUserDefaults class]] ? invocation.target : nil)
|
||||
changedWithValue:firstArg
|
||||
key:secondArg];
|
||||
}];
|
||||
[FKUserDefaultsSwizzleUtility
|
||||
swizzleSelector:@selector(setObject:forKey:)
|
||||
class:[NSUserDefaults class]
|
||||
block:^(NSInvocation* _Nonnull invocation) {
|
||||
__unsafe_unretained id firstArg = nil;
|
||||
__unsafe_unretained id secondArg = nil;
|
||||
[invocation getArgument:&firstArg atIndex:2];
|
||||
[invocation getArgument:&secondArg atIndex:3];
|
||||
[invocation invoke];
|
||||
[weakSelf userDefaults:([invocation.target
|
||||
isKindOfClass:[NSUserDefaults
|
||||
class]]
|
||||
? invocation.target
|
||||
: nil)
|
||||
changedWithValue:firstArg
|
||||
key:secondArg];
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithSuiteName:(NSString *)suiteName {
|
||||
if (self = [self init]) {
|
||||
_suiteName = suiteName;
|
||||
if (_suiteName) {
|
||||
_appSuiteUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:_suiteName];
|
||||
}
|
||||
- (instancetype)initWithSuiteName:(NSString*)suiteName {
|
||||
if (self = [self init]) {
|
||||
_suiteName = suiteName;
|
||||
if (_suiteName) {
|
||||
_appSuiteUserDefaults =
|
||||
[[NSUserDefaults alloc] initWithSuiteName:_suiteName];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)didConnect:(id<FlipperConnection>)connection {
|
||||
self.flipperConnection = connection;
|
||||
[connection receive:@"getAllSharedPreferences" withBlock:^(NSDictionary *params, id<FlipperResponder> responder) {
|
||||
NSMutableDictionary *userDefaults = [NSMutableDictionary new];
|
||||
userDefaults[kStandardUserDefaultsName] = [self.standardUserDefaults dictionaryRepresentation];
|
||||
if (self.appSuiteUserDefaults) {
|
||||
userDefaults[kAppSuiteUserDefaultsName] = [self.appSuiteUserDefaults dictionaryRepresentation];
|
||||
}
|
||||
[responder success:userDefaults];
|
||||
}];
|
||||
|
||||
[connection receive:@"setSharedPreference" withBlock:^(NSDictionary *params , id<FlipperResponder> responder) {
|
||||
NSUserDefaults *sharedPreferences = [self sharedPreferencesForParams:params];
|
||||
NSString *preferenceName = params[@"preferenceName"];
|
||||
[sharedPreferences setObject:params[@"preferenceValue"] forKey:preferenceName];
|
||||
[responder success:[sharedPreferences dictionaryRepresentation]];
|
||||
}];
|
||||
self.flipperConnection = connection;
|
||||
[connection receive:@"getAllSharedPreferences"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder) {
|
||||
NSMutableDictionary* userDefaults = [NSMutableDictionary new];
|
||||
userDefaults[kStandardUserDefaultsName] =
|
||||
[self.standardUserDefaults dictionaryRepresentation];
|
||||
if (self.appSuiteUserDefaults) {
|
||||
userDefaults[kAppSuiteUserDefaultsName] =
|
||||
[self.appSuiteUserDefaults dictionaryRepresentation];
|
||||
}
|
||||
[responder success:userDefaults];
|
||||
}];
|
||||
|
||||
[connection receive:@"setSharedPreference"
|
||||
withBlock:^(NSDictionary* params, id<FlipperResponder> responder) {
|
||||
NSUserDefaults* sharedPreferences =
|
||||
[self sharedPreferencesForParams:params];
|
||||
NSString* preferenceName = params[@"preferenceName"];
|
||||
[sharedPreferences setObject:params[@"preferenceValue"]
|
||||
forKey:preferenceName];
|
||||
[responder success:[sharedPreferences dictionaryRepresentation]];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)didDisconnect {
|
||||
self.flipperConnection = nil;
|
||||
self.flipperConnection = nil;
|
||||
}
|
||||
|
||||
- (NSString *)identifier {
|
||||
return @"Preferences";
|
||||
- (NSString*)identifier {
|
||||
return @"Preferences";
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (NSUserDefaults *)sharedPreferencesForParams:(NSDictionary *)params {
|
||||
NSString *const sharedPreferencesNameKey = @"sharedPreferencesName";
|
||||
- (NSUserDefaults*)sharedPreferencesForParams:(NSDictionary*)params {
|
||||
NSString* const sharedPreferencesNameKey = @"sharedPreferencesName";
|
||||
if (![params[sharedPreferencesNameKey] isKindOfClass:[NSString class]]) {
|
||||
return _standardUserDefaults;
|
||||
}
|
||||
|
||||
NSString *sharedPreferencesName = params[sharedPreferencesNameKey];
|
||||
return ([sharedPreferencesName isEqualToString:kAppSuiteUserDefaultsName]
|
||||
|
||||
NSString* sharedPreferencesName = params[sharedPreferencesNameKey];
|
||||
return (
|
||||
[sharedPreferencesName isEqualToString:kAppSuiteUserDefaultsName]
|
||||
? _appSuiteUserDefaults
|
||||
: _standardUserDefaults);
|
||||
}
|
||||
|
||||
- (void)userDefaults:(NSUserDefaults *)userDefaults changedWithValue:(id)value key:(NSString *)key {
|
||||
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;
|
||||
NSString *intervalStr = [NSString stringWithFormat:@"%f", interval];
|
||||
NSMutableDictionary *params = [@{@"name":key,
|
||||
@"time":intervalStr
|
||||
} mutableCopy];
|
||||
|
||||
if (!value) {
|
||||
[params setObject:@"YES" forKey:@"deleted"];
|
||||
} else {
|
||||
[params setObject:value forKey:@"value"];
|
||||
}
|
||||
|
||||
NSString *sharedPreferencesName = (userDefaults == _standardUserDefaults
|
||||
? kStandardUserDefaultsName
|
||||
: kAppSuiteUserDefaultsName);
|
||||
[params setObject:sharedPreferencesName forKey:@"preferences"];
|
||||
[self.flipperConnection send:@"sharedPreferencesChange" withParams:[params copy]];
|
||||
- (void)userDefaults:(NSUserDefaults*)userDefaults
|
||||
changedWithValue:(id)value
|
||||
key:(NSString*)key {
|
||||
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;
|
||||
NSString* intervalStr = [NSString stringWithFormat:@"%f", interval];
|
||||
NSMutableDictionary* params =
|
||||
[@{@"name" : key, @"time" : intervalStr} mutableCopy];
|
||||
|
||||
if (!value) {
|
||||
[params setObject:@"YES" forKey:@"deleted"];
|
||||
} else {
|
||||
[params setObject:value forKey:@"value"];
|
||||
}
|
||||
|
||||
NSString* sharedPreferencesName =
|
||||
(userDefaults == _standardUserDefaults ? kStandardUserDefaultsName
|
||||
: kAppSuiteUserDefaultsName);
|
||||
[params setObject:sharedPreferencesName forKey:@"preferences"];
|
||||
[self.flipperConnection send:@"sharedPreferencesChange"
|
||||
withParams:[params copy]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user