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.

141 lines
4.0KB

  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. #define KAISelf ((CSAdjunctListView *)self)
  7. @interface UIApplication (Kai)
  8. +(id)sharedApplication;
  9. -(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2;
  10. @end
  11. @interface CSAdjunctListView : UIView
  12. @property (nonatomic, assign) BOOL hasKai;
  13. -(UIStackView *)stackView;
  14. -(void)setStackView:(UIStackView *)arg1;
  15. -(void)KaiUpdate;
  16. @end
  17. @interface SBDashBoardAdjunctListView : UIView
  18. @property (nonatomic, assign) BOOL hasKai;
  19. -(UIStackView *)stackView;
  20. -(void)setStackView:(UIStackView *)arg1;
  21. -(void)KaiUpdate;
  22. @end
  23. @interface CSMainPageView : UIView
  24. -(void)updateForPresentation:(id)arg1;
  25. @end
  26. @interface _CSSingleBatteryChargingView : UIView
  27. @end
  28. @interface NSLayoutConstraint (Kai)
  29. +(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ;
  30. @end
  31. @interface CALayer (kai)
  32. @property (nonatomic, assign) BOOL continuousCorners;
  33. @end
  34. BOOL isUpdating = NO;
  35. //prefs
  36. BOOL enabled;
  37. BOOL disableGlyphs;
  38. BOOL hidePercent;
  39. BOOL showAll;
  40. BOOL hideDeviceLabel;
  41. NSInteger bannerStyle;
  42. NSInteger bannerAlign;
  43. double spacing;
  44. double glyphSize;
  45. double bannerHeight;
  46. double cornerRadius;
  47. double bannerWidthFactor;
  48. #import "KAIBattery.mm"
  49. #define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
  50. #define kIdentifier @"com.burritoz.kaiprefs"
  51. #define kSettingsChangedNotification (CFStringRef)@"com.burritoz.kaiprefs/reload"
  52. #define kSettingsPath @"/var/mobile/Library/Preferences/com.burritoz.kaiprefs.plist"
  53. NSDictionary *prefs = nil;
  54. static void *observer = NULL;
  55. static void reloadPrefs()
  56. {
  57. if ([NSHomeDirectory() isEqualToString:@"/var/mobile"])
  58. {
  59. CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  60. if (keyList)
  61. {
  62. prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
  63. if (!prefs)
  64. {
  65. prefs = [NSDictionary new];
  66. }
  67. CFRelease(keyList);
  68. }
  69. }
  70. else
  71. {
  72. prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
  73. }
  74. }
  75. static BOOL boolValueForKey(NSString *key, BOOL defaultValue) {
  76. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] boolValue] : defaultValue);
  77. }
  78. static double numberForValue(NSString *key, double defaultValue) {
  79. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue);
  80. }
  81. static void preferencesChanged()
  82. {
  83. CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
  84. reloadPrefs();
  85. enabled = boolValueForKey(@"enabled", YES);
  86. spacing = numberForValue(@"spacing", 5);
  87. glyphSize = numberForValue(@"glyphSize", 40);
  88. bannerHeight = numberForValue(@"bannerHeight", 80);
  89. cornerRadius = numberForValue(@"cornerRadius", 13);
  90. disableGlyphs = boolValueForKey(@"disableGlyphs", NO);
  91. hidePercent = boolValueForKey(@"hidePercent", NO);
  92. bannerStyle = numberForValue(@"bannerStyle", 1);
  93. showAll = boolValueForKey(@"showAll", NO);
  94. bannerWidthFactor = numberForValue(@"bannerWidthFactor", 0);
  95. hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
  96. bannerAlign = numberForValue(@"bannerAlign", 2);
  97. if(disableGlyphs) {
  98. glyphSize = 0;
  99. }
  100. }
  101. static void applyPrefs()
  102. {
  103. preferencesChanged();
  104. isUpdating = YES;
  105. [UIView animateWithDuration:0.3 animations:^{
  106. [KAIBattery sharedInstance].alpha = 0;
  107. } completion:^(BOOL finished){
  108. [[KAIBattery sharedInstance] updateBattery];
  109. [(CSAdjunctListView *)([KAIBattery sharedInstance].superview.superview) KaiUpdate];
  110. [UIView animateWithDuration:0.35 animations:^{
  111. [KAIBattery sharedInstance].alpha = 1;
  112. } completion:^(BOOL finished){
  113. isUpdating = NO;
  114. }];
  115. }];
  116. }