Browse Source

soon fix, this still broke

pull/1/head
Burrit0z 4 years ago
parent
commit
6aeb4cb375
6 changed files with 55 additions and 38 deletions
  1. +1
    -0
      KAIBattery.h
  2. +36
    -18
      KAIBattery.mm
  3. +0
    -5
      KAIBatteryCell.h
  4. +9
    -9
      KAIBatteryCell.mm
  5. +1
    -1
      Kai.h
  6. +8
    -5
      Kai.xm

+ 1
- 0
KAIBattery.h View File

@property (nonatomic, assign) BOOL isUpdating; @property (nonatomic, assign) BOOL isUpdating;
+(KAIBattery *)sharedInstance; +(KAIBattery *)sharedInstance;
-(instancetype)init; -(instancetype)init;
-(void)removeAllAndRefresh;
-(void)updateBattery; -(void)updateBattery;
@end @end

+ 36
- 18
KAIBattery.mm View File

#import "KAIBattery.h" #import "KAIBattery.h"


KAIBattery *instance; KAIBattery *instance;
NSMutableArray *addedCells = [[NSMutableArray alloc] init];

@implementation KAIBattery @implementation KAIBattery


-(instancetype)init { -(instancetype)init {


-(void)updateBattery { -(void)updateBattery {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"kai: battery platter called to update");
if(!self.isUpdating) { if(!self.isUpdating) {
self.isUpdating = YES; self.isUpdating = YES;
self.number = 0; self.number = 0;
} }
}*/ }*/


for(KAIBatteryCell *cell in addedCells) {
if(![devices containsObject:cell.device]) {
cell.device = nil;
[cell removeFromSuperview];
[self.displayingDevices removeObject:cell.label.text]; //lmaoo
} else {
[cell updateInfo];
}
}

for (BCBatteryDevice *device in devices) { for (BCBatteryDevice *device in devices) {
NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
//double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
BOOL charging = MSHookIvar<long long>(device, "_charging"); BOOL charging = MSHookIvar<long long>(device, "_charging");
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
//BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");


BOOL shouldAdd = NO; BOOL shouldAdd = NO;


NSLog(@"Kai: SHOULD ADD"); NSLog(@"Kai: SHOULD ADD");
} }


BOOL shouldRefresh = NO;

KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device]; KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device];


/* /*
@property (nonatomic, assign) BOOL lastLPM; @property (nonatomic, assign) BOOL lastLPM;
@property (nonatomic, assign) double lastPercent; @property (nonatomic, assign) double lastPercent;
*/ */
if(cell.lastChargingState != charging || cell.lastLPM != LPM || cell.lastPercent != batteryPercentage) {
shouldRefresh = YES;
NSLog(@"Kai: SHOULD REFRESH");
}


if(shouldAdd && [deviceName length]!=0) { if(shouldAdd && [deviceName length]!=0) {


if([self.displayingDevices containsObject:device] && shouldRefresh) {
NSLog(@"Kai: Updating cell: %@ for device:%@", cell, device);
} else if(![self.displayingDevices containsObject:deviceName]) {
if(cell==nil && ![self.displayingDevices containsObject:deviceName]) {
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device]; KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device];
[self addSubview:newCell]; [self addSubview:newCell];
[self.displayingDevices addObject:deviceName]; [self.displayingDevices addObject:deviceName];
[addedCells addObject:newCell];
//y+=bannerHeight + spacing; //y+=bannerHeight + spacing;
NSLog(@"Kai: Added cell: %@ for device:%@", cell, device);
} }
self.number +=1;
//self.number +=1;
y+=bannerHeight + spacing; y+=bannerHeight + spacing;
NSLog(@"Kai: incremented y, so now it is %f", y);
[cell updateInfo];


} else if(!shouldAdd) { } else if(!shouldAdd) {


if([self.displayingDevices containsObject:device]) {
if([self.displayingDevices containsObject:deviceName]) {
[cell removeFromSuperview]; [cell removeFromSuperview];
[self.displayingDevices removeObject:device];
NSLog(@"Kai: Removed cell: %@ for device: %@", cell, device);
[self.displayingDevices removeObject:deviceName];
} }


} }
} }
//[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES; //[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES;
self.isUpdating = NO; self.isUpdating = NO;
self.number = [self.subviews count];
} }
}); });
} }


-(void)removeAllAndRefresh {
for( UIView *view in self.subviews ) {
@try {
[view removeFromSuperview];
} @catch (NSException *exception) {
//Panik
}
}

self.displayingDevices = [[NSMutableArray alloc] init];

addedCells = nil;
[self updateBattery];
}

+(KAIBattery *)sharedInstance { +(KAIBattery *)sharedInstance {
return instance; return instance;
} }

+ 0
- 5
KAIBatteryCell.h View File

@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, assign) BOOL lastChargingState;
@property (nonatomic, assign) BOOL lastLPM;
@property (nonatomic, assign) double lastPercent;

-(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device; -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device;
-(void)updateInfo; -(void)updateInfo;
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device; +(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device;

+ 9
- 9
KAIBatteryCell.mm View File

#import "KAIBatteryCell.h" #import "KAIBatteryCell.h"


NSMutableArray *deviceInstances;
NSMutableArray *deviceInstances = [[NSMutableArray alloc] init];


@implementation KAIBatteryCell @implementation KAIBatteryCell


[self.battery.widthAnchor constraintEqualToConstant:20].active = YES; [self.battery.widthAnchor constraintEqualToConstant:20].active = YES;
[self.battery.heightAnchor constraintEqualToConstant:10].active = YES; [self.battery.heightAnchor constraintEqualToConstant:10].active = YES;


self.lastChargingState = charging;
self.lastLPM = LPM;
self.lastPercent = batteryPercentage;
[deviceInstances addObject:self];
} }


return self; return self;
} }


-(void)updateInfo { -(void)updateInfo {
NSLog(@"kai: updating cell info");


NSString *deviceName = MSHookIvar<NSString *>(self.device, "_name"); NSString *deviceName = MSHookIvar<NSString *>(self.device, "_name");
double batteryPercentage = MSHookIvar<long long>(self.device, "_percentCharge"); double batteryPercentage = MSHookIvar<long long>(self.device, "_percentCharge");
self.battery.chargePercent = (batteryPercentage*0.01); self.battery.chargePercent = (batteryPercentage*0.01);
if(charging) { self.battery.chargingState = 1; } else { self.battery.chargingState = 0; } if(charging) { self.battery.chargingState = 1; } else { self.battery.chargingState = 0; }
self.battery.showsInlineChargingIndicator = YES; self.battery.showsInlineChargingIndicator = YES;
if(LPM) self.battery.saverModeActive = YES;
if(LPM) { self.battery.saverModeActive = YES; } else { self.battery.saverModeActive = NO; }
if(kCFCoreFoundationVersionNumber > 1600) { if(kCFCoreFoundationVersionNumber > 1600) {
[self.battery setBodyColorAlpha:1.0]; [self.battery setBodyColorAlpha:1.0];
[self.battery setPinColorAlpha:1.0]; [self.battery setPinColorAlpha:1.0];


[self.glyphView setImage:[self.device glyph]]; [self.glyphView setImage:[self.device glyph]];


self.lastChargingState = charging;
self.lastLPM = LPM;
self.lastPercent = batteryPercentage;
[deviceInstances addObject:self];


} }


+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device { +(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device {
KAIBatteryCell *foundCell; KAIBatteryCell *foundCell;


NSString *deviceName = MSHookIvar<NSString *>(device, "_name");

for(KAIBatteryCell *cell in deviceInstances) { for(KAIBatteryCell *cell in deviceInstances) {
if(cell.device == device) {
if(cell.label.text == deviceName) {
foundCell = cell; foundCell = cell;
break; break;
} }
} }


return foundCell; return foundCell;
//return deviceInstances;
} }


@end @end

+ 1
- 1
Kai.h View File



isUpdating = YES; isUpdating = YES;


[[KAIBattery sharedInstance] updateBattery];
[[KAIBattery sharedInstance] removeAllAndRefresh];
[(CSAdjunctListView *)([KAIBattery sharedInstance].superview.superview) KaiUpdate]; [(CSAdjunctListView *)([KAIBattery sharedInstance].superview.superview) KaiUpdate];


isUpdating = NO; isUpdating = NO;

+ 8
- 5
Kai.xm View File



-(void)_layoutStackView { -(void)_layoutStackView {


//NSInteger lastSlot = [[self stackView].subviews count] -1;
NSInteger lastSlot = [[self stackView].subviews count] -1;
//this code is used to determine if kai is at the bottom of the stack view //this code is used to determine if kai is at the bottom of the stack view
//if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) {
if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBattery sharedInstance] && belowMusic) {
//if it is not, but the option to have kai below music is on, i simply remove from it's current pos. //if it is not, but the option to have kai below music is on, i simply remove from it's current pos.
//and insert into last slot. //and insert into last slot.
//[[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]];
//[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot];
//}
[[self stackView] removeArrangedSubview:[KAIBattery sharedInstance]];
[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot];
}
//makes kai lay itself out when the stack does //makes kai lay itself out when the stack does
NSLog(@"kai: laying out stack view");
[self KaiUpdate]; [self KaiUpdate];


%orig; %orig;


isUpdating = YES; isUpdating = YES;


NSLog(@"kai: kai info will update");

[[KAIBattery sharedInstance] updateBattery]; [[KAIBattery sharedInstance] updateBattery];
[self KaiUpdate]; [self KaiUpdate];



Loading…
Cancel
Save