From b126746a46bb7d2f497c0131c41a7f43bcb8253c Mon Sep 17 00:00:00 2001 From: Burrit0z Date: Tue, 28 Apr 2020 16:24:39 -0400 Subject: [PATCH] KOV --- KAIBattery.h | 2 +- KAIBattery.mm | 31 ++++++++++++++++++++++++------- Kai.xm | 23 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/KAIBattery.h b/KAIBattery.h index 2c04802..7dd9afa 100644 --- a/KAIBattery.h +++ b/KAIBattery.h @@ -17,7 +17,7 @@ +(id)sharedInstance; @end -@interface BCBatteryDevice : BCBatteryDeviceController +@interface BCBatteryDevice : NSObject -(id)glyph; @end diff --git a/KAIBattery.mm b/KAIBattery.mm index e6c7bcc..2844d19 100644 --- a/KAIBattery.mm +++ b/KAIBattery.mm @@ -28,6 +28,14 @@ long long lastPercentage; BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; NSArray *devices = MSHookIvar(bcb, "_sortedDevices"); + for( UIView *view in self.subviews ) { + @try { + [view removeFromSuperview]; + } @catch (NSException *exception) { + //Panik + } + } + for (BCBatteryDevice *device in devices) { NSString *deviceName = MSHookIvar(device, "_name"); double batteryPercentage = MSHookIvar(device, "_percentCharge"); @@ -41,9 +49,8 @@ long long lastPercentage; blank.frame = CGRectMake(0, 0 + y, self.frame.size.width, 80); blank.layer.masksToBounds = YES; blank.layer.cornerRadius = 13; - blank.alpha = 0.8; + blank.alpha = 0; //[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]]; - [self addSubview:blank]; NSString *labelText = [NSString stringWithFormat:@"%@", deviceName]; @@ -52,13 +59,14 @@ long long lastPercentage; [label setTextColor:[UIColor whiteColor]]; label.lineBreakMode = NSLineBreakByWordWrapping; label.numberOfLines = 0; + label.alpha = 0; [label setText:labelText]; - [self addSubview:label]; - _UIBatteryView *battery = [[_UIBatteryView alloc] init]; battery.chargePercent = (batteryPercentage*0.01); UILabel *percentLabel = [[UILabel alloc] init]; + percentLabel.alpha = 0; + battery.alpha = 0; battery.showsPercentage = NO; [percentLabel setFont:[UIFont systemFontOfSize:14]]; [percentLabel setTextColor:[UIColor whiteColor]]; @@ -66,7 +74,6 @@ long long lastPercentage; [percentLabel setTextAlignment:NSTextAlignmentRight]; percentLabel.numberOfLines = 0; [percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]]; - [self addSubview:percentLabel]; if(charging) battery.chargingState = 1; battery.showsInlineChargingIndicator = YES; if(LPM) battery.saverModeActive = YES; @@ -74,13 +81,12 @@ long long lastPercentage; [battery setBodyColorAlpha:1.0]; [battery setPinColorAlpha:1.0]; } - [self addSubview:battery]; UIImage *glyph = [device glyph]; UIImageView *glyphView = [[UIImageView alloc] init]; + glyphView.alpha = 0; glyphView.contentMode = UIViewContentModeScaleAspectFit; [glyphView setImage:glyph]; - [self addSubview:glyphView]; label.frame = CGRectMake(57.5,27.5 + y,275,25); glyphView.frame = CGRectMake(12.5,18.5 + y,40,40); @@ -89,6 +95,17 @@ long long lastPercentage; y+=85; self.number +=1; + + [self addSubview:blank]; + [self addSubview:percentLabel]; + [self addSubview:label]; + [self addSubview:battery]; + [self addSubview:glyphView]; + blank.alpha = 0.8; + percentLabel.alpha = 1; + battery.alpha = 1; + label.alpha = 1; + glyphView.alpha = 1; } } self.isUpdating = NO; diff --git a/Kai.xm b/Kai.xm index 8399b22..199de34 100644 --- a/Kai.xm +++ b/Kai.xm @@ -48,7 +48,7 @@ CGRect originalBattery; } %end*/ - +/* %hook SBCoverSheetPrimarySlidingViewController -(void)viewWillAppear:(BOOL)arg1 { @@ -63,7 +63,7 @@ CGRect originalBattery; [batteryWidget.battery updateBattery]; [batteryWidget KaiUpdate]; }*/ -%end +//%end %hook CSMainPageView @@ -79,7 +79,6 @@ CGRect originalBattery; setFrame = YES; batteryWidget = self; } - [self.battery updateBattery]; [self KaiUpdate]; } @@ -100,4 +99,22 @@ CGRect originalBattery; originalBattery.size.height ); } +%end + +%hook BCBatteryDevice + +- (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 { + + [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil]; + [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil]; + + //[self setValue:@"crash" forKeyPath:@"euhidehuud"]; + + return %orig; +} + +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ + NSLog(@"It works"); + +} %end \ No newline at end of file