Add color picker!

This commit is contained in:
2020-02-04 22:02:27 -05:00
parent 31559632e5
commit e1a9c4f9cb
7 changed files with 42 additions and 142 deletions

View File

@ -9,6 +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
include $(THEOS_MAKE_PATH)/tweak.mk include $(THEOS_MAKE_PATH)/tweak.mk

120
Tweak.xm
View File

@ -1,17 +1,11 @@
#import "ZenithDark.h" #import "ZenithDark.h"
#import <Cephei/HBPreferences.h>
#import <CepheiPrefs/HBRootListController.h>
#import <CepheiPrefs/HBAppearanceSettings.h>
/* /*
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.
Written for Cooper Hull, @mac-user669. Written for Cooper Hull, @mac-user669.
*/ */
%group Adaptive %group Adaptive
@ -25,7 +19,7 @@ Written for Cooper Hull, @mac-user669.
// if the tweak is enabled and the version is iOS 13 or later run our code // 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:kDarkColor]; [self setBackgroundColor:kColor1];
} }
else { else {
@ -40,17 +34,24 @@ else {
} }
// 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; %orig;
if (kEnabled) { 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: @"#FF00FF"];
// 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(kDarkColor); %orig(darkColor);
} }
} }
@ -63,89 +64,6 @@ 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 %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
%end %end
%group justDark
//We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
%hook ZNGrabberAccessoryView
// The method we then 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 {
//call the original function then pass our custom argument to the backgroundColor argument as shown below.
%orig(kDarkColor);
}
// 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
%group OLEDadaptive
// We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
%hook ZNGrabberAccessoryView
// this is called when iOS 13's dark mode is enabled!
-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
%orig(previousTraitCollection);
if (kEnabled) {
// if the tweak is enabled and the version is iOS 13 or later run our code
if (@available(iOS 13, *)) {
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
[self setBackgroundColor:kOLEDColor];
}
else {
[self setBackgroundColor:kLightColor];
}
}
}
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) {
// by default have our tweak overide this.
if (@available(iOS 13, *)) {
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
%orig(kOLEDColor);
}
}
else {
%orig;
}
}
}
%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
%end
%group OLEDgroup
//We then hook the class in this case Zenith's grabber view is called “ZNGrabberAccessoryView”
%hook ZNGrabberAccessoryView
// The method we then 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 {
//call the original function then pass our custom argument to the backgroundColor argument as shown below.
%orig(kOLEDColor);
}
// 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 static void loadPrefs() { // Load preferences to make sure changes are written to the plist
// Thanks to skittyblock! // Thanks to skittyblock!
@ -162,8 +80,6 @@ static void loadPrefs() { // Load preferences to make sure changes are written
} }
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
sortType = [([prefs objectForKey:@"sortingType"] ? [prefs objectForKey:@"sortingType"] : @"0") integerValue];
} }
@ -177,21 +93,7 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs
loadPrefs(); // Load our prefs loadPrefs(); // Load our prefs
if (kEnabled) { // If enabled if (kEnabled) { // If enabled
if (sortType == ZNDarkSortTypeAdaptive) {
%init(Adaptive); // Enable the group "Adaptive" %init(Adaptive); // Enable the group "Adaptive"
}
else if (sortType == ZNDarkSortTypeDark) {
%init(justDark); // Enable the group "Adaptive"
}
else if (sortType == ZNDarkSortTypeOLEDAdaptive) {
%init(OLEDadaptive); // Enable the group "OLEDgroup"
}
else if (sortType == ZNDarkSortTypeOLED) {
%init(OLEDgroup); // Enable the group "OLEDgroup"
}
} }
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);

View File

@ -12,6 +12,11 @@ ZenithDark Header file to keep the tweak.x file clean!
*/ */
#import <Cephei/HBPreferences.h>
#import <CepheiPrefs/HBRootListController.h>
#import <CepheiPrefs/HBAppearanceSettings.h>
#import "SparkColourPickerUtils.h"
// We then import UIKit so we can override the color property without this Theos doesn't have a clue what those properties are. // 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;
@ -19,14 +24,6 @@ ZenithDark Header file to keep the tweak.x file clean!
@interface ZNGrabberAccessoryView : UIImageView @interface ZNGrabberAccessoryView : UIImageView
@end @end
typedef NS_ENUM(NSUInteger, ZNDarkSortType) {
ZNDarkSortTypeAdaptive,
ZNDarkSortTypeDark,
ZNDarkSortTypeOLEDAdaptive,
ZNDarkSortTypeOLED
};
static ZNDarkSortType sortType = ZNDarkSortTypeAdaptive;
// a boolean value to store to the tweak's property list path to see if the user has enabled or disabled the tweak. // 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; BOOL kEnabled;
@ -39,6 +36,6 @@ NSMutableDictionary *prefs;
// Stock Zenith color we are using macros so we can call it later if need be. // 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 kLightColor [UIColor colorWithWhite:1.0 alpha:0.7]
#define kOLEDColor [UIColor colorWithWhite:0.0 alpha:0.75] #define kColor1 [UIColor redColor]
// the PLIST path where all user settings are stored. // 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

@ -1,8 +1,8 @@
Package: com.mac-user669.zenithdark Package: com.mac-user669.zenithdark
Version: 1.4.1 Version: 1.5
Architecture: iphoneos-arm Architecture: iphoneos-arm
Maintainer: mac-user669 Maintainer: mac-user669
Depends: mobilesubstrate, preferenceloader, com.muirey03.zenith, ws.hbang.common (>= 1.11), firmware (>=13.0) Depends: mobilesubstrate, preferenceloader, com.muirey03.zenith, ws.hbang.common (>= 1.11), firmware (>=13.0), com.spark.libsparkcolourpicker
Section: Tweaks Section: Tweaks
Description: Changes Zeniths tabs to a dark blur Description: Changes Zeniths tabs to a dark blur
Author: mac-user669 Author: mac-user669

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

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
include $(THEOS_MAKE_PATH)/bundle.mk include $(THEOS_MAKE_PATH)/bundle.mk

View File

@ -40,35 +40,35 @@
<key>label</key> <key>label</key>
<string>Enable</string> <string>Enable</string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
<key>label</key> <key>label</key>
<string>Color Type</string> <string>Color Options</string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSSegmentCell</string> <string>PSLinkCell</string>
<key>default</key> <key>cellClass</key>
<integer>0</integer> <string>SparkColourPickerCell</string>
<key>defaults</key> <key>libsparkcolourpicker</key>
<string>com.mac-user669.zenithdark</string> <dict>
<key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<key>key</key>
<string>kCustomDarkColor</string>
<key>fallback</key>
<string>#000000:0.44</string>
<key>alpha</key>
<true/>
</dict>
<key>label</key>
<string>Color</string>
<key>key</key> <key>key</key>
<string>sortingType</string> <string>kCustomDarkColor</string>
<key>validValues</key> <key>PostNotification</key>
<array> <string>com.mac-user669.zenithdark.prefschanged</string>
<integer>0</integer>
<integer>1</integer>
<integer>2</integer>
<integer>3</integer>
</array>
<key>validTitles</key>
<array>
<string>Adaptive</string>
<string>Dark</string>
<string>OLED Adaptive</string>
<string>OLED</string>
</array>
</dict> </dict>
<dict> <dict>