mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 04:36:48 +00:00
soon
This commit is contained in:
@ -31,6 +31,7 @@
|
|||||||
@property (nonatomic, assign) BOOL batterySaverModeActive;
|
@property (nonatomic, assign) BOOL batterySaverModeActive;
|
||||||
@property (nonatomic, strong) NSString *identifier;
|
@property (nonatomic, strong) NSString *identifier;
|
||||||
-(id)glyph;
|
-(id)glyph;
|
||||||
|
-(id)kaiCellForDevice;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface KAIBatteryCell : UIView
|
@interface KAIBatteryCell : UIView
|
||||||
@ -39,6 +40,8 @@
|
|||||||
@property (nonatomic, strong) UILabel *percentLabel;
|
@property (nonatomic, strong) UILabel *percentLabel;
|
||||||
@property (nonatomic, strong) UIImageView *glyphView;
|
@property (nonatomic, strong) UIImageView *glyphView;
|
||||||
@property (nonatomic, strong) _UIBatteryView *battery;
|
@property (nonatomic, strong) _UIBatteryView *battery;
|
||||||
|
@property (nonatomic, strong) NSLayoutConstraint *width;
|
||||||
|
@property (nonatomic, strong) NSLayoutConstraint *height;
|
||||||
-(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device;
|
-(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device;
|
||||||
-(void)updateInfo;
|
-(void)updateInfo;
|
||||||
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2;
|
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2;
|
||||||
|
@ -25,7 +25,6 @@ long long batteryPercentage;
|
|||||||
long long lastPercentage;
|
long long lastPercentage;
|
||||||
|
|
||||||
-(void)updateBattery {
|
-(void)updateBattery {
|
||||||
/*
|
|
||||||
self.spacing = spacing;
|
self.spacing = spacing;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
//NSLog(@"kai: battery platter called to update");
|
//NSLog(@"kai: battery platter called to update");
|
||||||
@ -33,87 +32,72 @@ long long lastPercentage;
|
|||||||
//NSLog(@"kai: IS Updating");
|
//NSLog(@"kai: IS Updating");
|
||||||
self.isUpdating = YES;
|
self.isUpdating = YES;
|
||||||
//self.number = 0;
|
//self.number = 0;
|
||||||
float y = 0;
|
//float y = 0;
|
||||||
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
||||||
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
||||||
if([devices count]!=0) {
|
|
||||||
//NSLog(@"kai: info is good, will proceed");
|
|
||||||
|
|
||||||
float ytwo = 0;
|
NSLog(@"kai: devices are %@", devices);
|
||||||
|
|
||||||
for(KAIBatteryCell *cell in self.subviews) {
|
for(KAIBatteryCell *cell in self.subviews) {
|
||||||
if([cell respondsToSelector:@selector(updateInfo)] && ![devices containsObject:cell.device]) { //to confirm is a cell and battery device does not exist
|
//BCBatteryDevice *device = cell.device;
|
||||||
//dispatch_async(dispatch_get_main_queue(), ^{
|
[cell updateInfo];
|
||||||
[UIView animateWithDuration:0.2 animations:^{
|
|
||||||
cell.alpha = 0;
|
|
||||||
} completion:^(BOOL finished){
|
|
||||||
[cell removeFromSuperview];
|
|
||||||
}];
|
|
||||||
//});
|
|
||||||
} else if([cell respondsToSelector:@selector(updateInfo)]) {
|
|
||||||
cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
|
|
||||||
[cell updateInfo];
|
|
||||||
ytwo+= bannerHeight + spacing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
BOOL shouldAdd = NO;
|
|
||||||
|
|
||||||
if(showAll) {
|
|
||||||
shouldAdd = YES;
|
|
||||||
//NSLog(@"Kai: SHOULD ADD");
|
|
||||||
} else if(!showAll && charging) {
|
|
||||||
shouldAdd = YES;
|
|
||||||
//NSLog(@"Kai: SHOULD ADD");
|
|
||||||
}
|
|
||||||
|
|
||||||
KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device frameToCreateNew:CGRectMake(0, y, self.frame.size.width, bannerHeight)];
|
|
||||||
cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
|
|
||||||
|
|
||||||
if(cell) {
|
|
||||||
cell.device = device;
|
|
||||||
//cell.frame = cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight); //bro im like creating my own stack view
|
|
||||||
//[cell updateInfo];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(shouldAdd && [deviceName length]!=0) {
|
|
||||||
if(![self.subviews containsObject:cell]) {
|
|
||||||
cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
|
|
||||||
cell.alpha = 0;
|
|
||||||
[self addSubview:cell];
|
|
||||||
[UIView animateWithDuration:0.3 animations:^{
|
|
||||||
cell.alpha = 1;
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
y+=bannerHeight + spacing;
|
|
||||||
|
|
||||||
} else if(!shouldAdd) {
|
|
||||||
//dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[UIView animateWithDuration:0.2 animations:^{
|
|
||||||
cell.alpha = 0;
|
|
||||||
} completion:^(BOOL finished){
|
|
||||||
[cell removeFromSuperview];
|
|
||||||
}];
|
|
||||||
//});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES;
|
|
||||||
self.number = [self.subviews count];
|
|
||||||
//[(CSAdjunctListView *)self.superview.superview KaiUpdate];
|
|
||||||
}
|
|
||||||
self.isUpdating = NO;
|
|
||||||
//NSLog(@"kai: finished update");
|
|
||||||
//[(CSAdjunctListView *)self.superview.superview KaiUpdate];
|
|
||||||
[(CSAdjunctListView *)self.superview.superview performSelector:@selector(KaiUpdate) withObject:(CSAdjunctListView *)self.superview.superview afterDelay:0.2];
|
|
||||||
}
|
}
|
||||||
});*/
|
|
||||||
|
for (BCBatteryDevice *device in devices) {
|
||||||
|
KAIBatteryCell *cell = [device kaiCellForDevice];
|
||||||
|
|
||||||
|
[cell updateInfo];
|
||||||
|
BOOL shouldAdd = NO;
|
||||||
|
|
||||||
|
if(showAll) {
|
||||||
|
shouldAdd = YES;
|
||||||
|
} else if(!showAll && device.charging) {
|
||||||
|
shouldAdd = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(![self.subviews containsObject:cell] && shouldAdd && [devices containsObject:device]) {
|
||||||
|
[cell setFrame:CGRectMake(0,0,self.frame.size.width, bannerHeight + spacing)];
|
||||||
|
[self addArrangedSubview:cell];
|
||||||
|
} else {
|
||||||
|
[self removeArrangedSubview:cell];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!cell.height) {
|
||||||
|
|
||||||
|
cell.height.active = NO;
|
||||||
|
cell.height = [cell.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)];
|
||||||
|
cell.height.active = YES;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
int height = (bannerHeight + spacing);
|
||||||
|
cell.height.constant = height;
|
||||||
|
|
||||||
|
UIStackView *s = self;
|
||||||
|
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!cell.width) {
|
||||||
|
|
||||||
|
cell.width.active = NO;
|
||||||
|
cell.width = [cell.widthAnchor constraintEqualToConstant:(self.frame.size.width)];
|
||||||
|
cell.width.active = YES;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
int width = self.frame.size.width;
|
||||||
|
cell.width.constant = width;
|
||||||
|
|
||||||
|
UIStackView *s = self;
|
||||||
|
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
self.number = [self.subviews count];
|
||||||
|
}
|
||||||
|
self.isUpdating = NO;
|
||||||
|
//NSLog(@"kai: finished update");
|
||||||
|
//[(CSAdjunctListView *)self.superview.superview KaiUpdate];
|
||||||
|
[(CSAdjunctListView *)self.superview.superview performSelector:@selector(KaiUpdate) withObject:(CSAdjunctListView *)self.superview.superview afterDelay:0.2];
|
||||||
|
});
|
||||||
self.number = [self.subviews count];
|
self.number = [self.subviews count];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,10 +110,6 @@ long long lastPercentage;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[KAIBatteryCell resetArray];
|
[KAIBatteryCell resetArray];
|
||||||
|
|
||||||
//self.displayingDevices = [[NSMutableArray alloc] init];
|
|
||||||
|
|
||||||
//addedCells = nil;
|
|
||||||
[self updateBattery];
|
[self updateBattery];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
Kai.xm
41
Kai.xm
@ -38,6 +38,7 @@
|
|||||||
//add kai to the stack view
|
//add kai to the stack view
|
||||||
[arg1 addArrangedSubview:battery];
|
[arg1 addArrangedSubview:battery];
|
||||||
}
|
}
|
||||||
|
[battery updateBattery];
|
||||||
|
|
||||||
//send the adjusted stackview as arg1
|
//send the adjusted stackview as arg1
|
||||||
%orig(arg1);
|
%orig(arg1);
|
||||||
@ -61,9 +62,9 @@
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
int height = (battery.number * (bannerHeight + spacing)); //big brain math
|
int height = (battery.number * (bannerHeight + spacing)); //big brain math
|
||||||
battery.heightConstraint.active = NO; //deactivation
|
//battery.heightConstraint.active = NO; //deactivation
|
||||||
battery.heightConstraint.constant = height;
|
battery.heightConstraint.constant = height;
|
||||||
battery.heightConstraint.active = YES; //forcing reactivation
|
//battery.heightConstraint.active = YES; //forcing reactivation
|
||||||
|
|
||||||
UIStackView *s = [self stackView];
|
UIStackView *s = [self stackView];
|
||||||
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
|
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
|
||||||
@ -110,41 +111,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
||||||
@try {
|
if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {
|
||||||
if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)]) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
|
|
||||||
if(self && self.kaiCell == nil) {
|
|
||||||
self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; }
|
|
||||||
((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
|
|
||||||
[((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight + spacing].active = YES;
|
|
||||||
|
|
||||||
//sends the noti to update battery info
|
//sends the noti to update battery info
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
|
||||||
[(KAIBatteryCell *)self.kaiCell updateInfo];
|
|
||||||
|
|
||||||
BOOL shouldAdd = NO;
|
|
||||||
|
|
||||||
if(showAll) {
|
|
||||||
shouldAdd = YES;
|
|
||||||
} else if(!showAll && self.charging) {
|
|
||||||
shouldAdd = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(![[KAIBatteryStack sharedInstance].subviews containsObject:self.kaiCell] && shouldAdd) {
|
|
||||||
[[KAIBatteryStack sharedInstance] addArrangedSubview:self.kaiCell];
|
|
||||||
} else if([[KAIBatteryStack sharedInstance].subviews containsObject:self.kaiCell] && !shouldAdd) {
|
|
||||||
[[KAIBatteryStack sharedInstance] removeArrangedSubview:self.kaiCell];
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} @catch (NSException *exc) {}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%new
|
%new
|
||||||
-(id)_kaiCell {
|
-(id)kaiCellForDevice {
|
||||||
|
if(self && self.kaiCell == nil) {
|
||||||
|
self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; }
|
||||||
|
((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
|
[((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight + spacing].active = YES;
|
||||||
|
|
||||||
|
[(KAIBatteryCell *)self.kaiCell updateInfo];
|
||||||
|
|
||||||
return self.kaiCell;
|
return self.kaiCell;
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
Reference in New Issue
Block a user