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.

131 lines
3.2KB

  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. self.frame = CGRectMake(
  77. original.origin.x,
  78. original.origin.y + (self.battery.number * 85),
  79. original.size.width,
  80. original.size.height
  81. );
  82. self.battery.frame = CGRectMake(
  83. originalBattery.origin.x,
  84. originalBattery.origin.y - (self.battery.number * 85) + 85,
  85. originalBattery.size.width,
  86. originalBattery.size.height
  87. );
  88. }
  89. %end
  90. %hook BCBatteryDevice
  91. - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 {
  92. [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
  93. [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil];
  94. //[self setValue:@"crash" forKeyPath:@"euhidehuud"];
  95. return %orig;
  96. }
  97. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  98. NSLog(@"It works");
  99. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiInfoChanged" object:nil userInfo:nil];
  100. }
  101. %end