-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.xm
205 lines (187 loc) · 14.1 KB
/
Tweak.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
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
#import <UIKit/UIKit.h>
@protocol WFCloudKitItem
@end
@protocol WFLoggableObject
@end
@protocol WFNaming
@end
@interface WFRecord : NSObject <NSCopying>
@end
@interface WFWorkflowRecord : WFRecord <WFNaming>
@property (copy, nonatomic) NSArray *actions; // ivar: _actions
@property (copy, nonatomic) NSString *minimumClientVersion; // ivar: _minimumClientVersion
@end
@interface WFSharedShortcut : NSObject <WFCloudKitItem, WFLoggableObject>
@property (retain, nonatomic) WFWorkflowRecord *workflowRecord; // ivar: _workflowRecord
-(id)workflowRecord;
@end
%hook WFSharedShortcut
-(id)workflowRecord {
id rettype = %orig;
NSArray *origShortcutActions = (NSArray *)[rettype actions];
NSMutableArray *newMutableShortcutActions = [origShortcutActions mutableCopy];
NSMutableDictionary *conditionalList = [[NSMutableDictionary alloc]init];
NSMutableDictionary *repeatList = [[NSMutableDictionary alloc]init];
int shortcutActionsObjectIndex = 0;
for (id shortcutActionsObject in origShortcutActions) {
if ([shortcutActionsObject isKindOfClass:[NSDictionary class]]){
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionIdentifier"] isEqualToString:@"is.workflow.actions.conditional"]) {
if ([shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]) {
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]) {
if ([conditionalList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]) {
//GroupingIdentifier in conditionalList already
//check the WFControlFlowMode, if @"2" after endif so remove conditional, @"1" needs WFControlFlowMode to be 2, if @"0" needs WFControlFlowMode to be 1 or 2
if ([[conditionalList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]integerValue] == 0) {
if (([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 1) || ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 2)) {
[conditionalList setObject:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"] forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
} else if ([[conditionalList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]integerValue] == 1) {
if ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 2) {
[conditionalList setObject:@"2" forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
} else {
//if @"2" or anything else remove
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
} else {
//check WFControlFlowMode and add if's GroupingIdentifier if no exist
if ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 0) {
[conditionalList setObject:@"0" forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
//strip conditional action from shortcut if bad WFControlFlowMode
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
}
}
}
} else {
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionIdentifier"] isEqualToString:@"is.workflow.actions.repeat.each"]) {
if ([shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]) {
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]) {
if ([repeatList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]) {
//GroupingIdentifier in repeatList already
//check the WFControlFlowMode, if @"2" after end so remove conditional, if @"0" needs WFControlFlowMode to be 2
if ([[repeatList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]integerValue] == 0) {
if (([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 1)) {
[repeatList setObject:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"] forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
}
} else {
//check WFControlFlowMode and add if's GroupingIdentifier if no exist
[repeatList setObject:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"] forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
if ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 0) {
//[repeatList setObject:@"0" forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
//strip repeat until action from shortcut if bad WFControlFlowMode
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
}
}
}
}
}
}
shortcutActionsObjectIndex++;
}
shortcutActionsObjectIndex = 0;
[rettype setActions:newMutableShortcutActions];
return rettype;
}
%end
%hook WFExtractShortcutResult
-(id)record {
id rettype = %orig;
NSArray *origShortcutActions = (NSArray *)[rettype actions];
NSMutableArray *newMutableShortcutActions = [origShortcutActions mutableCopy];
NSMutableDictionary *conditionalList = [[NSMutableDictionary alloc]init];
NSMutableDictionary *repeatList = [[NSMutableDictionary alloc]init];
int shortcutActionsObjectIndex = 0;
for (id shortcutActionsObject in origShortcutActions) {
if ([shortcutActionsObject isKindOfClass:[NSDictionary class]]){
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionIdentifier"] isEqualToString:@"is.workflow.actions.conditional"]) {
if ([shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]) {
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]) {
if ([conditionalList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]) {
//GroupingIdentifier in conditionalList already
//check the WFControlFlowMode, if @"2" after endif so remove conditional, @"1" needs WFControlFlowMode to be 2, if @"0" needs WFControlFlowMode to be 1 or 2
if ([[conditionalList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]integerValue] == 0) {
if (([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 1) || ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 2)) {
[conditionalList setObject:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"] forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
} else if ([[conditionalList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]integerValue] == 1) {
if ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 2) {
[conditionalList setObject:@"2" forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
} else {
//if @"2" or anything else remove
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
} else {
//check WFControlFlowMode and add if's GroupingIdentifier if no exist
if ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 0) {
[conditionalList setObject:@"0" forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
//strip conditional action from shortcut if bad WFControlFlowMode
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
}
}
}
} else {
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionIdentifier"] isEqualToString:@"is.workflow.actions.repeat.each"]) {
if ([shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]) {
if ([[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]) {
if ([repeatList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]) {
//GroupingIdentifier in repeatList already
//check the WFControlFlowMode, if @"2" after end so remove conditional, if @"0" needs WFControlFlowMode to be 2
if ([[repeatList objectForKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]]integerValue] == 0) {
if (([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 1)) {
[repeatList setObject:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"] forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
}
} else {
//check WFControlFlowMode and add if's GroupingIdentifier if no exist
[repeatList setObject:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"] forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
if ([[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"WFControlFlowMode"]integerValue] == 0) {
//[repeatList setObject:@"0" forKey:[[shortcutActionsObject objectForKey:@"WFWorkflowActionParameters"]objectForKey:@"GroupingIdentifier"]];
} else {
//strip repeat until action from shortcut if bad WFControlFlowMode
[newMutableShortcutActions removeObjectAtIndex:shortcutActionsObjectIndex];
shortcutActionsObjectIndex--;
}
}
}
}
}
}
}
shortcutActionsObjectIndex++;
}
shortcutActionsObjectIndex = 0;
[rettype setActions:newMutableShortcutActions];
return rettype;
}
%end