Browse Source

Switch to libCSColorPicker

master
mac-user669 4 years ago
parent
commit
c59707850a
8 changed files with 108 additions and 91 deletions
  1. +1
    -1
      Makefile
  2. +35
    -36
      Tweak.xm
  3. +7
    -15
      ZenithDark.h
  4. +1
    -1
      control
  5. +1
    -1
      zenithdarkprefs/Makefile
  6. +60
    -33
      zenithdarkprefs/Resources/Root.plist
  7. +1
    -0
      zenithdarkprefs/ZNDarkPrefsRootListController.h
  8. +2
    -4
      zenithdarkprefs/ZNDarkPrefsRootListController.m

+ 1
- 1
Makefile View File

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



+ 35
- 36
Tweak.xm View File

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);
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 (@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);
}
} }
}


else { else {
%orig; %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

// 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
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

} }




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.

} }

+ 7
- 15
ZenithDark.h View File

/* /*

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).


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 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" #define PLIST_PATH @"/var/mobile/Library/Preferences/com.mac-user669.zenithdark.plist"

+ 1
- 1
control View File

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>

+ 1
- 1
zenithdarkprefs/Makefile View File

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



+ 60
- 33
zenithdarkprefs/Resources/Root.plist View File

<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>
<key>cellClass</key>
<string>SparkColourPickerCell</string>
<key>libsparkcolourpicker</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<key>key</key>
<string>kCustomDarkColorEnabled</string>
<key>label</key>
<string>Custom Dark Color</string>
<key>PostNotification</key>
<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> <key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<string>com.mac-user669.zenithdark</string>
<key>defaultsPath</key>
<string>/Library/PreferenceBundles/ZenithDark.bundle</string>
<key>key</key> <key>key</key>
<string>kCustomDarkColor</string>
<key>fallback</key>
<string>#000000:0.44</string>
<string>kDarkCustomColor</string>
<key>label</key>
<string>Dark Color</string>
<key>fallback</key>
<string>70000000</string>
<key>alpha</key> <key>alpha</key>
<true/> <true/>
</dict> </dict>
<key>label</key>
<string>Dark Color</string>
<key>key</key>
<string>kCustomDarkColor</string>
<key>PostNotification</key>
<string>com.mac-user669.zenithdark.prefschanged</string>
</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>
<key>cellClass</key>
<string>SparkColourPickerCell</string>
<key>libsparkcolourpicker</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<key>key</key>
<string>kCustomLightColorEnabled</string>
<key>label</key>
<string>Custom Light Color</string>
<key>PostNotification</key>
<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> <key>defaults</key>
<string>com.mac-user669.zenithdark</string>
<string>com.mac-user669.zenithdark</string>
<key>defaultsPath</key>
<string>/Library/PreferenceBundles/ZenithDark.bundle</string>
<key>key</key> <key>key</key>
<string>kCustomLightColor</string>
<key>fallback</key>
<string>#FFFFFF:0.7</string>
<string>kLightCustomColor</string>
<key>label</key>
<string>Light Color</string>
<key>fallback</key>
<string>B3FFFFFF</string>
<key>alpha</key> <key>alpha</key>
<true/> <true/>
</dict> </dict>
<key>label</key>
<string>Light Color</string>
<key>key</key>
<string>kCustomLightColor</string>
<key>PostNotification</key>
<string>com.mac-user669.zenithdark.prefschanged</string>
</dict>


<dict> <dict>
<key>cell</key> <key>cell</key>
<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>

+ 1
- 0
zenithdarkprefs/ZNDarkPrefsRootListController.h View File

#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;

+ 2
- 4
zenithdarkprefs/ZNDarkPrefsRootListController.m View File

#import "ZNDarkPrefsRootListController.h" #import "ZNDarkPrefsRootListController.h"
#import <CepheiPrefs/HBAppearanceSettings.h>
#import <Cephei/HBRespringController.h>
#import <Cephei/HBPreferences.h>
#import "SparkColourPickerUtils.h"
#include <CSColorPicker/CSColorPicker.h>


#define THEME_COLOR \ #define THEME_COLOR \
[UIColor colorWithRed:0.82 \ [UIColor colorWithRed:0.82 \
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"]];

Loading…
Cancel
Save