mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 23:36:46 +00:00
comments for you bro :)
This commit is contained in:
29
Kai.h
29
Kai.h
@ -4,12 +4,8 @@
|
|||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
#define KAISelf ((CSAdjunctListView *)self)
|
#define KAISelf ((CSAdjunctListView *)self) //for use when calling self in KAITarget
|
||||||
|
#define KAIBattery UHDUEIHGCEBCHYDEICVKEVSAGJKBCXAHJGKVXHAS //lmao
|
||||||
@interface UIApplication (Kai)
|
|
||||||
+(id)sharedApplication;
|
|
||||||
-(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface CSAdjunctListView : UIView
|
@interface CSAdjunctListView : UIView
|
||||||
@property (nonatomic, assign) BOOL hasKai;
|
@property (nonatomic, assign) BOOL hasKai;
|
||||||
@ -18,24 +14,6 @@
|
|||||||
-(void)KaiUpdate;
|
-(void)KaiUpdate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface SBDashBoardAdjunctListView : UIView
|
|
||||||
@property (nonatomic, assign) BOOL hasKai;
|
|
||||||
-(UIStackView *)stackView;
|
|
||||||
-(void)setStackView:(UIStackView *)arg1;
|
|
||||||
-(void)KaiUpdate;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface CSMainPageView : UIView
|
|
||||||
-(void)updateForPresentation:(id)arg1;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface _CSSingleBatteryChargingView : UIView
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSLayoutConstraint (Kai)
|
|
||||||
+(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface CALayer (kai)
|
@interface CALayer (kai)
|
||||||
@property (nonatomic, assign) BOOL continuousCorners;
|
@property (nonatomic, assign) BOOL continuousCorners;
|
||||||
@end
|
@end
|
||||||
@ -59,6 +37,7 @@ double cornerRadius;
|
|||||||
double bannerWidthFactor;
|
double bannerWidthFactor;
|
||||||
double horizontalOffset;
|
double horizontalOffset;
|
||||||
|
|
||||||
|
//by importing here, I can use vars in the .mm of KAIBattery
|
||||||
#import "KAIBattery.mm"
|
#import "KAIBattery.mm"
|
||||||
|
|
||||||
#define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
|
#define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
|
||||||
@ -131,6 +110,8 @@ static void preferencesChanged()
|
|||||||
static void applyPrefs()
|
static void applyPrefs()
|
||||||
{
|
{
|
||||||
preferencesChanged();
|
preferencesChanged();
|
||||||
|
|
||||||
|
//here I remotely refresh the KAIView.
|
||||||
isUpdating = YES;
|
isUpdating = YES;
|
||||||
[UIView animateWithDuration:0.3 animations:^{
|
[UIView animateWithDuration:0.3 animations:^{
|
||||||
[KAIBattery sharedInstance].alpha = 0;
|
[KAIBattery sharedInstance].alpha = 0;
|
||||||
|
41
Kai.xm
41
Kai.xm
@ -1,16 +1,21 @@
|
|||||||
#import "Kai.h"
|
#import "Kai.h"
|
||||||
|
|
||||||
%hook KAITarget
|
%hook KAITarget //This class is defined in %ctor, KAITarget is not a class name.
|
||||||
|
|
||||||
%property (nonatomic, assign) BOOL hasKai;
|
%property (nonatomic, assign) BOOL hasKai;
|
||||||
|
|
||||||
-(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
|
||||||
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] 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
|
||||||
[self KaiUpdate];
|
[self KaiUpdate];
|
||||||
|
|
||||||
%orig;
|
%orig;
|
||||||
@ -20,19 +25,21 @@
|
|||||||
|
|
||||||
if(!KAISelf.hasKai) {
|
if(!KAISelf.hasKai) {
|
||||||
KAIBattery *battery = [[KAIBattery alloc] init];
|
KAIBattery *battery = [[KAIBattery alloc] init];
|
||||||
|
|
||||||
|
//Add noti observer
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(KaiInfo)
|
selector:@selector(KaiInfo)
|
||||||
name:@"KaiInfoChanged"
|
name:@"KaiInfoChanged"
|
||||||
object:nil];
|
object:nil];
|
||||||
KAISelf.hasKai = YES;
|
KAISelf.hasKai = YES;
|
||||||
|
|
||||||
UIStackView *newView = arg1;
|
if(![arg1.subviews containsObject:battery]) { //if not added
|
||||||
|
//add kai to the stack view
|
||||||
if(![arg1.subviews containsObject:battery]) {
|
[arg1 addArrangedSubview:battery];
|
||||||
[newView addArrangedSubview:battery];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%orig(newView);
|
//send the adjusted stackview as arg1
|
||||||
|
%orig(arg1);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,16 +54,18 @@
|
|||||||
|
|
||||||
battery.heightConstraint.active = NO;
|
battery.heightConstraint.active = NO;
|
||||||
battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:85];
|
battery.heightConstraint = [battery.heightAnchor constraintEqualToConstant:85];
|
||||||
|
//set an initial constraint
|
||||||
battery.heightConstraint.active = YES;
|
battery.heightConstraint.active = YES;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int height = ((battery.number * (bannerHeight + spacing)) - spacing + 5);
|
int height = ((battery.number * (bannerHeight + spacing)) - spacing + 5); //big brain math
|
||||||
battery.heightConstraint.active = NO;
|
battery.heightConstraint.active = NO;
|
||||||
battery.heightConstraint.constant = height;
|
battery.heightConstraint.constant = height;
|
||||||
battery.heightConstraint.active = YES;
|
battery.heightConstraint.active = YES;
|
||||||
|
|
||||||
UIStackView *s = [self stackView];
|
UIStackView *s = [self stackView];
|
||||||
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
|
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
|
||||||
|
//literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views)
|
||||||
}
|
}
|
||||||
|
|
||||||
}];
|
}];
|
||||||
@ -65,20 +74,30 @@
|
|||||||
|
|
||||||
%new
|
%new
|
||||||
-(void)KaiInfo {
|
-(void)KaiInfo {
|
||||||
|
|
||||||
if(!isUpdating) {
|
if(!isUpdating) {
|
||||||
|
|
||||||
isUpdating = YES;
|
isUpdating = YES;
|
||||||
[UIView animateWithDuration:0.3 animations:^{
|
[UIView animateWithDuration:0.3 animations:^{
|
||||||
|
|
||||||
|
//nice fade out
|
||||||
[KAIBattery sharedInstance].alpha = 0;
|
[KAIBattery sharedInstance].alpha = 0;
|
||||||
|
|
||||||
} completion:^(BOOL finished){
|
} completion:^(BOOL finished){
|
||||||
|
|
||||||
[[KAIBattery sharedInstance] updateBattery];
|
[[KAIBattery sharedInstance] updateBattery];
|
||||||
[self KaiUpdate];
|
[self KaiUpdate];
|
||||||
[UIView animateWithDuration:0.35 animations:^{
|
[UIView animateWithDuration:0.35 animations:^{
|
||||||
|
//fade back in
|
||||||
[KAIBattery sharedInstance].alpha = 1;
|
[KAIBattery sharedInstance].alpha = 1;
|
||||||
} completion:^(BOOL finished){
|
} completion:^(BOOL finished){
|
||||||
isUpdating = NO;
|
isUpdating = NO;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
|
||||||
@ -87,8 +106,8 @@
|
|||||||
|
|
||||||
- (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
|
- (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
|
||||||
|
|
||||||
|
//Posts a notification to self when these keys change
|
||||||
[self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
|
[self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
//[self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil];
|
|
||||||
[self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
|
[self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
[self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
|
[self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
|
|
||||||
@ -97,7 +116,8 @@
|
|||||||
|
|
||||||
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
|
//sends the noti to update battery info
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -107,6 +127,7 @@
|
|||||||
|
|
||||||
-(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
|
-(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
|
||||||
if(hideChargingAnimation) {
|
if(hideChargingAnimation) {
|
||||||
|
//Yeah bro this just makes the method never call to show the charging thing
|
||||||
%orig(NO,NO,NO);
|
%orig(NO,NO,NO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,6 +144,8 @@
|
|||||||
NULL,
|
NULL,
|
||||||
CFNotificationSuspensionBehaviorDeliverImmediately
|
CFNotificationSuspensionBehaviorDeliverImmediately
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
|
||||||
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
|
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
%init(KAITarget = cls);
|
%init(KAITarget = cls);
|
||||||
|
Reference in New Issue
Block a user