-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTweak.xm
46 lines (43 loc) · 1.8 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
#import <SpringBoard/SBAwayView.h>
#import <SpringBoard/SBAwayChargingView.h>
#import <SpringBoard/SBBatteryChargingView.h>
#define PATH @"/System/Library/CoreServices/SpringBoard.app"
static BOOL enableAnimateBattery=YES;
static BOOL animateFullStatus=YES;
static void getSettings(){
NSDictionary *defaults=[NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/net.limneos.animatebattery.plist"];
enableAnimateBattery=[defaults objectForKey:@"enabled"] ? [[defaults objectForKey:@"enabled"] boolValue] : YES;
animateFullStatus=[defaults objectForKey:@"allTiles"] ? [[defaults objectForKey:@"allTiles"] boolValue] : YES;
}
%hook SBAwayView
-(void)showChargingView{
%orig;
getSettings();
if (!enableAnimateBattery)
return;
SBBatteryChargingView *chargingView=[[self chargingView] chargingView];
UIImageView *battView=MSHookIvar<UIImageView *>(chargingView,"_topBatteryView");
if (chargingView.alpha>0 && ![battView isAnimating] ){
[chargingView setShowsReflection:NO];
NSMutableArray *images=[NSMutableArray array];
int startImage=animateFullStatus ? 1 : ([chargingView _currentBatteryIndex]-1>0 ? [chargingView _currentBatteryIndex]-1 : [chargingView _currentBatteryIndex]) ;
for (int i=startImage; i<=[chargingView _currentBatteryIndex]; i++){
[images addObject:[UIImage imageNamed:[NSString stringWithFormat:[chargingView _imageFormatString],i]]];
}
battView.animationImages = images;
battView.animationDuration = images.count>4 ? images.count/4 : 1;
battView.animationRepeatCount = 0;
[battView startAnimating];
}
}
-(void)hideChargingView{
if (!enableAnimateBattery){
%orig;
return;
}
UIImageView *charginView=[[self chargingView] chargingView];
UIImageView *battView=MSHookIvar<UIImageView *>(charginView,"_topBatteryView");
[battView stopAnimating];
%orig;
}
%end