Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed prefs
No need for respring anymore to change prefs

- Also a fancy header cell

- Lots of love added too
  • Loading branch information
ShyamLad committed Feb 11, 2019
1 parent 195cd6b commit 99d2374
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 25 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -21,4 +21,7 @@ of course

# License

BSD FLEX (look in the Class directory) and also BSD for this one.
BSD for FLEX (located in the classes directory) and also BSD for this one.


Flex icon made by GD Creativ, ZA from The Noun Project
62 changes: 39 additions & 23 deletions Tweak.xm
Expand Up @@ -11,36 +11,38 @@
#define kSettingsPath [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.ladshyam.FLEX12.plist"]

static BOOL hasBeenForceTapped = NO;
static BOOL enabled = YES;
static BOOL enabled_Locked = NO;
static float FLXForce = 2;


@interface NSUserDefaults (Tweak_Category)
- (id)objectForKey:(NSString *)key inDomain:(NSString *)domain;
- (void)setObject:(id)value forKey:(NSString *)key inDomain:(NSString *)domain;
@end

static NSString *nsDomainString = @"com.ladshyam.FLEX12";
static NSString *nsNotificationString = @"com.ladshyam.FLEX12/preferences.changed";

static void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSNumber *n1 = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"FLXEnabled" inDomain:nsDomainString];
enabled = (n1)? [n1 boolValue]:YES;
NSNumber *n2 = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"FLXLocked" inDomain:nsDomainString];
enabled_Locked = (n2)? [n2 boolValue]:YES;
NSNumber *n3 = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"FLXForce" inDomain:nsDomainString];
FLXForce = (n3)? [n3 floatValue]:2;
}

static NSDictionary *prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];

static void respring(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
[[%c(FBSystemService) sharedInstance] exitAndRelaunch:YES];
}

static void addDarwinObserver(CFNotificationCallback callBack, CFStringRef name) {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, callBack, name,
NULL, 0);
}

static bool GetPrefBool(NSString *key)
{
//Return NO for FLXLocked by default
BOOL defaultBool = [key isEqualToString:@"FLXLocked"] ? NO : YES;
NSLog(@"The bool value for %@ is %@", key, [[prefs valueForKey:key] boolValue]);
return [prefs valueForKey:key]? [[prefs valueForKey:key] boolValue] : defaultBool;

}

static double GetScaleFor(NSString *key) {
// Return 2 by default
NSDictionary *prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
return [prefs valueForKey:key] ? [[prefs valueForKey:key] doubleValue] : 2;
}

%hook UIWindow
- (BOOL)_shouldCreateContextAsSecure {
if (GetPrefBool(@"FLXLocked")) {
if (enabled_Locked) {
return [self isKindOfClass:%c(FLEXWindow)] ? YES : %orig;
}
return %orig;
Expand All @@ -52,12 +54,12 @@ static double GetScaleFor(NSString *key) {

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// NSLog(@"FLEXing12: We are touching");
if (GetPrefBool(@"FLXEnabled")) {
if (enabled) {
UITouch *currentTouch = [touches anyObject];
CGFloat currentForce = currentTouch.force;
// NSLog(@"forceForward: The Current Force is: %@", @(currentForce));

float toggleForce = GetScaleFor(@"FLXForce");
float toggleForce = FLXForce;
if(currentForce < toggleForce) {
hasBeenForceTapped = NO;
}
Expand All @@ -78,5 +80,19 @@ static double GetScaleFor(NSString *key) {
%ctor{

NSLog(@"Loading Flex");
addDarwinObserver(&respring, CFSTR("respring"));
notificationCallback(NULL, NULL, NULL, NULL, NULL);

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
&respring,
CFSTR("respring"),
NULL, 0);

// Register for 'PostNotification' notifications
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
notificationCallback,
(CFStringRef)nsNotificationString,
NULL,
CFNotificationSuspensionBehaviorCoalesce);
}
14 changes: 14 additions & 0 deletions flex12prefs/HeaderCell.h
@@ -0,0 +1,14 @@
#import <Preferences/PSControlTableCell.h>
#import <Preferences/PSListController.h>
#import <Preferences/PSSpecifier.h>
#import <Preferences/PSSwitchTableCell.h>
#import <Preferences/PSTableCell.h>
#import <Preferences/PSViewController.h>
#import "PreferencesTableCustomView-Protocol.h"

@interface NSArray(Private)
- (id)specifierForID:(id)id;
@end

@interface HeaderCell : PSTableCell <PreferencesTableCustomView>
@end
37 changes: 37 additions & 0 deletions flex12prefs/HeaderCell.m
@@ -0,0 +1,37 @@
#import "HeaderCell.h"

@implementation HeaderCell
- (id)initWithSpecifier:(PSSpecifier *)specifier{
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HeaderCell" specifier:specifier];
if (self) {
NSBundle *bundle = [NSBundle bundleForClass:self.class];
UIImage *banner = [UIImage imageNamed:@"FLEX12_git"
inBundle:bundle
compatibleWithTraitCollection:nil];
float width = [UIScreen mainScreen].bounds.size.width;
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, width, width / 4.582)];

[backgroundView setContentMode: UIViewContentModeScaleAspectFit];
backgroundView.image = banner;
[self addSubview: backgroundView];
}

return self;
}

#pragma mark - Protocols

- (CGFloat)preferredHeightForWidth:(CGFloat)width {
// Appears to be zero on the first call for w/e stupid reason. That breaks things?
if (width == 0) {
width = [UIScreen mainScreen].bounds.size.width;
}
// Our background has a ratio of 3.75w : 1h.
return width / 4.582 + 7.5;
}

- (CGFloat)preferredHeightForWidth:(CGFloat)width inTableView:(id)tableView {
return [self preferredHeightForWidth:width];
}

@end
6 changes: 6 additions & 0 deletions flex12prefs/PreferencesTableCustomView-Protocol.h
@@ -0,0 +1,6 @@
@protocol PreferencesTableCustomView
- (id)initWithSpecifier:(id)specifier;
@optional
- (CGFloat)preferredHeightForWidth:(CGFloat)width;
- (CGFloat)preferredHeightForWidth:(CGFloat)width inTableView:(id)tableView;
@end
10 changes: 9 additions & 1 deletion flex12prefs/Resources/Root.plist
@@ -1,6 +1,11 @@
{
title = "FLEX12";
items = (
{
cell = PSGroupCell;
headerCellClass = HeaderCell;

},
{
cell = PSGroupCell;
label = "Changes may require respring";
Expand All @@ -19,6 +24,7 @@
key = "FLXEnabled";
default = 1;
defaults = "com.ladshyam.FLEX12";
PostNotification = "com.ladshyam.FLEX12/preferences.changed";
},
{
cell = PSGroupCell;
Expand All @@ -30,6 +36,7 @@
key = "FLXLocked";
default = 0;
defaults = "com.ladshyam.FLEX12";
PostNotification = "com.ladshyam.FLEX12/preferences.changed";
},
{
cell = PSGroupCell;
Expand All @@ -48,10 +55,11 @@
// isSegmented = 1;
// segmentCount = 10;
defaults = "com.ladshyam.FLEX12";
PostNotification = "com.ladshyam.FLEX12/preferences.changed";
},
{
cell = PSGroupCell;
height = 20;
footerText = "FLEX12 v1.0 2019\nBy: Shyam Lad";
footerText = "Flex12 v1.0\nBy: Shyam Lad\n2019";
});
}
Binary file modified packages/com.ladshyam.flex12_1.0-1+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-2+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-3+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-4+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-5+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-6+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-7+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-8+debug_iphoneos-arm.deb
Binary file not shown.
Binary file modified packages/com.ladshyam.flex12_1.0-9+debug_iphoneos-arm.deb
Binary file not shown.

0 comments on commit 99d2374

Please sign in to comment.