diff --git a/DragonMake b/DragonMake index b4ea722..9ca3c69 100644 --- a/DragonMake +++ b/DragonMake @@ -8,3 +8,17 @@ kai: - Kai.xm frameworks: - BatteryCenter + +kaiPrefs: + dir: kaiprefs + type: bundle + files: + - KAIRootListController.m + archs: + - arm64 + - arm64e + frameworks: + - Preferences + stage: + - mkdir -p .dragon/_/Library/PreferenceLoader/Preferences/ + - cp entry.plist .dragon/_/Library/PreferenceLoader/Preferences/$name.plist diff --git a/KAIBattery.h b/KAIBattery.h index 924ebb5..df5c83f 100644 --- a/KAIBattery.h +++ b/KAIBattery.h @@ -11,6 +11,11 @@ @property (nonatomic, assign) NSInteger chargingState; @end +@interface MTMaterialView : UIView +@property (nonatomic, assign) BOOL recipeDynamic; +-(id)_initWithRecipe:(NSInteger)arg1 configuration:(NSInteger)arg2 initialWeighting:(CGFloat)arg3 scaleAdjustment:(id)arg4; +@end + @interface BCBatteryDeviceController @property (nonatomic, strong) NSArray *sortedDevices; -(id)_sortedDevices; diff --git a/KAIBattery.mm b/KAIBattery.mm index ec60d25..0775284 100644 --- a/KAIBattery.mm +++ b/KAIBattery.mm @@ -48,7 +48,7 @@ long long lastPercentage; if(charging) { - UIVisualEffectView *blank; + /*UIVisualEffectView *blank; if(@available(iOS 12.0, *)) { if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; @@ -57,7 +57,9 @@ long long lastPercentage; } } else { blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; - } + }*/ + MTMaterialView *blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil]; + //blank.recipeDynamic = NO; //makes it stay light blank.frame = CGRectMake(0, 0 + y, self.superview.bounds.size.width - 16, 80); blank.layer.masksToBounds = YES; blank.layer.cornerRadius = 13; @@ -97,8 +99,8 @@ long long lastPercentage; label.frame = CGRectMake(65.5,27.5 + y,275,25); glyphView.frame = CGRectMake(20.5,18.5 + y,40,40); - battery.frame = CGRectMake(310,35 + y,20,10); - percentLabel.frame = CGRectMake(265,35 + y,36,12); + battery.frame = CGRectMake(self.superview.bounds.size.width - 16 - 49,35 + y,20,10); + percentLabel.frame = CGRectMake(self.superview.bounds.size.width - 16 - 94,35 + y,36,12); y+=85; self.number +=1; @@ -123,7 +125,7 @@ long long lastPercentage; } -(void)darkLightMode { - for(UIVisualEffectView *view in self.subviews) { + /*for(UIVisualEffectView *view in self.subviews) { if(@available(iOS 12.0, *)) { if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { if([view respondsToSelector:@selector(setEffect:)]) view.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; @@ -132,7 +134,7 @@ long long lastPercentage; if([view respondsToSelector:@selector(setEffect:)]) view.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; } } - } + }*/ } @end \ No newline at end of file diff --git a/Kai.h b/Kai.h new file mode 100644 index 0000000..6f0e273 --- /dev/null +++ b/Kai.h @@ -0,0 +1,91 @@ +#include +#import +#include +#import +#import + +#import "KAIBattery.mm" +#define KAISelf ((CSAdjunctListView *)self) + +@interface UIApplication (Kai) ++(id)sharedApplication; +-(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2; +@end + +@interface CSAdjunctListView : UIView +@property (nonatomic, assign) BOOL hasKai; +-(UIStackView *)stackView; +-(void)setStackView:(UIStackView *)arg1; +-(void)KaiUpdate; +@end + +@interface SBDashBoardAdjunctListView : UIView +@property (nonatomic, assign) BOOL hasKai; +-(UIStackView *)stackView; +-(void)setStackView:(UIStackView *)arg1; +-(void)KaiUpdate; +@end + +@interface CSMainPageView : UIView +-(void)updateForPresentation:(id)arg1; +@end + +@interface _CSSingleBatteryChargingView : UIView +@end + +@interface NSLayoutConstraint (Kai) ++(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ; +@end + +//prefs +BOOL enabled; + + +#define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist" +#define kIdentifier @"com.burritoz.kaiprefs" +#define kSettingsChangedNotification (CFStringRef)@"com.burritoz.kaiprefs/reload" +#define kSettingsPath @"/var/mobile/Library/Preferences/com.burritoz.kaiprefs.plist" + +NSDictionary *prefs = nil; + +static void *observer = NULL; + +static void reloadPrefs() +{ + if ([NSHomeDirectory() isEqualToString:@"/var/mobile"]) + { + CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + + if (keyList) + { + prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost)); + + if (!prefs) + { + prefs = [NSDictionary new]; + } + CFRelease(keyList); + } + } + else + { + prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath]; + } +} + +static BOOL boolValueForKey(NSString *key, BOOL defaultValue) { + return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] boolValue] : defaultValue); +} + + +/*static double numberForValue(NSString *key, double defaultValue) { + return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue); +}*/ + +static void preferencesChanged() +{ + CFPreferencesAppSynchronize((CFStringRef)kIdentifier); + reloadPrefs(); + + enabled = boolValueForKey(@"enabled", YES); +} \ No newline at end of file diff --git a/Kai.xm b/Kai.xm index 15dcfc3..0c2916a 100644 --- a/Kai.xm +++ b/Kai.xm @@ -1,41 +1,4 @@ -#include -#import -#include -#import -#import - -#import "KAIBattery.mm" -#define KAISelf ((CSAdjunctListView *)self) - -@interface UIApplication (Kai) -+(id)sharedApplication; --(BOOL)launchApplicationWithIdentifier:(id)arg1 suspended:(BOOL)arg2; -@end - -@interface CSAdjunctListView : UIView -@property (nonatomic, assign) BOOL hasKai; --(UIStackView *)stackView; --(void)setStackView:(UIStackView *)arg1; --(void)KaiUpdate; -@end - -@interface SBDashBoardAdjunctListView : UIView -@property (nonatomic, assign) BOOL hasKai; --(UIStackView *)stackView; --(void)setStackView:(UIStackView *)arg1; --(void)KaiUpdate; -@end - -@interface CSMainPageView : UIView --(void)updateForPresentation:(id)arg1; -@end - -@interface _CSSingleBatteryChargingView : UIView -@end - -@interface NSLayoutConstraint (Kai) -+(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ; -@end +#import "Kai.h" %hook KAITarget @@ -113,7 +76,6 @@ - (id)initWithIdentifier:(id)arg1 vendor:(long long)arg2 productIdentifier:(long long)arg3 parts:(unsigned long long)arg4 matchIdentifier:(id)arg5 { - [self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"charging" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"powerSourceState" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"batterySaverModeActive" options:NSKeyValueObservingOptionNew context:nil]; @@ -148,6 +110,9 @@ %end %ctor { + preferencesChanged(); Class cls = kCFCoreFoundationVersionNumber > 1600 ? ([objc_getClass("CSAdjunctListView") class]) : ([objc_getClass("SBDashBoardAdjunctListView") class]); - %init(KAITarget = cls); + if(enabled) { + %init(KAITarget = cls); + } } diff --git a/build.ninja b/build.ninja deleted file mode 100644 index fd8245b..0000000 --- a/build.ninja +++ /dev/null @@ -1,181 +0,0 @@ -name = kai -lowername = kai - -# Build file for kai -# Generated at 05/20/20 09:51:19 - -pdirname = .dragon - -location = /Library/MobileSubstrate/DynamicLibraries/ -resource_dir = Resources -target = $pdirname/_$location$name.dylib - -stage2 = cp $name.plist $ - .dragon/_/Library/MobileSubstrate/DynamicLibraries/$name.plist - -builddir = $pdirname/build -objdir = $pdirname/obj -signdir = $pdirname/sign -signtarget = $signdir/$target.unsigned -symtarget = $signdir/$target.unsym - -dragondir = $$DRAGONBUILD -pwd = . -sysroot = $dragondir/sdks/iPhoneOS.sdk - -fwSearch = -F$sysroot/System/Library/Frameworks $ - -F$sysroot/System/Library/PrivateFrameworks -F$dragondir/frameworks -libSearch = -L$dragondir/lib -L. - -cc = clang++ -ccpp = clang++ -ld = clang++ -ldid = ldid -dsym = dsymutil -logos = $dragondir/bin/logos.pl -plutil = plutil -stage = true; - -targetios = 10.0 - -frameworks = -framework BatteryCenter -framework CoreFoundation -framework $ - Foundation -framework UIKit -framework CoreGraphics -framework $ - QuartzCore -framework CoreImage -framework AudioToolbox - -libs = -lsubstrate -lobjc -lc++ - -arc = -fobjc-arc -btarg = -DTARGET_IPHONE=1 -warnings = -Wall -optim = -O0 -debug = -fcolor-diagnostics - -header_includes = -cinclude = -I$dragondir/include -I$dragondir/vendor/include $ - -I$dragondir/include/_fallback -I$DRAGONBUILD/headers/ -I$pwd - -usrCflags = -usrLDflags = -usrLDIDFlags = -S - -lopt = -dynamiclib -ggdb -Xlinker -segalign -Xlinker 4000 -typeldflags = -install_name $location$name - -cflags = $cinclude -fmodules -fcxx-modules -fmodule-name=$name $ - -fbuild-session-file=.dragon/modules/ -fmodules-prune-after=345600 $ - -fmodules-prune-interval=86400 $ - -fmodules-validate-once-per-build-session $arc $fwSearch $ - -miphoneos-version-min=$targetios -isysroot $sysroot $btarg $warnings $ - $optim $debug $usrCflags $header_includes - -lflags = $cflags $typeldflags $frameworks $libs $lopt $libSearch $usrLDflags - -ldflags = $usrLDFlags - -pool solo - depth = 1 - -rule prelogos - command = cat $in | python3 $$DRAGONBUILD/bin/prelogos.py > $out - description = Processing $in with Pre/Logos - -rule logos - command = $logos $in > $out - description = Processing $in with Logos - -rule compilearm64 - command = $cc -arch arm64 $cflags -c $in -o $out - description = Compiling $in for arm64 - -rule compilexxarm64 - command = $cxx -arch arm64 $cflags -c $in -o $out - description = Compiling $in for arm64 - -rule linkarm64 - command = $ld -arch arm64 $lflags -o $out $in - description = Linking $name for arm64 - -rule compilearm64e - command = $cc -arch arm64e $cflags -c $in -o $out - description = Compiling $in for arm64e - -rule compilexxarm64e - command = $cxx -arch arm64e $cflags -c $in -o $out - description = Compiling $in for arm64e - -rule linkarm64e - command = $ld -arch arm64e $lflags -o $out $in - description = Linking $name for arm64e - -rule compilearmv7 - command = $cc -arch armv7 $cflags -c $in -o $out - description = Compiling $in for armv7 - -rule compilexxarmv7 - command = $cxx -arch armv7 $cflags -c $in -o $out - description = Compiling $in for armv7 - -rule linkarmv7 - command = $ld -arch armv7 $lflags -o $out $in - description = Linking $name for armv7 - -rule compilex86_64 - command = $cc -arch x86_64 $cflags -c $in -o $out - description = Compiling $in for x86_64 - -rule compilexxx86_64 - command = $cxx -arch x86_64 $cflags -c $in -o $out - description = Compiling $in for x86_64 - -rule linkx86_64 - command = $ld -arch x86_64 $lflags -o $out $in - description = Linking $name for x86_64 - -rule lipo - command = lipo -create $in -output $out - description = Merging architectures - -rule bundle - command = mkdir -p ".dragon/_$location/" && cp -r "$resource_dir/" $ - ".dragon/_$location" && cp $in $out - description = Copying Bundle Resources - pool = solo - -rule plist - command = $plutil -convert binary1 $in -o $out - description = Converting $in - -rule debug - command = $dsym "$in" 2&> /dev/null; cp $in $out - description = Generating Debug Symbols for $name - -rule sign - command = $ldid $usrLDIDFlags $in && cp $in $target - description = Signing $name - -rule stage - command = $stage $stage2 - description = Running Stage for $name - -build $builddir/logos/Kai.xm.mm: logos Kai.xm - -build $builddir/armv7/Kai.xm.mm.o: compilearmv7 $builddir/logos/Kai.xm.mm - -build $builddir/$name.armv7: linkarmv7 $builddir/armv7/Kai.xm.mm.o -build $builddir/arm64/Kai.xm.mm.o: compilearm64 $builddir/logos/Kai.xm.mm - -build $builddir/$name.arm64: linkarm64 $builddir/arm64/Kai.xm.mm.o -build $builddir/arm64e/Kai.xm.mm.o: compilearm64e $builddir/logos/Kai.xm.mm - -build $builddir/$name.arm64e: linkarm64e $builddir/arm64e/Kai.xm.mm.o -build $builddir/trash/stage: stage $target - -build $symtarget: lipo $builddir/$name.armv7 $builddir/$name.arm64 $ - $builddir/$name.arm64e - -build $signtarget: debug $symtarget - -build $target: sign $signtarget - -default $target $builddir/trash/stage - diff --git a/control b/control index 7b0879a..44a13b4 100644 --- a/control +++ b/control @@ -1,6 +1,6 @@ Package: com.burritoz.kai Name: Kai -Version: 0.0.3 +Version: 0.0.4 Architecture: iphoneos-arm Description: An awesome MobileSubstrate tweak! Maintainer: burrit0z diff --git a/kaiprefs/KAIRootListController.h b/kaiprefs/KAIRootListController.h new file mode 100644 index 0000000..da601c4 --- /dev/null +++ b/kaiprefs/KAIRootListController.h @@ -0,0 +1,24 @@ +#import +#import +#import +#import +#import + +@interface PSListController (kai) +-(void)setFrame:(CGRect)frame; +@end + +@interface KAIRootListController : PSListController +@end + +@protocol PreferencesTableCustomView +- (id)initWithSpecifier:(id)arg1; +@end + +@interface KaiHeaderCell : PSTableCell { + UIView *bgView; + UILabel *packageNameLabel; + UILabel *developerLabel; + UILabel *versionLabel; +} +@end diff --git a/kaiprefs/KAIRootListController.m b/kaiprefs/KAIRootListController.m new file mode 100644 index 0000000..c0741b9 --- /dev/null +++ b/kaiprefs/KAIRootListController.m @@ -0,0 +1,122 @@ +#include "KAIRootListController.h" + +NSBundle *tweakBundle; + +@implementation KAIRootListController + +- (NSArray *)specifiers { + if (!_specifiers) { + _specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self]; + } + + return _specifiers; +} + +-(void)viewWillAppear:(BOOL)arg1 { + self.navigationController.navigationController.navigationBar.barTintColor = [UIColor colorWithRed: 0.00 green: 0.77 blue: 0.95 alpha: 1.00]; + [self.navigationController.navigationController.navigationBar setShadowImage: [UIImage new]]; + self.navigationController.navigationController.navigationBar.tintColor = [UIColor whiteColor]; + self.navigationController.navigationController.navigationBar.translucent = NO; + + [[UISegmentedControl appearanceWhenContainedInInstancesOfClasses:@[self.class]] setTintColor:[UIColor colorWithRed: 0.00 green: 0.82 blue: 1.00 alpha: 1.00]]; + [[UISwitch appearanceWhenContainedInInstancesOfClasses:@[self.class]] setOnTintColor:[UIColor colorWithRed: 0.00 green: 0.82 blue: 1.00 alpha: 1.00]]; + [[UISlider appearanceWhenContainedInInstancesOfClasses:@[self.class]] setTintColor:[UIColor colorWithRed: 0.00 green: 0.82 blue: 1.00 alpha: 1.00]]; + +} + +- (void)viewWillDisappear:(BOOL)animated { + + [super viewWillDisappear:animated]; + + [self.navigationController.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]}]; + +} + +@end + +@implementation KaiHeaderCell // Header Cell + +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(id)reuseIdentifier specifier:(id)specifier { + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier]; + + if (self) { + + packageNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,90,self.contentView.bounds.size.width+30,50)]; + [packageNameLabel setTextAlignment:NSTextAlignmentRight]; + [packageNameLabel setFont:[UIFont systemFontOfSize:50 weight: UIFontWeightSemibold] ]; + packageNameLabel.textColor = [UIColor whiteColor]; + packageNameLabel.text = @"kai"; + + developerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,50,self.contentView.bounds.size.width+30,50)]; + [developerLabel setTextAlignment:NSTextAlignmentRight]; + [developerLabel setFont:[UIFont systemFontOfSize:22.5 weight: UIFontWeightMedium] ]; + developerLabel.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.85]; + developerLabel.alpha = 0.8; + developerLabel.text = @"Burrit0z"; + + + versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,130,self.contentView.bounds.size.width+30,50)]; + [versionLabel setTextAlignment:NSTextAlignmentRight]; + [versionLabel setFont:[UIFont systemFontOfSize:22 weight: UIFontWeightMedium] ]; + versionLabel.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.8]; + versionLabel.alpha = 0.8; + versionLabel.text = @"alpha"; + + NSBundle *bundle = [[NSBundle alloc]initWithPath:@"/Library/PreferenceBundles/KaiPrefs.bundle"]; + UIImage *phone = [UIImage imageWithContentsOfFile:[bundle pathForResource:@"kai" ofType:@"png"]]; + UIImageView *phoneImage = [[UIImageView alloc]initWithImage:phone]; + [phoneImage setFrame:self.frame]; + + bgView.backgroundColor = [UIColor colorWithRed: 0.00 green: 0.82 blue: 1.00 alpha: 1.00]; + + [self addSubview:packageNameLabel]; + [self addSubview:developerLabel]; + [self addSubview:versionLabel]; + [self addSubview:phoneImage]; + + } + return self; + +} + +- (instancetype)initWithSpecifier:(PSSpecifier *)specifier { + return [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"KaiHeaderCell" specifier:specifier]; +} + +- (void)setFrame:(CGRect)frame { + frame.origin.x = 0; + //frame.origin.y = 43; + [super setFrame:frame]; +} + +- (CGFloat)preferredHeightForWidth:(CGFloat)arg1{ + return 200.0f; +} + + +-(void)layoutSubviews{ + [super layoutSubviews]; + + bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.bounds.size.width, 200)]; + + UIColor *topColor = [UIColor colorWithRed: 0.00 green: 0.82 blue: 1.00 alpha: 1.00]; + UIColor *bottomColor = [UIColor colorWithRed: 0.23 green: 0.48 blue: 0.84 alpha: 1.00]; + + CAGradientLayer *theViewGradient = [CAGradientLayer layer]; + theViewGradient.colors = [NSArray arrayWithObjects: (id)topColor.CGColor, (id)bottomColor.CGColor, nil]; + theViewGradient.startPoint = CGPointMake(0.5, 0.0); + theViewGradient.endPoint = CGPointMake(0.5, 1.0); + theViewGradient.frame = bgView.bounds; + + //Add gradient to view + [bgView.layer insertSublayer:theViewGradient atIndex:0]; + [self insertSubview:bgView atIndex:0]; + +} + + +- (CGFloat)preferredHeightForWidth:(CGFloat)width inTableView:(id)tableView { + return [self preferredHeightForWidth:width]; +} + +@end diff --git a/kaiprefs/Resources/Info.plist b/kaiprefs/Resources/Info.plist new file mode 100644 index 0000000..7325f41 --- /dev/null +++ b/kaiprefs/Resources/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + kaiPrefs + CFBundleIdentifier + com.burritoz.kaiprefs + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSPrincipalClass + KAIRootListController + + diff --git a/kaiprefs/Resources/Root.plist b/kaiprefs/Resources/Root.plist new file mode 100644 index 0000000..8aa73e4 --- /dev/null +++ b/kaiprefs/Resources/Root.plist @@ -0,0 +1,31 @@ + + + + + items + + + cell + PSGroupCell + headerCellClass + KaiHeaderCell + height + 175 + + + cell + PSSwitchCell + default + + defaults + com.burritoz.kaiprefs + key + enabled + label + Enable + + + title + kai + + diff --git a/kaiprefs/Resources/kai.png b/kaiprefs/Resources/kai.png new file mode 100644 index 0000000..69e0060 Binary files /dev/null and b/kaiprefs/Resources/kai.png differ diff --git a/kaiprefs/entry.plist b/kaiprefs/entry.plist new file mode 100644 index 0000000..6dfe8c0 --- /dev/null +++ b/kaiprefs/entry.plist @@ -0,0 +1,21 @@ + + + + + entry + + bundle + kaiPrefs + cell + PSLinkCell + detail + KAIRootListController + icon + icon.png + isController + + label + kai + + +