Dark tabs for Zenith! Mirror of https://github.com/mac-user669/ZenithDark
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

126 rindas
4.0KB

  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 Tweak13
  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. // if the tweak is enabled and the version is iOS 13 or later run our code
  16. if (@available(iOS 13, *)) {
  17. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  18. [self setBackgroundColor:kDarkModeColor];
  19. }
  20. else {
  21. [self setBackgroundColor:kLightModeColor];
  22. }
  23. }
  24. }
  25. else {
  26. %orig(previousTraitCollection);
  27. }
  28. }
  29. // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  30. // Since the grabber view is of type UIImageView we can modify this method :)
  31. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  32. %orig;
  33. if (kEnabled) {
  34. // by default have our tweak overide this.
  35. if (@available(iOS 13, *)) {
  36. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  37. %orig(kDarkModeColor);
  38. }
  39. }
  40. else {
  41. %orig;
  42. }
  43. }
  44. }
  45. %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
  46. %end
  47. static BOOL ios13;
  48. %group Tweak12
  49. //We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  50. %hook ZNGrabberAccessoryView
  51. // The method we then modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  52. // Since the grabber view is of type UIImageView we can modify this method :)
  53. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  54. //call the original function then pass our custom argument to the backgroundColor argument as shown below.
  55. %orig(kDarkModeColor);
  56. }
  57. // 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
  58. %end
  59. %end
  60. static void loadPrefs() { // Load preferences to make sure changes are written to the plist
  61. // Thanks to skittyblock!
  62. CFArrayRef keyList = CFPreferencesCopyKeyList(CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  63. if(keyList) {
  64. prefs = (NSMutableDictionary *)CFPreferencesCopyMultiple(keyList, CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  65. CFRelease(keyList);
  66. } else {
  67. prefs = nil;
  68. }
  69. if (!prefs) {
  70. prefs = [NSMutableDictionary dictionaryWithContentsOfFile:PLIST_PATH];
  71. }
  72. kEnabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue]; //our preference values that write to a plist file when a user selects somethings
  73. }
  74. // Thanks to skittyblock!
  75. static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  76. loadPrefs();
  77. }
  78. %ctor { // Our constructor
  79. loadPrefs(); // Load our prefs
  80. if (kEnabled) { // If enabled
  81. if (@available(iOS 13, *)) { // If the device is running iOS 13
  82. ios13 = YES; // Set "iOS13" to "YES"
  83. %init(Tweak13); // Enable the group "Tweak13"
  84. } else {
  85. ios13 = NO; // Set "iOS13" to "NO"
  86. %init(Tweak12); // Enable the group "Tweak12"
  87. }
  88. }
  89. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR("com.mac-user669.zenithdark.prefschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  90. 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.
  91. }