mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 10:36:47 +00:00
commit
This commit is contained in:
@ -24,6 +24,8 @@
|
|||||||
@interface KAIBattery : UIView
|
@interface KAIBattery : UIView
|
||||||
@property (nonatomic, strong) NSArray *devices;
|
@property (nonatomic, strong) NSArray *devices;
|
||||||
@property (nonatomic, assign) NSInteger number;
|
@property (nonatomic, assign) NSInteger number;
|
||||||
|
@property (nonatomic, assign) BOOL isUpdating;
|
||||||
|
+(KAIBattery *)sharedInstance;
|
||||||
-(instancetype)initWithFrame:(CGRect)arg1;
|
-(instancetype)initWithFrame:(CGRect)arg1;
|
||||||
-(void)updateBattery;
|
-(void)updateBattery;
|
||||||
@end
|
@end
|
@ -1,9 +1,11 @@
|
|||||||
#import "KAIBattery.h"
|
#import "KAIBattery.h"
|
||||||
|
|
||||||
|
KAIBattery *instance;
|
||||||
@implementation KAIBattery
|
@implementation KAIBattery
|
||||||
|
|
||||||
-(instancetype)initWithFrame:(CGRect)arg1 {
|
-(instancetype)initWithFrame:(CGRect)arg1 {
|
||||||
self = [super initWithFrame:arg1];
|
self = [super initWithFrame:arg1];
|
||||||
|
instance = self;
|
||||||
if (self) {
|
if (self) {
|
||||||
/*self.batteryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25,-10,220,120)];
|
/*self.batteryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25,-10,220,120)];
|
||||||
[self.batteryLabel setFont:[UIFont systemFontOfSize:13]];
|
[self.batteryLabel setFont:[UIFont systemFontOfSize:13]];
|
||||||
@ -20,15 +22,9 @@ long long batteryPercentage;
|
|||||||
long long lastPercentage;
|
long long lastPercentage;
|
||||||
|
|
||||||
-(void)updateBattery {
|
-(void)updateBattery {
|
||||||
|
if(!self.isUpdating) {
|
||||||
|
self.isUpdating = YES;
|
||||||
self.number = 0;
|
self.number = 0;
|
||||||
NSArray* subViews = self.subviews;
|
|
||||||
for( UIView *view in subViews ) {
|
|
||||||
@try {
|
|
||||||
[view removeFromSuperview];
|
|
||||||
} @catch (NSException *exception) {
|
|
||||||
//Panik
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
||||||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
||||||
|
|
||||||
@ -44,7 +40,8 @@ long long lastPercentage;
|
|||||||
UIVisualEffectView *blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
|
UIVisualEffectView *blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
|
||||||
blank.frame = CGRectMake(0, 0 + y, self.frame.size.width, 80);
|
blank.frame = CGRectMake(0, 0 + y, self.frame.size.width, 80);
|
||||||
blank.layer.masksToBounds = YES;
|
blank.layer.masksToBounds = YES;
|
||||||
blank.layer.cornerRadius = 18;
|
blank.layer.cornerRadius = 13;
|
||||||
|
blank.alpha = 0.8;
|
||||||
//[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]];
|
//[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]];
|
||||||
[self addSubview:blank];
|
[self addSubview:blank];
|
||||||
|
|
||||||
@ -90,10 +87,16 @@ long long lastPercentage;
|
|||||||
battery.frame = CGRectMake(310,35 + y,20,10);
|
battery.frame = CGRectMake(310,35 + y,20,10);
|
||||||
percentLabel.frame = CGRectMake(265,35 + y,36,12);
|
percentLabel.frame = CGRectMake(265,35 + y,36,12);
|
||||||
|
|
||||||
y+=90;
|
y+=85;
|
||||||
self.number +=1;
|
self.number +=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.isUpdating = NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+(KAIBattery *)sharedInstance {
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
128
Kai.xm
128
Kai.xm
@ -5,16 +5,6 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
#import "KAIBattery.mm"
|
#import "KAIBattery.mm"
|
||||||
BOOL setFrame = NO;
|
|
||||||
KAIBattery *batteryWidget;
|
|
||||||
CGRect original;
|
|
||||||
|
|
||||||
/*
|
|
||||||
- (void)addObserver:(NSObject *)observer
|
|
||||||
forKeyPath:(NSString *)keyPath
|
|
||||||
options:(NSKeyValueObservingOptions)options
|
|
||||||
context:(void *)context*/
|
|
||||||
|
|
||||||
|
|
||||||
@interface UIApplication (Kai)
|
@interface UIApplication (Kai)
|
||||||
+(id)sharedApplication;
|
+(id)sharedApplication;
|
||||||
@ -24,7 +14,22 @@ CGRect original;
|
|||||||
@interface CSMainPageView : UIView
|
@interface CSMainPageView : UIView
|
||||||
@property (nonatomic, strong) KAIBattery *battery;
|
@property (nonatomic, strong) KAIBattery *battery;
|
||||||
-(void)updateForPresentation:(id)arg1;
|
-(void)updateForPresentation:(id)arg1;
|
||||||
|
-(void)KaiUpdate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
BOOL setFrame = NO;
|
||||||
|
CSMainPageView *batteryWidget;
|
||||||
|
CGRect original;
|
||||||
|
CGRect originalBattery;
|
||||||
|
|
||||||
|
/*
|
||||||
|
- (void)addObserver:(NSObject *)observer
|
||||||
|
forKeyPath:(NSString *)keyPath
|
||||||
|
options:(NSKeyValueObservingOptions)options
|
||||||
|
context:(void *)context*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
%hook BCBatterDeviceController
|
%hook BCBatterDeviceController
|
||||||
|
|
||||||
@ -48,9 +53,16 @@ CGRect original;
|
|||||||
|
|
||||||
-(void)viewWillAppear:(BOOL)arg1 {
|
-(void)viewWillAppear:(BOOL)arg1 {
|
||||||
%orig;
|
%orig;
|
||||||
[batteryWidget updateBattery];
|
[batteryWidget.battery updateBattery];
|
||||||
}
|
[batteryWidget KaiUpdate];
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
-(void)viewWillDisappear:(BOOL)arg1 {
|
||||||
|
%orig;
|
||||||
|
[batteryWidget.battery updateBattery];
|
||||||
|
[batteryWidget KaiUpdate];
|
||||||
|
}*/
|
||||||
%end
|
%end
|
||||||
|
|
||||||
|
|
||||||
@ -59,93 +71,33 @@ CGRect original;
|
|||||||
|
|
||||||
-(void)updateForPresentation:(id)arg1 {
|
-(void)updateForPresentation:(id)arg1 {
|
||||||
%orig;
|
%orig;
|
||||||
UIView *object = self;
|
|
||||||
if(!setFrame) {
|
if(!setFrame) {
|
||||||
original = self.frame;
|
original = self.frame;
|
||||||
|
self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, self.frame.origin.y + 150, self.frame.size.width - 16, self.frame.size.height)];
|
||||||
self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 155, object.frame.size.width - 16, object.frame.size.height)];
|
originalBattery = self.battery.frame;
|
||||||
[self addSubview:self.battery];
|
[self addSubview:self.battery];
|
||||||
setFrame = YES;
|
setFrame = YES;
|
||||||
batteryWidget = self.battery;
|
batteryWidget = self;
|
||||||
|
}
|
||||||
[self.battery updateBattery];
|
[self.battery updateBattery];
|
||||||
|
[self KaiUpdate];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object.frame = CGRectMake(
|
%new
|
||||||
|
-(void)KaiUpdate {
|
||||||
|
self.frame = CGRectMake(
|
||||||
original.origin.x,
|
original.origin.x,
|
||||||
original.origin.y + (self.battery.number * 90),
|
original.origin.y + (self.battery.number * 85),
|
||||||
original.size.width,
|
original.size.width,
|
||||||
original.size.height
|
original.size.height
|
||||||
);
|
);
|
||||||
|
|
||||||
//[self.battery updateBattery];
|
self.battery.frame = CGRectMake(
|
||||||
/*
|
originalBattery.origin.x,
|
||||||
NSArray* subViews = self.subviews;
|
originalBattery.origin.y - (self.battery.number * 85) + 85,
|
||||||
for( UIView *view in subViews ) {
|
originalBattery.size.width,
|
||||||
if([view isMemberOfClass:[objc_getClass("UILabel") class]] || [view isMemberOfClass:[objc_getClass("_UIBatteryView") class]] || [view isKindOfClass:[objc_getClass("UIImageView") class]]) {
|
originalBattery.size.height
|
||||||
@try {
|
);
|
||||||
[view removeFromSuperview];
|
|
||||||
} @catch (NSException *exception) {
|
|
||||||
//Panik
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
|
||||||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
|
||||||
for (BCBatteryDevice *device in devices) {
|
|
||||||
NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
|
|
||||||
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
|
|
||||||
BOOL charging = MSHookIvar<long long>(device, "_charging");
|
|
||||||
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
|
|
||||||
if(charging) {
|
|
||||||
|
|
||||||
NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
|
|
||||||
|
|
||||||
UILabel *label = [[UILabel alloc] init];
|
|
||||||
[label setFont:[UIFont systemFontOfSize:18]];
|
|
||||||
[label setTextColor:[UIColor whiteColor]];
|
|
||||||
label.lineBreakMode = NSLineBreakByWordWrapping;
|
|
||||||
label.numberOfLines = 0;
|
|
||||||
[label setText:labelText];
|
|
||||||
|
|
||||||
[self addSubview:label];
|
|
||||||
|
|
||||||
_UIBatteryView *battery = [[_UIBatteryView alloc] init];
|
|
||||||
battery.chargePercent = (batteryPercentage*0.01);
|
|
||||||
UILabel *percentLabel = [[UILabel alloc] init];
|
|
||||||
//if(self.percentEnabled) {
|
|
||||||
// battery.showsPercentage = YES;
|
|
||||||
// } else {
|
|
||||||
battery.showsPercentage = NO;
|
|
||||||
[percentLabel setFont:[UIFont systemFontOfSize:14]];
|
|
||||||
[percentLabel setTextColor:[UIColor whiteColor]];
|
|
||||||
percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
|
||||||
[percentLabel setTextAlignment:NSTextAlignmentRight];
|
|
||||||
percentLabel.numberOfLines = 0;
|
|
||||||
[percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
|
|
||||||
[self addSubview:percentLabel];
|
|
||||||
//}
|
|
||||||
if(charging) battery.chargingState = 2;
|
|
||||||
if(LPM) battery.saverModeActive = YES;
|
|
||||||
if(kCFCoreFoundationVersionNumber > 1600) {
|
|
||||||
[battery setBodyColorAlpha:1.0];
|
|
||||||
[battery setPinColorAlpha:1.0];
|
|
||||||
}
|
|
||||||
[self addSubview:battery];
|
|
||||||
|
|
||||||
UIImage *glyph = [device glyph];
|
|
||||||
UIImageView *glyphView = [[UIImageView alloc] init];
|
|
||||||
//if(self.glyphsEnabled) {
|
|
||||||
glyphView.contentMode = UIViewContentModeScaleAspectFit;
|
|
||||||
[glyphView setImage:glyph];
|
|
||||||
[self addSubview:glyphView];
|
|
||||||
//}
|
|
||||||
|
|
||||||
label.frame = CGRectMake(10,20,275,25);
|
|
||||||
glyphView.frame = CGRectMake(27,25,17,15);
|
|
||||||
battery.frame = CGRectMake(325,25,20,10);
|
|
||||||
percentLabel.frame = CGRectMake(285,25,36,12);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
%end
|
%end
|
Reference in New Issue
Block a user