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.

151 lines
4.4KB

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