Device battery indicators on your Lock Screen
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

135 lines
3.9KB

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