Guest User

Untitled

a guest
Jul 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. #import <UIKit/UIKit.h>
  2.  
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #import <dlfcn.h>
  7.  
  8. extern void GSSendAppPreferencesChanged(NSString *bundleID, NSString *key);
  9.  
  10. static void updatePref(NSString *key)
  11. {
  12. GSSendAppPreferencesChanged(@"com.apple.springboard", key);
  13. }
  14.  
  15. // Determines if the device is capable of running on this platform. If your toggle is device specific like only for
  16. BOOL isCapable()
  17. {
  18. return YES;
  19. }
  20.  
  21. // This runs when iPhone springboard resets. This is on boot or respring.
  22. BOOL isEnabled()
  23. {
  24. NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
  25. if(plistDict != nil)
  26. {
  27. int AutoLockT = [[plistDict objectForKey:@"SBAutoLockTime"] intValue];
  28. if (AutoLockT != -1)
  29. return YES;
  30. }
  31. return NO;
  32. }
  33.  
  34. // This function is optional and should only be used if it is likely for the toggle to become out of sync
  35. // with the state while the iPhone is running. It must be very fast or you will slow down the animated
  36. // showing of the sbsettings window. Imagine 12 slow toggles trying to refresh tate on show.
  37. BOOL getStateFast()
  38. {
  39. return isEnabled();
  40. }
  41.  
  42. // Pass in state to set. YES for enable, NO to disable.
  43. void setState(BOOL Enable)
  44. {
  45. FILE* fp = NULL;
  46. int AutoLockT = 0;
  47. int AutoDimT = 0;
  48.  
  49. // If we're already in the state being requested, don't do anything.
  50. if(isEnabled() != Enable)
  51. {
  52. NSMutableDictionary *plistDict = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
  53. if(plistDict != nil)
  54. {
  55. if (Enable == NO)
  56. {
  57. AutoLockT = [[plistDict objectForKey:@"SBAutoLockTime"] intValue];
  58. AutoDimT = [[plistDict objectForKey:@"SBAutoDimTime"] intValue];
  59.  
  60. // Store off current autolock values.
  61. fp = fopen("/var/mobile/Library/SBSettings/autolock.sav","wb");
  62. if(fp != NULL)
  63. {
  64. fwrite(&AutoLockT, sizeof(AutoLockT), 1, fp);
  65. fwrite(&AutoDimT, sizeof(AutoDimT), 1, fp);
  66. fclose(fp);
  67. }
  68.  
  69. [plistDict setValue:[NSNumber numberWithInt:-1] forKey:@"SBAutoLockTime"];
  70. [plistDict writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically: YES];
  71. [plistDict setValue:[NSNumber numberWithInt:-1] forKey:@"SBAutoDimTime"];
  72. [plistDict writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically: YES];
  73. }
  74. else if (Enable == YES)
  75. {
  76. // Store off current autolock values.
  77. fp = fopen("/var/mobile/Library/SBSettings/autolock.sav","rb");
  78. if(fp != NULL)
  79. {
  80. fread(&AutoLockT, sizeof(AutoLockT), 1, fp);
  81. fread(&AutoDimT, sizeof(AutoDimT), 1, fp);
  82. fclose(fp);
  83. remove("/var/mobile/Library/SBSettings/autolock.sav");
  84. }
  85. else
  86. {
  87. AutoDimT = 45;
  88. AutoLockT = 60;
  89. }
  90.  
  91. [plistDict setValue:[NSNumber numberWithInt:AutoLockT] forKey:@"SBAutoLockTime"];
  92. [plistDict writeToFile:@"/var/mobile/Library/Preferences/com.apple.springbord.plist" atomically: YES];
  93. [plistDict setValue:[NSNumber numberWithInt:AutoDimT] forKey:@"SBAutoDimTime"];
  94. [plistDict writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically: YES];
  95. }
  96.  
  97. updatePref(@"SBAutoLockTime");
  98. updatePref(@"SBAutoDimTime");
  99. }
  100. }
  101. }
  102.  
  103. // Amount of time spinner should spin in seconds after the toggle is selected.
  104. float getDelayTime()
  105. {
  106. return 0.6f;
  107. }
  108.  
  109. // Runs when the dylib is loaded. Only useful for debug. Function can be omitted.
  110. __attribute__((constructor))
  111. static void toggle_initializer()
  112. {
  113. NSLog(@"Initializing AutoLock Toggle\n");
  114. }
Add Comment
Please, Sign In to add comment