From b8d14801b6d24fd6893f64ceeb208c666d22273c Mon Sep 17 00:00:00 2001 From: Burrit0z Date: Fri, 22 May 2020 20:08:45 -0400 Subject: [PATCH] im so done, at least stack view works --- KAIBatteryCell.mm | 6 +++--- KAIBatteryStack.mm | 2 +- Kai.xm | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/KAIBatteryCell.mm b/KAIBatteryCell.mm index 40a97f9..1bc17d1 100644 --- a/KAIBatteryCell.mm +++ b/KAIBatteryCell.mm @@ -9,11 +9,11 @@ NSMutableArray *deviceInstances = [[NSMutableArray alloc] init]; if(self && device!=nil) { self.device = device; - + NSString *deviceName = device.name; double batteryPercentage = device.percentCharge; - BOOL charging = device.charging; - BOOL LPM = device.batterySaverModeActive; + BOOL charging = MSHookIvar(device, "_charging"); + BOOL LPM = MSHookIvar(device, "_batterySaverModeActive"); UIView *blank; if(bannerStyle==1) { diff --git a/KAIBatteryStack.mm b/KAIBatteryStack.mm index 0b9999f..c6763be 100644 --- a/KAIBatteryStack.mm +++ b/KAIBatteryStack.mm @@ -12,7 +12,7 @@ KAIBatteryStack *instance; self.displayingDevices = [[NSMutableArray alloc] init]; self.axis = 1; self.distribution = 0; - self.spacing = spacing; + self.spacing = 0; self.alignment = 0; [self updateBattery]; //self.clipsToBounds = YES; diff --git a/Kai.xm b/Kai.xm index b6e67cd..a99a8e6 100644 --- a/Kai.xm +++ b/Kai.xm @@ -110,11 +110,15 @@ } -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ - if(self && self.kaiCell == nil) { - self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,0,0) device:self]; } - ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO; - [((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight].active = YES; + @try { + 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 [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil]; [(KAIBatteryCell *)self.kaiCell updateInfo]; @@ -134,8 +138,15 @@ } }); + } + } @catch (NSException *exc) {} } + +%new +-(id)_kaiCell { + return self.kaiCell; +} %end %hook KAICSTarget //Again, not a class