mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 17:46:47 +00:00
soon fix, this still broke
This commit is contained in:
@ -5,5 +5,6 @@
|
|||||||
@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
|
@ -1,6 +1,8 @@
|
|||||||
#import "KAIBattery.h"
|
#import "KAIBattery.h"
|
||||||
|
|
||||||
KAIBattery *instance;
|
KAIBattery *instance;
|
||||||
|
NSMutableArray *addedCells = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
@implementation KAIBattery
|
@implementation KAIBattery
|
||||||
|
|
||||||
-(instancetype)init {
|
-(instancetype)init {
|
||||||
@ -19,6 +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");
|
||||||
if(!self.isUpdating) {
|
if(!self.isUpdating) {
|
||||||
self.isUpdating = YES;
|
self.isUpdating = YES;
|
||||||
self.number = 0;
|
self.number = 0;
|
||||||
@ -34,11 +37,21 @@ long long lastPercentage;
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@ -50,8 +63,6 @@ long long lastPercentage;
|
|||||||
NSLog(@"Kai: SHOULD ADD");
|
NSLog(@"Kai: SHOULD ADD");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL shouldRefresh = NO;
|
|
||||||
|
|
||||||
KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device];
|
KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -59,43 +70,50 @@ long long lastPercentage;
|
|||||||
@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) {
|
if(cell==nil && ![self.displayingDevices containsObject:deviceName]) {
|
||||||
NSLog(@"Kai: Updating cell: %@ for device:%@", cell, device);
|
|
||||||
} else if(![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];
|
[self.displayingDevices removeObject:deviceName];
|
||||||
NSLog(@"Kai: Removed cell: %@ for device: %@", cell, device);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//[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;
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,6 @@
|
|||||||
@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;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#import "KAIBatteryCell.h"
|
#import "KAIBatteryCell.h"
|
||||||
|
|
||||||
NSMutableArray *deviceInstances;
|
NSMutableArray *deviceInstances = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
@implementation KAIBatteryCell
|
@implementation KAIBatteryCell
|
||||||
|
|
||||||
@ -113,15 +113,14 @@ NSMutableArray *deviceInstances;
|
|||||||
[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;
|
[deviceInstances addObject:self];
|
||||||
self.lastLPM = LPM;
|
|
||||||
self.lastPercent = batteryPercentage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
@ -133,7 +132,7 @@ NSMutableArray *deviceInstances;
|
|||||||
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];
|
||||||
@ -143,9 +142,7 @@ NSMutableArray *deviceInstances;
|
|||||||
|
|
||||||
[self.glyphView setImage:[self.device glyph]];
|
[self.glyphView setImage:[self.device glyph]];
|
||||||
|
|
||||||
self.lastChargingState = charging;
|
[deviceInstances addObject:self];
|
||||||
self.lastLPM = LPM;
|
|
||||||
self.lastPercent = batteryPercentage;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,14 +154,17 @@ NSMutableArray *deviceInstances;
|
|||||||
+(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
|
2
Kai.h
2
Kai.h
@ -114,7 +114,7 @@ static void applyPrefs()
|
|||||||
|
|
||||||
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;
|
||||||
|
13
Kai.xm
13
Kai.xm
@ -6,16 +6,17 @@
|
|||||||
|
|
||||||
-(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] removeArrangedSubview:[KAIBattery sharedInstance]];
|
||||||
//[[self stackView] insertArrangedSubview:[KAIBattery sharedInstance] atIndex:lastSlot];
|
[[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;
|
||||||
@ -79,6 +80,8 @@
|
|||||||
|
|
||||||
isUpdating = YES;
|
isUpdating = YES;
|
||||||
|
|
||||||
|
NSLog(@"kai: kai info will update");
|
||||||
|
|
||||||
[[KAIBattery sharedInstance] updateBattery];
|
[[KAIBattery sharedInstance] updateBattery];
|
||||||
[self KaiUpdate];
|
[self KaiUpdate];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user