This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
AEContext.mm
241 lines (200 loc) · 7.27 KB
/
AEContext.mm
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//
// AEContext.m
// AssistantExtensions
//
// Created by Kexik on 12/29/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "AEContext.h"
#import "AESupport.h"
#import "AEExtension.h"
#import "AESpringBoardMsgCenter.h"
#import "shared.h"
#import <objc/runtime.h>
@implementation AEContext
static NSMutableDictionary* s_contexts = nil;
-(AEContext*)initWithRefId:(NSString*)refId
{
if ( (self = [super init]) )
{
_referenceId = [refId copy];
if (!_referenceId) _referenceId = [@"00000000-0000-0000-0000-000000000000" copy];
_completed = NO;
_object = nil;
NSLog(@"AE: A new context for request %@.", refId);
}
return self;
}
+(AEContext*)contextWithRefId:(NSString*)refId
{
if (!s_contexts) s_contexts = [[NSMutableDictionary alloc] init];
if (!refId) refId = @"00000000-0000-0000-0000-000000000000";
AEContext* ctx = [s_contexts objectForKey:refId];
if (ctx) return ctx;
ctx = [[[AEContext alloc] initWithRefId:refId] autorelease];
if (!ctx) return nil;
[s_contexts setObject:ctx forKey:refId];
return ctx;
}
-(void)dealloc
{
NSLog(@"AE: Context for request %@ released.", _referenceId);
[_object release];
[_referenceId release];
[super dealloc];
}
-(void)setObject:(NSObject<SECommand>*)obj
{
[_object autorelease];
_object = [obj retain];
}
-(SOObject*)createObjectDict:(NSString*)className group:(NSString*)group properties:(NSDictionary*)props
{
return SOCreateObjectDict(group, className, [[props mutableCopy] autorelease]);
}
-(SOObject*)createAssistantUtteranceView:(NSString*)text
{
return [self createAssistantUtteranceView:text speakableText:text dialogIdentifier:@"Misc#Ident"];
}
-(SOObject*)createAssistantUtteranceView:(NSString*)text speakableText:(NSString*)speakableText
{
return [self createAssistantUtteranceView:text speakableText:speakableText dialogIdentifier:@"Misc#Ident"];
}
-(SOObject*)createAssistantUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogIdentifier:(NSString*)dialogIdentifier
{
return SOCreateAssistantUtteranceView(text, speakableText, dialogIdentifier);
}
-(SOObject*)createSnippet:(NSString*)snippetClass properties:(NSDictionary*)props
{
NSMutableDictionary* lowLevelProps = [NSMutableDictionary dictionaryWithObjectsAndKeys:
props,@"snippetProps", snippetClass,@"snippetClass", nil];
return SOCreateObjectDict(@"me.k3a.ace.extension", @"Snippet", lowLevelProps);
}
-(BOOL)sendAceObject:(NSString*)className group:(NSString*)group properties:(NSDictionary*)props
{
if (_completed)
NSLog(@"SE WARNING: Trying to send an object to already completed request %@!", _referenceId);
NSMutableDictionary* dict = SOCreateAceObjectDict(_referenceId, group, className, [[props mutableCopy] autorelease]);
// listenAfterSpeaking hack!
if ([className isEqualToString:@"AddViews"] && [group isEqualToString:@"com.apple.ace.assistant"])
{
NSArray* views = [props objectForKey:@"views"];
for (NSDictionary* view in views)
{
NSDictionary* props = [view objectForKey:@"properties"];
if ([[props objectForKey:@"listenAfterSpeaking"] boolValue])
{
_listenAfterSpeaking = YES;
break;
}
}
}
// send
return AESendToClient(dict);
}
-(BOOL)sendRequestCompleted
{
NSMutableDictionary* dict = SOCreateAceRequestCompleted(_referenceId);
// send
BOOL ret = AESendToClient(dict);
_completed = TRUE;
NSLog(@"AE: Request %@ completed.", _referenceId);
[s_contexts removeObjectForKey:_referenceId];
RequestCompleted(); // inform AEExtension that it's done
return ret;
}
-(BOOL)sendAddViews:(NSArray*)views
{
return [self sendAddViews:views dialogPhase:@"Completion" scrollToTop:NO temporary:NO];
}
-(BOOL)sendAddViews:(NSArray*)views dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary
{
NSMutableDictionary* dict = SOCreateAceAddViews(_referenceId, views, dialogPhase, scrollToTop, temporary);
// listenAfterSpeaking hack!
for (NSDictionary* view in views)
{
NSDictionary* props = [view objectForKey:@"properties"];
if ([[props objectForKey:@"listenAfterSpeaking"] boolValue])
{
_listenAfterSpeaking = YES;
break;
}
}
// send
return AESendToClient(dict);
}
-(BOOL)sendAddViewsSnippet:(NSString*)snippetClass properties:(NSDictionary*)props
{
return [self sendAddViewsSnippet:snippetClass properties:props dialogPhase:@"Completion" scrollToTop:NO temporary:NO];
}
-(BOOL)sendAddViewsSnippet:(NSString*)snippetClass properties:(NSDictionary*)props dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary
{
if (!props) props = [NSDictionary dictionary];
NSArray* views = [NSArray arrayWithObject:[self createSnippet:snippetClass properties:props]];
return [self sendAddViews:views dialogPhase:dialogPhase scrollToTop:scrollToTop temporary:temporary];
}
-(BOOL)sendAddViewsUtteranceView:(NSString*)text
{
return [self sendAddViewsUtteranceView:text speakableText:text dialogPhase:@"Completion" scrollToTop:NO temporary:NO];
}
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText
{
return [self sendAddViewsUtteranceView:text speakableText:speakableText dialogPhase:@"Completion" scrollToTop:NO temporary:NO];
}
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary
{
NSMutableDictionary* dict = SOCreateAceAddViewsUtteranceView(_referenceId, text, speakableText, dialogPhase, scrollToTop, temporary);
// send
return AESendToClient(dict);
}
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary listenAfterSpeaking:(BOOL)listen
{
NSMutableDictionary* dict = SOCreateAceAddViewsUtteranceView(_referenceId, text, speakableText, dialogPhase, scrollToTop, temporary);
[[dict objectForKey:@"properties"] setObject:[NSNumber numberWithBool:listen] forKey:@"listenAfterSpeaking"];
_listenAfterSpeaking = listen;
// send
return AESendToClient(dict);
}
-(void)dismissAssistant
{
IPCCall(@"me.k3a.AssistantExtensions", @"DismissAssistant", nil);
}
-(SOLocationData)getLocationDataShowReflection:(BOOL)show;
{
return [[AESpringBoardMsgCenter sharedInstance] getLocationData:_referenceId showReflection:show];
}
-(BOOL)sendAceObjectToClient:(SOAceObject*)obj //SINCE 1.0.2
{
return AESendToClient(obj);
}
-(BOOL)sendAceObjectToServer:(SOAceObject*)obj //SINCE 1.0.2
{
return AESendToServer(obj);
}
-(void)blockRestOfRequest //SINCE 1.0.2
{
[[AESpringBoardMsgCenter sharedInstance] ignoreRestOfRequest:_referenceId];
}
-(BOOL)requestHasCompleted
{
return _completed;
}
-(NSObject<SECommand>*)object
{
return _object;
}
-(NSString*)refId
{
return _referenceId;
}
-(BOOL)wasListenAfterSpeaking
{
return _listenAfterSpeaking;
}
-(void)beginExclusiveMode
{
}
-(void)endExclusiveMode
{
}
@end