Switch to libCSColorPicker

This commit is contained in:
2020-02-06 17:53:33 -05:00
parent 91f37f3213
commit c59707850a
8 changed files with 112 additions and 95 deletions

View File

@ -9,7 +9,7 @@ TWEAK_NAME = ZenithDark
ZenithDark_FILES = Tweak.xm ZenithDark_FILES = Tweak.xm
ZenithDark_FRAMEWORKS = UIKit CoreGraphics ZenithDark_FRAMEWORKS = UIKit CoreGraphics
ZenithDark_EXTRA_FRAMEWORKS += Cephei ZenithDark_EXTRA_FRAMEWORKS += Cephei
ZenithDark_LIBRARIES = sparkcolourpicker $(TWEAK_NAME)_LDFLAGS += -lCSColorPicker
include $(THEOS_MAKE_PATH)/tweak.mk include $(THEOS_MAKE_PATH)/tweak.mk

View File

@ -7,58 +7,51 @@ All code was written for learning purposes and credit must be given to the origi
Written for Cooper Hull, @mac-user669. 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 %hook ZNGrabberAccessoryView
// this is called when iOS 13's dark mode is enabled! // this is called when iOS 13's dark mode is enabled!
-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { -(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
%orig(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
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
[self setBackgroundColor:kColor1]; [self setBackgroundColor:[UIColor cscp_colorFromHexString:StringForPreferenceKey(@"kDarkCustomColor")]];
} }
else { 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. // 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 :) // Since the grabber view is of type UIImageView we can modify this method :)
-(void)setBackgroundColor:(UIColor *)backgroundColor { -(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. // by default have our tweak overide this.
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
%orig(darkColor); if (kCustomDarkColorEnabled) {
%orig([UIColor cscp_colorFromHexString:StringForPreferenceKey(@"kDarkCustomColor")]);
}
else {
%orig(kDarkModeColor);
} }
} }
@ -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 %end
static void loadPrefs() { // Load preferences to make sure changes are written to the plist 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]; 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 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(); loadPrefs();
} }
%ctor { // Our constructor %ctor { // Our constructor
loadPrefs(); // Load our prefs loadPrefs(); // Load our prefs
if (kEnabled) { // If enabled 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); 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. 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.
} }

View File

@ -1,5 +1,4 @@
/* /*
Dark Mode for Zenith's Grabber view! Dark Mode for Zenith's Grabber view!
Copyright 2020 J.K. Hayslip (@iKilledAppl3) & ToxicAppl3 INSDC/iKilledAppl3 LLC. 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. 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). Written for Cooper Hull, (@mac-user669).
ZenithDark Header file to keep the tweak.x file clean! ZenithDark Header file to keep the tweak.x file clean!
*/ */
#import <Cephei/HBPreferences.h> #import <Cephei/HBPreferences.h>
#import <CepheiPrefs/HBRootListController.h> #import <CepheiPrefs/HBRootListController.h>
#import <CepheiPrefs/HBAppearanceSettings.h> #import <CepheiPrefs/HBAppearanceSettings.h>
#import "SparkColourPickerUtils.h" #include <CSColorPicker/CSColorPicker.h>
// 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; @import UIKit;
// We make an interface to let Theos know that ZNGrabberAccessoryView is of type UIImageView.
@interface ZNGrabberAccessoryView : UIImageView @interface ZNGrabberAccessoryView : UIImageView
@end @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; NSMutableDictionary *prefs;
// Dark Zenith color we are using macros so we can call it later if need be. #define kDarkModeColor [UIColor colorWithWhite:0.0 alpha:0.44]
#define kDarkColor [UIColor colorWithWhite:0.0 alpha:0.44]
// Stock Zenith color we are using macros so we can call it later if need be. #define kLightModeColor [UIColor colorWithWhite:1.0 alpha:0.7]
#define kLightColor [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" #define PLIST_PATH @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist"

View File

@ -2,7 +2,7 @@ Package: com.mac-user669.zenithdark
Version: 1.5 Version: 1.5
Architecture: iphoneos-arm Architecture: iphoneos-arm
Maintainer: mac-user669 <cooper@cooperhull.com> Maintainer: mac-user669 <cooper@cooperhull.com>
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 Section: Tweaks
Description: Changes Zeniths tabs to a dark blur Description: Changes Zeniths tabs to a dark blur
Author: mac-user669 <cooper@cooperhull.com> Author: mac-user669 <cooper@cooperhull.com>

View File

@ -12,7 +12,7 @@ ZenithDarkPrefs_INSTALL_PATH = /Library/PreferenceBundles
ZenithDarkPrefs_FRAMEWORKS = UIKit ZenithDarkPrefs_FRAMEWORKS = UIKit
ZenithDarkPrefs_PRIVATE_FRAMEWORKS = Preferences ZenithDarkPrefs_PRIVATE_FRAMEWORKS = Preferences
ZenithDarkPrefs_EXTRA_FRAMEWORKS = Cephei CepheiPrefs ZenithDarkPrefs_EXTRA_FRAMEWORKS = Cephei CepheiPrefs
ZenithDarkPrefs_LIBRARIES = sparkcolourpicker $(BUNDLE_NAME)_LDFLAGS += -lCSColorPicker
include $(THEOS_MAKE_PATH)/bundle.mk include $(THEOS_MAKE_PATH)/bundle.mk

View File

@ -45,67 +45,92 @@
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
<key>label</key> <key>label</key>
<string>Color Options</string> <string></string>
<key>footerText</key> <key>footerText</key>
<string>Default: #000000:0.44</string> <string></string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSLinkCell</string> <string>PSSwitchCell</string>
<key>cellClass</key> <key>default</key>
<string>SparkColourPickerCell</string> <false/>
<key>libsparkcolourpicker</key>
<dict>
<key>defaults</key> <key>defaults</key>
<string>com.mac-user669.zenithdark</string> <string>com.mac-user669.zenithdark</string>
<key>key</key> <key>key</key>
<string>kCustomDarkColor</string> <string>kCustomDarkColorEnabled</string>
<key>fallback</key>
<string>#000000:0.44</string>
<key>alpha</key>
<true/>
</dict>
<key>label</key> <key>label</key>
<string>Dark Color</string> <string>Custom Dark Color</string>
<key>key</key>
<string>kCustomDarkColor</string>
<key>PostNotification</key> <key>PostNotification</key>
<string>com.mac-user669.zenithdark.prefschanged</string> <string>com.mac-user669.zenithdark.prefschanged</string>
</dict> </dict>
<dict>
<key>PostNotification</key>
<string>com.mac-user669.zenithdark.prefschanged</string>
<key>cell</key>
<string>PSLinkCell</string>
<key>cellClass</key>
<string>CSColorDisplayCell</string>
<key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<key>defaultsPath</key>
<string>/Library/PreferenceBundles/ZenithDark.bundle</string>
<key>key</key>
<string>kDarkCustomColor</string>
<key>label</key>
<string>Dark Color</string>
<key>fallback</key>
<string>70000000</string>
<key>alpha</key>
<true/>
</dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
<key>label</key> <key>label</key>
<string></string> <string></string>
<key>footerText</key> <key>footerText</key>
<string>Default: #FFFFFF:0.7</string> <string></string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSLinkCell</string> <string>PSSwitchCell</string>
<key>cellClass</key> <key>default</key>
<string>SparkColourPickerCell</string> <false/>
<key>libsparkcolourpicker</key>
<dict>
<key>defaults</key> <key>defaults</key>
<string>com.mac-user669.zenithdark</string> <string>com.mac-user669.zenithdark</string>
<key>key</key> <key>key</key>
<string>kCustomLightColor</string> <string>kCustomLightColorEnabled</string>
<key>fallback</key>
<string>#FFFFFF:0.7</string>
<key>alpha</key>
<true/>
</dict>
<key>label</key> <key>label</key>
<string>Light Color</string> <string>Custom Light Color</string>
<key>key</key>
<string>kCustomLightColor</string>
<key>PostNotification</key> <key>PostNotification</key>
<string>com.mac-user669.zenithdark.prefschanged</string> <string>com.mac-user669.zenithdark.prefschanged</string>
</dict> </dict>
<dict>
<key>PostNotification</key>
<string>com.mac-user669.zenithdark.prefschanged</string>
<key>cell</key>
<string>PSLinkCell</string>
<key>cellClass</key>
<string>CSColorDisplayCell</string>
<key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<key>defaultsPath</key>
<string>/Library/PreferenceBundles/ZenithDark.bundle</string>
<key>key</key>
<string>kLightCustomColor</string>
<key>label</key>
<string>Light Color</string>
<key>fallback</key>
<string>B3FFFFFF</string>
<key>alpha</key>
<true/>
</dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
@ -157,6 +182,8 @@
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSButtonCell</string> <string>PSButtonCell</string>
<key>cellClass</key>
<string>HBTintedTableCell</string>
<key>label</key> <key>label</key>
<string>Reset Settings</string> <string>Reset Settings</string>
<key>action</key> <key>action</key>

View File

@ -1,6 +1,7 @@
#import <Preferences/PSListController.h> #import <Preferences/PSListController.h>
#import <CepheiPrefs/HBRootListController.h> #import <CepheiPrefs/HBRootListController.h>
#import <CepheiPrefs/HBAppearanceSettings.h> #import <CepheiPrefs/HBAppearanceSettings.h>
#import <Cephei/HBRespringController.h>
#import <Cephei/HBPreferences.h> #import <Cephei/HBPreferences.h>
@import UIKit; @import UIKit;

View File

@ -1,8 +1,5 @@
#import "ZNDarkPrefsRootListController.h" #import "ZNDarkPrefsRootListController.h"
#import <CepheiPrefs/HBAppearanceSettings.h> #include <CSColorPicker/CSColorPicker.h>
#import <Cephei/HBRespringController.h>
#import <Cephei/HBPreferences.h>
#import "SparkColourPickerUtils.h"
#define THEME_COLOR \ #define THEME_COLOR \
[UIColor colorWithRed:0.82 \ [UIColor colorWithRed:0.82 \
@ -91,6 +88,7 @@
return _specifiers; return _specifiers;
} }
- (void)respring { - (void)respring {
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; // Dismisses keyboard [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; // Dismisses keyboard
[HBRespringController respringAndReturnTo:[NSURL URLWithString:@"prefs:root=ZenithDark"]]; [HBRespringController respringAndReturnTo:[NSURL URLWithString:@"prefs:root=ZenithDark"]];