-
Notifications
You must be signed in to change notification settings - Fork 9
/
Tweak.xm
83 lines (66 loc) · 2.32 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
//
// Tweak.xm
// Swizzle
//
// Created by Tanner Bennett on 2016-10-06
// Copyright © 2016 Tanner Bennett. All rights reserved.
//
#import "Interfaces.h"
static FLEXToolbarItem * kSwizzleItem = nil;
static FLEXToolbarItem * kMoveItem = nil;
static BOOL showingSwizzle = NO;
FLEXExplorerViewController *TBFLEXExplorerVC() {
return [(FLEXManager *)[NSClassFromString(@"FLEXManager") sharedManager] explorerViewController];
}
void FLEXExplorerToolbarSwapItemWithMoveItem(FLEXExplorerToolbar *toolbar, FLEXToolbarItem *item) {
NSInteger idx = [toolbar.toolbarItems indexOfObject:toolbar.moveItem];
NSMutableArray *items = toolbar.toolbarItems.mutableCopy;
[toolbar.moveItem removeFromSuperview];
[toolbar addSubview:item];
toolbar.moveItem = item;
[items replaceObjectAtIndex:idx withObject:item];
toolbar.toolbarItems = items;
[toolbar setNeedsLayout];
[toolbar layoutIfNeeded];
}
%group Explorer
%hook FLEXManager
%new
- (void)__toggleSwizzleMenu {
[TBFLEXExplorerVC() toggleToolWithViewControllerProvider:^UIViewController *{
return [TBTweakRootViewController dismissAction:^{
[self __toggleSwizzleMenu];
}];
} completion:^{
showingSwizzle = !showingSwizzle;
}];
}
%end
%hook FLEXExplorerViewController
- (void)updateButtonStates {
%orig;
kSwizzleItem.enabled = YES;
if (self.currentMode == FLEXExplorerModeDefault) {
FLEXToolbarItem *current = self.explorerToolbar.moveItem;
if (current != kSwizzleItem) {
kMoveItem = current;
FLEXExplorerToolbarSwapItemWithMoveItem(self.explorerToolbar, kSwizzleItem);
}
} else if (kMoveItem) {
FLEXExplorerToolbarSwapItemWithMoveItem(self.explorerToolbar, kMoveItem);
}
}
%end
%end
%ctor {
SwizzleInit();
FLEXManager *flex = [NSClassFromString(@"FLEXManager") sharedManager];
if (flex) {
// Create Swizzle button
UIImage *icon = [NSClassFromString(@"FLEXResources") globeIcon];
kSwizzleItem = [NSClassFromString(@"FLEXToolbarItem") toolbarItemWithTitle:@"Tweak" image:icon];
[kSwizzleItem addTarget:flex action:@selector(__toggleSwizzleMenu) forControlEvents:UIControlEventTouchUpInside];
// Add it to the FLEXExplorerViewController toolbar
%init(Explorer);
}
}