mirror of
https://github.com/Burrit0z/kai
synced 2025-07-01 17:16:47 +00:00
fix shit, other stuff. reformat comments
This commit is contained in:
@ -51,3 +51,10 @@
|
|||||||
- Fix very unoptimized code, made it more-ish optimized
|
- Fix very unoptimized code, made it more-ish optimized
|
||||||
- Below music option now moves kai just below the media controls, and not to the very bottom.
|
- Below music option now moves kai just below the media controls, and not to the very bottom.
|
||||||
- Fixed kai going below Axon with below music player option on
|
- Fixed kai going below Axon with below music player option on
|
||||||
|
|
||||||
|
1.4.0:
|
||||||
|
- Adds iOS 14 support
|
||||||
|
|
||||||
|
1.5.0:
|
||||||
|
- Replace the code that handles hiding kai when media plays
|
||||||
|
- Fix edge cases where battery info would not update completely until an update was called for again
|
||||||
|
@ -57,38 +57,32 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetOffset {
|
- (void)resetOffset { // holy fucking shit i just read this method, what is this garbage????
|
||||||
if (kaiAlign != 0 && reAlignSelf) {
|
if (kaiAlign != 0 && reAlignSelf) {
|
||||||
[UIView animateWithDuration:0.2
|
[UIView animateWithDuration:0.2 animations:^{
|
||||||
animations:^{
|
|
||||||
if (bannerAlign == 1) { // left
|
if (bannerAlign == 1) { // left
|
||||||
[self setContentOffset:CGPointMake(0 + horizontalOffset, self.contentOffset.y)];
|
|
||||||
|
|
||||||
|
[self setContentOffset:CGPointMake(0 + horizontalOffset, self.contentOffset.y)];
|
||||||
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
||||||
|
|
||||||
} else if (bannerAlign == 2) { // center
|
} else if (bannerAlign == 2) { // center
|
||||||
[self setContentOffset:CGPointMake(((-1 * self.stackHolder.frame.size.width) / 2) + (self.stack.frame.size.width / 2) + horizontalOffset, self.contentOffset.y)];
|
[self setContentOffset:CGPointMake(((-1 * self.stackHolder.frame.size.width) / 2) + (self.stack.frame.size.width / 2) + horizontalOffset, self.contentOffset.y)];
|
||||||
|
|
||||||
CGFloat top = 0, left = 0;
|
CGFloat top = 0, left = 0;
|
||||||
if (self.contentSize.width < self.bounds.size.width) {
|
if (self.contentSize.width < self.bounds.size.width) left = (self.bounds.size.width - self.contentSize.width) * 0.5f;
|
||||||
left = (self.bounds.size.width - self.contentSize.width) * 0.5f;
|
if (self.contentSize.height < self.bounds.size.height) top = (self.bounds.size.height - self.contentSize.height) * 0.5f;
|
||||||
}
|
|
||||||
if (self.contentSize.height < self.bounds.size.height) {
|
|
||||||
top = (self.bounds.size.height - self.contentSize.height) * 0.5f;
|
|
||||||
}
|
|
||||||
self.contentInset = UIEdgeInsetsMake(top, left, top, left);
|
self.contentInset = UIEdgeInsetsMake(top, left, top, left);
|
||||||
|
|
||||||
} else if (bannerAlign == 3) { // right
|
} else if (bannerAlign == 3) { // right
|
||||||
[self setContentOffset:CGPointMake((-1 * self.stackHolder.frame.size.width) + self.stack.frame.size.width + horizontalOffset, self.contentOffset.y)];
|
[self setContentOffset:CGPointMake((-1 * self.stackHolder.frame.size.width) + self.stack.frame.size.width + horizontalOffset, self.contentOffset.y)];
|
||||||
|
|
||||||
CGFloat top = 0, left = 0;
|
CGFloat top = 0, left = 0;
|
||||||
if (self.contentSize.width < self.bounds.size.width) {
|
if(self.contentSize.width < self.bounds.size.width) left = (self.bounds.size.width - self.contentSize.width);
|
||||||
left = (self.bounds.size.width - self.contentSize.width);
|
if(self.contentSize.height < self.bounds.size.height) top = (self.bounds.size.height - self.contentSize.height);
|
||||||
}
|
|
||||||
if (self.contentSize.height < self.bounds.size.height) {
|
|
||||||
top = (self.bounds.size.height - self.contentSize.height);
|
|
||||||
}
|
|
||||||
self.contentInset = UIEdgeInsetsMake(top, left, top, left);
|
self.contentInset = UIEdgeInsetsMake(top, left, top, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,6 +92,11 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateBattery {
|
- (void)updateBattery {
|
||||||
|
if(self.isUpdating == YES) {
|
||||||
|
self.queued = YES;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
|
||||||
NSArray *devices = [bcb connectedDevices];
|
NSArray *devices = [bcb connectedDevices];
|
||||||
@ -110,7 +109,6 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!self.isUpdating && self.oldCountOfDevices != 0 && ([devices count] + 1 == self.oldCountOfDevices || [devices count] - 1 == self.oldCountOfDevices || [devices count] == self.oldCountOfDevices)) {
|
if (!self.isUpdating && self.oldCountOfDevices != 0 && ([devices count] + 1 == self.oldCountOfDevices || [devices count] - 1 == self.oldCountOfDevices || [devices count] == self.oldCountOfDevices)) {
|
||||||
//if(!self.isUpdating) {
|
|
||||||
|
|
||||||
self.isUpdating = YES;
|
self.isUpdating = YES;
|
||||||
|
|
||||||
@ -209,11 +207,10 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isUpdating is set to NO in this block
|
||||||
|
// adds a cooldown, essentially
|
||||||
queueTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(dispatchQueue) userInfo:nil repeats:NO];
|
queueTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(dispatchQueue) userInfo:nil repeats:NO];
|
||||||
//self.isUpdating = NO;
|
|
||||||
|
|
||||||
} else if (self.isUpdating) {
|
|
||||||
self.queued = YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.oldCountOfDevices = [devices count];
|
self.oldCountOfDevices = [devices count];
|
||||||
@ -336,16 +333,17 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dispatchQueue {
|
- (void)dispatchQueue {
|
||||||
|
[queueTimer invalidate];
|
||||||
|
queueTimer = nil;
|
||||||
|
|
||||||
self.isUpdating = NO;
|
self.isUpdating = NO;
|
||||||
if (self.queued) {
|
if (self.queued) {
|
||||||
|
self.queued = NO;
|
||||||
[self updateBattery];
|
[self updateBattery];
|
||||||
if ([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
|
if ([self.superview.superview.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
|
||||||
[(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
|
[(NCNotificationListView *)(self.superview.superview.superview) fixComplicationsViewFrame];
|
||||||
}
|
}
|
||||||
self.queued = NO;
|
|
||||||
}
|
}
|
||||||
[queueTimer invalidate];
|
|
||||||
queueTimer = nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (KAIBatteryPlatter *)sharedInstance {
|
+ (KAIBatteryPlatter *)sharedInstance {
|
||||||
|
7
Kai.h
7
Kai.h
@ -4,7 +4,6 @@
|
|||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
#define KAISelf ((CSAdjunctListView *)self) // for use when calling self in KAITarget
|
#define KAISelf ((CSAdjunctListView *)self) // for use when calling self in KAITarget
|
||||||
#define afterMusicIndex(cls, obj) [[[cls sharedListViewForKai] stackView].subviews indexOfObject:obj]
|
|
||||||
|
|
||||||
@interface CSAdjunctListView : UIView
|
@interface CSAdjunctListView : UIView
|
||||||
@property (nonatomic, assign) BOOL hasKai;
|
@property (nonatomic, assign) BOOL hasKai;
|
||||||
@ -12,6 +11,12 @@
|
|||||||
- (void)_layoutStackView;
|
- (void)_layoutStackView;
|
||||||
- (void)setStackView:(UIStackView *)arg1;
|
- (void)setStackView:(UIStackView *)arg1;
|
||||||
+ (id)sharedListViewForKai;
|
+ (id)sharedListViewForKai;
|
||||||
|
+ (void)reorderKai;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface SBMediaController : NSObject
|
||||||
|
@property (nonatomic, strong) id nowPlayingApplication;
|
||||||
|
- (BOOL)isPlaying;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface CALayer (kai)
|
@interface CALayer (kai)
|
||||||
|
69
Kai.xm
69
Kai.xm
@ -1,49 +1,38 @@
|
|||||||
#import "Kai.h"
|
#import "Kai.h"
|
||||||
|
|
||||||
CSAdjunctListView *list;
|
CSAdjunctListView *list;
|
||||||
Class mediaClass;
|
|
||||||
|
|
||||||
%group main
|
%group main
|
||||||
|
|
||||||
%hook Media
|
%hook SBMediaController
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
%orig;
|
|
||||||
if(removeForMedia) {
|
|
||||||
shouldBeAdded = YES;
|
|
||||||
|
|
||||||
[[KAIBatteryPlatter sharedInstance] updateBattery];
|
|
||||||
|
|
||||||
|
- (BOOL)isPlaying {
|
||||||
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
|
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
|
||||||
|
BOOL playing = %orig;
|
||||||
|
|
||||||
if(!belowMusic) { //cursed
|
if(!removeForMedia) {
|
||||||
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
[cls reorderKai];
|
||||||
[[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
|
return playing;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didMoveToSuperview {
|
// if removeForMedia
|
||||||
%orig;
|
if(self.nowPlayingApplication && shouldBeAdded) {
|
||||||
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
|
// a valid playing app, and it was shown
|
||||||
|
|
||||||
if([[[cls sharedListViewForKai] stackView].arrangedSubviews containsObject:self]) {
|
|
||||||
if(belowMusic) {//cursed
|
|
||||||
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
|
||||||
[[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:afterMusicIndex(cls, self)];
|
|
||||||
} else {
|
|
||||||
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
|
||||||
[[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(removeForMedia) {
|
|
||||||
shouldBeAdded = NO;
|
shouldBeAdded = NO;
|
||||||
|
|
||||||
[[KAIBatteryPlatter sharedInstance] removeFromSuperview];
|
[[KAIBatteryPlatter sharedInstance] removeFromSuperview];
|
||||||
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
||||||
}
|
|
||||||
|
return playing;
|
||||||
|
} else if(!playing && self.nowPlayingApplication == nil) {
|
||||||
|
// not playing and the app is nil
|
||||||
|
shouldBeAdded = YES;
|
||||||
|
|
||||||
|
// if we don't want to hide kai, fix its order
|
||||||
|
[cls reorderKai];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
@ -91,7 +80,6 @@ Class mediaClass;
|
|||||||
|
|
||||||
isUpdating = YES;
|
isUpdating = YES;
|
||||||
|
|
||||||
//NSLog(@"kai: kai info will update");
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
[[KAIBatteryPlatter sharedInstance] updateBattery];
|
[[KAIBatteryPlatter sharedInstance] updateBattery];
|
||||||
@ -118,6 +106,19 @@ Class mediaClass;
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
+ (void)reorderKai {
|
||||||
|
NSLog(@"[Kai]: Reordering kai");
|
||||||
|
UIStackView *stack = [[self sharedListViewForKai] stackView];
|
||||||
|
if(belowMusic) { // cursed
|
||||||
|
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
||||||
|
[stack addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
||||||
|
} else {
|
||||||
|
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
|
||||||
|
[stack insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
|
||||||
%hook SBCoverSheetPrimarySlidingViewController
|
%hook SBCoverSheetPrimarySlidingViewController
|
||||||
@ -188,6 +189,8 @@ Class mediaClass;
|
|||||||
if(hideChargingAnimation) {
|
if(hideChargingAnimation) {
|
||||||
// Yeah bro this just makes the method never call to show the charging thing
|
// Yeah bro this just makes the method never call to show the charging thing
|
||||||
%orig(NO,NO,NO);
|
%orig(NO,NO,NO);
|
||||||
|
} else {
|
||||||
|
%orig(arg1, arg2, arg3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +198,8 @@ Class mediaClass;
|
|||||||
if(hideChargingAnimation) {
|
if(hideChargingAnimation) {
|
||||||
// Same idea
|
// Same idea
|
||||||
%orig(NO,NO,NO,NO);
|
%orig(NO,NO,NO,NO);
|
||||||
|
} else {
|
||||||
|
%orig(arg1, arg2, arg3, arg4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,8 +220,6 @@ Class mediaClass;
|
|||||||
|
|
||||||
// Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
|
// Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
|
||||||
|
|
||||||
mediaClass = kCFCoreFoundationVersionNumber > 1600 ? %c(CSAdjunctItemView) : %c(SBDashBoardAdjunctItemView);
|
|
||||||
|
|
||||||
Class cls = kCFCoreFoundationVersionNumber > 1600 ? %c(CSAdjunctListView) : %c(SBDashBoardAdjunctListView);
|
Class cls = kCFCoreFoundationVersionNumber > 1600 ? %c(CSAdjunctListView) : %c(SBDashBoardAdjunctListView);
|
||||||
|
|
||||||
Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? %c(CSCoverSheetViewController) : %c(SBDashBoardViewController);
|
Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? %c(CSCoverSheetViewController) : %c(SBDashBoardViewController);
|
||||||
@ -226,7 +229,7 @@ Class mediaClass;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
%init(main, Media = mediaClass, KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
|
%init(main, KAITarget = cls, KAICSTarget = CSCls); // BIG BRAIN BRO!!
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog(@"[kai]: loaded into %@", [NSBundle mainBundle].bundleIdentifier);
|
NSLog(@"[kai]: loaded into %@", [NSBundle mainBundle].bundleIdentifier);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Package: com.burritoz.kai
|
Package: com.burritoz.kai
|
||||||
Name: Kai
|
Name: Kai
|
||||||
Version: 1.4.0
|
Version: 1.5.0
|
||||||
Architecture: iphoneos-arm
|
Architecture: iphoneos-arm
|
||||||
Description: Device battery indicators on your lock screen!
|
Description: Device battery indicators on your lock screen!
|
||||||
Maintainer: burrit0z
|
Maintainer: burrit0z
|
||||||
|
Reference in New Issue
Block a user