Skip to content

Simulator compile target and some scripts for it #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
ARCHS = armv7 armv7s arm64 arm64e
TARGET = iphone:clang:11.2:5.0
SIMULATOR ?= 0

ifeq ($(SIMULATOR), 1)
ARCHS = i386 x86_64
TARGET = simulator:clang:12.1:9.0
else
ARCHS = armv7 armv7s arm64 arm64e
TARGET = iphone:clang:12.1.2:9.0
endif

GO_EASY_ON_ME = 0
FINALPACKAGE = 1
Expand All @@ -15,6 +22,10 @@ $(LIBRARY_NAME)_FRAMEWORKS = UIKit CoreGraphics CoreFoundation
$(LIBRARY_NAME)_PRIVATE_FRAMEWORKS = Preferences
$(LIBRARY_NAME)_CFLAGS += -fobjc-arc -I$(INCLUDES) -IPrefix.pch

ifeq ($(SIMULATOR), 1)
$(LIBRARY_NAME)_CFLAGS += -D SIMULATOR=1
endif

after-install::
install.exec "killall -9 Preferences"

Expand Down
8 changes: 8 additions & 0 deletions create_universal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set -e

make

make SIMULATOR=1

lipo ./.theos/obj/iphone_simulator/libCSColorPicker.dylib ./.theos/obj/libCSColorPicker.dylib -output ./libCSColorPicker.dylib -create
# Creates a dylib that can be properly linked from tweaks targetting both simulator and real devices
36 changes: 36 additions & 0 deletions install_simulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set -e

make SIMULATOR=1

THEOS_OBJ_DIR=./.theos/obj/iphone_simulator

#install libCSColorPicker into all additionally installed simulators

for runtime in /Library/Developer/CoreSimulator/Profiles/Runtimes/*
do
if [ -d "$runtime" ]; then
echo "Installing libCSColorPicker to $runtime"
SIMULATOR_ROOT=$runtime/Contents/Resources/RuntimeRoot
SIMULATOR_LIB_PATH=$SIMULATOR_ROOT/usr/lib

if [ -d "$SIMULATOR_LIB_PATH" ]; then
sudo rm -rf "$SIMULATOR_LIB_PATH/libCSColorPicker.dylib" ||:
sudo cp -rf "$THEOS_OBJ_DIR/libCSColorPicker.dylib" "$SIMULATOR_LIB_PATH"
fi
fi
done

#install libCSColorPicker into the simulator that ships with Xcode

for SIMULATOR_ROOT in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
do
if [ -d "$SIMULATOR_ROOT" ]; then
echo "Installing libCSColorPicker to $SIMULATOR_ROOT"
SIMULATOR_LIB_PATH=$SIMULATOR_ROOT/usr/lib

if [ -d "$SIMULATOR_LIB_PATH" ]; then
sudo rm -rf "$SIMULATOR_LIB_PATH/libCSColorPicker.dylib" ||:
sudo cp -rf "$THEOS_OBJ_DIR/libCSColorPicker.dylib" "$SIMULATOR_LIB_PATH"
fi
fi
done
23 changes: 14 additions & 9 deletions source/Cells/CSColorDisplayCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#import <Cells/CSColorDisplayCell.h>

#import <simulator.h>

// get the associated view controller from a UIView
// credits https://stackoverflow.com/questions/1372977/given-a-view-how-do-i-get-its-viewcontroller/24590678
#define UIViewParentController(__view) ({ UIResponder *__responder = __view; while ([__responder isKindOfClass:[UIView class]]) __responder = [__responder nextResponder]; (UIViewController *)__responder; })

@implementation CSColorDisplayCell
@synthesize cellColorDisplay;

Expand All @@ -26,14 +32,13 @@ - (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier {
}

- (void)refreshCellWithColor:(UIColor *)color {

if (!color) {
color = [self previewColor];
} else {
[self.specifier setProperty:color.cscp_hexStringWithAlpha forKey:@"hexValue"];
[self.specifier setProperty:color forKey:@"color"];
}

[self.specifier setProperty:color.cscp_hexStringWithAlpha forKey:@"hexValue"];
[self.specifier setProperty:color forKey:@"color"];
}
self.cellColorDisplay.backgroundColor = color;
self.detailTextLabel.text = [NSString stringWithFormat:@"#%@", [color cscp_hexString]];
}
Expand Down Expand Up @@ -99,9 +104,9 @@ - (UIColor *)previewColor {
NSDictionary *prefsDict, *defaultsDict;
UIColor *color;

userPrefsPath = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", [self.specifier propertyForKey:@"defaults"]];
defaultsPlistPath = [[NSBundle bundleWithPath:[self.specifier propertyForKey:@"defaultsPath"]] pathForResource:@"defaults" ofType:@"plist"];
motuumLSDefaultsPath = [[NSBundle bundleWithPath:@"/Library/PreferenceBundles/motuumLS.bundle"] pathForResource:@"com.creaturesurvive.motuumls_defaults" ofType:@"plist"];
userPrefsPath = rPath([NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", [self.specifier propertyForKey:@"defaults"]]);
defaultsPlistPath = rPath([[NSBundle bundleWithPath:[self.specifier propertyForKey:@"defaultsPath"]] pathForResource:@"defaults" ofType:@"plist"]);
motuumLSDefaultsPath = rPath([[NSBundle bundleWithPath:@"/Library/PreferenceBundles/motuumLS.bundle"] pathForResource:@"com.creaturesurvive.motuumls_defaults" ofType:@"plist"]);

if ((prefsDict = [NSDictionary dictionaryWithContentsOfFile:userPrefsPath])) {
hex = prefsDict[[self.specifier propertyForKey:@"key"]];
Expand All @@ -119,7 +124,7 @@ - (UIColor *)previewColor {
hex = [self.specifier propertyForKey:@"fallback"] ? : @"FF0000";
}

color = [UIColor cscp_colorFromHexString:hex];
color = [UIColor cscp_colorFromHexString:hex];
[self.specifier setProperty:hex forKey:@"hexValue"];
[self.specifier setProperty:color forKey:@"color"];

Expand Down
12 changes: 8 additions & 4 deletions source/Cells/CSGradientDisplayCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#import <Cells/CSGradientDisplayCell.h>

// get the associated view controller from a UIView
// credits https://stackoverflow.com/questions/1372977/given-a-view-how-do-i-get-its-viewcontroller/24590678
#define UIViewParentController(__view) ({ UIResponder *__responder = __view; while ([__responder isKindOfClass:[UIView class]]) __responder = [__responder nextResponder]; (UIViewController *)__responder; })

@implementation CSGradientDisplayCell
@synthesize cellColorDisplay, gradient;

Expand All @@ -27,15 +31,15 @@ - (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier {
}

- (void)refreshCellWithColors:(NSArray<UIColor *> *)newColors {

if (!newColors) {
newColors = [self previewColors];
} else {
[self.specifier setProperty:newColors.lastObject.cscp_hexString forKey:@"hexValue"];
[self.specifier setProperty:newColors.lastObject forKey:@"color"];
[self.specifier setProperty:newColors forKey:@"colors"];
}

self.detailTextLabel.text = nil;
NSMutableArray<id> *colors = [NSMutableArray new];
for (UIColor *color in newColors) {
Expand Down Expand Up @@ -69,13 +73,13 @@ - (void)configureColorDisplay {
self.cellColorDisplay.layer.cornerRadius = CGRectGetHeight(self.cellColorDisplay.frame) / 4;
self.cellColorDisplay.layer.borderWidth = 2;
self.cellColorDisplay.layer.borderColor = [UIColor lightGrayColor].CGColor;

self.gradient = [CAGradientLayer layer];
self.gradient.frame = self.cellColorDisplay.bounds;
self.gradient.cornerRadius = self.cellColorDisplay.layer.cornerRadius;
self.gradient.startPoint = CGPointMake(0, 0.5);
self.gradient.endPoint = CGPointMake(1, 0.5);

[self.cellColorDisplay.layer addSublayer:self.gradient];
[self setAccessoryView:self.cellColorDisplay];
}
Expand Down
19 changes: 11 additions & 8 deletions source/Controllers/CSColorPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#import <Controllers/CSColorPickerViewController.h>

#import <simulator.h>

#define SLIDER_HEIGHT 40.0
#define GRADIENT_HEIGHT 50.0
#define ALERT_TITLE @"Set Hex Color"
Expand Down Expand Up @@ -201,17 +203,17 @@ - (void)setColor:(UIColor *)color animated:(BOOL)animated{
[self setColorInformationTextWithInformationFromColor:color];
};

if (animated)
if (animated)
[UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ update(); } completion:nil];
else
else
update();
}

- (void)setColorInformationTextWithInformationFromColor:(UIColor *)color {
[self.colorInformationLable setText:[self informationStringForColor:color]];
UIColor *legibilityTint = (!color.cscp_light && color.cscp_alpha > 0.5) ? UIColor.whiteColor : UIColor.blackColor;
UIColor *shadowColor = legibilityTint == UIColor.blackColor ? UIColor.whiteColor : UIColor.blackColor;

[self.colorInformationLable setTextColor:legibilityTint];
[self.colorInformationLable.layer setShadowColor:[shadowColor CGColor]];
[self.colorInformationLable setFont:[UIFont boldSystemFontOfSize:[self isLandscape] ? 16 : 20]];
Expand All @@ -234,10 +236,11 @@ - (void)saveColor {
NSString *key = [self.specifier propertyForKey:@"key"];
NSString *defaults = [self.specifier propertyForKey:@"defaults"];

NSString *plistPath = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", defaults];
NSString *plistPath = rPath([NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", defaults]);
NSMutableDictionary *prefsDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath] ? : [NSMutableDictionary new];

UITableViewCell *cell = [self.specifier propertyForKey:@"cellObject"];

// save via plist
[prefsDict setObject:saveValue forKey:key];
[prefsDict writeToFile:plistPath atomically:NO];
Expand All @@ -248,19 +251,19 @@ - (void)saveColor {

// save in domain for NSUserDefaults
[[NSUserDefaults standardUserDefaults] setObject:saveValue forKey:key inDomain:defaults];

if (cell && [cell isKindOfClass:[CSColorDisplayCell class]])
[(CSColorDisplayCell *)cell refreshCellWithColor:[self colorForRGBSliders]];
else if (cell && [cell isKindOfClass:[CSGradientDisplayCell class]])
[(CSGradientDisplayCell *)cell refreshCellWithColors:self.colors];

if ([self.specifier propertyForKey:@"PostNotification"])
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(),
(CFStringRef)[self.specifier propertyForKey:@"PostNotification"],
(CFStringRef)[self.specifier propertyForKey:@"PostNotification"],
NULL,
YES);

if ([self.specifier propertyForKey:@"callbackAction"]) {
SEL callback = NSSelectorFromString([self.specifier propertyForKey:@"callbackAction"]);
if ([self.specifier.target respondsToSelector:callback]) {
Expand Down
14 changes: 14 additions & 0 deletions source/simulator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifdef SIMULATOR

@interface UIView ()
@property(nonatomic, readonly) UIEdgeInsets safeAreaInsets; //9.2 sdk needed for simulator and this property was added in 11
@end

extern NSString* simulatorPath(NSString* path);
#define rPath(args ...) ({ simulatorPath(args); })

#else

#define rPath(args ...) ({ args; })

#endif
19 changes: 19 additions & 0 deletions source/simulator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifdef SIMULATOR

extern NSString *UISystemRootDirectory();

#define currentUser NSHomeDirectory().pathComponents[2]

NSString* simulatorPath(NSString* path)
{
if([path hasPrefix:@"/var/mobile/"] || [path hasPrefix:@"/User/"])
{
NSString* simulatorID = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject].pathComponents[7];
NSString* strippedPath = [path stringByReplacingOccurrencesOfString:@"/var/mobile/" withString:@""];
strippedPath = [strippedPath stringByReplacingOccurrencesOfString:@"/User/" withString:@""];
return [NSString stringWithFormat:@"/Users/%@/Library/Developer/CoreSimulator/Devices/%@/data/%@", currentUser, simulatorID, strippedPath];
}
return [UISystemRootDirectory() stringByAppendingPathComponent:path];
}

#endif