From c59707850a1eca172ddcbc8ad77fb97a940e1bcb Mon Sep 17 00:00:00 2001 From: mac-user669 Date: Thu, 6 Feb 2020 17:53:33 -0500 Subject: [PATCH] Switch to libCSColorPicker --- Makefile | 2 +- Tweak.xm | 71 ++++++------ ZenithDark.h | 22 ++-- control | 2 +- zenithdarkprefs/Makefile | 2 +- zenithdarkprefs/Resources/Root.plist | 101 +++++++++++------- .../ZNDarkPrefsRootListController.h | 1 + .../ZNDarkPrefsRootListController.m | 6 +- 8 files changed, 112 insertions(+), 95 deletions(-) diff --git a/Makefile b/Makefile index 9866ab3..8a3d1f6 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ TWEAK_NAME = ZenithDark ZenithDark_FILES = Tweak.xm ZenithDark_FRAMEWORKS = UIKit CoreGraphics ZenithDark_EXTRA_FRAMEWORKS += Cephei -ZenithDark_LIBRARIES = sparkcolourpicker +$(TWEAK_NAME)_LDFLAGS += -lCSColorPicker include $(THEOS_MAKE_PATH)/tweak.mk diff --git a/Tweak.xm b/Tweak.xm index 7ed6d52..43c43d0 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -7,60 +7,53 @@ All code was written for learning purposes and credit must be given to the origi Written for Cooper Hull, @mac-user669. */ -%group Adaptive -// We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView” + +BOOL kEnabled; +BOOL kCustomDarkColorEnabled; +BOOL kCustomLightColorEnabled; + +inline NSString *StringForPreferenceKey(NSString *key) { + NSDictionary *prefs = [NSDictionary dictionaryWithContentsOfFile:PLIST_PATH] ? : [NSDictionary new]; + return prefs[key]; +} + +%group TweakGroup %hook ZNGrabberAccessoryView // this is called when iOS 13's dark mode is enabled! -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { - %orig(previousTraitCollection); - if (kEnabled) { - NSString* colourString = NULL; - NSDictionary* preferencesDictionary = [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist"]; - if(preferencesDictionary) - { - colourString = [preferencesDictionary objectForKey: @"kCustomLightColor"]; - } - - UIColor* lightColor = [SparkColourPickerUtils colourWithString: colourString withFallback: @"#FFFFFF:0.7"]; - // if the tweak is enabled and the version is iOS 13 or later run our code + %orig(previousTraitCollection); if (@available(iOS 13, *)) { if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { - [self setBackgroundColor:kColor1]; + [self setBackgroundColor:[UIColor cscp_colorFromHexString:StringForPreferenceKey(@"kDarkCustomColor")]]; } else { - [self setBackgroundColor:lightColor]; + if (kCustomLightColorEnabled) { + [self setBackgroundColor:[UIColor cscp_colorFromHexString:StringForPreferenceKey(@"kLightCustomColor")]]; + } + else { + [self setBackgroundColor:kLightModeColor]; + } } } } -else { - %orig(previousTraitCollection); -} - -} - // the method we modify is this method that is called from UIImageView to set the backgroundColor of the image view. // Since the grabber view is of type UIImageView we can modify this method :) -(void)setBackgroundColor:(UIColor *)backgroundColor { - %orig; - if (kEnabled) { - NSString* colourString = NULL; - NSDictionary* preferencesDictionary = [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist"]; - if(preferencesDictionary) - { - colourString = [preferencesDictionary objectForKey: @"kCustomDarkColor"]; - } - - UIColor* darkColor = [SparkColourPickerUtils colourWithString: colourString withFallback: @"#000000:0.44"]; // by default have our tweak overide this. if (@available(iOS 13, *)) { if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { - %orig(darkColor); + if (kCustomDarkColorEnabled) { + %orig([UIColor cscp_colorFromHexString:StringForPreferenceKey(@"kDarkCustomColor")]); + } + + else { + %orig(kDarkModeColor); + } } - } else { %orig; @@ -68,7 +61,9 @@ else { } } - %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 + +// 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 +%end %end static void loadPrefs() { // Load preferences to make sure changes are written to the plist @@ -86,7 +81,11 @@ static void loadPrefs() { // Load preferences to make sure changes are written prefs = [NSMutableDictionary dictionaryWithContentsOfFile:PLIST_PATH]; } + kEnabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue]; //our preference values that write to a plist file when a user selects somethings + kCustomDarkColorEnabled = [([prefs objectForKey:@"kCustomDarkColorEnabled"] ?: @(NO)) boolValue]; //our preference values that write to a plist file when a user selects somethings + kCustomLightColorEnabled = [([prefs objectForKey:@"kCustomLightColorEnabled"] ?: @(NO)) boolValue]; //our preference values that write to a plist file when a user selects somethings + } @@ -95,16 +94,16 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs loadPrefs(); } + %ctor { // Our constructor loadPrefs(); // Load our prefs if (kEnabled) { // If enabled - %init(Adaptive); // Enable the group "Adaptive" + %init(TweakGroup); // Enable the group "TweakGroup" } CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR("com.mac-user669.zenithdark.prefschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); 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. - } \ No newline at end of file diff --git a/ZenithDark.h b/ZenithDark.h index 37bbb8a..8b20e92 100644 --- a/ZenithDark.h +++ b/ZenithDark.h @@ -1,5 +1,4 @@ /* - Dark Mode for Zenith's Grabber view! Copyright 2020 J.K. Hayslip (@iKilledAppl3) & ToxicAppl3 INSDC/iKilledAppl3 LLC. All code was written for learning purposes and credit must be given to the original author. @@ -7,36 +6,29 @@ All code was written for learning purposes and credit must be given to the origi Written for Cooper Hull, (@mac-user669). ZenithDark Header file to keep the tweak.x file clean! - - */ #import #import #import -#import "SparkColourPickerUtils.h" +#include -// We then import UIKit so we can override the color property without this Theos doesn't have a clue what those properties are. @import UIKit; -// We make an interface to let Theos know that ZNGrabberAccessoryView is of type UIImageView. @interface ZNGrabberAccessoryView : UIImageView @end -// a boolean value to store to the tweak's property list path to see if the user has enabled or disabled the tweak. -BOOL kEnabled; -//Prefs dictionary NSMutableDictionary *prefs; -// Dark Zenith color we are using macros so we can call it later if need be. -#define kDarkColor [UIColor colorWithWhite:0.0 alpha:0.44] +#define kDarkModeColor [UIColor colorWithWhite:0.0 alpha:0.44] -// Stock Zenith color we are using macros so we can call it later if need be. -#define kLightColor [UIColor colorWithWhite:1.0 alpha:0.7] +#define kLightModeColor [UIColor colorWithWhite:1.0 alpha:0.7] -#define kColor1 [UIColor redColor] // Color used for testing +#define kColor1 [UIColor redColor] // Color used for testing +#define kColor2 [UIColor greenColor] // Color used for testing +#define kColor3 [UIColor blueColor] // Color used for testing +#define kColor4 [UIColor cyanColor] // Color used for testing -// the PLIST path where all user settings are stored. #define PLIST_PATH @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist" diff --git a/control b/control index c4d01d3..4728b36 100644 --- a/control +++ b/control @@ -2,7 +2,7 @@ Package: com.mac-user669.zenithdark Version: 1.5 Architecture: iphoneos-arm Maintainer: mac-user669 -Depends: mobilesubstrate, preferenceloader, com.muirey03.zenith, ws.hbang.common (>= 1.11), firmware (>=13.0), com.spark.libsparkcolourpicker +Depends: mobilesubstrate, preferenceloader, com.muirey03.zenith, ws.hbang.common (>= 1.11), firmware (>=13.0) Section: Tweaks Description: Changes Zeniths tabs to a dark blur Author: mac-user669 diff --git a/zenithdarkprefs/Makefile b/zenithdarkprefs/Makefile index 1916a17..3204ba7 100644 --- a/zenithdarkprefs/Makefile +++ b/zenithdarkprefs/Makefile @@ -12,7 +12,7 @@ ZenithDarkPrefs_INSTALL_PATH = /Library/PreferenceBundles ZenithDarkPrefs_FRAMEWORKS = UIKit ZenithDarkPrefs_PRIVATE_FRAMEWORKS = Preferences ZenithDarkPrefs_EXTRA_FRAMEWORKS = Cephei CepheiPrefs -ZenithDarkPrefs_LIBRARIES = sparkcolourpicker +$(BUNDLE_NAME)_LDFLAGS += -lCSColorPicker include $(THEOS_MAKE_PATH)/bundle.mk diff --git a/zenithdarkprefs/Resources/Root.plist b/zenithdarkprefs/Resources/Root.plist index c05f6f1..45fd0c3 100644 --- a/zenithdarkprefs/Resources/Root.plist +++ b/zenithdarkprefs/Resources/Root.plist @@ -45,67 +45,92 @@ cell PSGroupCell label - Color Options + footerText - Default: #000000:0.44 + cell - PSLinkCell - cellClass - SparkColourPickerCell - libsparkcolourpicker - - defaults - com.mac-user669.zenithdark - key - kCustomDarkColor - fallback - #000000:0.44 - alpha - - - label - Dark Color + PSSwitchCell + default + + defaults + com.mac-user669.zenithdark key - kCustomDarkColor + kCustomDarkColorEnabled + label + Custom Dark Color PostNotification com.mac-user669.zenithdark.prefschanged + + + PostNotification + com.mac-user669.zenithdark.prefschanged + cell + PSLinkCell + cellClass + CSColorDisplayCell + defaults + com.mac-user669.zenithdark + defaultsPath + /Library/PreferenceBundles/ZenithDark.bundle + key + kDarkCustomColor + label + Dark Color + fallback + 70000000 + alpha + + + cell PSGroupCell label footerText - Default: #FFFFFF:0.7 + cell - PSLinkCell - cellClass - SparkColourPickerCell - libsparkcolourpicker - - defaults - com.mac-user669.zenithdark - key - kCustomLightColor - fallback - #FFFFFF:0.7 - alpha - - - label - Light Color + PSSwitchCell + default + + defaults + com.mac-user669.zenithdark key - kCustomLightColor + kCustomLightColorEnabled + label + Custom Light Color PostNotification com.mac-user669.zenithdark.prefschanged + + PostNotification + com.mac-user669.zenithdark.prefschanged + cell + PSLinkCell + cellClass + CSColorDisplayCell + defaults + com.mac-user669.zenithdark + defaultsPath + /Library/PreferenceBundles/ZenithDark.bundle + key + kLightCustomColor + label + Light Color + fallback + B3FFFFFF + alpha + + + cell PSGroupCell @@ -157,6 +182,8 @@ cell PSButtonCell + cellClass + HBTintedTableCell label Reset Settings action diff --git a/zenithdarkprefs/ZNDarkPrefsRootListController.h b/zenithdarkprefs/ZNDarkPrefsRootListController.h index fd4cf6d..fc10219 100644 --- a/zenithdarkprefs/ZNDarkPrefsRootListController.h +++ b/zenithdarkprefs/ZNDarkPrefsRootListController.h @@ -1,6 +1,7 @@ #import #import #import +#import #import @import UIKit; diff --git a/zenithdarkprefs/ZNDarkPrefsRootListController.m b/zenithdarkprefs/ZNDarkPrefsRootListController.m index 283ab9e..b12472f 100644 --- a/zenithdarkprefs/ZNDarkPrefsRootListController.m +++ b/zenithdarkprefs/ZNDarkPrefsRootListController.m @@ -1,8 +1,5 @@ #import "ZNDarkPrefsRootListController.h" -#import -#import -#import -#import "SparkColourPickerUtils.h" +#include #define THEME_COLOR \ [UIColor colorWithRed:0.82 \ @@ -91,6 +88,7 @@ return _specifiers; } + - (void)respring { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; // Dismisses keyboard [HBRespringController respringAndReturnTo:[NSURL URLWithString:@"prefs:root=ZenithDark"]];