Dark tabs for Zenith! Mirror of https://github.com/mac-user669/ZenithDark
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

202 lines
6.3KB

  1. #import "ZenithDark.h"
  2. #import <Cephei/HBPreferences.h>
  3. #import <CepheiPrefs/HBRootListController.h>
  4. #import <CepheiPrefs/HBAppearanceSettings.h>
  5. /*
  6. Dark Mode for Zenith's Grabber view!
  7. Copyright 2020 J.K. Hayslip (@iKilledAppl3) & ToxicAppl3 INSDC/iKilledAppl3 LLC.
  8. All code was written for learning purposes and credit must be given to the original author.
  9. Written for Cooper Hull, @mac-user669.
  10. */
  11. %group Adaptive
  12. // We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  13. %hook ZNGrabberAccessoryView
  14. // this is called when iOS 13's dark mode is enabled!
  15. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  16. %orig(previousTraitCollection);
  17. if (kEnabled) {
  18. // if the tweak is enabled and the version is iOS 13 or later run our code
  19. if (@available(iOS 13, *)) {
  20. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  21. [self setBackgroundColor:kDarkColor];
  22. }
  23. else {
  24. [self setBackgroundColor:kLightColor];
  25. }
  26. }
  27. }
  28. else {
  29. %orig(previousTraitCollection);
  30. }
  31. }
  32. // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  33. // Since the grabber view is of type UIImageView we can modify this method :)
  34. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  35. %orig;
  36. if (kEnabled) {
  37. // by default have our tweak overide this.
  38. if (@available(iOS 13, *)) {
  39. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  40. %orig(kDarkColor);
  41. }
  42. }
  43. else {
  44. %orig;
  45. }
  46. }
  47. }
  48. %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
  49. %end
  50. %group justDark
  51. //We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  52. %hook ZNGrabberAccessoryView
  53. // The method we then modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  54. // Since the grabber view is of type UIImageView we can modify this method :)
  55. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  56. //call the original function then pass our custom argument to the backgroundColor argument as shown below.
  57. %orig(kDarkColor);
  58. }
  59. // 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. %end
  62. %group OLEDadaptive
  63. // We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  64. %hook ZNGrabberAccessoryView
  65. // this is called when iOS 13's dark mode is enabled!
  66. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  67. %orig(previousTraitCollection);
  68. if (kEnabled) {
  69. // if the tweak is enabled and the version is iOS 13 or later run our code
  70. if (@available(iOS 13, *)) {
  71. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  72. [self setBackgroundColor:kOLEDColor];
  73. }
  74. else {
  75. [self setBackgroundColor:kLightColor];
  76. }
  77. }
  78. }
  79. else {
  80. %orig(previousTraitCollection);
  81. }
  82. }
  83. // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  84. // Since the grabber view is of type UIImageView we can modify this method :)
  85. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  86. %orig;
  87. if (kEnabled) {
  88. // by default have our tweak overide this.
  89. if (@available(iOS 13, *)) {
  90. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  91. %orig(kOLEDColor);
  92. }
  93. }
  94. else {
  95. %orig;
  96. }
  97. }
  98. }
  99. %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
  100. %end
  101. %group OLEDgroup
  102. //We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  103. %hook ZNGrabberAccessoryView
  104. // The method we then modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  105. // Since the grabber view is of type UIImageView we can modify this method :)
  106. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  107. //call the original function then pass our custom argument to the backgroundColor argument as shown below.
  108. %orig(kOLEDColor);
  109. }
  110. // 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
  111. %end
  112. %end
  113. static void loadPrefs() { // Load preferences to make sure changes are written to the plist
  114. // Thanks to skittyblock!
  115. CFArrayRef keyList = CFPreferencesCopyKeyList(CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  116. if(keyList) {
  117. prefs = (NSMutableDictionary *)CFPreferencesCopyMultiple(keyList, CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  118. CFRelease(keyList);
  119. } else {
  120. prefs = nil;
  121. }
  122. if (!prefs) {
  123. prefs = [NSMutableDictionary dictionaryWithContentsOfFile:PLIST_PATH];
  124. }
  125. kEnabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue]; //our preference values that write to a plist file when a user selects somethings
  126. sortType = [([prefs objectForKey:@"sortingType"] ? [prefs objectForKey:@"sortingType"] : @"0") integerValue];
  127. }
  128. // Thanks to skittyblock!
  129. static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  130. loadPrefs();
  131. }
  132. %ctor { // Our constructor
  133. loadPrefs(); // Load our prefs
  134. if (kEnabled) { // If enabled
  135. if (sortType == ZNDarkSortTypeAdaptive) {
  136. %init(Adaptive); // Enable the group "Adaptive"
  137. }
  138. else if (sortType == ZNDarkSortTypeDark) {
  139. %init(justDark); // Enable the group "Adaptive"
  140. }
  141. else if (sortType == ZNDarkSortTypeOLEDAdaptive) {
  142. %init(OLEDadaptive); // Enable the group "OLEDgroup"
  143. }
  144. else if (sortType == ZNDarkSortTypeOLED) {
  145. %init(OLEDgroup); // Enable the group "OLEDgroup"
  146. }
  147. }
  148. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR("com.mac-user669.zenithdark.prefschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  149. 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.
  150. }