Device battery indicators on your Lock Screen
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Kai.xm 6.0KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #import "Kai.h"
  2. %group main
  3. %hook KAITarget //This class is defined in %ctor, KAITarget is not a class name.
  4. %property (nonatomic, assign) BOOL hasKai;
  5. -(void)_layoutStackView {
  6. NSInteger lastSlot = [[self stackView].subviews count] -1;
  7. //this code is used to determine if kai is at the bottom of the stack view
  8. if([[self stackView].subviews objectAtIndex:lastSlot] != [KAIBatteryStack sharedInstance] && belowMusic) {
  9. //if it is not, but the option to have kai below music is on, i simply remove from it's current pos.
  10. //and insert into last slot.
  11. [[self stackView] removeArrangedSubview:[KAIBatteryStack sharedInstance]];
  12. [[self stackView] insertArrangedSubview:[KAIBatteryStack sharedInstance] atIndex:lastSlot];
  13. }
  14. %orig;
  15. }
  16. -(void)setStackView:(UIStackView *)arg1 {
  17. if(!KAISelf.hasKai) {
  18. KAIBatteryStack *battery = [[KAIBatteryStack alloc] init];
  19. //Add noti observer
  20. [[NSNotificationCenter defaultCenter] addObserver:self
  21. selector:@selector(KaiInfo)
  22. name:@"KaiInfoChanged"
  23. object:nil];
  24. KAISelf.hasKai = YES;
  25. if(![arg1.subviews containsObject:battery]) { //if not added
  26. //add kai to the stack view
  27. [arg1 addArrangedSubview:battery];
  28. }
  29. [battery updateBattery];
  30. //send the adjusted stackview as arg1
  31. %orig(arg1);
  32. }
  33. }
  34. %new
  35. -(void)KaiInfo {
  36. if(!isUpdating) {
  37. isUpdating = YES;
  38. //NSLog(@"kai: kai info will update");
  39. dispatch_async(dispatch_get_main_queue(), ^{
  40. [[KAIBatteryStack sharedInstance] updateBattery];
  41. isUpdating = NO;
  42. });
  43. }
  44. }
  45. %end
  46. %hook BCBatteryDevice
  47. %property (nonatomic, strong) KAIBatteryCell *kaiCell;
  48. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  49. //Posts a notification to self when these keys change
  50. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  51. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  52. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  53. return %orig;
  54. }
  55. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  56. //if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {
  57. //sends the noti to update battery info
  58. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  59. //}
  60. }
  61. %new
  62. -(id)kaiCellForDevice {
  63. if(self && self.kaiCell == nil) {
  64. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; }
  65. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  66. [((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight + spacing].active = YES;
  67. [(KAIBatteryCell *)self.kaiCell updateInfo];
  68. return self.kaiCell;
  69. }
  70. %new
  71. -(void)resetKaiCellForNewPrefs {
  72. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self];
  73. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  74. [((KAIBatteryCell *)self.kaiCell).heightAnchor constraintEqualToConstant:bannerHeight + spacing].active = YES;
  75. [(KAIBatteryCell *)self.kaiCell updateInfo];
  76. }
  77. %end
  78. %hook KAICSTarget //Again, not a class
  79. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  80. if(hideChargingAnimation) {
  81. //Yeah bro this just makes the method never call to show the charging thing
  82. %orig(NO,NO,NO);
  83. }
  84. }
  85. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12
  86. if(hideChargingAnimation) {
  87. //Same idea
  88. %orig(NO,NO,NO,NO);
  89. }
  90. }
  91. %end
  92. %end
  93. %group drm
  94. %hook SBIconController
  95. -(void)viewDidAppear:(BOOL)arg1 {
  96. %orig;
  97. UIAlertController* alert2 = [UIAlertController alertControllerWithTitle:@"kai"
  98. message:@"Woops! Chariz is saying your device has not purchased Multipla! You must have purchased Multipla to use the kai beta. Please make sure to link your device to your Chariz account!"
  99. preferredStyle:UIAlertControllerStyleAlert];
  100. UIAlertAction* yes = [UIAlertAction actionWithTitle:@"I understand" style:UIAlertActionStyleDestructive
  101. handler:^(UIAlertAction * action) {
  102. }];
  103. [alert2 addAction:yes];
  104. [self presentViewController:alert2 animated:YES completion:nil];
  105. }
  106. %end
  107. %end
  108. %ctor {
  109. preferencesChanged();
  110. CFNotificationCenterAddObserver(
  111. CFNotificationCenterGetDarwinNotifyCenter(),
  112. &observer,
  113. (CFNotificationCallback)applyPrefs,
  114. kSettingsChangedNotification,
  115. NULL,
  116. CFNotificationSuspensionBehaviorDeliverImmediately
  117. );
  118. //Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
  119. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  120. Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]);
  121. //BOOL bypass = YES;
  122. BOOL bypass = NO;
  123. if(([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.list"] && [[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.md5sums"]) || bypass) {
  124. %init(main, KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
  125. } else if(!bypass && !([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.list"] && [[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/dpkg/info/xyz.burritoz.thomz.multipla.md5sums"])) {
  126. //if(0==1)
  127. %init(drm);
  128. }
  129. }