Dark tabs for Zenith! Mirror of https://github.com/mac-user669/ZenithDark
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

98 linhas
3.0KB

  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. // We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
  9. %hook ZNGrabberAccessoryView
  10. // this is called when iOS 13's dark mode is enabled!
  11. -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  12. %orig(previousTraitCollection);
  13. if (kEnabled) {
  14. // if the tweak is enabled and the version is iOS 13 or later run our code
  15. if (@available(iOS 13, *)) {
  16. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  17. [self setBackgroundColor:kDarkModeColor];
  18. }
  19. else {
  20. [self setBackgroundColor:kLightModeColor];
  21. }
  22. }
  23. }
  24. else {
  25. %orig(previousTraitCollection);
  26. }
  27. }
  28. // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view.
  29. // Since the grabber view is of type UIImageView we can modify this method :)
  30. -(void)setBackgroundColor:(UIColor *)backgroundColor {
  31. %orig;
  32. if (kEnabled) {
  33. // by default have our tweak overide this.
  34. if (@available(iOS 13, *)) {
  35. if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  36. %orig(kDarkModeColor);
  37. }
  38. }
  39. else {
  40. %orig;
  41. }
  42. }
  43. }
  44. // 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
  45. %end
  46. // Load preferences to make sure changes are written to the plist
  47. static void loadPrefs() {
  48. // Thanks to skittyblock!
  49. CFArrayRef keyList = CFPreferencesCopyKeyList(CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  50. if(keyList) {
  51. prefs = (NSMutableDictionary *)CFPreferencesCopyMultiple(keyList, CFSTR("com.mac-user669.zenithdark"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
  52. CFRelease(keyList);
  53. } else {
  54. prefs = nil;
  55. }
  56. if (!prefs) {
  57. prefs = [NSMutableDictionary dictionaryWithContentsOfFile:PLIST_PATH];
  58. }
  59. //our preference values that write to a plist file when a user selects somethings
  60. kEnabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue];
  61. }
  62. // thanks to skittyblock!
  63. static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  64. loadPrefs();
  65. }
  66. // our constructor
  67. %ctor {
  68. // load our prefs
  69. loadPrefs();
  70. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR("com.mac-user669.zenithdark.prefschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  71. // We use this to make sure we load Zenith's dynamic library at runtime so we can modify it with our tweak.
  72. dlopen ("/Library/MobileSubstrate/DynamicLibraries/Zenith.dylib", RTLD_NOW);
  73. }