forked from k3a/AssistantExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAEDevHelper.xm
70 lines (54 loc) · 2.14 KB
/
AEDevHelper.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#import "shared.h"
#import "AESpringBoardMsgCenter.h"
@interface AEAssistantViewHelper : NSObject
@end
@implementation AEAssistantViewHelper
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
NSString* text = [[alertView textFieldAtIndex:0] text];
if (text && [text length])
{
IPCCall(@"me.k3a.AssistantExtensions", @"ActivateAssistant", nil);
IPCCall(@"me.k3a.AssistantExtensions", @"SubmitQuery", [NSDictionary dictionaryWithObjectsAndKeys:text,@"query",nil]);
}
}
}
-(void)hideTapped
{
IPCCall(@"me.k3a.AssistantExtensions", @"DismissAssistant", nil);
}
-(void)queryTapped
{
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Query" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
[dialog release];
}
@end
static AEAssistantViewHelper* s_aeHelper = nil;
%hook SBAssistantView
- (id)initWithFrame:(struct CGRect)rect
{
id ret = %orig;
if (!s_aeHelper) s_aeHelper = [AEAssistantViewHelper new];
NSNumber* debugButtons = [[AESpringBoardMsgCenter sharedInstance] prefForKey:@"debugButtons"];
if (debugButtons && [debugButtons boolValue])
{
UIView* _contentView = nil;
object_getInstanceVariable(self, "_contentView", (void**)&_contentView);
UIButton* btnHide = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnHide setFrame:CGRectMake(20,440, 50, 32)];
[btnHide setTitle:@"Hide" forState:UIControlStateNormal];
[btnHide addTarget:s_aeHelper action:@selector(hideTapped) forControlEvents:UIControlEventTouchUpInside];
[_contentView addSubview:btnHide];
UIButton* btnQuery = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnQuery setFrame:CGRectMake(20,400, 50, 32)];
[btnQuery setTitle:@"Query" forState:UIControlStateNormal];
[btnQuery addTarget:s_aeHelper action:@selector(queryTapped) forControlEvents:UIControlEventTouchUpInside];
[_contentView addSubview:btnQuery];
}
return ret;
}
%end