Device battery indicators on your Lock Screen
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

195 lines
6.7KB

  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. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  15. [(NCNotificationListView *)(KAISelf.superview) fixComplicationsViewFrame];
  16. }
  17. [[KAIBatteryStack sharedInstance] setNumber:[KAIBatteryStack sharedInstance].number];
  18. %orig;
  19. }
  20. -(void)setStackView:(UIStackView *)arg1 {
  21. if(!KAISelf.hasKai) {
  22. KAIBatteryStack *battery = [[KAIBatteryStack alloc] init];
  23. //Add noti observer
  24. [[NSNotificationCenter defaultCenter] addObserver:self
  25. selector:@selector(KaiInfo)
  26. name:@"KaiInfoChanged"
  27. object:nil];
  28. KAISelf.hasKai = YES;
  29. if(![arg1.subviews containsObject:battery]) { //if not added
  30. //add kai to the stack view
  31. [arg1 addArrangedSubview:battery];
  32. }
  33. [battery updateBattery];
  34. //send the adjusted stackview as arg1
  35. %orig(arg1);
  36. }
  37. }
  38. %new
  39. -(void)KaiInfo {
  40. if(!isUpdating) {
  41. isUpdating = YES;
  42. //NSLog(@"kai: kai info will update");
  43. dispatch_async(dispatch_get_main_queue(), ^{
  44. [[KAIBatteryStack sharedInstance] updateBattery];
  45. if([KAIBatteryStack sharedInstance].number == 0) {
  46. [[KAIBatteryStack sharedInstance] removeFromSuperview];
  47. [[self stackView] removeArrangedSubview:[KAIBatteryStack sharedInstance]];
  48. } else if(![[self stackView].subviews containsObject:[KAIBatteryStack sharedInstance]]) {
  49. [[self stackView] addSubview:[KAIBatteryStack sharedInstance]];
  50. [[self stackView] addArrangedSubview:[KAIBatteryStack sharedInstance]];
  51. }
  52. if([KAISelf.superview respondsToSelector:@selector(fixComplicationsViewFrame)]) {
  53. [KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.35];
  54. //[KAISelf.superview performSelector:@selector(fixComplicationsViewFrame) withObject:KAISelf.superview afterDelay:0.5];
  55. }
  56. isUpdating = NO;
  57. });
  58. }
  59. }
  60. %end
  61. %hook BCBatteryDevice
  62. %property (nonatomic, strong) KAIBatteryCell *kaiCell;
  63. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  64. //Posts a notification to self when these keys change
  65. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  66. [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil];
  67. [self addObserver:self forKeyPath:@"percentCharge" options:NSKeyValueObservingOptionNew context:nil];
  68. return %orig;
  69. }
  70. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  71. //if([self isMemberOfClass:[objc_getClass("BCBatteryDevice") class]] && [self respondsToSelector:@selector(_kaiCell)] && object == self && ([keyPath isEqualToString:@"charging"] || [keyPath isEqualToString:@"percentCharge"] || [keyPath isEqualToString:@"batterySaverModeActive"])) {
  72. //sends the noti to update battery info
  73. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  74. //}
  75. }
  76. %new
  77. -(id)kaiCellForDevice {
  78. if(self && self.kaiCell == nil) {
  79. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self]; }
  80. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  81. [(KAIBatteryCell *)self.kaiCell updateInfo];
  82. return self.kaiCell;
  83. }
  84. %new
  85. -(void)resetKaiCellForNewPrefs {
  86. self.kaiCell = [[KAIBatteryCell alloc] initWithFrame:CGRectMake(0,0,[KAIBatteryStack sharedInstance].frame.size.width,0) device:self];
  87. ((KAIBatteryCell *)self.kaiCell).translatesAutoresizingMaskIntoConstraints = NO;
  88. [(KAIBatteryCell *)self.kaiCell updateInfo];
  89. }
  90. %end
  91. %hook KAICSTarget //Again, not a class
  92. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 {
  93. if(hideChargingAnimation) {
  94. //Yeah bro this just makes the method never call to show the charging thing
  95. %orig(NO,NO,NO);
  96. }
  97. }
  98. -(void)_transitionChargingViewToVisible:(BOOL)arg1 showBattery:(BOOL)arg2 animated:(BOOL)arg3 force:(BOOL)arg4 { //might just be ios12
  99. if(hideChargingAnimation) {
  100. //Same idea
  101. %orig(NO,NO,NO,NO);
  102. }
  103. }
  104. %end
  105. %end
  106. %group drm
  107. %hook SBIconController
  108. -(void)viewDidAppear:(BOOL)arg1 {
  109. %orig;
  110. UIAlertController* alert2 = [UIAlertController alertControllerWithTitle:@"kai"
  111. 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!"
  112. preferredStyle:UIAlertControllerStyleAlert];
  113. UIAlertAction* yes = [UIAlertAction actionWithTitle:@"I understand" style:UIAlertActionStyleDestructive
  114. handler:^(UIAlertAction * action) {
  115. }];
  116. [alert2 addAction:yes];
  117. [self presentViewController:alert2 animated:YES completion:nil];
  118. }
  119. %end
  120. %end
  121. %ctor {
  122. preferencesChanged();
  123. CFNotificationCenterAddObserver(
  124. CFNotificationCenterGetDarwinNotifyCenter(),
  125. &observer,
  126. (CFNotificationCallback)applyPrefs,
  127. kSettingsChangedNotification,
  128. NULL,
  129. CFNotificationSuspensionBehaviorDeliverImmediately
  130. );
  131. //Bro Muirey helped me figure out a logical way to do this because iOS 12-13 classes have changed
  132. Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]);
  133. Class CSCls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSCoverSheetViewController") class]) : ([objc_getClass("SBDashBoardViewController") class]);
  134. //BOOL bypass = YES;
  135. BOOL bypass = NO;
  136. 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) {
  137. %init(main, KAITarget = cls, KAICSTarget = CSCls); //BIG BRAIN BRO!!
  138. } 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"])) {
  139. //if(0==1)
  140. %init(drm);
  141. }
  142. }