diff --git a/KAIBatteryCell.h b/KAIBatteryCell.h index d8219e5..5605374 100644 --- a/KAIBatteryCell.h +++ b/KAIBatteryCell.h @@ -32,6 +32,7 @@ @property (nonatomic, strong) NSString *identifier; -(id)glyph; -(id)kaiCellForDevice; +-(void)resetKaiCellForNewPrefs; @end @interface KAIBatteryCell : UIView @@ -44,6 +45,4 @@ @property (nonatomic, strong) NSLayoutConstraint *height; -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device; -(void)updateInfo; -+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2; -+(void)resetArray; @end \ No newline at end of file diff --git a/KAIBatteryCell.mm b/KAIBatteryCell.mm index bc0074c..b071f33 100644 --- a/KAIBatteryCell.mm +++ b/KAIBatteryCell.mm @@ -1,7 +1,5 @@ #import "KAIBatteryCell.h" -NSMutableArray *deviceInstances = [[NSMutableArray alloc] init]; - @implementation KAIBatteryCell -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device { @@ -113,7 +111,6 @@ NSMutableArray *deviceInstances = [[NSMutableArray alloc] init]; [self.battery.widthAnchor constraintEqualToConstant:20].active = YES; [self.battery.heightAnchor constraintEqualToConstant:10].active = YES; - [deviceInstances addObject:self]; } return self; @@ -166,28 +163,4 @@ NSMutableArray *deviceInstances = [[NSMutableArray alloc] init]; } -+(instancetype)cellForDeviceIfExists:(BCBatteryDevice *)device frameToCreateNew:(CGRect)arg2 { - KAIBatteryCell *foundCell; - - //NSString *deviceName = MSHookIvar(device, "_name"); - - for(KAIBatteryCell *cell in deviceInstances) { - if(cell.device == device || [cell.device.identifier isEqualToString:device.identifier]) { - foundCell = cell; - break; - } - } - - if(foundCell == nil) { - foundCell = [[KAIBatteryCell alloc] initWithFrame:arg2 device:device]; - } - - return foundCell; - //return deviceInstances; -} - -+(void)resetArray { - deviceInstances = [[NSMutableArray alloc] init]; -} - @end \ No newline at end of file diff --git a/KAIBatteryStack.h b/KAIBatteryStack.h index c978a9a..0f5eda4 100644 --- a/KAIBatteryStack.h +++ b/KAIBatteryStack.h @@ -5,6 +5,6 @@ @property (nonatomic, assign) BOOL isUpdating; +(KAIBatteryStack *)sharedInstance; -(instancetype)init; --(void)removeAllAndRefresh; +-(void)refreshForPrefs; -(void)updateBattery; @end \ No newline at end of file diff --git a/KAIBatteryStack.mm b/KAIBatteryStack.mm index d22dcc1..cff0247 100644 --- a/KAIBatteryStack.mm +++ b/KAIBatteryStack.mm @@ -36,7 +36,7 @@ long long lastPercentage; BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; NSArray *devices = MSHookIvar(bcb, "_sortedDevices"); - NSLog(@"kai: devices are %@", devices); + //NSLog(@"kai: devices are %@", devices); for (BCBatteryDevice *device in devices) { KAIBatteryCell *cell = [device kaiCellForDevice]; @@ -70,20 +70,6 @@ long long lastPercentage; } } - - for(KAIBatteryCell *cell in self.subviews) { - //BCBatteryDevice *device = cell.device; - [cell updateInfo]; - if(![devices containsObject:cell.device]) { - [UIView animateWithDuration:0.3 animations:^{ - cell.alpha = 0; - } completion:^(BOOL finished) { - [cell removeFromSuperview]; - [self removeArrangedSubview:cell]; - cell.alpha = 1; - }]; - } - } self.number = [self.subviews count]; } @@ -95,16 +81,12 @@ long long lastPercentage; self.number = [self.subviews count]; } --(void)removeAllAndRefresh { - for( UIView *view in self.subviews ) { - @try { - [view removeFromSuperview]; - } @catch (NSException *exception) { - //Panik - } +-(void)refreshForPrefs { + BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; + NSArray *devices = MSHookIvar(bcb, "_sortedDevices"); + for(BCBatteryDevice *device in devices) { + [device resetKaiCellForNewPrefs]; } - [KAIBatteryCell resetArray]; - [self updateBattery]; } +(KAIBatteryStack *)sharedInstance { diff --git a/Kai.h b/Kai.h index 0584ab8..a8c2254 100644 --- a/Kai.h +++ b/Kai.h @@ -115,7 +115,7 @@ static void applyPrefs() isUpdating = YES; - [[KAIBatteryStack sharedInstance] removeAllAndRefresh]; + [[KAIBatteryStack sharedInstance] refreshForPrefs]; [(CSAdjunctListView *)([KAIBatteryStack sharedInstance].superview.superview) KaiUpdate]; isUpdating = NO; diff --git a/Kai.xm b/Kai.xm index 1a63d98..6624969 100644 --- a/Kai.xm +++ b/Kai.xm @@ -50,6 +50,21 @@ -(void)KaiUpdate { KAIBatteryStack *battery = [KAIBatteryStack sharedInstance]; //battery.number = [battery.subviews count]; + BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; + NSArray *devices = MSHookIvar(bcb, "_sortedDevices"); + for(KAIBatteryCell *cell in battery.subviews) { + //BCBatteryDevice *device = cell.device; + [cell updateInfo]; + if(![devices containsObject:cell.device]) { + [UIView animateWithDuration:0.3 animations:^{ + cell.alpha = 0; + } completion:^(BOOL finished) { + [cell removeFromSuperview]; + [battery removeArrangedSubview:cell]; + cell.alpha = 1; + }]; + } + } [UIView animateWithDuration:0.3 animations:^{ @@ -130,6 +145,15 @@ return self.kaiCell; } + +%new +-(void)resetKaiCellForNewPrefs { + 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].active = YES; + + [(KAIBatteryCell *)self.kaiCell updateInfo]; +} %end %hook KAICSTarget //Again, not a class