Device battery indicators on your Lock Screen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.3KB

  1. #include <CoreFoundation/CoreFoundation.h>
  2. #import <Foundation/Foundation.h>
  3. #include <stdio.h>
  4. #import <objc/runtime.h>
  5. #import <UIKit/UIKit.h>
  6. #import "KAIBattery.mm"
  7. @interface UIApplication (Kai)
  8. +(id)sharedApplication;
  9. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  10. @end
  11. @interface CSMainPageView : UIView
  12. @property (nonatomic, strong) KAIBattery *battery;
  13. -(void)updateForPresentation:(id)arg1;
  14. -(void)KaiUpdate;
  15. @end
  16. @interface SBCoverSheetPrimarySlidingViewController
  17. -(void)KaiUpdate;
  18. @end
  19. BOOL setFrame = NO;
  20. CSMainPageView *batteryWidget;
  21. CGRect original;
  22. CGRect originalBattery;
  23. /*
  24. - (void)addObserver:(NSObject *)observer
  25. forKeyPath:(NSString *)keyPath
  26. options:(NSKeyValueObservingOptions)options
  27. context:(void *)context*/
  28. /*
  29. %hook BCBatterDeviceController
  30. +(id)sharedInstance {
  31. [%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
  32. return %orig;
  33. }
  34. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  35. if ([keyPath isEqualToString:@"sortedDevices"]) {
  36. [[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
  37. }
  38. }
  39. %end*/
  40. %hook SBCoverSheetPrimarySlidingViewController
  41. -(void)viewWillAppear:(BOOL)arg1 {
  42. %orig;
  43. [[NSNotificationCenter defaultCenter] addObserver:self
  44. selector:@selector(KaiUpdate)
  45. name:@"KaiInfoChanged"
  46. object:nil];
  47. }
  48. %new
  49. -(void)KaiUpdate {
  50. [batteryWidget.battery updateBattery];
  51. [batteryWidget KaiUpdate];
  52. }
  53. /*
  54. -(void)viewWillDisappear:(BOOL)arg1 {
  55. %orig;
  56. [batteryWidget.battery updateBattery];
  57. [batteryWidget KaiUpdate];
  58. }*/
  59. %end
  60. %hook CSMainPageView
  61. %property (nonatomic, strong) KAIBattery *battery;
  62. -(void)updateForPresentation:(id)arg1 {
  63. %orig;
  64. if(!setFrame) {
  65. original = self.frame;
  66. self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, self.frame.origin.y + 150, self.frame.size.width - 16, self.frame.size.height)];
  67. originalBattery = self.battery.frame;
  68. [self addSubview:self.battery];
  69. setFrame = YES;
  70. batteryWidget = self;
  71. }
  72. [self KaiUpdate];
  73. }
  74. %new
  75. -(void)KaiUpdate {
  76. [UIView animateWithDuration:0.3 animations:^{
  77. self.frame = CGRectMake(
  78. original.origin.x,
  79. original.origin.y + (self.battery.number * 85),
  80. original.size.width,
  81. original.size.height
  82. );
  83. self.battery.frame = CGRectMake(
  84. originalBattery.origin.x,
  85. originalBattery.origin.y - (self.battery.number * 85) + 85,
  86. originalBattery.size.width,
  87. originalBattery.size.height
  88. );
  89. }];
  90. }
  91. %end
  92. %hook BCBatteryDevice
  93. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  94. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  95. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  96. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  97. return %orig;
  98. }
  99. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  100. dispatch_async(dispatch_get_main_queue(), ^{
  101. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  102. });
  103. }
  104. %end
  105. %hook CSScrollView
  106. %end