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.

149 lines
4.8KB

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