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.

157 lines
4.9KB

  1. #include <CoreFoundation/CoreFoundation.h>
  2. #import <Foundation/Foundation.h>
  3. #import <UIKit/UIKit.h>
  4. #import <objc/runtime.h>
  5. #define KAISelf ((CSAdjunctListView *)self) // for use when calling self in KAITarget
  6. @interface CSAdjunctListView : UIView
  7. @property (nonatomic, assign) BOOL hasKai;
  8. - (UIStackView *)stackView;
  9. - (void)_layoutStackView;
  10. - (void)setStackView:(UIStackView *)arg1;
  11. - (NSInteger)getMediaIndexForClass:(Class)cls;
  12. - (void)performReorder;
  13. + (id)sharedListViewForKai;
  14. + (void)reorderKai;
  15. @end
  16. @interface SBMediaController : NSObject
  17. @property (nonatomic, strong) id nowPlayingApplication;
  18. - (BOOL)isPlaying;
  19. @end
  20. @interface CALayer (kai)
  21. @property (nonatomic, assign) BOOL continuousCorners;
  22. @end
  23. @interface SBCoverSheetPrimarySlidingViewController : UIViewController
  24. @end
  25. @interface APEPlatter : UIView
  26. @property (nonatomic, assign) BOOL removed;
  27. + (APEPlatter *)sharedInstance;
  28. @end
  29. @interface NCNotificationListView : UIView
  30. - (void)fixComplicationsViewFrame;
  31. @end
  32. BOOL ios13 = NO;
  33. BOOL isUpdating = NO;
  34. BOOL shouldBeAdded = YES;
  35. // prefs
  36. BOOL enabled;
  37. BOOL disableGlyphs;
  38. BOOL hidePercent;
  39. BOOL showAll;
  40. BOOL hideDeviceLabel;
  41. BOOL hideChargingAnimation;
  42. BOOL showAllMinusInternal;
  43. BOOL hideBatteryIcon;
  44. BOOL reAlignSelf;
  45. BOOL showPhone;
  46. BOOL removeForMedia;
  47. BOOL extraPaddingAfter;
  48. NSInteger bannerStyle;
  49. NSInteger bannerAlign;
  50. NSInteger textColor;
  51. NSInteger placement;
  52. double spacing;
  53. double glyphSize;
  54. double bannerHeight;
  55. double cornerRadius;
  56. double bannerWidthFactor;
  57. double horizontalOffset;
  58. double bannerAlpha;
  59. double kaiAlign;
  60. double spacingHorizontal;
  61. // by importing here, I can use vars in the .mm files
  62. #import "KAIBatteryCell.mm"
  63. #import "KAIBatteryPlatter.mm"
  64. #import "KAIStackView.mm"
  65. #define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
  66. #define kIdentifier @"com.burritoz.kaiprefs"
  67. #define kSettingsChangedNotification (CFStringRef) @"com.burritoz.kaiprefs/reload"
  68. #define kSettingsPath @"/var/mobile/Library/Preferences/com.burritoz.kaiprefs.plist"
  69. NSDictionary *prefs = nil;
  70. static void *observer = NULL;
  71. static void reloadPrefs() {
  72. if ([NSHomeDirectory() isEqualToString:@"/var/mobile"]) {
  73. CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  74. if (keyList) {
  75. prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
  76. if (!prefs) {
  77. prefs = [NSDictionary new];
  78. }
  79. CFRelease(keyList);
  80. }
  81. } else {
  82. prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
  83. }
  84. }
  85. static BOOL boolValueForKey(NSString *key, BOOL defaultValue) {
  86. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] boolValue] : defaultValue);
  87. }
  88. static double numberForValue(NSString *key, double defaultValue) {
  89. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue);
  90. }
  91. static void preferencesChanged() {
  92. CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
  93. reloadPrefs();
  94. enabled = boolValueForKey(@"enabled", YES);
  95. spacing = numberForValue(@"spacing", 5);
  96. glyphSize = numberForValue(@"glyphSize", 30);
  97. bannerHeight = numberForValue(@"bannerHeight", 80);
  98. cornerRadius = numberForValue(@"cornerRadius", 13);
  99. disableGlyphs = boolValueForKey(@"disableGlyphs", NO);
  100. hidePercent = boolValueForKey(@"hidePercent", NO);
  101. bannerStyle = numberForValue(@"bannerStyle", 1);
  102. showAll = boolValueForKey(@"showAll", YES);
  103. bannerWidthFactor = numberForValue(@"bannerWidthFactor", 0);
  104. hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
  105. bannerAlign = numberForValue(@"bannerAlign", 2);
  106. horizontalOffset = numberForValue(@"horizontalOffset", 0);
  107. placement = numberForValue(@"placement", 1);
  108. hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
  109. textColor = numberForValue(@"textColor", 0);
  110. bannerAlpha = numberForValue(@"bannerAlpha", 1);
  111. showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO);
  112. kaiAlign = numberForValue(@"kaiAlign", 0);
  113. spacingHorizontal = numberForValue(@"spacingHorizontal", 8);
  114. hideBatteryIcon = boolValueForKey(@"hideBatteryIcon", NO);
  115. reAlignSelf = boolValueForKey(@"reAlignSelf", YES);
  116. extraPaddingAfter = boolValueForKey(@"extraPaddingAfter", NO);
  117. showPhone = boolValueForKey(@"showPhone", YES);
  118. removeForMedia = boolValueForKey(@"removeForMedia", NO);
  119. if (disableGlyphs) {
  120. glyphSize = 0;
  121. }
  122. }
  123. static void applyPrefs() {
  124. preferencesChanged();
  125. isUpdating = YES;
  126. [[KAIBatteryPlatter sharedInstance] refreshForPrefs]; // so hard (not)
  127. [(CSAdjunctListView *)([KAIBatteryPlatter sharedInstance].superview.superview) _layoutStackView];
  128. [[NSNotificationCenter defaultCenter] postNotificationName:@"KaiResetOffset" object:nil userInfo:nil];
  129. isUpdating = NO;
  130. }