AssistantPlus/assistant+/AssistantHooks.xm

193 lines
5.4 KiB
Plaintext
Raw Normal View History

2015-03-14 18:24:48 +00:00
#import <Foundation/Foundation.h>
2015-03-14 21:47:16 +00:00
#import "assistantpluspluginmanager/AssistantPlusHeaders.h"
#import "assistantpluspluginmanager/AssistantHeaders.h"
#import "assistantpluspluginmanager/APPluginManager.h"
#import "assistantpluspluginmanager/APSession.h"
2015-03-21 06:07:04 +00:00
#import "assistantpluspluginmanager/APSpringboardUtils.h"
2015-03-14 21:47:16 +00:00
#import <libobjcipc/objcipc.h>
2015-03-14 18:24:48 +00:00
@protocol SAAceSerializable <NSObject>
@end
@interface SBUIPluginController : NSObject
@end
@interface SAUIAppPunchOut : NSObject
@end
@interface SAUIConfirmationOptions : NSObject
@end
static BOOL defaultHandling = YES;
2015-03-15 20:51:49 +00:00
static AFConnection *currConnection;
static APPluginManager *pluginManager;
BOOL shouldHandleRequest(NSString *text, APSession *currSession) {
2015-03-21 06:07:04 +00:00
pluginManager = [[%c(APSpringboardUtils) sharedUtils] getPluginManager];
NSLog(@"Manager: %@", pluginManager);
NSSet *tokens = [NSSet setWithArray:[text componentsSeparatedByString: @" "]];
return [pluginManager handleCommand:text withTokens:tokens withSession:currSession];
2015-03-15 20:51:49 +00:00
}
2015-03-14 18:24:48 +00:00
%hook BasicAceContext
2015-03-15 20:51:49 +00:00
- (Class)classWithClassName:(NSString*)name group:(NSString*)group {
id r;
2015-03-15 20:51:49 +00:00
if ([name isEqualToString:@"SnippetObject"] && [group isEqualToString:@"zaid.assistantplus.plugin"]) {
r = NSClassFromString(@"SAUISnippet");
} else {
r = %orig;
2015-03-15 20:51:49 +00:00
}
return r;
}
%end
2015-03-14 18:24:48 +00:00
2015-03-21 06:07:04 +00:00
%hook SiriUISnippetViewController
-(void)setSnippet:(id)arg1 {
%log;
%orig;
}
%end
2015-03-15 20:51:49 +00:00
%hook SiriUIPluginManager
2015-03-14 18:24:48 +00:00
2015-03-15 20:51:49 +00:00
- (id)transcriptItemForObject:(AceObject*)arg1 {
NSDictionary *properties = [arg1 properties];
if (properties) {
NSString *className = properties[@"snippetClass"];
if (className) {
NSLog(@"AP: Looking for custom snippet: %@", className);
2015-03-21 06:07:04 +00:00
id<APPluginSnippet> customClass = [[NSClassFromString(className) alloc] initWithProperties:properties[@"snippetProps"]];
if ([customClass respondsToSelector:@selector(view)]) {
UIViewController *customVC = (UIViewController*)customClass;
2015-03-15 20:51:49 +00:00
SiriUISnippetViewController *vc = [[%c(SiriUISnippetViewController) alloc] init];
object_setClass(vc, [%c(APPluginSnippetViewController) class]);
[(APPluginSnippetViewController*)vc setCustomView:customVC];
SiriUITranscriptItem *item = [%c(SiriUITranscriptItem) transcriptItemWithAceObject:arg1];
item.viewController = vc;
return item;
} else {
NSLog(@"AP ERROR: %@ did not respond to customView", className);
2015-03-15 20:51:49 +00:00
}
} else {
NSLog(@"AP: No custom class for snippet, going to default!");
2015-03-15 20:51:49 +00:00
}
} else {
NSLog(@"AP ERROR: No properties for snippet, this shouldn't hapepn...");
2015-03-15 20:51:49 +00:00
}
id r = %orig;
return r;
}
2015-03-14 18:24:48 +00:00
2015-03-15 20:51:49 +00:00
%end
2015-03-14 18:24:48 +00:00
%hook AFConnection
- (void)_doCommand:(SAUIAddViews*)arg1 reply:(id)arg2 {
NSLog(@"Doing: %@", arg1);
2015-03-15 20:51:49 +00:00
if ([arg1 respondsToSelector:@selector(views)]) {
NSLog(@"Views: %@", arg1.views);
}
2015-03-14 18:24:48 +00:00
%log;
%orig;
}
- (void)clearContext { %log; %orig; }
2015-03-21 06:07:04 +00:00
- (void)sendReplyCommand:(id)arg1 {
%log;
}
2015-03-14 18:24:48 +00:00
- (void)startRequestWithCorrectedText:(NSString*)text forSpeechIdentifier:(id)arg2 {
NSLog(@"AP: Starting request with corrected text: %@", text);
APSession *currSession = [APSession sessionWithRefId:nil andConnection:self];
if (shouldHandleRequest(text, currSession)) {
NSLog(@"Handling!");
} else {
%orig;
}
}
2015-03-14 18:24:48 +00:00
- (void)startAcousticIDRequestWithOptions:(id)arg1 { %log; %orig; }
- (void)startSpeechPronunciationRequestWithOptions:(id)arg1 pronunciationContext:(id)arg2 { %log; %orig; }
- (void)startSpeechRequestWithOptions:(id)arg1 {
NSLog(@"%@", arg1);
%log;
%orig;
}
- (void)startContinuationRequestWithUserInfo:(id)arg1 { %log; %orig; }
- (void)startDirectActionRequestWithString:(id)arg1 { %log; %orig; }
- (void)startRequestWithText:(NSString*)text {
NSLog(@"AP: Starting request with text: %@", text);
2015-03-14 18:24:48 +00:00
APSession *currSession = [APSession sessionWithRefId:nil andConnection:self];
if (shouldHandleRequest(text, currSession)) {
2015-03-14 18:24:48 +00:00
NSLog(@"Handling!");
} else {
NSLog(@"Default!");
2015-03-14 21:47:16 +00:00
%orig;
2015-03-14 18:24:48 +00:00
}
}
%end
2015-03-21 06:07:04 +00:00
%hook AFUISiriSession
- (void)_requestContextWithCompletion:(id)arg1 {
NSLog(@"%@", arg1);
%log;
%orig;
}
- (void)_requestDidFinishWithError:(id)arg1 {
NSLog(@"%@", arg1);
%log;
%orig;
}
- (void)assistantConnectionRequestFinished:(id)arg1 {
NSLog(@"%@", arg1);
%log;
%orig;
}
- (void)end {
%log;
%orig;
}
%end
2015-03-14 18:24:48 +00:00
%hook AFConnectionClientServiceDelegate
- (void)speechRecognized:(SASSpeechRecognized*)arg1 {
NSMutableString *phraseBuilder = [NSMutableString string];
for (AFSpeechPhrase *currPhrase in arg1.recognition.phrases) {
if (currPhrase.interpretations.count > 0) {
SASInterpretation *currInterpretation = currPhrase.interpretations[0];
if (currInterpretation.tokens.count > 0) {
AFSpeechToken *currToken = currInterpretation.tokens[0];
[phraseBuilder appendString:[NSString stringWithFormat:@"%@ ", currToken.text]];
}
}
}
NSLog(@"AP Starting Speech Query: %@", phraseBuilder);
2015-03-14 18:24:48 +00:00
2015-03-21 06:07:04 +00:00
AFConnection *connection = MSHookIvar<AFConnection*>(self, "_connection");
2015-03-15 20:51:49 +00:00
2015-03-21 06:07:04 +00:00
APSession *currSession = [APSession sessionWithRefId:nil andConnection:connection];
if (shouldHandleRequest(phraseBuilder, currSession)) {
2015-03-15 20:51:49 +00:00
defaultHandling = NO;
NSLog(@"Handling with plugin!");
} else {
defaultHandling = YES;
2015-03-15 20:51:49 +00:00
NSLog(@"Going to default!");
%orig;
2015-03-15 20:51:49 +00:00
}
2015-03-14 18:24:48 +00:00
}
- (void)requestDidFinish{ %log; %orig; }
- (void)requestDidReceiveCommand:(id)arg1 reply:(CDUnknownBlockType*)arg2 {
%log;
if (defaultHandling) {
%orig;
}
}
%end