Dark tabs for Zenith! Mirror of https://github.com/mac-user669/ZenithDark
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 line
2.4KB

  1. /*
  2. Dark Mode for Zenith's Grabber view!
  3. Copyright 2020 J.K. Hayslip (@iKilledAppl3) & ToxicAppl3 INSDC/iKilledAppl3 LLC.
  4. All code was written for learning purposes and credit must be given to the original author.
  5. Written for Cooper Hull, @(mac-user669).
  6. */
  7. #import "ZenithDark.h"
  8. static BOOL enabled;
  9. static void loadPrefs() {
  10. static NSMutableDictionary *settings;
  11. CFArrayRef keyList = CFPreferencesCopyKeyList(CFSTR("com.mac-user669.zenithdarkprefs"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  12. if (keyList) {
  13. settings = (NSMutableDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, CFSTR("com.mac-user669.zenithdarkprefs"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
  14. CFRelease(keyList);
  15. } else {
  16. settings = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.mac-user669.zenithdarkprefs.plist"];
  17. }
  18. enabled = [([settings objectForKey:@"enabled"] ? [settings objectForKey:@"enabled"] : @(YES)) boolValue];
  19. }
  20. // We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  21. %hook ZNGrabberAccessoryView
  22. // this is called when iOS 13's dark mode is enabled!
  23. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  24. if (enabled) {
  25. %orig(previousTraitCollection);
  26. if (@available(iOS 13, *)) {
  27. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  28. [self setBackgroundColor:kDarkModeColor];
  29. }
  30. else {
  31. [self setBackgroundColor:kLightModeColor];
  32. }
  33. }
  34. }
  35. %orig;
  36. }
  37. // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  38. // Since the grabber view is of type UIImageView we can modify this method :)
  39. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  40. if (enabled) {
  41. // by default have our tweak overide this.
  42. if (@available(iOS 13, *)) {
  43. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  44. %orig(kDarkModeColor);
  45. }
  46. else {
  47. %orig;
  48. }
  49. }
  50. }
  51. %orig;
  52. }
  53. // 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
  54. %end
  55. // our constructor
  56. %ctor {
  57. loadPrefs();
  58. // We use this to make sure we load Zenith's dynamic library at runtime so we can modify it with our tweak.
  59. dlopen ("/Library/MobileSubstrate/DynamicLibraries/Zenith.dylib", RTLD_NOW);
  60. }