-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExportTweaks.xm
50 lines (45 loc) · 2 KB
/
ExportTweaks.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
#import <Headers/Interfaces.h>
%group ExportTweaks
%hook PackageListViewController
- (void)viewDidLoad{
%orig;
if ([self.title isEqualToString:@"Packages"]) {
UIBarButtonItem *exportButton([[UIBarButtonItem alloc] initWithTitle:@"Export" style:UIBarButtonItemStylePlain target:self action:@selector(exportButtonClicked:)]);
[[self navigationItem] setLeftBarButtonItem:exportButton];
}
}
%new
-(void)exportButtonClicked:(UIButton*)button{
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Export"
message:@"Would you like to save your package list? This will copy each package and its corresponding version to your clipboard."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Copy" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {[self copyPackages];}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
alert.view.tintColor = [prefs colorForKey:@"tintColor"];
[self presentViewController:alert animated:YES completion:nil];
}
%new
-(void)copyPackages {
NSMutableString *bodyFromArray = [[NSMutableString alloc] init];
NSArray *packages = MSHookIvar<NSArray *>(self, "_packages");
for (Package* object in packages)
{
NSString *packageName = MSHookIvar<NSString *>(object, "_name");
NSString *packageVersion = MSHookIvar<NSString *>(object, "_version");
[bodyFromArray appendString:[NSString stringWithFormat:@"%@: %@\n", packageName, packageVersion]];
}
[bodyFromArray deleteCharactersInRange:NSMakeRange([bodyFromArray length]-1, 1)];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = bodyFromArray;
}
%end
%end
%ctor {
if ([prefs boolForKey:@"exportBtn"]) {
%init(ExportTweaks);
}
}