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.

120 lines
2.9KB

  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. BOOL setFrame = NO;
  17. CSMainPageView *batteryWidget;
  18. CGRect original;
  19. CGRect originalBattery;
  20. /*
  21. - (void)addObserver:(NSObject *)observer
  22. forKeyPath:(NSString *)keyPath
  23. options:(NSKeyValueObservingOptions)options
  24. context:(void *)context*/
  25. /*
  26. %hook BCBatterDeviceController
  27. +(id)sharedInstance {
  28. [%orig addObserver:self forKeyPath:@"sortedDevices" options:NSKeyValueObservingOptionNew context:nil];
  29. return %orig;
  30. }
  31. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  32. if ([keyPath isEqualToString:@"sortedDevices"]) {
  33. [[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.weather" suspended:NO];
  34. }
  35. }
  36. %end*/
  37. /*
  38. %hook SBCoverSheetPrimarySlidingViewController
  39. -(void)viewWillAppear:(BOOL)arg1 {
  40. %orig;
  41. [batteryWidget.battery updateBattery];
  42. [batteryWidget KaiUpdate];
  43. }
  44. /*
  45. -(void)viewWillDisappear:(BOOL)arg1 {
  46. %orig;
  47. [batteryWidget.battery updateBattery];
  48. [batteryWidget KaiUpdate];
  49. }*/
  50. //%end
  51. %hook CSMainPageView
  52. %property (nonatomic, strong) KAIBattery *battery;
  53. -(void)updateForPresentation:(id)arg1 {
  54. %orig;
  55. if(!setFrame) {
  56. original = self.frame;
  57. self.battery = [[KAIBattery alloc] initWithFrame:CGRectMake(8, self.frame.origin.y + 150, self.frame.size.width - 16, self.frame.size.height)];
  58. originalBattery = self.battery.frame;
  59. [self addSubview:self.battery];
  60. setFrame = YES;
  61. batteryWidget = self;
  62. }
  63. [self KaiUpdate];
  64. }
  65. %new
  66. -(void)KaiUpdate {
  67. self.frame = CGRectMake(
  68. original.origin.x,
  69. original.origin.y + (self.battery.number * 85),
  70. original.size.width,
  71. original.size.height
  72. );
  73. self.battery.frame = CGRectMake(
  74. originalBattery.origin.x,
  75. originalBattery.origin.y - (self.battery.number * 85) + 85,
  76. originalBattery.size.width,
  77. originalBattery.size.height
  78. );
  79. }
  80. %end
  81. %hook BCBatteryDevice
  82. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  83. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  84. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  85. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  86. return %orig;
  87. }
  88. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  89. NSLog(@"It works");
  90. }
  91. %end