Dark tabs for Zenith! Mirror of https://github.com/mac-user669/ZenithDark
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.

Tweak.xm 3.9KB

il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #import "ZenithDark.h"
  2. /*
  3. Dark Mode for Zenith's Grabber view!
  4. Copyright 2020 J.K. Hayslip (@iKilledAppl3) & ToxicAppl3 INSDC/iKilledAppl3 LLC.
  5. All code was written for learning purposes and credit must be given to the original author.
  6. Written for Cooper Hull, @mac-user669.
  7. */
  8. %group Adaptive
  9. // We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  10. %hook ZNGrabberAccessoryView
  11. // this is called when iOS 13's dark mode is enabled!
  12. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  13. %orig(previousTraitCollection);
  14. if (kEnabled) {
  15. NSString* colourString = NULL;
  16. NSDictionary* preferencesDictionary = [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist"];
  17. if(preferencesDictionary)
  18. {
  19. colourString = [preferencesDictionary objectForKey: @"kCustomLightColor"];
  20. }
  21. UIColor* lightColor = [SparkColourPickerUtils colourWithString: colourString withFallback: @"#FFFFFF:0.7"];
  22. // if the tweak is enabled and the version is iOS 13 or later run our code
  23. if (@available(iOS 13, *)) {
  24. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  25. [self setBackgroundColor:kColor1];
  26. }
  27. else {
  28. [self setBackgroundColor:lightColor];
  29. }
  30. }
  31. }
  32. else {
  33. %orig(previousTraitCollection);
  34. }
  35. }
  36. // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  37. // Since the grabber view is of type UIImageView we can modify this method :)
  38. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  39. %orig;
  40. if (kEnabled) {
  41. NSString* colourString = NULL;
  42. NSDictionary* preferencesDictionary = [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist"];
  43. if(preferencesDictionary)
  44. {
  45. colourString = [preferencesDictionary objectForKey: @"kCustomDarkColor"];
  46. }
  47. UIColor* darkColor = [SparkColourPickerUtils colourWithString: colourString withFallback: @"#000000:0.44"];
  48. // by default have our tweak overide this.
  49. if (@available(iOS 13, *)) {
  50. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  51. %orig(darkColor);
  52. }
  53. }
  54. else {
  55. %orig;
  56. }
  57. }
  58. }
  59. %end // We need to make sure we tell theos that we are finished hooking this class not doing so with cause the end of the world :P
  60. %end
  61. static void loadPrefs() { // Load preferences to make sure changes are written to the plist
  62. // Thanks to skittyblock!
  63. CFArrayRef keyList = CFPreferencesCopyKeyList(CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  64. if(keyList) {
  65. prefs = (NSMutableDictionary *)CFPreferencesCopyMultiple(keyList, CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  66. CFRelease(keyList);
  67. } else {
  68. prefs = nil;
  69. }
  70. if (!prefs) {
  71. prefs = [NSMutableDictionary dictionaryWithContentsOfFile:PLIST_PATH];
  72. }
  73. kEnabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue]; //our preference values that write to a plist file when a user selects somethings
  74. }
  75. // Thanks to skittyblock!
  76. static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  77. loadPrefs();
  78. }
  79. %ctor { // Our constructor
  80. loadPrefs(); // Load our prefs
  81. if (kEnabled) { // If enabled
  82. %init(Adaptive); // Enable the group "Adaptive"
  83. }
  84. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR("com.mac-user669.zenithdark.prefschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  85. dlopen ("/Library/MobileSubstrate/DynamicLibraries/Zenith.dylib", RTLD_NOW); // We use this to make sure we load Zenith's dynamic library at runtime so we can modify it with our tweak.
  86. }