-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTweak.xm
executable file
·259 lines (210 loc) · 6.4 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#import <QuartzCore/QuartzCore.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <substrate.h>
#define kBundlePath @"/Library/PreferenceBundles/SpinSettingsSettings.bundle"
#define SYS_VER_GREAT_OR_EQUAL(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:64] != NSOrderedAscending)
static NSString * SSSpeed = @"2.0";
static BOOL enableTweak = NO;
@interface UIImage ()
@property (assign,nonatomic) CGRect mediaImageSubRect;
-(CGRect)mediaImageSubRect;
@end
@interface SBIcon : NSObject
-(id)leafIdentifier;
@end
@interface SBIconView : UIView
@end
@implementation SBIconView
@end
@interface SBIconImageView : SBIconView
@end
@implementation SBIconImageView
@end
@interface SBLiveIconImageView : SBIconImageView
@end
@implementation SBLiveIconImageView
@end
@interface SBSettingsIconImageView : SBLiveIconImageView
-(id)initWithFrame:(CGRect)frame;
- (UIImageView*)dcImage;
- (void)setDcImage:(UIImageView*)value;
-(void)dealloc;
-(void)updateAnimatingState;
-(void)updateImageAnimated:(BOOL)animated;
- (void)rotateImageView;
-(void)setIsSpinning:(BOOL)value;
-(bool)isSpinning;
-(void)setDynamicFrame:(CGRect)frame;
-(void)setHasAdjusted:(BOOL)value;
-(bool)hasAdjusted;
@end
//potentially need to check if device is unlocked
@interface SBLockScreenManager : NSObject
+(id)sharedInstance;
-(BOOL)isUILocked;
@end
%subclass SBSettingsIconImageView : SBLiveIconImageView
%new - (UIImageView*)dcImage
{
return objc_getAssociatedObject(self,@selector(dcImage));
}
%new - (void)setDcImage:(UIImageView*)value
{
objc_setAssociatedObject(self,@selector(dcImage),value,OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new - (BOOL)hasAdjusted
{
return [(NSNumber*)objc_getAssociatedObject(self,@selector(hasAdjusted)) boolValue];
}
%new - (void)setHasAdjusted:(BOOL)value
{
objc_setAssociatedObject(self,@selector(hasAdjusted),[NSNumber numberWithBool:value],OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new - (BOOL)isSpinning
{
return [(NSNumber*)objc_getAssociatedObject(self,@selector(isSpinning)) boolValue];
}
%new - (void)setIsSpinning:(BOOL)value
{
objc_setAssociatedObject(self,@selector(isSpinning),[NSNumber numberWithBool:value],OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%new - (void)setDynamicFrame:(CGRect)frameVar
{
NSLog(@"Resetting the frame: %@", NSStringFromCGRect(frameVar));
if (self.dcImage && !self.hasAdjusted)
{
CGRect imageRect = CGRectMake(frameVar.origin.x,frameVar.origin.y,frameVar.size.width,frameVar.size.height);
[self.dcImage setFrame:imageRect];
self.hasAdjusted = 1;
}
}
%new - (bool)isNumeric:(NSString*)checkText
{
return [[NSScanner scannerWithString:checkText] scanFloat:NULL];
}
-(id)initWithFrame:(CGRect)frame
{
id orig = %orig;
if (orig != nil)
{
NSLog(@"Attaching the Core image to our settings icon");
NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];
NSString *imagePath = [bundle pathForResource:@"Core" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
self.dcImage = [[UIImageView alloc] initWithImage: image];
CGRect iconRect = CGRectMake(0,0,0,0);
[self.dcImage setFrame:iconRect];
self.dcImage.clipsToBounds = YES;
self.isSpinning = 1;
self.hasAdjusted = 0;
[self addSubview:self.dcImage];
}
return orig;
}
-(void)dealloc
{
NSLog(@"SpinSettings deallocated");
self.isSpinning = 0;
self.hasAdjusted = 0;
[self.dcImage release];
%orig;
}
-(void)updateAnimatingState
{
%orig;
if (enableTweak)
[self.dcImage setHidden:0];
else
[self.dcImage setHidden:1];
if (self.hasAdjusted)
{
if([[self.dcImage.layer animationKeys] count] < 1)
[self rotateImageView];
}
}
%new - (void)rotateImageView
{
if (self.isSpinning)
{
CGFloat duration = [self isNumeric:SSSpeed] ? [SSSpeed floatValue] : 2.0;
[UIView animateWithDuration:duration delay:0.0f options:UIViewAnimationOptionCurveLinear
animations:^{
self.dcImage.transform = CGAffineTransformRotate(self.dcImage.transform, M_PI / 2);
}
completion: ^(BOOL finished) {
if (finished) {
[self rotateImageView];
}
}];
}
}
%end
%subclass SBSettingsApplicationIcon : SBApplicationIcon
-(Class)iconImageViewClassForLocation:(int)arg1
{
return %c(SBSettingsIconImageView);
}
%end
%hook SBIcon
-(Class)iconImageViewClassForLocation:(int)arg1
{
Class orig = %orig;
return orig;
}
%end
%hook SBApplication
-(Class)iconClass
{
Class orig = %orig;
NSString * identifier = MSHookIvar<NSString*>(self,"_bundleIdentifier");
if([identifier isEqualToString:@"com.apple.Preferences"]){
return %c(SBSettingsApplicationIcon);
//If we just return orig here in order to disable the tweak, we would have to respring for any changes to be applied.
//Thus hiding the view through functions in the SBSettingsIconImageView class is an alternative that does not require a respring.
}
else
return orig;
}
%end
%hook SBIconView
-(void)_setIcon:(id)icon animated:(BOOL)animated
{
%orig;
if ([[icon leafIdentifier] isEqualToString:@"com.apple.Preferences"])
{
NSLog(@"_setIcon for Preferences");
SBSettingsIconImageView * img = MSHookIvar<SBSettingsIconImageView*>(self,"_iconImageView");
if([img isKindOfClass:%c(SBSettingsIconImageView)])
{
NSLog(@"Our image ivar is of the correct class.");
[img setDynamicFrame:[img bounds]];
}
}
}
%end
static void loadPrefs()
{
NSLog(@"Loading SpinSettings prefs");
CFPreferencesAppSynchronize(CFSTR("com.joshdoctors.spinsettings"));
enableTweak = !CFPreferencesCopyAppValue(CFSTR("enableTweak"), CFSTR("com.joshdoctors.spinsettings")) ? NO : [(id)CFPreferencesCopyAppValue(CFSTR("enableTweak"), CFSTR("com.joshdoctors.spinsettings")) boolValue];
if (enableTweak) {
NSLog(@"[SpinSettings] We are enabled");
} else {
NSLog(@"[SpinSettings] We are NOT enabled");
}
SSSpeed = (NSString*)CFPreferencesCopyAppValue(CFSTR("SSSpeed"), CFSTR("com.joshdoctors.spinsettings")) ?: @"2.0";
[SSSpeed retain];
NSLog(@"SSSpeed: %@",SSSpeed);
}
%ctor
{
NSLog(@"Loading SpinSettings");
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)loadPrefs,
CFSTR("com.joshdoctors.spinsettings/settingschanged"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
loadPrefs();
}