-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.x
145 lines (111 loc) · 5.78 KB
/
Tweak.x
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
/* How to Hook with Logos
Hooks are written with syntax similar to that of an Objective-C @implementation.
You don't need to #include <substrate.h>, it will be done automatically, as will
the generation of a class list and an automatic constructor.
%hook ClassName
// Hooking a class method
+ (id)sharedInstance {
return %orig;
}
// Hooking an instance method with an argument.
- (void)messageName:(int)argument {
%log; // Write a message about this call, including its class, name and arguments, to the system log.
%orig; // Call through to the original function with its original arguments.
%orig(nil); // Call through to the original function with a custom argument.
// If you use %orig(), you MUST supply all arguments (except for self and _cmd, the automatically generated ones.)
}
// Hooking an instance method with no arguments.
- (id)noArguments {
%log;
id awesome = %orig;
[awesome doSomethingElse];
return awesome;
}
// Always make sure you clean up after yourself; Not doing so could have grave consequences!
%end
*/
@interface EDMGenericWebViewController: UIViewController
@property (strong) UIActivityIndicatorView * indicatorView;
// @property (strong) NSObject *attachment;
-(void)presentShareController:(NSArray *)items barItem:(UIBarButtonItem * _Nullable)barItem;
@end
%hook EDMGenericWebViewController
%property (strong) UIActivityIndicatorView * indicatorView;
%new
-(void)downloadAction:(UIBarButtonItem *)sender {
NSLog(@"EdmodoFixer: Downloading from url: %@", [[self performSelector:@selector(attachment)] performSelector:@selector(downloadURL)]);
[self.indicatorView startAnimating];
NSString *attachmentName = [[self performSelector:@selector(attachment)] performSelector:@selector(name)];
NSURL *url = [[self performSelector:@selector(attachment)] performSelector:@selector(downloadURL)];
NSString *tmpDir = NSTemporaryDirectory();
NSString *localURL = [tmpDir stringByAppendingPathComponent:attachmentName];
NSURL *urlToShare = [NSURL fileURLWithPath:localURL];
if ([[NSFileManager defaultManager] fileExistsAtPath:localURL]) {
[self presentShareController:@[urlToShare] barItem:sender];
[self.indicatorView stopAnimating];
} else {
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data && data.length > 0) {
NSLog(@"EdmodoFixer: Attachment downloaded successfully");
BOOL isCreated = [[NSFileManager defaultManager] createFileAtPath:localURL contents:data attributes:nil];
if (isCreated) {
NSLog(@"EdmodoFixer: File created succesfully");
NSArray *items = @[urlToShare];
[self presentShareController:items barItem:sender];
} else {
NSLog(@"EdmodoFixer: Error creating file from downloaded data");
}
} else {
NSLog(@"EdmodoFixer: Data downloaded == null ");
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.indicatorView stopAnimating];
});
}];
[dataTask resume];
}
}
%new
-(void)presentShareController:(NSArray *)items barItem:(UIBarButtonItem * _Nullable)barItem {
UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
if (barItem) {
shareController.popoverPresentationController.barButtonItem = barItem;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:shareController animated:YES completion:nil];
});
}
-(void)loadView {
%orig();
self.indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
self.indicatorView.hidesWhenStopped = YES;
self.indicatorView.frame = CGRectMake(0,0, 30, 30);
self.indicatorView.color = [UIColor orangeColor];
self.indicatorView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview: self.indicatorView];
[self performSelector:@selector(setConstraints)];
}
%new
-(void)setConstraints {
[[self.indicatorView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor] setActive:YES];
[[self.indicatorView.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor] setActive:YES];
[[self.indicatorView.heightAnchor constraintEqualToConstant:20] setActive:YES];
[[self.indicatorView.widthAnchor constraintEqualToConstant:20] setActive:YES];
}
-(void)viewWillAppear:(bool)arg2 {
%orig(arg2);
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Download" style: UIBarButtonItemStylePlain target:self action:@selector(downloadAction:)];
NSArray *currentItems = [self.navigationItem rightBarButtonItems];
NSArray *newItems = [currentItems arrayByAddingObject: item];
[self.navigationItem setRightBarButtonItems: newItems animated:YES];
}
+(void)openAttachment:(id)arg2 {
NSLog(@"EdmodoFixer: arg2 class = %@", [arg2 class]);
NSLog(@"EdmodoFixer: %@", [arg2 performSelector:@selector(_methodDescription)]);
NSLog(@"EdmofoFixer: file size: %ld", (long)[arg2 performSelector:@selector(size)]);
NSLog(@"EdmofoFixer: file url: %@", [arg2 performSelector:@selector(downloadURL)]);
NSLog(@"EdmofoFixer: attachment type: %@", [arg2 performSelector:@selector(attachmentType)]);
NSLog(@"EdmofoFixer: attachment name: %@", [arg2 performSelector:@selector(name)]);
%orig(arg2);
}
%end