1
0
mirror of https://github.com/Burrit0z/kai synced 2025-06-30 21:06:46 +00:00

progress towards not trash

This commit is contained in:
Burrit0z
2020-05-22 11:06:54 -04:00
parent f71e68376c
commit f84e7aac38
4 changed files with 32 additions and 63 deletions

View File

@ -1,7 +1,7 @@
#import "KAIBattery.h" #import "KAIBattery.h"
KAIBattery *instance; KAIBattery *instance;
NSMutableArray *addedCells = [[NSMutableArray alloc] init]; //NSMutableArray *showingCells = [[NSMutableArray alloc] init];
@implementation KAIBattery @implementation KAIBattery
@ -21,7 +21,7 @@ long long lastPercentage;
-(void)updateBattery { -(void)updateBattery {
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");
if(!self.isUpdating) { if(!self.isUpdating) {
self.isUpdating = YES; self.isUpdating = YES;
self.number = 0; self.number = 0;
@ -29,30 +29,15 @@ long long lastPercentage;
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
/*for( UIView *view in self.subviews ) { for(KAIBatteryCell *cell in self.subviews) {
@try { if([cell respondsToSelector:@selector(updateInfo)] && ![devices containsObject:cell.device]) { //to confirm is a cell and battery device does not exist
[view removeFromSuperview]; [cell removeFromSuperview];
} @catch (NSException *exception) { } else if([cell respondsToSelector:@selector(updateInfo)]) {
//Panik [cell updateInfo];
}
}*/
for(KAIBatteryCell *cell in addedCells) {
if(cell.device!=nil) {
NSString *cellName = MSHookIvar<NSString *>(cell.device, "_name");
if(![addedCells containsObject:cellName]) {
cell.device = nil;
[cell removeFromSuperview];
[self.displayingDevices removeObject:cell.label.text]; //lmaoo
} else {
[cell updateInfo];
}
} else {
//[cell removeFromSuperview];
//[addedCells removeObject:cell];
} }
} }
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");
@ -63,41 +48,23 @@ long long lastPercentage;
if(showAll) { if(showAll) {
shouldAdd = YES; shouldAdd = YES;
NSLog(@"Kai: SHOULD ADD"); //NSLog(@"Kai: SHOULD ADD");
} else if(!showAll && charging) { } else if(!showAll && charging) {
shouldAdd = YES; shouldAdd = YES;
NSLog(@"Kai: SHOULD ADD"); //NSLog(@"Kai: SHOULD ADD");
} }
KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device]; KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device frameToCreateNew:CGRectMake(0, y, self.frame.size.width, bannerHeight)];
/*
@property (nonatomic, assign) BOOL lastChargingState;
@property (nonatomic, assign) BOOL lastLPM;
@property (nonatomic, assign) double lastPercent;
*/
if(shouldAdd && [deviceName length]!=0) { if(shouldAdd && [deviceName length]!=0) {
if(![self.subviews containsObject:cell]) {
if(cell==nil && ![self.displayingDevices containsObject:deviceName]) { cell.frame = CGRectMake(0, y, self.frame.size.width, bannerHeight);
KAIBatteryCell *newCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0, y, self.frame.size.width, bannerHeight) device:device]; [self addSubview:cell];
[self addSubview:newCell];
[self.displayingDevices addObject:deviceName];
[addedCells addObject:newCell];
//y+=bannerHeight + spacing;
} }
//self.number +=1;
y+=bannerHeight + spacing; y+=bannerHeight + spacing;
} else if(!shouldAdd) { } else if(!shouldAdd) {
[cell removeFromSuperview];
if([self.displayingDevices containsObject:deviceName]) {
cell.device = nil;
[cell removeFromSuperview];
[self.displayingDevices removeObject:deviceName];
[addedCells removeObject:cell];
}
} }
} }
//[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES; //[self.heightAnchor constraintEqualToConstant:(self.number * 85)].active = YES;
@ -116,9 +83,9 @@ long long lastPercentage;
} }
} }
self.displayingDevices = [[NSMutableArray alloc] init]; //self.displayingDevices = [[NSMutableArray alloc] init];
addedCells = nil; //addedCells = nil;
[self updateBattery]; [self updateBattery];
} }

View File

@ -24,6 +24,7 @@
@end @end
@interface BCBatteryDevice : NSObject @interface BCBatteryDevice : NSObject
@property (nonatomic, strong) NSString *accessoryIdentifier;
-(id)glyph; -(id)glyph;
@end @end
@ -35,5 +36,5 @@
@property (nonatomic, strong) _UIBatteryView *battery; @property (nonatomic, strong) _UIBatteryView *battery;
-(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 frameToCreateNew:(CGRect)arg2;
@end @end

View File

@ -120,7 +120,7 @@ NSMutableArray *deviceInstances = [[NSMutableArray alloc] init];
} }
-(void)updateInfo { -(void)updateInfo {
NSLog(@"kai: updating cell info"); //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");
@ -142,29 +142,30 @@ NSMutableArray *deviceInstances = [[NSMutableArray alloc] init];
[self.glyphView setImage:[self.device glyph]]; [self.glyphView setImage:[self.device glyph]];
[deviceInstances addObject:self];
} }
-(void)removeFromSuperview { +(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2 {
[super removeFromSuperview];
[deviceInstances removeObject:self];
}
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device {
KAIBatteryCell *foundCell; KAIBatteryCell *foundCell;
NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); //NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
for(KAIBatteryCell *cell in deviceInstances) { for(KAIBatteryCell *cell in deviceInstances) {
if(cell.label.text == deviceName) { if(cell.device == device || [cell.device.accessoryIdentifier isEqualToString:device.accessoryIdentifier]) {
foundCell = cell; foundCell = cell;
break; break;
} }
} }
if(foundCell == nil) {
foundCell = [[KAIBatteryCell alloc] initWithFrame:arg2 device:device];
}
return foundCell; return foundCell;
//return deviceInstances; //return deviceInstances;
} }
+(id)array {
return deviceInstances;
}
@end @end

2
Kai.xm
View File

@ -80,7 +80,7 @@
isUpdating = YES; isUpdating = YES;
NSLog(@"kai: kai info will update"); //NSLog(@"kai: kai info will update");
[[KAIBattery sharedInstance] updateBattery]; [[KAIBattery sharedInstance] updateBattery];
[self KaiUpdate]; [self KaiUpdate];