mirror of
https://github.com/SoPat712/YTLitePlus.git
synced 2025-10-30 12:23:58 -04:00
added files via upload
This commit is contained in:
18
Tweaks/Alderis/lcpshim/ColorFunctions.m
Normal file
18
Tweaks/Alderis/lcpshim/ColorFunctions.m
Normal file
@@ -0,0 +1,18 @@
|
||||
@import Alderis;
|
||||
#import "libcolorpicker.h"
|
||||
|
||||
UIColor *LCPParseColorString(NSString *hexString, NSString *fallback) {
|
||||
UIColor *result = [[UIColor alloc] initWithHbcp_propertyListValue:hexString];
|
||||
if (result == nil && fallback != nil) {
|
||||
result = [[UIColor alloc] initWithHbcp_propertyListValue:fallback];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
UIColor *colorFromDefaultsWithKey(NSString *identifier, NSString *key, NSString *fallback) {
|
||||
id result = CFBridgingRelease(CFPreferencesCopyValue((__bridge CFStringRef)key, (__bridge CFStringRef)identifier, CFSTR("mobile"), kCFPreferencesCurrentHost));
|
||||
if ([result isKindOfClass:NSString.class]) {
|
||||
return LCPParseColorString((NSString *)result, fallback);
|
||||
}
|
||||
return LCPParseColorString(fallback, nil);
|
||||
}
|
||||
11
Tweaks/Alderis/lcpshim/HBColorPickerTableCell+Private.h
Normal file
11
Tweaks/Alderis/lcpshim/HBColorPickerTableCell+Private.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#import "libcolorpicker.h"
|
||||
|
||||
@interface HBColorPickerTableCell ()
|
||||
|
||||
- (UIColor *)_colorValue;
|
||||
- (void)_setColorValue:(UIColor *)color;
|
||||
- (void)_updateValue;
|
||||
|
||||
- (void)_present;
|
||||
|
||||
@end
|
||||
5
Tweaks/Alderis/lcpshim/HBColorPickerTableCell.h
Normal file
5
Tweaks/Alderis/lcpshim/HBColorPickerTableCell.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#import <Preferences/PSTableCell.h>
|
||||
|
||||
@interface HBColorPickerTableCell : PSTableCell
|
||||
|
||||
@end
|
||||
127
Tweaks/Alderis/lcpshim/HBColorPickerTableCell.m
Normal file
127
Tweaks/Alderis/lcpshim/HBColorPickerTableCell.m
Normal file
@@ -0,0 +1,127 @@
|
||||
@import Alderis;
|
||||
#import "libcolorpicker.h"
|
||||
#import <Preferences/PSSpecifier.h>
|
||||
|
||||
@interface UIView ()
|
||||
- (UIViewController *)_viewControllerForAncestor;
|
||||
@end
|
||||
|
||||
@interface HBColorPickerTableCell () <HBColorPickerDelegate>
|
||||
@end
|
||||
|
||||
@implementation HBColorPickerTableCell {
|
||||
HBColorWell *_colorWell;
|
||||
HBColorPickerViewController *_viewController;
|
||||
}
|
||||
|
||||
#pragma mark - PSTableCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
|
||||
specifier.cellType = PSButtonCell;
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
|
||||
if (self) {
|
||||
self.textLabel.textColor = self.tintColor;
|
||||
self.textLabel.highlightedTextColor = self.tintColor;
|
||||
|
||||
_colorWell = [[HBColorWell alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
|
||||
_colorWell.isDragInteractionEnabled = YES;
|
||||
_colorWell.isDropInteractionEnabled = YES;
|
||||
[_colorWell addTarget:self action:@selector(_present) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_colorWell addTarget:self action:@selector(_colorWellValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
self.accessoryView = _colorWell;
|
||||
|
||||
// This relies on an implementation detail - do not do this yourself!
|
||||
[self addInteraction:[[UIDropInteraction alloc] initWithDelegate:_colorWell]];
|
||||
|
||||
[self _updateValue];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier {
|
||||
specifier.cellType = PSButtonCell;
|
||||
[super refreshCellContentsWithSpecifier:specifier];
|
||||
[self _updateValue];
|
||||
self.textLabel.textColor = self.tintColor;
|
||||
self.textLabel.highlightedTextColor = self.tintColor;
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
|
||||
UIColor *color = _colorWell.color;
|
||||
[super setHighlighted:highlighted animated:animated];
|
||||
// stop deleting my background color Apple!!!
|
||||
_colorWell.color = color;
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
||||
if (selected) {
|
||||
[self _present];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tintColorDidChange {
|
||||
[super tintColorDidChange];
|
||||
self.textLabel.textColor = self.tintColor;
|
||||
self.textLabel.highlightedTextColor = self.tintColor;
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (NSString *)_hbcp_defaults {
|
||||
return self.specifier.properties[@"defaults"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_key {
|
||||
return self.specifier.properties[@"key"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_default {
|
||||
return self.specifier.properties[@"default"];
|
||||
}
|
||||
|
||||
- (BOOL)_hbcp_supportsAlpha {
|
||||
return self.specifier.properties[@"showAlphaSlider"] ? ((NSNumber *)self.specifier.properties[@"showAlphaSlider"]).boolValue : NO;
|
||||
}
|
||||
|
||||
#pragma mark - Getters/setters
|
||||
|
||||
- (UIColor *)_colorValue {
|
||||
return LCPParseColorString([self.specifier performGetter], self._hbcp_default) ?: [UIColor colorWithWhite:0.6 alpha:1];
|
||||
}
|
||||
|
||||
- (void)_setColorValue:(UIColor *)color {
|
||||
[self.specifier performSetterWithValue:color.hbcp_propertyListValue];
|
||||
[self _updateValue];
|
||||
}
|
||||
|
||||
- (void)_updateValue {
|
||||
_colorWell.color = self._colorValue;
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)_present {
|
||||
_viewController = [[HBColorPickerViewController alloc] init];
|
||||
_viewController.delegate = self;
|
||||
_viewController.popoverPresentationController.sourceView = self;
|
||||
|
||||
HBColorPickerConfiguration *configuration = [[HBColorPickerConfiguration alloc] initWithColor:self._colorValue];
|
||||
configuration.title = self.textLabel.text;
|
||||
configuration.supportsAlpha = self._hbcp_supportsAlpha;
|
||||
_viewController.configuration = configuration;
|
||||
|
||||
UIViewController *rootViewController = self._viewControllerForAncestor ?: [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
[rootViewController presentViewController:_viewController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)_colorWellValueChanged:(HBColorWell *)sender {
|
||||
[self _setColorValue:sender.color];
|
||||
}
|
||||
|
||||
#pragma mark - HBColorPickerDelegate
|
||||
|
||||
- (void)colorPicker:(HBColorPickerViewController *)colorPicker didSelectColor:(UIColor *)color {
|
||||
[self _setColorValue:color];
|
||||
}
|
||||
|
||||
@end
|
||||
13
Tweaks/Alderis/lcpshim/Makefile
Normal file
13
Tweaks/Alderis/lcpshim/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
TARGET = iphone:clang:15.5:13.0
|
||||
ARCHS = arm64
|
||||
FINALPACKAGE = 1
|
||||
include $(THEOS)/makefiles/common.mk
|
||||
|
||||
LIBRARY_NAME = libcolorpicker
|
||||
|
||||
libcolorpicker_FILES = $(wildcard *.m)
|
||||
libcolorpicker_PRIVATE_FRAMEWORKS = Preferences
|
||||
libcolorpicker_EXTRA_FRAMEWORKS = Alderis
|
||||
libcolorpicker_CFLAGS = -Wno-unguarded-availability -Wno-deprecated-declarations -fmodules
|
||||
|
||||
include $(THEOS_MAKE_PATH)/library.mk
|
||||
66
Tweaks/Alderis/lcpshim/PFColorAlert.m
Normal file
66
Tweaks/Alderis/lcpshim/PFColorAlert.m
Normal file
@@ -0,0 +1,66 @@
|
||||
@import Alderis;
|
||||
#import "libcolorpicker.h"
|
||||
|
||||
@interface PFColorAlert () <HBColorPickerDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation PFColorAlert {
|
||||
PFColorAlert *_strongSelf;
|
||||
HBColorPickerViewController *_viewController;
|
||||
UIColor *_color;
|
||||
BOOL _showAlpha;
|
||||
PFColorAlertCompletion _completion;
|
||||
}
|
||||
|
||||
+ (PFColorAlert *)colorAlertWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha {
|
||||
return [[self.class alloc] initWithStartColor:startColor showAlpha:showAlpha];
|
||||
}
|
||||
|
||||
- (PFColorAlert *)initWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_color = startColor;
|
||||
_showAlpha = showAlpha;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)displayWithCompletion:(PFColorAlertCompletion)completion {
|
||||
_completion = [completion copy];
|
||||
_viewController = [[HBColorPickerViewController alloc] init];
|
||||
_viewController.delegate = self;
|
||||
|
||||
UIColor *color = _color ?: [UIColor colorWithWhite:0.6 alpha:1];
|
||||
HBColorPickerConfiguration *configuration = [[HBColorPickerConfiguration alloc] initWithColor:color];
|
||||
configuration.supportsAlpha = _showAlpha;
|
||||
_viewController.configuration = configuration;
|
||||
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
_viewController.popoverPresentationController.sourceView = window;
|
||||
_viewController.popoverPresentationController.sourceRect = window.bounds;
|
||||
_viewController.popoverPresentationController.permittedArrowDirections = 0;
|
||||
[window.rootViewController presentViewController:_viewController animated:YES completion:nil];
|
||||
|
||||
// Keep a strong reference to ourself. The color picker delegate is weakly stored by
|
||||
// HBColorPickerViewController, but some users of PFColorAlert do not keep a strong reference to
|
||||
// the PFColorAlert instance after calling displayWithCompletion:, causing this class to get
|
||||
// deallocated and the delegate never called.
|
||||
_strongSelf = self;
|
||||
}
|
||||
|
||||
- (void)close {
|
||||
_completion(_color);
|
||||
_strongSelf = nil;
|
||||
}
|
||||
|
||||
- (void)colorPicker:(HBColorPickerViewController *)colorPicker didSelectColor:(UIColor *)color {
|
||||
_color = [color copy];
|
||||
[self close];
|
||||
}
|
||||
|
||||
- (void)colorPickerDidCancel:(HBColorPickerViewController *)colorPicker {
|
||||
[self close];
|
||||
}
|
||||
|
||||
@end
|
||||
30
Tweaks/Alderis/lcpshim/PFColorCell.m
Normal file
30
Tweaks/Alderis/lcpshim/PFColorCell.m
Normal file
@@ -0,0 +1,30 @@
|
||||
#import "libcolorpicker.h"
|
||||
#import <Preferences/PSSpecifier.h>
|
||||
|
||||
@interface PFColorCell : PFLiteColorCell
|
||||
|
||||
@end
|
||||
|
||||
@implementation PFColorCell
|
||||
|
||||
- (NSString *)_hbcp_defaults {
|
||||
return self.specifier.properties[@"color_defaults"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_key {
|
||||
return self.specifier.properties[@"color_key"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_default {
|
||||
return self.specifier.properties[@"color_fallback"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_postNotification {
|
||||
return self.specifier.properties[@"color_postNotification"];
|
||||
}
|
||||
|
||||
- (BOOL)_hbcp_supportsAlpha {
|
||||
return self.specifier.properties[@"usesAlpha"] ? ((NSNumber *)self.specifier.properties[@"usesAlpha"]).boolValue : NO;
|
||||
}
|
||||
|
||||
@end
|
||||
71
Tweaks/Alderis/lcpshim/PFLiteColorCell.m
Normal file
71
Tweaks/Alderis/lcpshim/PFLiteColorCell.m
Normal file
@@ -0,0 +1,71 @@
|
||||
@import Alderis;
|
||||
#import "libcolorpicker.h"
|
||||
#import "HBColorPickerTableCell+Private.h"
|
||||
#import <Preferences/PSSpecifier.h>
|
||||
|
||||
@implementation PFLiteColorCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
|
||||
if (self) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
NSLog(@"Alderis: %@: Using libcolorpicker compatibility class. Please consider switching to HBColorPickerTableCell. This warning will only be logged once.", self.class);
|
||||
});
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (NSString *)_hbcp_defaults {
|
||||
return self.specifier.properties[@"libcolorpicker"][@"defaults"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_key {
|
||||
return self.specifier.properties[@"libcolorpicker"][@"key"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_default {
|
||||
return self.specifier.properties[@"libcolorpicker"][@"fallback"];
|
||||
}
|
||||
|
||||
- (NSString *)_hbcp_postNotification {
|
||||
return self.specifier.properties[@"libcolorpicker"][@"PostNotification"];
|
||||
}
|
||||
|
||||
- (BOOL)_hbcp_supportsAlpha {
|
||||
return self.specifier.properties[@"libcolorpicker"][@"alpha"] ? ((NSNumber *)self.specifier.properties[@"libcolorpicker"][@"alpha"]).boolValue : NO;
|
||||
}
|
||||
|
||||
#pragma mark - Getters/setters
|
||||
|
||||
- (UIColor *)_colorValue {
|
||||
if (self._hbcp_defaults != nil && self._hbcp_key != nil) {
|
||||
// libcolorpicker compatibility
|
||||
NSString *path = [NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", self._hbcp_defaults];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:path];
|
||||
return LCPParseColorString(dictionary[self._hbcp_key], self._hbcp_default);
|
||||
}
|
||||
return [super _colorValue];
|
||||
}
|
||||
|
||||
- (void)_setColorValue:(UIColor *)color {
|
||||
// libcolorpicker compatibility
|
||||
if (self._hbcp_defaults != nil && self._hbcp_key != nil) {
|
||||
NSLog(@"Alderis: %@: Writing directly to plist file (libcolorpicker compatibility). I’m going to do it since it seems to be somewhat common, but you should be ashamed of yourself. https://hbang.github.io/Alderis/preference-bundles.html", self.class);
|
||||
|
||||
NSString *path = [NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", self._hbcp_defaults];
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:path] ?: [NSMutableDictionary dictionary];
|
||||
dictionary[self._hbcp_key] = color.hbcp_propertyListValue;
|
||||
[dictionary writeToFile:path atomically:YES];
|
||||
if (self._hbcp_postNotification != nil) {
|
||||
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)self._hbcp_postNotification, nil, nil, YES);
|
||||
}
|
||||
[self _updateValue];
|
||||
} else {
|
||||
[super _setColorValue:color];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
5
Tweaks/Alderis/lcpshim/PFSimpleLiteColorCell.m
Normal file
5
Tweaks/Alderis/lcpshim/PFSimpleLiteColorCell.m
Normal file
@@ -0,0 +1,5 @@
|
||||
#import "libcolorpicker.h"
|
||||
|
||||
@implementation PFSimpleLiteColorCell
|
||||
|
||||
@end
|
||||
19
Tweaks/Alderis/lcpshim/UIColor+PFColor.m
Normal file
19
Tweaks/Alderis/lcpshim/UIColor+PFColor.m
Normal file
@@ -0,0 +1,19 @@
|
||||
@import Alderis;
|
||||
#import "libcolorpicker.h"
|
||||
|
||||
@implementation UIColor (PFColor)
|
||||
|
||||
+ (UIColor *)PF_colorWithHex:(NSString *)hexString {
|
||||
return [[self.class alloc] initWithHbcp_propertyListValue:hexString];
|
||||
}
|
||||
|
||||
+ (NSString *)PF_hexFromColor:(UIColor *)color {
|
||||
return color.hbcp_propertyListValue;
|
||||
}
|
||||
|
||||
+ (NSString *)hexFromColor:(UIColor *)color {
|
||||
NSLog(@"Alderis: +[UIColor(PFColor) hexFromColor:]: Please migrate to +[UIColor(PFColor) PF_hexFromColor:]. This unprefixed method will be removed in future.");
|
||||
return [self PF_hexFromColor:color];
|
||||
}
|
||||
|
||||
@end
|
||||
53
Tweaks/Alderis/lcpshim/libcolorpicker.h
Normal file
53
Tweaks/Alderis/lcpshim/libcolorpicker.h
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Alderis libcolorpicker Compatibility
|
||||
// https://github.com/hbang/Alderis
|
||||
//
|
||||
// All interfaces declared in this file are deprecated and only provided for out-of-the-box
|
||||
// compatibility with libcolorpicker. Do not write new code that uses these interfaces.
|
||||
//
|
||||
|
||||
@import UIKit;
|
||||
#import <sys/cdefs.h>
|
||||
#import <Preferences/PSTableCell.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern UIColor *LCPParseColorString(NSString *hexString, NSString *fallback);
|
||||
|
||||
__attribute__((__deprecated__))
|
||||
extern UIColor *colorFromDefaultsWithKey(NSString *identifier, NSString *key, NSString *fallback);
|
||||
__END_DECLS
|
||||
|
||||
@interface UIColor (PFColor)
|
||||
|
||||
+ (UIColor *)PF_colorWithHex:(NSString *)hexString;
|
||||
+ (NSString *)PF_hexFromColor:(UIColor *)color;
|
||||
|
||||
/// Do not use this unprefixed method. Migrate to +[UIColor PF_hexFromColor:] immediately. It will
|
||||
/// be removed in a future release.
|
||||
+ (NSString *)hexFromColor:(UIColor *)color __deprecated_msg("Use +[UIColor PF_hexFromColor:]");
|
||||
|
||||
@end
|
||||
|
||||
typedef void (^PFColorAlertCompletion)(UIColor *color);
|
||||
|
||||
@interface PFColorAlert : NSObject
|
||||
|
||||
+ (instancetype)colorAlertWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha;
|
||||
- (instancetype)initWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha;
|
||||
|
||||
- (void)displayWithCompletion:(PFColorAlertCompletion)completion;
|
||||
- (void)close;
|
||||
|
||||
@end
|
||||
|
||||
@interface HBColorPickerTableCell : PSTableCell
|
||||
|
||||
@end
|
||||
|
||||
@interface PFLiteColorCell : HBColorPickerTableCell
|
||||
|
||||
@end
|
||||
|
||||
@interface PFSimpleLiteColorCell : PFLiteColorCell
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user