mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 10:56:47 +00:00
initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
*.deb
|
||||||
|
.DS_Store
|
10
DragonMake
Normal file
10
DragonMake
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
package_name: kai
|
||||||
|
install_command: sbreload
|
||||||
|
|
||||||
|
kai:
|
||||||
|
type: tweak
|
||||||
|
logos_files:
|
||||||
|
- Kai.xm
|
||||||
|
frameworks:
|
||||||
|
- BatteryCenter
|
29
KAIBattery.h
Normal file
29
KAIBattery.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <substrate.h>
|
||||||
|
|
||||||
|
@interface _UIBatteryView : UIView
|
||||||
|
@property (nonatomic, assign) CGFloat chargePercent;
|
||||||
|
@property (nonatomic, assign) CGFloat bodyColorAlpha;
|
||||||
|
@property (nonatomic, assign) CGFloat pinColorAlpha;
|
||||||
|
@property (nonatomic, assign) BOOL showsPercentage;
|
||||||
|
@property (nonatomic, assign) BOOL saverModeActive;
|
||||||
|
@property (nonatomic, assign) BOOL showsInlineChargingIndicator;
|
||||||
|
@property (nonatomic, assign) NSInteger chargingState;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface BCBatteryDeviceController
|
||||||
|
@property (nonatomic, strong) NSArray *sortedDevices;
|
||||||
|
-(id)_sortedDevices;
|
||||||
|
+(id)sharedInstance;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface BCBatteryDevice : BCBatteryDeviceController
|
||||||
|
-(id)glyph;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface KAIBattery : UIView
|
||||||
|
@property (nonatomic, strong) NSArray *devices;
|
||||||
|
@property (nonatomic, assign) NSInteger number;
|
||||||
|
-(instancetype)initWithFrame:(CGRect)arg1;
|
||||||
|
-(void)updateBattery;
|
||||||
|
@end
|
99
KAIBattery.mm
Normal file
99
KAIBattery.mm
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#import "KAIBattery.h"
|
||||||
|
|
||||||
|
@implementation KAIBattery
|
||||||
|
|
||||||
|
-(instancetype)initWithFrame:(CGRect)arg1 {
|
||||||
|
self = [super initWithFrame:arg1];
|
||||||
|
if (self) {
|
||||||
|
/*self.batteryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25,-10,220,120)];
|
||||||
|
[self.batteryLabel setFont:[UIFont systemFontOfSize:13]];
|
||||||
|
[self.batteryLabel setTextColor:[UIColor whiteColor]];
|
||||||
|
self.batteryLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
self.batteryLabel.numberOfLines = 0;*/
|
||||||
|
[self updateBattery];
|
||||||
|
//[self addSubview:self.batteryLabel];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long batteryPercentage;
|
||||||
|
long long lastPercentage;
|
||||||
|
|
||||||
|
-(void)updateBattery {
|
||||||
|
self.number = 0;
|
||||||
|
NSArray* subViews = self.subviews;
|
||||||
|
for( UIView *view in subViews ) {
|
||||||
|
@try {
|
||||||
|
[view removeFromSuperview];
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
//Panik
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
||||||
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
||||||
|
|
||||||
|
for (BCBatteryDevice *device in devices) {
|
||||||
|
NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
|
||||||
|
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
|
||||||
|
BOOL charging = MSHookIvar<long long>(device, "_charging");
|
||||||
|
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
|
||||||
|
|
||||||
|
float y;
|
||||||
|
if(charging) {
|
||||||
|
|
||||||
|
UIVisualEffectView *blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
|
||||||
|
blank.frame = CGRectMake(0, 0 + y, self.frame.size.width, 80);
|
||||||
|
blank.layer.masksToBounds = YES;
|
||||||
|
blank.layer.cornerRadius = 18;
|
||||||
|
//[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]];
|
||||||
|
[self addSubview:blank];
|
||||||
|
|
||||||
|
NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
|
||||||
|
|
||||||
|
UILabel *label = [[UILabel alloc] init];
|
||||||
|
[label setFont:[UIFont systemFontOfSize:16]];
|
||||||
|
[label setTextColor:[UIColor whiteColor]];
|
||||||
|
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
label.numberOfLines = 0;
|
||||||
|
[label setText:labelText];
|
||||||
|
|
||||||
|
[self addSubview:label];
|
||||||
|
|
||||||
|
_UIBatteryView *battery = [[_UIBatteryView alloc] init];
|
||||||
|
battery.chargePercent = (batteryPercentage*0.01);
|
||||||
|
UILabel *percentLabel = [[UILabel alloc] init];
|
||||||
|
battery.showsPercentage = NO;
|
||||||
|
[percentLabel setFont:[UIFont systemFontOfSize:14]];
|
||||||
|
[percentLabel setTextColor:[UIColor whiteColor]];
|
||||||
|
percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
[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;
|
||||||
|
if(kCFCoreFoundationVersionNumber > 1600) {
|
||||||
|
[battery setBodyColorAlpha:1.0];
|
||||||
|
[battery setPinColorAlpha:1.0];
|
||||||
|
}
|
||||||
|
[self addSubview:battery];
|
||||||
|
|
||||||
|
UIImage *glyph = [device glyph];
|
||||||
|
UIImageView *glyphView = [[UIImageView alloc] init];
|
||||||
|
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);
|
||||||
|
battery.frame = CGRectMake(310,35 + y,20,10);
|
||||||
|
percentLabel.frame = CGRectMake(265,35 + y,36,12);
|
||||||
|
|
||||||
|
y+=90;
|
||||||
|
self.number +=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
1
Kai.plist
Normal file
1
Kai.plist
Normal file
@ -0,0 +1 @@
|
|||||||
|
{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
|
150
Kai.xm
Normal file
150
Kai.xm
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#import <objc/runtime.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#import "KAIBattery.mm"
|
||||||
|
BOOL setFrame = NO;
|
||||||
|
KAIBattery *batteryWidget;
|
||||||
|
CGRect original;
|
||||||
|
|
||||||
|
/*
|
||||||
|
- (void)addObserver:(NSObject *)observer
|
||||||
|
forKeyPath:(NSString *)keyPath
|
||||||
|
options:(NSKeyValueObservingOptions)options
|
||||||
|
context:(void *)context*/
|
||||||
|
|
||||||
|
|
||||||
|
@interface UIApplication (Kai)
|
||||||
|
+(id)sharedApplication;
|
||||||
|
-(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface CSMainPageView : UIView
|
||||||
|
@property (nonatomic, strong) KAIBattery *battery;
|
||||||
|
-(void)updateForPresentation:(id)arg1;
|
||||||
|
@end
|
||||||
|
/*
|
||||||
|
%hook BCBatterDeviceController
|
||||||
|
|
||||||
|
+(id)sharedInstance {
|
||||||
|
[%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
|
return %orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
||||||
|
|
||||||
|
if ([keyPath isEqualToString:@"sortedDevices"]) {
|
||||||
|
[[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
%end*/
|
||||||
|
|
||||||
|
%hook SBCoverSheetPrimarySlidingViewController
|
||||||
|
|
||||||
|
-(void)viewWillAppear:(BOOL)arg1 {
|
||||||
|
%orig;
|
||||||
|
[batteryWidget updateBattery];
|
||||||
|
}
|
||||||
|
|
||||||
|
%end
|
||||||
|
|
||||||
|
|
||||||
|
%hook CSMainPageView
|
||||||
|
%property (nonatomic, strong) KAIBattery *battery;
|
||||||
|
|
||||||
|
-(void)updateForPresentation:(id)arg1 {
|
||||||
|
%orig;
|
||||||
|
UIView *object = self;
|
||||||
|
if(!setFrame) {
|
||||||
|
original = self.frame;
|
||||||
|
|
||||||
|
self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, 155, object.frame.size.width - 16, object.frame.size.height)];
|
||||||
|
[self addSubview:self.battery];
|
||||||
|
setFrame = YES;
|
||||||
|
batteryWidget = self.battery;
|
||||||
|
}
|
||||||
|
|
||||||
|
object.frame = CGRectMake(
|
||||||
|
original.origin.x,
|
||||||
|
original.origin.y - (self.battery.number * 90),
|
||||||
|
original.size.width,
|
||||||
|
original.size.height + (self.battery.number * 90)
|
||||||
|
);
|
||||||
|
|
||||||
|
//[self.battery updateBattery];
|
||||||
|
/*
|
||||||
|
NSArray* subViews = self.subviews;
|
||||||
|
for( UIView *view in subViews ) {
|
||||||
|
if([view isMemberOfClass:[objc_getClass("UILabel") class]] || [view isMemberOfClass:[objc_getClass("_UIBatteryView") class]] || [view isKindOfClass:[objc_getClass("UIImageView") class]]) {
|
||||||
|
@try {
|
||||||
|
[view removeFromSuperview];
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
//Panik
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
||||||
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
||||||
|
for (BCBatteryDevice *device in devices) {
|
||||||
|
NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
|
||||||
|
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
|
||||||
|
BOOL charging = MSHookIvar<long long>(device, "_charging");
|
||||||
|
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
|
||||||
|
if(charging) {
|
||||||
|
|
||||||
|
NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
|
||||||
|
|
||||||
|
UILabel *label = [[UILabel alloc] init];
|
||||||
|
[label setFont:[UIFont systemFontOfSize:18]];
|
||||||
|
[label setTextColor:[UIColor whiteColor]];
|
||||||
|
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
label.numberOfLines = 0;
|
||||||
|
[label setText:labelText];
|
||||||
|
|
||||||
|
[self addSubview:label];
|
||||||
|
|
||||||
|
_UIBatteryView *battery = [[_UIBatteryView alloc] init];
|
||||||
|
battery.chargePercent = (batteryPercentage*0.01);
|
||||||
|
UILabel *percentLabel = [[UILabel alloc] init];
|
||||||
|
//if(self.percentEnabled) {
|
||||||
|
// battery.showsPercentage = YES;
|
||||||
|
// } else {
|
||||||
|
battery.showsPercentage = NO;
|
||||||
|
[percentLabel setFont:[UIFont systemFontOfSize:14]];
|
||||||
|
[percentLabel setTextColor:[UIColor whiteColor]];
|
||||||
|
percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
[percentLabel setTextAlignment:NSTextAlignmentRight];
|
||||||
|
percentLabel.numberOfLines = 0;
|
||||||
|
[percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
|
||||||
|
[self addSubview:percentLabel];
|
||||||
|
//}
|
||||||
|
if(charging) battery.chargingState = 2;
|
||||||
|
if(LPM) battery.saverModeActive = YES;
|
||||||
|
if(kCFCoreFoundationVersionNumber > 1600) {
|
||||||
|
[battery setBodyColorAlpha:1.0];
|
||||||
|
[battery setPinColorAlpha:1.0];
|
||||||
|
}
|
||||||
|
[self addSubview:battery];
|
||||||
|
|
||||||
|
UIImage *glyph = [device glyph];
|
||||||
|
UIImageView *glyphView = [[UIImageView alloc] init];
|
||||||
|
//if(self.glyphsEnabled) {
|
||||||
|
glyphView.contentMode = UIViewContentModeScaleAspectFit;
|
||||||
|
[glyphView setImage:glyph];
|
||||||
|
[self addSubview:glyphView];
|
||||||
|
//}
|
||||||
|
|
||||||
|
label.frame = CGRectMake(10,20,275,25);
|
||||||
|
glyphView.frame = CGRectMake(27,25,17,15);
|
||||||
|
battery.frame = CGRectMake(325,25,20,10);
|
||||||
|
percentLabel.frame = CGRectMake(285,25,36,12);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
%end
|
91
backup.mm
Normal file
91
backup.mm
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
#import "KAIBattery.h"
|
||||||
|
|
||||||
|
@implementation KAIBattery
|
||||||
|
|
||||||
|
-(instancetype)initWithFrame:(CGRect)arg1 {
|
||||||
|
self = [super initWithFrame:arg1];
|
||||||
|
if (self) {
|
||||||
|
/*self.batteryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25,-10,220,120)];
|
||||||
|
[self.batteryLabel setFont:[UIFont systemFontOfSize:13]];
|
||||||
|
[self.batteryLabel setTextColor:[UIColor whiteColor]];
|
||||||
|
self.batteryLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
self.batteryLabel.numberOfLines = 0;*/
|
||||||
|
[self updateBattery];
|
||||||
|
//[self addSubview:self.batteryLabel];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long batteryPercentage;
|
||||||
|
long long lastPercentage;
|
||||||
|
|
||||||
|
-(void)updateBattery {
|
||||||
|
NSArray* subViews = self.subviews;
|
||||||
|
for( UIView *view in subViews ) {
|
||||||
|
@try {
|
||||||
|
[view removeFromSuperview];
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
//Panik
|
||||||
|
}
|
||||||
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
||||||
|
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
|
||||||
|
|
||||||
|
for (BCBatteryDevice *device in devices) {
|
||||||
|
NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
|
||||||
|
double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
|
||||||
|
BOOL charging = MSHookIvar<long long>(device, "_charging");
|
||||||
|
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
|
||||||
|
|
||||||
|
NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
|
||||||
|
|
||||||
|
UILabel *label = [[UILabel alloc] init];
|
||||||
|
if([devices count]>=4) {
|
||||||
|
[label setFont:[UIFont systemFontOfSize:19]];
|
||||||
|
}
|
||||||
|
[label setTextColor:[UIColor whiteColor]];
|
||||||
|
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
label.numberOfLines = 0;
|
||||||
|
[label setText:labelText];
|
||||||
|
|
||||||
|
[self addSubview:label];
|
||||||
|
|
||||||
|
_UIBatteryView *battery = [[_UIBatteryView alloc] init];
|
||||||
|
battery.chargePercent = (batteryPercentage*0.01);
|
||||||
|
UILabel *percentLabel = [[UILabel alloc] init];
|
||||||
|
battery.showsPercentage = NO;
|
||||||
|
[percentLabel setFont:[UIFont systemFontOfSize:14]];
|
||||||
|
[percentLabel setTextColor:[UIColor whiteColor]];
|
||||||
|
percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
|
[percentLabel setTextAlignment:NSTextAlignmentRight];
|
||||||
|
percentLabel.numberOfLines = 0;
|
||||||
|
[percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
|
||||||
|
[self addSubview:percentLabel];
|
||||||
|
if(charging) battery.chargingState = 1;
|
||||||
|
if(LPM) battery.saverModeActive = YES;
|
||||||
|
if(kCFCoreFoundationVersionNumber > 1600) {
|
||||||
|
[battery setBodyColorAlpha:1.0];
|
||||||
|
[battery setPinColorAlpha:1.0];
|
||||||
|
}
|
||||||
|
[self addSubview:battery];
|
||||||
|
|
||||||
|
UIImage *glyph = [device glyph];
|
||||||
|
UIImageView *glyphView = [[UIImageView alloc] init];
|
||||||
|
glyphView.contentMode = UIViewContentModeScaleAspectFit;
|
||||||
|
[glyphView setImage:glyph];
|
||||||
|
[self addSubview:glyphView];
|
||||||
|
|
||||||
|
label.frame = CGRectMake(57.5,27.5,275,25);
|
||||||
|
glyphView.frame = CGRectMake(12.5,18.5,40,40);
|
||||||
|
battery.frame = CGRectMake(310,35,20,10);
|
||||||
|
percentLabel.frame = CGRectMake(265,35,36,12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
label.frame = CGRectMake(57.5,27.5,275,25);
|
||||||
|
glyphView.frame = CGRectMake(12.5,18.5,40,40);
|
||||||
|
battery.frame = CGRectMake(310,35,20,10);
|
||||||
|
percentLabel.frame = CGRectMake(265,35,36,12);*/
|
||||||
|
|
||||||
|
@end
|
Reference in New Issue
Block a user