mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 05:52:58 +00:00
More stubbs on model proxies
This commit is contained in:
@@ -965,8 +965,7 @@
|
|||||||
4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */,
|
4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */,
|
||||||
4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */,
|
4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */,
|
||||||
4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */,
|
4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */,
|
||||||
4CCCD83C1C8DFF20002B77B6 /* MPEntryProxy.h */,
|
4CB44EEE1C972BFD00EE2D60 /* Proxies */,
|
||||||
4CCCD83D1C8DFF20002B77B6 /* MPEntryProxy.m */,
|
|
||||||
);
|
);
|
||||||
name = Model;
|
name = Model;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -1299,6 +1298,15 @@
|
|||||||
name = Protocolls;
|
name = Protocolls;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
4CB44EEE1C972BFD00EE2D60 /* Proxies */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
4CCCD83C1C8DFF20002B77B6 /* MPEntryProxy.h */,
|
||||||
|
4CCCD83D1C8DFF20002B77B6 /* MPEntryProxy.m */,
|
||||||
|
);
|
||||||
|
name = Proxies;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
4CCFA12C1BF0CC7A0078E0A1 /* Databases */ = {
|
4CCFA12C1BF0CC7A0078E0A1 /* Databases */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@interface MPEntryProxy : NSProxy
|
@interface MPEntryProxy : NSProxy
|
||||||
|
|
||||||
|
@property (strong, readonly) KPKEntry *entry;
|
||||||
|
|
||||||
- (instancetype)initWithEntry:(KPKEntry *)entry;
|
- (instancetype)initWithEntry:(KPKEntry *)entry;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,47 +9,92 @@
|
|||||||
#import "MPEntryProxy.h"
|
#import "MPEntryProxy.h"
|
||||||
#import <KeePassKit/KeePassKit.h>
|
#import <KeePassKit/KeePassKit.h>
|
||||||
|
|
||||||
|
@interface MPSubEntryProxy : NSProxy
|
||||||
|
|
||||||
|
@property (weak) MPEntryProxy *entryProxy;
|
||||||
|
@property (nonatomic, readonly) id target;
|
||||||
|
|
||||||
|
- (instancetype)initWithEntryProxy:(MPEntryProxy *)entryProxy;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MPSubEntryProxy
|
||||||
|
|
||||||
|
- (instancetype)initWithEntryProxy:(MPEntryProxy *)entryProxy {
|
||||||
|
_entryProxy = entryProxy;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)target {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface MPAutotypeProxy : MPSubEntryProxy
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MPAutotypeProxy
|
||||||
|
|
||||||
|
- (id)target {
|
||||||
|
return self.entryProxy.entry.autotype;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MPTimeInfoProxy : MPSubEntryProxy
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MPTimeInfoProxy
|
||||||
|
|
||||||
|
- (id)target {
|
||||||
|
return self.entryProxy.entry.timeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
|
||||||
@interface MPEntryProxy ()
|
@interface MPEntryProxy ()
|
||||||
|
|
||||||
@property (strong) KPKEntry *entry;
|
@property (strong) KPKEntry *entry;
|
||||||
@property (strong) NSMutableDictionary *valueStore;
|
@property (strong) KPKEntry *changedEntry;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MPEntryProxy
|
@implementation MPEntryProxy
|
||||||
|
|
||||||
|
- (NSSet *)mutatingSelectors {
|
||||||
|
static NSSet *set;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
set = [NSSet setWithArray:@[ [NSValue valueWithPointer:@selector(addCustomAttribute:)],
|
||||||
|
[NSValue valueWithPointer:@selector(removeCustomAttribute:)],
|
||||||
|
[NSValue valueWithPointer:@selector(addBinary:)],
|
||||||
|
[NSValue valueWithPointer:@selector(removeBinary:)],
|
||||||
|
[NSValue valueWithPointer:@selector(addAssociation:)],
|
||||||
|
[NSValue valueWithPointer:@selector(removeAssociation:)] ]];
|
||||||
|
});
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
- (instancetype)initWithEntry:(KPKEntry *)entry {
|
- (instancetype)initWithEntry:(KPKEntry *)entry {
|
||||||
if(!entry) {
|
if(!entry) {
|
||||||
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:nil userInfo:nil];
|
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:nil userInfo:nil];
|
||||||
}
|
}
|
||||||
_entry = entry;
|
_entry = entry;
|
||||||
_valueStore = [[NSMutableDictionary alloc] init];
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forwardInvocation:(NSInvocation *)invocation {
|
- (void)forwardInvocation:(NSInvocation *)invocation {
|
||||||
NSLog(@"forwardInvocation: %@", NSStringFromSelector(invocation.selector));
|
|
||||||
NSString *seletor = NSStringFromSelector(invocation.selector);
|
NSString *seletor = NSStringFromSelector(invocation.selector);
|
||||||
|
if([[self mutatingSelectors] containsObject:[NSValue valueWithPointer:invocation.selector]]) {
|
||||||
|
NSLog(@"Mutation detected.");
|
||||||
|
}
|
||||||
|
|
||||||
if([seletor hasPrefix:@"set"]) {
|
if([seletor hasPrefix:@"set"]) {
|
||||||
NSLog(@"forwardInvocation: setter detected");
|
NSLog(@"forwardInvocation: setter detected");
|
||||||
NSString *property = [seletor substringFromIndex:3].lowercaseString; // lowercase fist letter!!!
|
|
||||||
if(invocation.methodSignature.numberOfArguments == 3) {
|
|
||||||
id value;
|
|
||||||
[invocation getArgument:&value atIndex:2];
|
|
||||||
NSLog(@"forwardInvocation: captured value %@", value);
|
|
||||||
if(value) {
|
|
||||||
self.valueStore[property] = value;
|
|
||||||
}
|
|
||||||
return; // captures getter, just return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
id change = self.valueStore[seletor.lowercaseString];
|
|
||||||
if(change) {
|
|
||||||
NSLog(@"forwardInvocation: hit cached value. Returning cache!");
|
|
||||||
[invocation setReturnValue:&change];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[invocation invokeWithTarget:self.entry];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user