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.3KB

  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. //by importing here, I can use vars in the .mm files
  53. #import "KAIBatteryCell.mm"
  54. #import "KAIStackView.mm"
  55. #import "KAIBatteryPlatter.mm"
  56. #define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
  57. #define kIdentifier @"com.burritoz.kaiprefs"
  58. #define kSettingsChangedNotification (CFStringRef)@"com.burritoz.kaiprefs/reload"
  59. #define kSettingsPath @"/var/mobile/Library/Preferences/com.burritoz.kaiprefs.plist"
  60. NSDictionary *prefs = nil;
  61. static void *observer = NULL;
  62. static void reloadPrefs()
  63. {
  64. if ([NSHomeDirectory() isEqualToString:@"/var/mobile"])
  65. {
  66. CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  67. if (keyList)
  68. {
  69. prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
  70. if (!prefs)
  71. {
  72. prefs = [NSDictionary new];
  73. }
  74. CFRelease(keyList);
  75. }
  76. }
  77. else
  78. {
  79. prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
  80. }
  81. }
  82. static BOOL boolValueForKey(NSString *key, BOOL defaultValue) {
  83. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] boolValue] : defaultValue);
  84. }
  85. static double numberForValue(NSString *key, double defaultValue) {
  86. return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue);
  87. }
  88. static void preferencesChanged()
  89. {
  90. CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
  91. reloadPrefs();
  92. enabled = boolValueForKey(@"enabled", YES);
  93. spacing = numberForValue(@"spacing", 5);
  94. glyphSize = numberForValue(@"glyphSize", 30);
  95. bannerHeight = numberForValue(@"bannerHeight", 80);
  96. cornerRadius = numberForValue(@"cornerRadius", 13);
  97. disableGlyphs = boolValueForKey(@"disableGlyphs", NO);
  98. hidePercent = boolValueForKey(@"hidePercent", NO);
  99. bannerStyle = numberForValue(@"bannerStyle", 1);
  100. showAll = boolValueForKey(@"showAll", NO);
  101. bannerWidthFactor = numberForValue(@"bannerWidthFactor", 0);
  102. hideDeviceLabel = boolValueForKey(@"hideDeviceLabel", NO);
  103. bannerAlign = numberForValue(@"bannerAlign", 2);
  104. horizontalOffset = numberForValue(@"horizontalOffset", 0);
  105. belowMusic = boolValueForKey(@"belowMusic", NO);
  106. hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
  107. textColor = numberForValue(@"textColor", 0);
  108. bannerAlpha = numberForValue(@"bannerAlpha", 1);
  109. showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO);
  110. kaiAlign = numberForValue(@"kaiAlign", 0);
  111. if(disableGlyphs) {
  112. glyphSize = 0;
  113. }
  114. }
  115. static void applyPrefs()
  116. {
  117. preferencesChanged();
  118. isUpdating = YES;
  119. [[KAIBatteryPlatter sharedInstance] refreshForPrefs]; //so hard (not)
  120. [(CSAdjunctListView *)([KAIBatteryPlatter sharedInstance].superview.superview) _layoutStackView];
  121. isUpdating = NO;
  122. }