-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.xm
222 lines (181 loc) · 8.08 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
Copyright (C) 2016 developersBliss
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <UIKit/UIKit.h>
#include "SpringBoard/SBControlCenterContentView.H"
#include "SpringBoard/SBControlCenterSeparatorView.h"
#include "SpringBoard/SBControlCenterController.h"
#include "SpringBoard/SBCCAirStuffSectionController.h"
#include "SpringBoard/SBCCBrightnessSectionController.h"
#include "SpringBoard/SBCCMediaControlsSectionController.h"
#include "SpringBoard/SBCCQuickLaunchSectionController.h"
#include "SpringBoard/SBCCSettingsSectionController.h"
#include "SpringBoard/SBControlCenterContentContainerView.h"
#include "SpringBoard/SBMediaController.h"
#include "BluetoothManager/BluetoothManager.h"
NSMutableDictionary * _CCHSections;
void loadPreferences() {
//Get prefs
if (![[NSFileManager defaultManager] fileExistsAtPath:@"/var/mobile/Library/Preferences/com.developersbliss.cchide2.plist"]) {
//If the plist doesn't exist, make it with default values.
_CCHSections = [[NSMutableDictionary alloc] init];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.settings"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.brightness"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.media-controls"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.air-stuff"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.quick-launch"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"conditionalMediaControlsSection"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"conditionalAirplaySection"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"separators"];
[_CCHSections setObject:[NSNumber numberWithBool:NO] forKey:@"landscape"];
[_CCHSections writeToFile:@"/var/mobile/Library/Preferences/com.developersbliss.cchide2.plist" atomically:YES];
} else {
_CCHSections = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.developersbliss.cchide2.plist"];
}
}
%hook SBControlCenterController
-(void)_beginPresentation {
loadPreferences();
if ([[_CCHSections objectForKey:@"com.apple.controlcenter.air-stuff"] boolValue] && [[_CCHSections objectForKey:@"conditionalAirplaySection"] boolValue]) {
BluetoothManager* manager = [objc_getClass("BluetoothManager") sharedInstance];
BOOL bluetoothIsOn = [manager enabled];
BOOL isAirPlayEnabled = MSHookIvar<SBCCAirStuffSectionController *>(MSHookIvar<id>(MSHookIvar<id>(self, "_viewController"), "_contentView"), "_airplaySection").airPlayEnabled;
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"isAirPlayEnabled" message:isAirPlayEnabled?@"YES":@"NO" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];
if (!(bluetoothIsOn || isAirPlayEnabled)) {
[_CCHSections setObject:[NSNumber numberWithBool:NO] forKey:@"com.apple.controlcenter.air-stuff"];
}
}
if ([[_CCHSections objectForKey:@"com.apple.controlcenter.media-controls"] boolValue] && [[_CCHSections objectForKey:@"conditionalMediaControlsSection"] boolValue]) {
BOOL nowPlaying = MSHookIvar<BOOL>([objc_getClass("SBMediaController") sharedInstance], "_lastNowPlayingAppIsPlaying");
if (!nowPlaying) {
[_CCHSections setObject:[NSNumber numberWithBool:NO] forKey:@"com.apple.controlcenter.media-controls"];
}
}
%orig;
//Prevent CC from being visible if no sections are set to show.
if ((![[_CCHSections objectForKey:@"com.apple.controlcenter.settings"] boolValue] &&
![[_CCHSections objectForKey:@"com.apple.controlcenter.brightness"] boolValue] &&
![[_CCHSections objectForKey:@"com.apple.controlcenter.media-controls"] boolValue] &&
![[_CCHSections objectForKey:@"com.apple.controlcenter.air-stuff"] boolValue] &&
![[_CCHSections objectForKey:@"com.apple.controlcenter.quick-launch"] boolValue])) {
if ([self respondsToSelector:@selector(cancelTransition)]) {
[self cancelTransition];
} else {
[self _cancelTransition];
}
} else if (![[_CCHSections objectForKey:@"landscape"] boolValue]) {
//Make everything visible in landscape.
int orientation = MSHookIvar<int>(self, "_orientation");
if (orientation == 3 || orientation == 4) {
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.settings"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.brightness"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.media-controls"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.air-stuff"];
[_CCHSections setObject:[NSNumber numberWithBool:YES] forKey:@"com.apple.controlcenter.quick-launch"];
}
}
}
%end
%hook SBCCAirStuffSectionController
-(BOOL)enabledForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return NO;
}
}
-(CGSize)contentSizeForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return CGSizeMake(0, 0);
}
}
%end
%hook SBCCBrightnessSectionController
-(BOOL)enabledForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return NO;
}
}
-(CGSize)contentSizeForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return CGSizeMake(0, 0);
}
}
%end
%hook SBCCMediaControlsSectionController
-(BOOL)enabledForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return NO;
}
}
-(CGSize)contentSizeForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return CGSizeMake(0, 0);
}
}
%end
%hook SBCCQuickLaunchSectionController
-(BOOL)enabledForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return NO;
}
}
-(CGSize)contentSizeForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return CGSizeMake(0, 0);
}
}
%end
%hook SBCCSettingsSectionController
-(BOOL)enabledForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return NO;
}
}
-(CGSize)contentSizeForOrientation:(int)orientation {
if ([[_CCHSections objectForKey:self.sectionIdentifier] boolValue]) {
return %orig;
} else {
return CGSizeMake(0, 0);
}
}
%end
%hook SBControlCenterSeparatorView
//Hiding the seperators
+(float)defaultBreadthForOrientation:(int)orientation {
if (!_CCHSections) {
loadPreferences();
}
if (![[_CCHSections objectForKey:@"separators"] boolValue]) {
return 0;
} else {
return %orig;
}
}
%end