ソースを参照

soon fix, this still broke

pull/1/head
Burrit0z 4年前
コミット
6aeb4cb375
6個のファイルの変更55行の追加38行の削除
  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 ファイルの表示

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

+ 36
- 18
KAIBattery.mm ファイルの表示

@@ -1,6 +1,8 @@
#import "KAIBattery.h"

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

@implementation KAIBattery

-(instancetype)init {
@@ -19,6 +21,7 @@ long long lastPercentage;

-(void)updateBattery {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"kai: battery platter called to update");
if(!self.isUpdating) {
self.isUpdating = YES;
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) {
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 LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
//BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");

BOOL shouldAdd = NO;

@@ -50,8 +63,6 @@ long long lastPercentage;
NSLog(@"Kai: SHOULD ADD");
}

BOOL shouldRefresh = NO;

KAIBatteryCell *cell = [KAIBatteryCell cellForDeviceIfExists:device];

/*
@@ -59,43 +70,50 @@ long long lastPercentage;
@property (nonatomic, assign) BOOL lastLPM;
@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([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];
[self addSubview:newCell];
[self.displayingDevices addObject:deviceName];
[addedCells addObject:newCell];
//y+=bannerHeight + spacing;
NSLog(@"Kai: Added cell: %@ for device:%@", cell, device);
}
self.number +=1;
//self.number +=1;
y+=bannerHeight + spacing;
NSLog(@"Kai: incremented y, so now it is %f", y);
[cell updateInfo];

} else if(!shouldAdd) {

if([self.displayingDevices containsObject:device]) {
if([self.displayingDevices containsObject:deviceName]) {
[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.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 {
return instance;
}

+ 0
- 5
KAIBatteryCell.h ファイルの表示

@@ -33,11 +33,6 @@
@property (nonatomic, strong) UILabel *percentLabel;
@property (nonatomic, strong) UIImageView *glyphView;
@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;
-(void)updateInfo;
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device;

+ 9
- 9
KAIBatteryCell.mm ファイルの表示

@@ -1,6 +1,6 @@
#import "KAIBatteryCell.h"

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

@implementation KAIBatteryCell

@@ -113,15 +113,14 @@ NSMutableArray *deviceInstances;
[self.battery.widthAnchor constraintEqualToConstant:20].active = YES;
[self.battery.heightAnchor constraintEqualToConstant:10].active = YES;

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

return self;
}

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

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

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

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

}

@@ -157,14 +154,17 @@ NSMutableArray *deviceInstances;
+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device {
KAIBatteryCell *foundCell;

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

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

return foundCell;
//return deviceInstances;
}

@end

+ 1
- 1
Kai.h ファイルの表示

@@ -114,7 +114,7 @@ static void applyPrefs()

isUpdating = YES;

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

isUpdating = NO;

+ 8
- 5
Kai.xm ファイルの表示

@@ -6,16 +6,17 @@

-(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
//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.
//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
NSLog(@"kai: laying out stack view");
[self KaiUpdate];

%orig;
@@ -79,6 +80,8 @@

isUpdating = YES;

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

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


読み込み中…
キャンセル
保存