Dark tabs for Zenith! Mirror of https://github.com/mac-user669/ZenithDark
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Tweak.xm 4.8KB

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