1
0
mirror of https://github.com/Burrit0z/kai synced 2025-07-02 06:46:47 +00:00

Compare commits

15 Commits

Author SHA1 Message Date
ded80ae5a6 rebrand 2021-05-16 16:38:00 -04:00
df58fc48a7 Merge pull request #3 from evanknapke/master
Fix grammar issues and improve formatting
2021-01-03 10:22:26 -05:00
f8092f7b0d Update LICENSE 2021-01-02 21:03:17 -05:00
4e971ed592 Update Kai.h 2020-12-31 10:29:03 -05:00
dfe38157b1 layout properly 2020-12-25 11:07:05 -05:00
2250468f6f better placement options 2020-12-25 00:23:34 -05:00
c5add0a58a fix shit, other stuff. reformat comments 2020-12-24 23:24:17 -05:00
08027c7e9c Fix grammar issues and improve formatting 2020-10-01 11:38:06 -04:00
be1399f3d2 changed default preferences 2020-09-25 13:40:53 -04:00
e7f00664cd fix ios 14.0.1 crash (temp fix) 2020-09-25 13:25:40 -04:00
cee2aa6a0f Update KAIBatteryCell.mm 2020-09-24 20:00:55 -04:00
b734b0681b finish ios 14 (works ios 14.0) 2020-09-24 13:46:37 -04:00
1ef3ed3576 start ios 14 work 2020-09-22 19:20:19 -04:00
67bec552b4 Create LICENSE 2020-09-01 22:31:43 -04:00
52a4f5aa9a manually update control file 2020-08-30 09:38:32 -04:00
13 changed files with 565 additions and 367 deletions

View File

@ -50,4 +50,12 @@
1.3.1: 1.3.1:
- 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
- There are now 3 placement options: Top, Below Media Player, and Bottom

View File

@ -9,17 +9,19 @@
NSString *deviceName = device.name; NSString *deviceName = device.name;
double batteryPercentage = device.percentCharge; double batteryPercentage = device.percentCharge;
BOOL charging = MSHookIvar<long long>(device, "_charging"); BOOL charging = [device isCharging];
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive"); BOOL LPM = [device isBatterySaverModeActive];
UIView *blur; UIView *blur;
UIView *blurPlatter = [[UIView alloc] init]; UIView *blurPlatter = [[UIView alloc] init];
if (bannerStyle == 1) { if (bannerStyle == 1) {
if (kCFCoreFoundationVersionNumber > 1600) { if (kCFCoreFoundationVersionNumber > 1600 && kCFCoreFoundationVersionNumber < 1740) {
blur = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil]; blur = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil];
} else if (kCFCoreFoundationVersionNumber < 1600) { } else if (kCFCoreFoundationVersionNumber < 1600) { // ios 12
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
} } else if(kCFCoreFoundationVersionNumber >= 1740) { // ios 14 :fr:
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular]];
}
} else if (bannerStyle == 2) { } else if (bannerStyle == 2) {
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
} else if (bannerStyle == 3) { } else if (bannerStyle == 3) {
@ -75,10 +77,13 @@
[self.battery setPinColorAlpha:1.0]; [self.battery setPinColorAlpha:1.0];
} }
UIImage *glyph = [device glyph]; UIImage *glyph = ios13 ? [device glyph] : [device batteryWidgetGlyph];
glyph = [glyph imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.glyphView = [[UIImageView alloc] init]; self.glyphView = [[UIImageView alloc] init];
self.glyphView.contentMode = UIViewContentModeScaleAspectFit; self.glyphView.contentMode = UIViewContentModeScaleAspectFit;
[self.glyphView setImage:glyph]; [self.glyphView setImage:glyph];
self.glyphView.tintColor = [UIColor whiteColor];
[self addSubview:blurPlatter]; [self addSubview:blurPlatter];
[blurPlatter addSubview:blur]; [blurPlatter addSubview:blur];
@ -87,13 +92,13 @@
[self addSubview:self.battery]; [self addSubview:self.battery];
[self addSubview:self.glyphView]; [self addSubview:self.glyphView];
// Blur Platter // Blur Platter
blurPlatter.translatesAutoresizingMaskIntoConstraints = NO; blurPlatter.translatesAutoresizingMaskIntoConstraints = NO;
if (bannerAlign == 2) { //center if (bannerAlign == 2) { // center
[blurPlatter.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES; [blurPlatter.centerXAnchor constraintEqualToAnchor:self.centerXAnchor].active = YES;
} else if (bannerAlign == 1) { //left } else if (bannerAlign == 1) { // left
[blurPlatter.leftAnchor constraintEqualToAnchor:self.leftAnchor].active = YES; [blurPlatter.leftAnchor constraintEqualToAnchor:self.leftAnchor].active = YES;
} else if (bannerAlign == 3) { //right } else if (bannerAlign == 3) { // right
[blurPlatter.rightAnchor constraintEqualToAnchor:self.rightAnchor].active = YES; [blurPlatter.rightAnchor constraintEqualToAnchor:self.rightAnchor].active = YES;
} }
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
@ -104,7 +109,7 @@
[self.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES; [self.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES;
// Blur // Blur
blur.translatesAutoresizingMaskIntoConstraints = NO; blur.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[blur.centerXAnchor constraintEqualToAnchor:blurPlatter.centerXAnchor], [blur.centerXAnchor constraintEqualToAnchor:blurPlatter.centerXAnchor],
@ -113,7 +118,7 @@
[blur.heightAnchor constraintEqualToAnchor:blurPlatter.heightAnchor] [blur.heightAnchor constraintEqualToAnchor:blurPlatter.heightAnchor]
]]; ]];
// Percent label // Percent label
self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO; self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[self.percentLabel.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor], [self.percentLabel.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor],
@ -121,7 +126,7 @@
[self.percentLabel.heightAnchor constraintEqualToConstant:12] [self.percentLabel.heightAnchor constraintEqualToConstant:12]
]]; ]];
// Label // Label
self.label.translatesAutoresizingMaskIntoConstraints = NO; self.label.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor [self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor
@ -135,7 +140,7 @@
[self.label.rightAnchor constraintEqualToAnchor:self.label.leftAnchor].active = YES; [self.label.rightAnchor constraintEqualToAnchor:self.label.leftAnchor].active = YES;
} }
// Glyph View // Glyph View
self.glyphView.translatesAutoresizingMaskIntoConstraints = NO; self.glyphView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[self.glyphView.leftAnchor constraintEqualToAnchor:blurPlatter.leftAnchor [self.glyphView.leftAnchor constraintEqualToAnchor:blurPlatter.leftAnchor
@ -145,7 +150,7 @@
[self.glyphView.heightAnchor constraintEqualToConstant:glyphSize] [self.glyphView.heightAnchor constraintEqualToConstant:glyphSize]
]]; ]];
// Battery // Battery
self.battery.translatesAutoresizingMaskIntoConstraints = NO; self.battery.translatesAutoresizingMaskIntoConstraints = NO;
if (!hideBatteryIcon) { if (!hideBatteryIcon) {
[self.battery.widthAnchor constraintEqualToConstant:20].active = YES; [self.battery.widthAnchor constraintEqualToConstant:20].active = YES;
@ -193,10 +198,10 @@
- (void)updateInfo { - (void)updateInfo {
if (self.device != nil) { if (self.device != nil) {
NSString *deviceName = MSHookIvar<NSString *>(self.device, "_name"); NSString *deviceName = [self.device name];
double batteryPercentage = MSHookIvar<long long>(self.device, "_percentCharge"); double batteryPercentage = [self.device percentCharge];
BOOL charging = MSHookIvar<long long>(self.device, "_charging"); BOOL charging = [self.device isCharging];
BOOL LPM = MSHookIvar<BOOL>(self.device, "_batterySaverModeActive"); BOOL LPM = [self.device isBatterySaverModeActive];
self.label.text = [NSString stringWithFormat:@"%@", deviceName]; self.label.text = [NSString stringWithFormat:@"%@", deviceName];
[self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger)batteryPercentage)]]; [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger)batteryPercentage)]];
@ -218,9 +223,6 @@
} }
[self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger)batteryPercentage)]]; [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger)batteryPercentage)]];
self.battery.chargePercent = (batteryPercentage * 0.01); self.battery.chargePercent = (batteryPercentage * 0.01);
[self.glyphView setImage:[self.device glyph]];
} else {
} }
} }
@ -229,4 +231,4 @@
[super removeFromSuperview]; [super removeFromSuperview];
} }
@end @end

View File

@ -29,7 +29,7 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
[self setContentSize:self.stack.frame.size]; [self setContentSize:self.stack.frame.size];
[self resetOffset]; [self resetOffset];
//Add noti observer // Add noti observer
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(resetOffset) selector:@selector(resetOffset)
name:@"KaiResetOffset" name:@"KaiResetOffset"
@ -41,11 +41,11 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
[self.stackHolder.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES; [self.stackHolder.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES;
if (kaiAlign == 0) { if (kaiAlign == 0) {
if (bannerAlign == 2) { //center if (bannerAlign == 2) { // center
self.subviewAligner = [self.stack.centerXAnchor constraintEqualToAnchor:self.stackHolder.centerXAnchor constant:horizontalOffset]; self.subviewAligner = [self.stack.centerXAnchor constraintEqualToAnchor:self.stackHolder.centerXAnchor constant:horizontalOffset];
} else if (bannerAlign == 1) { //left } else if (bannerAlign == 1) { // left
self.subviewAligner = [self.stack.leftAnchor constraintEqualToAnchor:self.stackHolder.leftAnchor constant:horizontalOffset]; self.subviewAligner = [self.stack.leftAnchor constraintEqualToAnchor:self.stackHolder.leftAnchor constant:horizontalOffset];
} else if (bannerAlign == 3) { //right } else if (bannerAlign == 3) { // right
self.subviewAligner = [self.stack.rightAnchor constraintEqualToAnchor:self.stackHolder.rightAnchor constant:horizontalOffset]; self.subviewAligner = [self.stack.rightAnchor constraintEqualToAnchor:self.stackHolder.rightAnchor constant:horizontalOffset];
} }
@ -57,39 +57,33 @@ 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.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); [self setContentOffset:CGPointMake(0 + horizontalOffset, self.contentOffset.y)];
} else if (bannerAlign == 2) { //center self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
[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; } else if (bannerAlign == 2) { // center
if (self.contentSize.width < self.bounds.size.width) { [self setContentOffset:CGPointMake(((-1 * self.stackHolder.frame.size.width) / 2) + (self.stack.frame.size.width / 2) + horizontalOffset, self.contentOffset.y)];
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;
}
self.contentInset = UIEdgeInsetsMake(top, left, top, left);
} else if (bannerAlign == 3) { //right CGFloat top = 0, left = 0;
[self setContentOffset:CGPointMake((-1 * self.stackHolder.frame.size.width) + self.stack.frame.size.width + horizontalOffset, self.contentOffset.y)]; if (self.contentSize.width < self.bounds.size.width) 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;
self.contentInset = UIEdgeInsetsMake(top, left, top, left);
CGFloat top = 0, left = 0; } else if (bannerAlign == 3) { // right
if (self.contentSize.width < self.bounds.size.width) { [self setContentOffset:CGPointMake((-1 * self.stackHolder.frame.size.width) + self.stack.frame.size.width + horizontalOffset, self.contentOffset.y)];
left = (self.bounds.size.width - self.contentSize.width);
} CGFloat top = 0, left = 0;
if (self.contentSize.height < self.bounds.size.height) { if(self.contentSize.width < self.bounds.size.width) left = (self.bounds.size.width - self.contentSize.width);
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,9 +92,14 @@ 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 = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); NSArray *devices = [bcb connectedDevices];
if (self.oldCountOfDevices == -100) { if (self.oldCountOfDevices == -100) {
self.oldCountOfDevices = [devices count] + 1; self.oldCountOfDevices = [devices count] + 1;
@ -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;
@ -119,11 +117,11 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
for (BCBatteryDevice *device in devices) { for (BCBatteryDevice *device in devices) {
KAIBatteryCell *cell = [device kaiCellForDevice]; KAIBatteryCell *cell = [device kaiCellForDevice];
BOOL charging = MSHookIvar<long long>(device, "_charging"); BOOL charging = [device isCharging];
BOOL internal = MSHookIvar<BOOL>(device, "_internal"); BOOL internal = [device isInternal];
BOOL shouldAdd = NO; BOOL shouldAdd = NO;
BOOL fake = MSHookIvar<BOOL>(device, "_fake"); BOOL fake = [device isFake];
NSString *deviceName = MSHookIvar<NSString *>(device, "_name"); NSString *deviceName = [device name];
if (!fake) { if (!fake) {
if (showAll) { if (showAll) {
@ -187,13 +185,13 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
[self.stack removeArrangedSubview:cell]; [self.stack removeArrangedSubview:cell];
cell.alpha = 1; cell.alpha = 1;
}]; }];
NSString *deviceName = MSHookIvar<NSString *>(cell.device, "_name"); NSString *deviceName = [cell.device name];
[deviceNames removeObject:deviceName]; [deviceNames removeObject:deviceName];
[cellsForDeviceNames removeObject:cell]; [cellsForDeviceNames removeObject:cell];
} }
for (KAIBatteryCell *cell in self.stack.subviews) { for (KAIBatteryCell *cell in self.stack.subviews) {
if (![devices containsObject:cell.device] || cell.device == nil) { //not existing, remove if (![devices containsObject:cell.device] || cell.device == nil) { // not existing, remove
NSString *deviceName = cell.label.text; NSString *deviceName = cell.label.text;
[UIView animateWithDuration:0.3 [UIView animateWithDuration:0.3
animations:^{ animations:^{
@ -209,12 +207,11 @@ 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];
@ -230,7 +227,7 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
} }
- (void)setContentOffset:(CGPoint)arg1 { - (void)setContentOffset:(CGPoint)arg1 {
[self setContentSize:self.stack.frame.size]; //sometimes the view gets "stuck", this fixes it [self setContentSize:self.stack.frame.size]; // sometimes the view gets "stuck", this fixes it
[super setContentOffset:CGPointMake(arg1.x, 0)]; [super setContentOffset:CGPointMake(arg1.x, 0)];
} }
@ -243,8 +240,8 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
[s removeArrangedSubview:self]; [s removeArrangedSubview:self];
[self removeFromSuperview]; [self removeFromSuperview];
} else if (self.number != 0 && self.superview == nil && shouldBeAdded == YES) { } else if (self.number != 0 && self.superview == nil && shouldBeAdded == YES) {
[[[[objc_getClass("CSAdjunctListView") class] sharedListViewForKai] stackView] addArrangedSubview:self]; Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
//[self performSelector:@selector(calculateHeight) withObject:self afterDelay:0.1]; [cls reorderKai];
} }
[UIView animateWithDuration:0.3 [UIView animateWithDuration:0.3
@ -270,7 +267,7 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
int height = (self.number * (bannerHeight + spacing)); int height = (self.number * (bannerHeight + spacing));
int extra = extraPaddingAfter ? spacing : 0; int extra = extraPaddingAfter ? spacing : 0;
if (kaiAlign == 0) { if (kaiAlign == 0) {
//self.stack.widthConstraint.constant = bannerWidthFactor; // self.stack.widthConstraint.constant = bannerWidthFactor;
} else { } else {
height = bannerHeight + spacing; height = bannerHeight + spacing;
} }
@ -282,11 +279,11 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
} }
self.heightConstraint.constant = height; self.heightConstraint.constant = height;
self.stack.heightConstraint.constant = height - extra; //minus extra because it will stretch cell spacing otherwise self.stack.heightConstraint.constant = height - extra; // minus extra because it will stretch cell spacing otherwise
UIStackView *s = (UIStackView *)(self.superview); UIStackView *s = (UIStackView *)(self.superview);
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) // literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views)
} }
[self setContentSize:self.stack.frame.size]; [self setContentSize:self.stack.frame.size];
@ -306,23 +303,23 @@ NSMutableArray *cellsForDeviceNames = [[NSMutableArray alloc] init];
@try { @try {
[view removeFromSuperview]; [view removeFromSuperview];
} @catch (NSException *exception) { } @catch (NSException *exception) {
//Panik // Panik
} }
} }
BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance]; BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices"); NSArray *devices = [bcb connectedDevices];
for (BCBatteryDevice *device in devices) { for (BCBatteryDevice *device in devices) {
[device resetKaiCellForNewPrefs]; [device resetKaiCellForNewPrefs];
} }
if (kaiAlign == 0) { if (kaiAlign == 0) {
self.subviewAligner.active = NO; self.subviewAligner.active = NO;
if (bannerAlign == 2) { //center if (bannerAlign == 2) { // center
self.subviewAligner = [self.stack.centerXAnchor constraintEqualToAnchor:self.stackHolder.centerXAnchor constant:horizontalOffset]; self.subviewAligner = [self.stack.centerXAnchor constraintEqualToAnchor:self.stackHolder.centerXAnchor constant:horizontalOffset];
} else if (bannerAlign == 1) { //left } else if (bannerAlign == 1) { // left
self.subviewAligner = [self.stack.leftAnchor constraintEqualToAnchor:self.stackHolder.leftAnchor constant:horizontalOffset]; self.subviewAligner = [self.stack.leftAnchor constraintEqualToAnchor:self.stackHolder.leftAnchor constant:horizontalOffset];
} else if (bannerAlign == 3) { //right } else if (bannerAlign == 3) { // right
self.subviewAligner = [self.stack.rightAnchor constraintEqualToAnchor:self.stackHolder.rightAnchor constant:horizontalOffset]; self.subviewAligner = [self.stack.rightAnchor constraintEqualToAnchor:self.stackHolder.rightAnchor constant:horizontalOffset];
} }
@ -336,26 +333,27 @@ 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 {
return instance; return instance;
} }
//This is for compatibility (did i spell that right?) // This is for compatibility (did i spell that right?)
//basically this fixes it crashing in landscape: // basically this fixes it crashing in landscape:
- (void)setSizeToMimic:(CGSize)arg1 { - (void)setSizeToMimic:(CGSize)arg1 {
} }
@end @end

View File

@ -19,7 +19,7 @@
@interface BCBatteryDeviceController : NSObject @interface BCBatteryDeviceController : NSObject
@property (nonatomic, strong) NSArray *sortedDevices; @property (nonatomic, strong) NSArray *sortedDevices;
- (id)_sortedDevices; - (id)connectedDevices;
+ (id)sharedInstance; + (id)sharedInstance;
@end @end
@ -27,12 +27,13 @@
@property (nonatomic, strong) id kaiCell; @property (nonatomic, strong) id kaiCell;
@property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) long long percentCharge; @property (nonatomic, assign) long long percentCharge;
@property (nonatomic, assign) BOOL charging; @property (nonatomic, assign, getter=isCharging) BOOL charging;
@property (nonatomic, assign) BOOL fake; @property (nonatomic, assign, getter=isFake) BOOL fake;
@property (nonatomic, assign) BOOL internal; @property (nonatomic, assign, getter=isInternal) BOOL internal;
@property (nonatomic, assign) BOOL batterySaverModeActive; @property (nonatomic, assign, getter=isBatterySaverModeActive) BOOL batterySaverModeActive;
@property (nonatomic, strong) NSString *identifier; @property (nonatomic, strong) NSString *identifier;
- (id)glyph; - (id)glyph; // ios 13
- (id)batteryWidgetGlyph; // ios 14
- (id)kaiCellForDevice; - (id)kaiCellForDevice;
- (void)resetKaiCellForNewPrefs; - (void)resetKaiCellForNewPrefs;
@end @end
@ -71,4 +72,4 @@
@interface UIView (kai) @interface UIView (kai)
- (void)_didRemoveSubview:(UIView *)arg1; - (void)_didRemoveSubview:(UIView *)arg1;
@end @end

34
Kai.h
View File

@ -3,15 +3,22 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#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;
- (UIStackView *)stackView; - (UIStackView *)stackView;
- (void)_layoutStackView; - (void)_layoutStackView;
- (void)setStackView:(UIStackView *)arg1; - (void)setStackView:(UIStackView *)arg1;
- (NSInteger)getMediaIndexForClass:(Class)cls;
- (void)performReorder;
+ (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)
@ -26,19 +33,24 @@
+ (APEPlatter *)sharedInstance; + (APEPlatter *)sharedInstance;
@end @end
@interface APEPlacceholder : UIView
+ (APEPlacceholder *)sharedInstance;
@end
@interface NCNotificationListView : UIView @interface NCNotificationListView : UIView
- (void)fixComplicationsViewFrame; - (void)fixComplicationsViewFrame;
@end @end
BOOL ios13 = NO;
BOOL isUpdating = NO; BOOL isUpdating = NO;
BOOL shouldBeAdded = YES; BOOL shouldBeAdded = YES;
//prefs // prefs
BOOL enabled; BOOL enabled;
BOOL disableGlyphs; BOOL disableGlyphs;
BOOL hidePercent; BOOL hidePercent;
BOOL showAll; BOOL showAll;
BOOL belowMusic;
BOOL hideDeviceLabel; BOOL hideDeviceLabel;
BOOL hideChargingAnimation; BOOL hideChargingAnimation;
BOOL showAllMinusInternal; BOOL showAllMinusInternal;
@ -50,6 +62,7 @@ BOOL extraPaddingAfter;
NSInteger bannerStyle; NSInteger bannerStyle;
NSInteger bannerAlign; NSInteger bannerAlign;
NSInteger textColor; NSInteger textColor;
NSInteger placement;
double spacing; double spacing;
double glyphSize; double glyphSize;
double bannerHeight; double bannerHeight;
@ -60,7 +73,7 @@ double bannerAlpha;
double kaiAlign; double kaiAlign;
double spacingHorizontal; double spacingHorizontal;
//by importing here, I can use vars in the .mm files // by importing here, I can use vars in the .mm files
#import "KAIBatteryCell.mm" #import "KAIBatteryCell.mm"
#import "KAIBatteryPlatter.mm" #import "KAIBatteryPlatter.mm"
#import "KAIStackView.mm" #import "KAIStackView.mm"
@ -111,12 +124,12 @@ static void preferencesChanged() {
disableGlyphs = boolValueForKey(@"disableGlyphs", NO); disableGlyphs = boolValueForKey(@"disableGlyphs", NO);
hidePercent = boolValueForKey(@"hidePercent", NO); hidePercent = boolValueForKey(@"hidePercent", NO);
bannerStyle = numberForValue(@"bannerStyle", 1); bannerStyle = numberForValue(@"bannerStyle", 1);
showAll = boolValueForKey(@"showAll", NO); showAll = boolValueForKey(@"showAll", YES);
bannerWidthFactor = numberForValue(@"bannerWidthFactor", 0); bannerWidthFactor = numberForValue(@"bannerWidthFactor", 0);
hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO); hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
bannerAlign = numberForValue(@"bannerAlign", 2); bannerAlign = numberForValue(@"bannerAlign", 2);
horizontalOffset = numberForValue(@"horizontalOffset", 0); horizontalOffset = numberForValue(@"horizontalOffset", 0);
belowMusic = boolValueForKey(@"belowMusic", NO); placement = numberForValue(@"placement", 1);
hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES); hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
textColor = numberForValue(@"textColor", 0); textColor = numberForValue(@"textColor", 0);
bannerAlpha = numberForValue(@"bannerAlpha", 1); bannerAlpha = numberForValue(@"bannerAlpha", 1);
@ -136,12 +149,13 @@ static void preferencesChanged() {
static void applyPrefs() { static void applyPrefs() {
preferencesChanged(); preferencesChanged();
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
isUpdating = YES; isUpdating = YES;
[[KAIBatteryPlatter sharedInstance] refreshForPrefs]; //so hard (not) [[KAIBatteryPlatter sharedInstance] refreshForPrefs]; // so hard (not)
[(CSAdjunctListView *)([KAIBatteryPlatter sharedInstance].superview.superview) _layoutStackView]; [cls reorderKai];
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiResetOffset" object:nil userInfo:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiResetOffset" object:nil userInfo:nil];
isUpdating = NO; isUpdating = NO;
} }

158
Kai.xm
View File

@ -1,54 +1,45 @@
#import "Kai.h" #import "Kai.h"
CSAdjunctListView *list; CSAdjunctListView *list;
Class mediaClass;
%group main %group main
%hook Media %hook SBMediaController
- (void)dealloc { - (BOOL)isPlaying {
%orig; Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
if(removeForMedia) { BOOL playing = %orig;
if(!removeForMedia) {
[cls reorderKai];
return playing;
}
// if removeForMedia
if(self.nowPlayingApplication && shouldBeAdded) {
// a valid playing app, and it was shown
shouldBeAdded = NO;
[[KAIBatteryPlatter sharedInstance] removeFromSuperview];
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[[cls sharedListViewForKai] _layoutStackView];
return playing;
} else if(!playing && self.nowPlayingApplication == nil) {
// not playing and the app is nil
shouldBeAdded = YES; shouldBeAdded = YES;
[[KAIBatteryPlatter sharedInstance] updateBattery]; // if we don't want to hide kai, fix its order
[cls reorderKai];
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
if(!belowMusic) { //cursed
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[[[cls sharedListViewForKai] stackView] insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:0];
}
}
}
- (void)didMoveToSuperview {
%orig;
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
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;
[[KAIBatteryPlatter sharedInstance] removeFromSuperview];
[[[cls sharedListViewForKai] stackView] removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
}
} }
return playing;
} }
%end %end
%hook KAITarget //This class is defined in %ctor, KAITarget is not a class name. %hook KAITarget // This class is defined in %ctor, KAITarget is not a class name.
%property (nonatomic, assign) BOOL hasKai; %property (nonatomic, assign) BOOL hasKai;
@ -65,20 +56,20 @@ Class mediaClass;
KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame]; KAIBatteryPlatter *battery = [[KAIBatteryPlatter alloc] initWithFrame:[self stackView].frame];
//Add noti observer // 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;
if(![arg1.subviews containsObject:battery]) { //if not added if(![arg1.subviews containsObject:battery]) { // if not added
//add kai to the stack view // add kai to the stack view
[arg1 addArrangedSubview:battery]; [self performReorder];
} }
[battery updateBattery]; [battery updateBattery];
//send the adjusted stackview as arg1 // send the adjusted stackview as arg1
%orig(arg1); %orig(arg1);
} }
@ -91,7 +82,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];
@ -113,11 +103,59 @@ Class mediaClass;
} }
%new
- (NSInteger)getMediaIndexForClass:(Class)cls {
UIView *mediaPlayer;
int index = 0;
for(UIView *subview in [self stackView].subviews) {
if([subview isKindOfClass:cls]) {
return index;
}
index++;
}
return NSNotFound;
}
%new
- (void)performReorder {
UIStackView *stack = [self stackView];
if(placement == 1) { //top
BOOL isAperio = NO;
@try {
isAperio = [stack.subviews[0] isKindOfClass:%c(APEPlatter)];
// index 0 would be the platter, 1 would be placeholder
} @catch(NSException *exc) {}
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:isAperio];
// so, 0 if not aperio, 1 if aperio
} else if(placement == 2) { //after media
Class mediaClass = kCFCoreFoundationVersionNumber > 1600 ? %c(CSAdjunctItemView) : %c(SBDashBoardAdjunctItemView);
NSInteger mediaIndex = [self getMediaIndexForClass:mediaClass];
if(mediaIndex == NSNotFound) mediaIndex = 0;
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack insertArrangedSubview:[KAIBatteryPlatter sharedInstance] atIndex:mediaIndex];
} else if(placement == 3) { // bottom
[stack removeArrangedSubview:[KAIBatteryPlatter sharedInstance]];
[stack addArrangedSubview:[KAIBatteryPlatter sharedInstance]];
}
[self _layoutStackView];
}
%new %new
+ (id)sharedListViewForKai { + (id)sharedListViewForKai {
return list; return list;
} }
%new
+ (void)reorderKai {
NSLog(@"[Kai]: Reordering kai");
[[self sharedListViewForKai] performReorder];
}
%end %end
%hook SBCoverSheetPrimarySlidingViewController %hook SBCoverSheetPrimarySlidingViewController
@ -140,21 +178,21 @@ Class mediaClass;
%property (nonatomic, strong) KAIBatteryCell *kaiCell; %property (nonatomic, strong) KAIBatteryCell *kaiCell;
- (void)setCharging:(BOOL)arg1 { - (void)setCharging:(BOOL)arg1 {
//sends the noti to update battery info // sends the noti to update battery info
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
%orig; %orig;
} }
- (void)setBatterySaverModeActive:(BOOL)arg1 { - (void)setBatterySaverModeActive:(BOOL)arg1 {
//sends the noti to update battery info // sends the noti to update battery info
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
%orig; %orig;
} }
- (void)setPercentCharge:(NSInteger)arg1 { - (void)setPercentCharge:(NSInteger)arg1 {
//sends the noti to update battery info // sends the noti to update battery info
if(arg1!=0) { if(arg1 != 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
} }
%orig; %orig;
} }
@ -176,25 +214,29 @@ Class mediaClass;
%new %new
- (void)resetKaiCellForNewPrefs { - (void)resetKaiCellForNewPrefs {
self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self]; self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryPlatter sharedInstance].frame.size.width,0) device:self];
((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO; ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
[(KAIBatteryCell *)self.kaiCell updateInfo]; [(KAIBatteryCell *)self.kaiCell updateInfo];
} }
%end %end
%hook KAICSTarget //Again, not a class %hook KAICSTarget // Again, not a class
- (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 // 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);
} }
} }
- (void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12 - (void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { // might just be ios12
if(hideChargingAnimation) { if(hideChargingAnimation) {
//Same idea // Same idea
%orig(NO,NO,NO,NO); %orig(NO,NO,NO,NO);
} else {
%orig(arg1, arg2, arg3, arg4);
} }
} }
@ -213,16 +255,18 @@ Class mediaClass;
CFNotificationSuspensionBehaviorDeliverImmediately CFNotificationSuspensionBehaviorDeliverImmediately
); );
//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 ? ([objc_getClass("CSAdjunctItemView") class]) : ([objc_getClass("SBDashBoardAdjunctItemView") class]); Class cls = kCFCoreFoundationVersionNumber > 1600 ? %c(CSAdjunctListView) : %c(SBDashBoardAdjunctListView);
Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]); Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? %c(CSCoverSheetViewController) : %c(SBDashBoardViewController);
Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]); if(kCFCoreFoundationVersionNumber < 1740) {
ios13 = YES; // wow very pog version you have
}
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);

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 ren7995
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,9 +1,12 @@
Package: com.burritoz.kai Package: com.burritoz.kai
Name: Kai Name: Kai
Version: 1.3.1 Version: 1.5.1
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: ren7995
Author: burrit0z Author: ren7995
Section: Tweaks Section: Tweaks
Depends: mobilesubstrate (>= 0.9.5000), preferenceloader, ws.hbang.common (>=1.14) Depends: mobilesubstrate (>= 0.9.5000), preferenceloader, ws.hbang.common (>=1.14)
Icon: https://chariz.com/cdn/icon/kai/icon@3x.png
Depiction: https://repo.chariz.com/package/com.burritoz.kai/
SileoDepiction: https://repo.chariz.com/api/sileo/package/com.burritoz.kai/depiction.json

View File

@ -1,25 +1,36 @@
# kai # kai
Oh my gosh this code is so bad
## All your batteries, at a glance ## All Your Batteries, at a Glance
kai will show any Bluetooth device that provides battery information, meaning you can check the battery of your phone, your watch, your AirPods, and your AirPods case, all from the lock screen. Quickly and easily. kai will show any Bluetooth device that provides battery information, meaning you can check the battery of your iPhone, your Apple Watch, your AirPods, and your AirPods case, all from the lockscreen. Quickly and easily.
## Compatibility ## Compatibility
kai works with many, many lock screen tweaks, such as Kalm, Grupi, Axon, Quart, Complications, Watermelon, Veza, QuickLS, Jellyfish, and way more! kai works with many, many lockscreen tweak:
- Kalm
- Grupi
- Axon
- Quart
- Complications
- Watermelon
- Veza
- QuickLS
- Jellyfish
- And more!
## Make it yours ## Make it Yours
kai comes with a multitude of customization options, so you can fine-tune your settings to fit you and your setup. kai comes with a multitude of customization options, so you can fine-tune your settings to fit you and your setup.
## Big and Bold, or small and simple ## Big and Bold, or Small and Simple
kai offers two main options for displaying battery information. (a) Vertical mode, to make kai fit in with your notifications, and (b) horizontal mode, an unobtrusive, scrollable, and tiny mode that doesn't take up any more space on your lock screen than it needs to. kai offers two main options for displaying battery information. (a) Vertical mode, to make kai fit in with your notifications, and (b) horizontal mode, an unobtrusive, scrollable, and tiny mode that doesn't take up any more space on your lock screen than it needs to.
## Full feature/option list ## Full Feature/Option List
- Option to hide the large battery view coversheet charging animations on the lock screen - Option to hide the large battery view coversheet charging animations on the lock screen
- Show all or just charging devices on kai - Show all or just charging devices on kai
- Option to show Bluetooth devices always, and the phone just when charging - Option to show Bluetooth devices always, and the phone only when charging
- Option to hide device glyphs on kai cells - Option to hide device glyphs on kai cells
- Option to hide percent label on kai cells - Option to hide percent label on kai cells
- Option to hide the device name label on kai cells - Option to hide the device name label on kai cells
- Two-axis options, a vertical mode, or horizontal mode - Two-axis options: vertical mode, or horizontal mode
- Choose between adaptive, light, or dark mode for kai's cells - Choose between adaptive, light, or dark mode for kai's cells
- Choose between adaptive, white, or black text for labels on kai's cells - Choose between adaptive, white, or black text for labels on kai's cells
- Choose to align kai to the left, right, or center for vertical mode - Choose to align kai to the left, right, or center for vertical mode
@ -37,4 +48,4 @@ kai offers two main options for displaying battery information. (a) Vertical mod
Special thanks to my amazing beta testers in the server I co-own with Thomz. I could not have tested kai so extensively and brought it to where it is today without them. Thanks to Thomz (@Thomzi07 on Twitter) for making kai's icon, and depiction screenshots, and Thenatis (@thenatis1 on Twitter) for helping with design, and for making the banner for kai. Additionally, kai is inspired by LaughingQuoll's Maple tweak series and Apple's AirPower design. kai was built with inspiration from this. However, the main reason I made kai is because the Maple series does not work with notification grouping tweaks like Axon and Grupi. Additionally, kai features a wider range of customization options. Special thanks to my amazing beta testers in the server I co-own with Thomz. I could not have tested kai so extensively and brought it to where it is today without them. Thanks to Thomz (@Thomzi07 on Twitter) for making kai's icon, and depiction screenshots, and Thenatis (@thenatis1 on Twitter) for helping with design, and for making the banner for kai. Additionally, kai is inspired by LaughingQuoll's Maple tweak series and Apple's AirPower design. kai was built with inspiration from this. However, the main reason I made kai is because the Maple series does not work with notification grouping tweaks like Axon and Grupi. Additionally, kai features a wider range of customization options.
## Socials and Support ## Socials and Support
If you are encountering issues, or simply wish to reach out, you can contact me at my email (burrit0ztweaks@gmail.com) or join the discord server I co-own with Thomz to get support. Discord server invite link: https://discord.gg/NQ3uXtJ If you are encountering issues, or simply wish to reach out, you can contact me at my email (lau7995ren@gmail.com) or join the discord server I co-own with Thomz to get support. Discord server invite link: https://discord.gg/NQ3uXtJ

View File

@ -3,278 +3,358 @@
KAIRootListController *controller; KAIRootListController *controller;
NSBundle *tweakBundle; NSBundle *tweakBundle;
//thank god for renai // thank god for renai
static inline NSString *getPackageVersion() { static inline NSString *getPackageVersion() {
NSString *packageVersion = [NSString stringWithFormat:@"${%@}", @"Version"]; NSString *packageVersion = [NSString stringWithFormat:@"${%@}", @"Version"];
int status; int status;
NSMutableArray<NSString *> *argsv0 = [NSMutableArray array]; NSMutableArray<NSString *> *argsv0 = [NSMutableArray array];
for (NSString *string in @[ @"/usr/bin/dpkg-query", @"-Wf", packageVersion, @"com.burritoz.kai" ]) { for (NSString *string in @[
[argsv0 @"/usr/bin/dpkg-query", @"-Wf", packageVersion, @"com.burritoz.kai"
addObject:[NSString stringWithFormat:@"'%@'", ]) {
[string stringByReplacingOccurrencesOfString:@"'" [argsv0
withString:@"\\'" addObject:
options:NSRegularExpressionSearch [NSString
range:NSMakeRange( stringWithFormat:
0, string.length)]]]; @"'%@'",
} [string
stringByReplacingOccurrencesOfString:@"'"
withString:@"\\'"
options:
NSRegularExpressionSearch
range:
NSMakeRange(
0,
string
.length)]]];
}
NSString *argsv1 = [argsv0 componentsJoinedByString:@" "]; NSString *argsv1 = [argsv0 componentsJoinedByString:@" "];
FILE *file = popen(argsv1.UTF8String, "r"); FILE *file = popen(argsv1.UTF8String, "r");
if (!file) { if (!file) {
return nil; return nil;
} }
char data[1024]; char data[1024];
NSMutableString *output = [NSMutableString string]; NSMutableString *output = [NSMutableString string];
while (fgets(data, 1024, file) != NULL) { while (fgets(data, 1024, file) != NULL) {
[output appendString:[NSString stringWithUTF8String:data]]; [output appendString:[NSString stringWithUTF8String:data]];
} }
int result = pclose(file); int result = pclose(file);
status = result; status = result;
if (status == 0) { if (status == 0) {
return output ?: @"🏴‍☠️ Pirated"; return output ?: @"🏴‍☠️ Pirated";
} }
return @"🏴‍☠️ Pirated"; return @"🏴‍☠️ Pirated";
} }
//////// ////////
static void respringNeeded() { static void respringNeeded() {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Respring" UIAlertController *alert = [UIAlertController
message:@"Changing this requires a respring for it to take effect. Would you like to respring now?" alertControllerWithTitle:@"Respring"
preferredStyle:UIAlertControllerStyleActionSheet]; message:@"Changing this requires a respring for it to "
@"take effect. Would you like to respring now?"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"No" UIAlertAction *defaultAction =
style:UIAlertActionStyleCancel [UIAlertAction actionWithTitle:@"No"
handler:^(UIAlertAction *action){ style:UIAlertActionStyleCancel
}]; handler:^(UIAlertAction *action){
}];
UIAlertAction *yes = [UIAlertAction actionWithTitle:@"Respring" UIAlertAction *yes = [UIAlertAction
style:UIAlertActionStyleDestructive actionWithTitle:@"Respring"
handler:^(UIAlertAction *action) { style:UIAlertActionStyleDestructive
NSTask *t = [[NSTask alloc] init]; handler:^(UIAlertAction *action) {
[t setLaunchPath:@"usr/bin/killall"]; NSTask *t = [[NSTask alloc] init];
[t setArguments:[NSArray arrayWithObjects:@"backboardd", nil]]; [t setLaunchPath:@"usr/bin/killall"];
[t launch]; [t setArguments:[NSArray arrayWithObjects:@"backboardd", nil]];
}]; [t launch];
}];
[alert addAction:defaultAction]; [alert addAction:defaultAction];
[alert addAction:yes]; [alert addAction:yes];
[controller presentViewController:alert animated:YES completion:nil]; [controller presentViewController:alert animated:YES completion:nil];
} }
static void applyPrefs() { static void applyPrefs() {
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("com.burritoz.kaiprefs/reload"), nil, nil, true); CFNotificationCenterPostNotification(
CFNotificationCenterGetDarwinNotifyCenter(),
CFSTR("com.burritoz.kaiprefs/reload"), nil, nil, true);
} }
@implementation KAIRootListController @implementation KAIRootListController
- (NSArray *)specifiers { - (NSArray *)specifiers {
if (!_specifiers) { if (!_specifiers) {
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self]; _specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
} }
return _specifiers; return _specifiers;
} }
- (void)viewWillAppear:(BOOL)arg1 { - (void)viewWillAppear:(BOOL)arg1 {
[[UISegmentedControl appearanceWhenContainedInInstancesOfClasses:@[ self.class ]] setTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]]; [[UISegmentedControl
[[UISwitch appearanceWhenContainedInInstancesOfClasses:@[ self.class ]] setOnTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]]; appearanceWhenContainedInInstancesOfClasses:@[ self.class ]]
[[UISlider appearanceWhenContainedInInstancesOfClasses:@[ self.class ]] setTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]]; setTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]];
[[UISwitch appearanceWhenContainedInInstancesOfClasses:@[ self.class ]]
setOnTintColor:[UIColor colorWithRed:0.00
green:0.82
blue:1.00
alpha:1.00]];
[[UISlider appearanceWhenContainedInInstancesOfClasses:@[ self.class ]]
setTintColor:[UIColor colorWithRed:0.00 green:0.82 blue:1.00 alpha:1.00]];
} }
- (void)viewWillDisappear:(BOOL)arg1 { - (void)viewWillDisappear:(BOOL)arg1 {
[super viewWillDisappear:arg1]; [super viewWillDisappear:arg1];
} }
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.navigationItem.titleView = [UIView new]; self.navigationItem.titleView = [UIView new];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
self.titleLabel.font = [UIFont systemFontOfSize:17.5]; self.titleLabel.font = [UIFont systemFontOfSize:17.5];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.titleLabel.text = @"kai"; self.titleLabel.text = @"kai";
self.titleLabel.alpha = 0.0; self.titleLabel.alpha = 0.0;
self.titleLabel.textAlignment = NSTextAlignmentCenter; self.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.navigationItem.titleView addSubview:self.titleLabel]; [self.navigationItem.titleView addSubview:self.titleLabel];
self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
self.iconView.contentMode = UIViewContentModeScaleAspectFit; self.iconView.contentMode = UIViewContentModeScaleAspectFit;
self.iconView.image = [UIImage imageWithContentsOfFile:@"/Library/PreferenceBundles/kaiPrefs.bundle/icon.png"]; self.iconView.image =
self.iconView.translatesAutoresizingMaskIntoConstraints = NO; [UIImage imageWithContentsOfFile:
self.iconView.alpha = 1.0; @"/Library/PreferenceBundles/kaiPrefs.bundle/icon.png"];
[self.navigationItem.titleView addSubview:self.iconView]; self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
self.iconView.alpha = 1.0;
[self.navigationItem.titleView addSubview:self.iconView];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[self.titleLabel.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor], [self.titleLabel.topAnchor
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor], constraintEqualToAnchor:self.navigationItem.titleView.topAnchor],
[self.titleLabel.trailingAnchor constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor], [self.titleLabel.leadingAnchor
[self.titleLabel.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor], constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor],
[self.iconView.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor], [self.titleLabel.trailingAnchor
[self.iconView.leadingAnchor constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor], constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor],
[self.iconView.trailingAnchor constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor], [self.titleLabel.bottomAnchor
[self.iconView.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor], constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor],
]]; [self.iconView.topAnchor
constraintEqualToAnchor:self.navigationItem.titleView.topAnchor],
[self.iconView.leadingAnchor
constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor],
[self.iconView.trailingAnchor
constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor],
[self.iconView.bottomAnchor
constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor],
]];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Pirated :(" UIAlertController *alert = [UIAlertController
message:@"Please install kai from Chariz repository." alertControllerWithTitle:@"Pirated :("
preferredStyle:UIAlertControllerStyleAlert]; message:@"Please install kai from Chariz repository."
preferredStyle:UIAlertControllerStyleAlert];
if ([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/com.burritoz.kai.list"] && [[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/com.burritoz.kai.md5sums"]) { if ([[NSFileManager defaultManager]
// nothing fileExistsAtPath:@"/var/lib/dpkg/info/com.burritoz.kai.list"] &&
} else { [[NSFileManager defaultManager]
[self presentViewController:alert animated:YES completion:nil]; fileExistsAtPath:@"/var/lib/dpkg/info/com.burritoz.kai.md5sums"]) {
} // nothing
} else {
[self presentViewController:alert animated:YES completion:nil];
}
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)respringNeeded, CFSTR("com.burritoz.kaiprefs.respringneeded"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(), NULL,
(CFNotificationCallback)respringNeeded,
CFSTR("com.burritoz.kaiprefs.respringneeded"), NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)applyPrefs, CFSTR("com.burritoz.kaiprefs.apply"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(), NULL,
(CFNotificationCallback)applyPrefs, CFSTR("com.burritoz.kaiprefs.apply"),
NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
controller = self; controller = self;
} }
- (void)resetPrefs:(id)sender { - (void)resetPrefs:(id)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Reset Preferences" UIAlertController *alert = [UIAlertController
message:@"Are you sure you want to reset all of your preferences? This action CANNOT be undone! Your device will respring." alertControllerWithTitle:@"Reset Preferences"
preferredStyle:UIAlertControllerStyleAlert]; message:@"Are you sure you want to reset all of your "
@"preferences? This action CANNOT be undone! "
@"Your device will respring."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"No" UIAlertAction *defaultAction =
style:UIAlertActionStyleDefault [UIAlertAction actionWithTitle:@"No"
handler:^(UIAlertAction *action){ style:UIAlertActionStyleDefault
}]; handler:^(UIAlertAction *action){
UIAlertAction *yes = [UIAlertAction actionWithTitle:@"Yes" }];
style:UIAlertActionStyleDestructive UIAlertAction *yes = [UIAlertAction
handler:^(UIAlertAction *action) { actionWithTitle:@"Yes"
NSUserDefaults *prefs = [[NSUserDefaults standardUserDefaults] init]; style:UIAlertActionStyleDestructive
[prefs removePersistentDomainForName:@"com.burritoz.kaiprefs"]; handler:^(UIAlertAction *action) {
NSUserDefaults *prefs =
[[NSUserDefaults standardUserDefaults] init];
[prefs removePersistentDomainForName:@"com.burritoz.kaiprefs"];
NSTask *f = [[NSTask alloc] init]; NSTask *f = [[NSTask alloc] init];
[f setLaunchPath:@"/usr/bin/killall"]; [f setLaunchPath:@"/usr/bin/killall"];
[f setArguments:[NSArray arrayWithObjects:@"backboardd", nil]]; [f setArguments:[NSArray arrayWithObjects:@"backboardd", nil]];
[f launch]; [f launch];
}]; }];
[alert addAction:defaultAction]; [alert addAction:defaultAction];
[alert addAction:yes]; [alert addAction:yes];
[self presentViewController:alert animated:YES completion:nil]; [self presentViewController:alert animated:YES completion:nil];
} }
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y; CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY > 120) { if (offsetY > 120) {
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2
animations:^{ animations:^{
self.iconView.alpha = 1.0; self.iconView.alpha = 1.0;
self.titleLabel.alpha = 0.0; self.titleLabel.alpha = 0.0;
}]; }];
} else { } else {
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2
animations:^{ animations:^{
self.iconView.alpha = 0.0; self.iconView.alpha = 0.0;
self.titleLabel.alpha = 1.0; self.titleLabel.alpha = 1.0;
}]; }];
} }
} }
- (void)followMeBurritoz { - (void)followMeRen {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/burrit0ztweaks"]]; [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"https://twitter.com/ren7995"]];
} }
- (void)followMeOnTwitterThomz { - (void)followMeOnTwitterThomz {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/thomzi07"]]; [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"https://twitter.com/thomzi07"]];
} }
@end @end
@implementation KaiHeaderCell // Header Cell @implementation KaiHeaderCell // Header Cell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(id)reuseIdentifier specifier:(id)specifier { - (instancetype)initWithStyle:(UITableViewCellStyle)style
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier]; reuseIdentifier:(id)reuseIdentifier
specifier:(id)specifier {
self = [super initWithStyle:style
reuseIdentifier:reuseIdentifier
specifier:specifier];
if (self) { if (self) {
UILabel *tweakLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, self.contentView.bounds.size.width + 30, 50)]; UILabel *tweakLabel = [[UILabel alloc]
[tweakLabel setTextAlignment:NSTextAlignmentLeft]; initWithFrame:CGRectMake(20, 30,
[tweakLabel setFont:[UIFont systemFontOfSize:50 weight:UIFontWeightRegular]]; self.contentView.bounds.size.width + 30, 50)];
tweakLabel.text = @"kai"; [tweakLabel setTextAlignment:NSTextAlignmentLeft];
[tweakLabel setFont:[UIFont systemFontOfSize:50
weight:UIFontWeightRegular]];
tweakLabel.text = @"kai";
UILabel *devLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, self.contentView.bounds.size.width + 30, 50)]; UILabel *devLabel = [[UILabel alloc]
[devLabel setTextAlignment:NSTextAlignmentLeft]; initWithFrame:CGRectMake(20, 70,
[devLabel setFont:[UIFont systemFontOfSize:20 weight:UIFontWeightMedium]]; self.contentView.bounds.size.width + 30, 50)];
devLabel.alpha = 0.8; [devLabel setTextAlignment:NSTextAlignmentLeft];
devLabel.text = getPackageVersion(); [devLabel setFont:[UIFont systemFontOfSize:20 weight:UIFontWeightMedium]];
devLabel.alpha = 0.8;
devLabel.text = getPackageVersion();
NSBundle *bundle = [[NSBundle alloc] initWithPath:@"/Library/PreferenceBundles/kaiPrefs.bundle"]; NSBundle *bundle = [[NSBundle alloc]
UIImage *logo = [UIImage imageWithContentsOfFile:[bundle pathForResource:@"iconFullSize" ofType:@"png"]]; initWithPath:@"/Library/PreferenceBundles/kaiPrefs.bundle"];
UIImageView *icon = [[UIImageView alloc] initWithImage:logo]; UIImage *logo =
icon.frame = CGRectMake(self.contentView.bounds.size.width - 35, 35, 70, 70); [UIImage imageWithContentsOfFile:[bundle pathForResource:@"iconFullSize"
icon.translatesAutoresizingMaskIntoConstraints = NO; ofType:@"png"]];
UIImageView *icon = [[UIImageView alloc] initWithImage:logo];
icon.frame =
CGRectMake(self.contentView.bounds.size.width - 35, 35, 70, 70);
icon.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:tweakLabel]; [self addSubview:tweakLabel];
[self addSubview:devLabel]; [self addSubview:devLabel];
[self addSubview:icon]; [self addSubview:icon];
[icon.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:-20].active = YES; [icon.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:-20]
[icon.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active = YES; .active = YES;
[icon.widthAnchor constraintEqualToConstant:70].active = YES; [icon.centerYAnchor constraintEqualToAnchor:self.centerYAnchor].active =
[icon.heightAnchor constraintEqualToConstant:70].active = YES; YES;
[icon.widthAnchor constraintEqualToConstant:70].active = YES;
[icon.heightAnchor constraintEqualToConstant:70].active = YES;
icon.layer.masksToBounds = YES; icon.layer.masksToBounds = YES;
icon.layer.cornerRadius = 15; icon.layer.cornerRadius = 15;
} }
return self; return self;
} }
- (instancetype)initWithSpecifier:(PSSpecifier *)specifier { - (instancetype)initWithSpecifier:(PSSpecifier *)specifier {
return [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"KaiHeaderCell" specifier:specifier]; return [self initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"KaiHeaderCell"
specifier:specifier];
} }
- (void)setFrame:(CGRect)frame { - (void)setFrame:(CGRect)frame {
frame.origin.x = 0; frame.origin.x = 0;
[super setFrame:frame]; [super setFrame:frame];
} }
- (CGFloat)preferredHeightForWidth:(CGFloat)arg1 { - (CGFloat)preferredHeightForWidth:(CGFloat)arg1 {
return 140.0f; return 140.0f;
} }
@end @end
@implementation Thomz_TwitterCell // lil copy of HBTwitterCell from Cephei @implementation Thomz_TwitterCell // lil copy of HBTwitterCell from Cephei
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier { - (instancetype)initWithStyle:(UITableViewCellStyle)style
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier]; reuseIdentifier:(NSString *)reuseIdentifier
specifier:(PSSpecifier *)specifier {
self = [super initWithStyle:style
reuseIdentifier:reuseIdentifier
specifier:specifier];
if (self) { if (self) {
UILabel *User = [[UILabel alloc] initWithFrame:CGRectMake(70, 15, 200, 20)]; UILabel *User = [[UILabel alloc] initWithFrame:CGRectMake(70, 15, 200, 20)];
[User setText:specifier.properties[@"user"]]; [User setText:specifier.properties[@"user"]];
[User setFont:[User.font fontWithSize:15]]; [User setFont:[User.font fontWithSize:15]];
UILabel *Description = [[UILabel alloc] initWithFrame:CGRectMake(70, 35, 200, 20)]; UILabel *Description =
[Description setText:specifier.properties[@"description"]]; [[UILabel alloc] initWithFrame:CGRectMake(70, 35, 200, 20)];
[Description setFont:[Description.font fontWithSize:10]]; [Description setText:specifier.properties[@"description"]];
[Description setFont:[Description.font fontWithSize:10]];
NSBundle *bundle = [[NSBundle alloc] initWithPath:@"/Library/PreferenceBundles/kaiPrefs.bundle"]; NSBundle *bundle = [[NSBundle alloc]
initWithPath:@"/Library/PreferenceBundles/kaiPrefs.bundle"];
UIImage *profilePicture; UIImage *profilePicture;
profilePicture = [UIImage imageWithContentsOfFile:[bundle pathForResource:specifier.properties[@"image"] ofType:@"jpg"]]; profilePicture = [UIImage
UIImageView *profilePictureView = [[UIImageView alloc] initWithImage:profilePicture]; imageWithContentsOfFile:[bundle
[profilePictureView.layer setMasksToBounds:YES]; pathForResource:specifier
[profilePictureView.layer setCornerRadius:20]; .properties[@"image"]
[profilePictureView setFrame:CGRectMake(15, 15, 40, 40)]; ofType:@"jpg"]];
UIImageView *profilePictureView =
[[UIImageView alloc] initWithImage:profilePicture];
[profilePictureView.layer setMasksToBounds:YES];
[profilePictureView.layer setCornerRadius:20];
[profilePictureView setFrame:CGRectMake(15, 15, 40, 40)];
[self addSubview:User]; [self addSubview:User];
[self addSubview:Description]; [self addSubview:Description];
[self addSubview:profilePictureView]; [self addSubview:profilePictureView];
} }
return self; return self;
} }
@end @end

View File

@ -18,15 +18,15 @@
<key>cellClass</key> <key>cellClass</key>
<string>Thomz_TwitterCell</string> <string>Thomz_TwitterCell</string>
<key>user</key> <key>user</key>
<string>Burrit0z</string> <string>ren7995</string>
<key>description</key> <key>description</key>
<string>Developer</string> <string>Developer</string>
<key>height</key> <key>height</key>
<integer>70</integer> <integer>70</integer>
<key>image</key> <key>image</key>
<string>burritoz</string> <string>ren7995</string>
<key>action</key> <key>action</key>
<string>followMeBurritoz</string> <string>followMeRen</string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
@ -104,7 +104,7 @@
<key>cell</key> <key>cell</key>
<string>PSSwitchCell</string> <string>PSSwitchCell</string>
<key>default</key> <key>default</key>
<false/> <true/>
<key>defaults</key> <key>defaults</key>
<string>com.burritoz.kaiprefs</string> <string>com.burritoz.kaiprefs</string>
<key>key</key> <key>key</key>
@ -332,18 +332,34 @@
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSSwitchCell</string> <string>PSGroupCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>belowMusic</string>
<key>label</key> <key>label</key>
<string>Show kai Below Music</string> <string>Vertical Placement</string>
</dict>
<dict>
<key>cell</key>
<string>PSSegmentCell</string>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>default</key>
<string>1</string>
<key>key</key>
<string>placement</string>
<key>validValues</key>
<array>
<string>1</string>
<string>2</string>
<string>3</string>
</array>
<key>validTitles</key>
<array>
<string>Top</string>
<string>Below Media Player</string>
<string>Bottom</string>
</array>
<key>PostNotification</key> <key>PostNotification</key>
<string>com.burritoz.kaiprefs.apply</string> <string>com.burritoz.kaiprefs.apply</string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB