Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
feat: add optional prefs
Browse files Browse the repository at this point in the history
Signed-off-by: 82Flex <82flex@gmail.com>
  • Loading branch information
Lessica committed Jun 17, 2024
1 parent e8a8534 commit d152a05
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# clang-format
BasedOnStyle: LLVM
IndentWidth: 4
AccessModifierOffset: -4
ContinuationIndentWidth: 4
ColumnLimit: 120
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ TrollSpeed_CODESIGN_FLAGS += -Ssupports/entitlements.plist

include $(THEOS_MAKE_PATH)/application.mk

SUBPROJECTS += prefs
ifneq ($(FINALPACKAGE),1)
SUBPROJECTS += memory_pressure
include $(THEOS_MAKE_PATH)/aggregate.mk
endif

include $(THEOS_MAKE_PATH)/aggregate.mk

before-all::
$(ECHO_NOTHING)defaults write $(LAUNCHD_PLIST) ProgramArguments -array "$(THEOS_PACKAGE_INSTALL_PREFIX)/Applications/TrollSpeed.app/TrollSpeed" "-hud" || true$(ECHO_END)
$(ECHO_NOTHING)plutil -convert xml1 $(LAUNCHD_PLIST)$(ECHO_END)
Expand Down
16 changes: 16 additions & 0 deletions prefs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARCHS := arm64 arm64e
TARGET := iphone:clang:15.6:14.0
INSTALL_TARGET_PROCESSES := Preferences

include $(THEOS)/makefiles/common.mk

BUNDLE_NAME += TrollSpeedPrefs

TrollSpeedPrefs_FILES += TSPrefsRootListController.m
TrollSpeedPrefs_FRAMEWORKS += UIKit
TrollSpeedPrefs_PRIVATE_FRAMEWORKS += Preferences
TrollSpeedPrefs_INSTALL_PATH += /Library/PreferenceBundles
TrollSpeedPrefs_CFLAGS += -fobjc-arc
TrollSpeedPrefs_CFLAGS += -I../supports/

include $(THEOS_MAKE_PATH)/bundle.mk
24 changes: 24 additions & 0 deletions prefs/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>TrollSpeedPrefs</string>
<key>CFBundleIdentifier</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string>TSPrefsRootListController</string>
</dict>
</plist>
131 changes: 131 additions & 0 deletions prefs/Resources/Root.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Custom Font Size</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>key</key>
<string>usesCustomFontSize</string>
<key>label</key>
<string>Uses Custom Font Size</string>
<key>PostNotification</key>
<string>ch.xxtou.notification.hud.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSSliderCell</string>
<key>default</key>
<real>9</real>
<key>defaults</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>key</key>
<string>realCustomFontSize</string>
<key>label</key>
<string>Custom Font Size</string>
<key>max</key>
<real>12</real>
<key>min</key>
<real>8</real>
<key>showValue</key>
<true/>
<key>PostNotification</key>
<string>ch.xxtou.notification.hud.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Custom Offset</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>key</key>
<string>usesCustomOffset</string>
<key>label</key>
<string>Uses Custom Offset</string>
<key>PostNotification</key>
<string>ch.xxtou.notification.hud.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSSliderCell</string>
<key>default</key>
<real>0</real>
<key>defaults</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>key</key>
<string>realCustomOffsetX</string>
<key>label</key>
<string>Custom Offset X</string>
<key>max</key>
<real>100</real>
<key>min</key>
<real>-100</real>
<key>showValue</key>
<true/>
<key>PostNotification</key>
<string>ch.xxtou.notification.hud.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSSliderCell</string>
<key>default</key>
<real>0</real>
<key>defaults</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>key</key>
<string>realCustomOffsetY</string>
<key>label</key>
<string>Custom Offset Y</string>
<key>max</key>
<real>100</real>
<key>min</key>
<real>-100</real>
<key>showValue</key>
<true/>
<key>PostNotification</key>
<string>ch.xxtou.notification.hud.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string></string>
<key>footerText</key>
<string>Made with ♥ by @Lessica and @jmpews</string>
</dict>
<dict>
<key>cell</key>
<string>PSButtonCell</string>
<key>label</key>
<string>Reset to Default</string>
<key>action</key>
<string>resetToDefaults:</string>
<key>defaults</key>
<string>ch.xxtou.hudapp.prefs</string>
<key>PostNotification</key>
<string>ch.xxtou.notification.hud.reload</string>
</dict>
</array>
<key>title</key>
<string>TrollSpeed</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
"Custom Offset" = "Custom Offset";

"Uses Custom Offset" = "Uses Custom Offset";

"Reset to Default" = "Reset to Default";
Binary file added prefs/Resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added prefs/Resources/icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added prefs/Resources/icon@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions prefs/Resources/zh_Hans.lproj/Root.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"Appearance" = "外观";

"Custom Font Size" = "自定义字体大小";

"Uses Custom Font Size" = "使用自定义字体大小";

"Custom Offset" = "自定义偏移位置";

"Uses Custom Offset" = "使用自定义偏移位置";

"Reset to Default" = "重置为默认值";
5 changes: 5 additions & 0 deletions prefs/TSPrefsRootListController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Preferences/PSListController.h>

@interface TSPrefsRootListController : PSListController

@end
58 changes: 58 additions & 0 deletions prefs/TSPrefsRootListController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#import <Foundation/Foundation.h>
#import <Preferences/PSSpecifier.h>

#import <rootless.h>

#import "TSPrefsRootListController.h"

@implementation TSPrefsRootListController

- (NSArray *)specifiers {
if (!_specifiers) {
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
}
return _specifiers;
}

- (id)readPreferenceValue:(PSSpecifier *)specifier {
NSString *containerPath =
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSString *path = [NSString
stringWithFormat:ROOT_PATH_NS("%@/Preferences/%@.plist"), containerPath, specifier.properties[@"defaults"]];
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
return (settings[specifier.properties[@"key"]]) ?: specifier.properties[@"default"];
}

- (void)setPreferenceValue:(id)value specifier:(PSSpecifier *)specifier {
NSString *containerPath =
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSString *path = [NSString
stringWithFormat:ROOT_PATH_NS("%@/Preferences/%@.plist"), containerPath, specifier.properties[@"defaults"]];
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
[settings setObject:value forKey:specifier.properties[@"key"]];
[settings writeToFile:path atomically:YES];
CFStringRef notificationName = (__bridge CFStringRef)specifier.properties[@"PostNotification"];
if (notificationName) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL,
YES);
}
}

- (void)resetToDefaults:(PSSpecifier *)specifier {
NSString *containerPath =
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSString *path = [NSString
stringWithFormat:ROOT_PATH_NS("%@/Preferences/%@.plist"), containerPath, specifier.properties[@"defaults"]];
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings writeToFile:path atomically:YES];
CFStringRef notificationName = (__bridge CFStringRef)specifier.properties[@"PostNotification"];
if (notificationName) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL,
YES);
}
[self reloadSpecifiers];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>entry</key>
<dict>
<key>bundle</key>
<string>TrollSpeedPrefs</string>
<key>cell</key>
<string>PSLinkCell</string>
<key>detail</key>
<string>TSPrefsRootListController</string>
<key>icon</key>
<string>icon.png</string>
<key>isController</key>
<true/>
<key>label</key>
<string>TrollSpeed</string>
</dict>
</dict>
</plist>
60 changes: 55 additions & 5 deletions sources/HUDRootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <ifaddrs.h>
#import <objc/runtime.h>
#import <mach/vm_param.h>
#import <Foundation/Foundation.h>

#import "HUDPresetPosition.h"
#import "HUDRootViewController.h"
Expand Down Expand Up @@ -686,11 +687,60 @@ - (void)setCurrentLandscapePositionY:(CGFloat)positionY
}

#if !NO_TROLL
- (BOOL)usesCustomFontSize { return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomFontSize]; }
- (CGFloat)realCustomFontSize { return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomFontSize]; }
- (BOOL)usesCustomOffset { return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomOffset]; }
- (CGFloat)realCustomOffsetX { return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetX]; }
- (CGFloat)realCustomOffsetY { return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetY]; }
#define PREFS_PATH "/var/mobile/Library/Preferences/ch.xxtou.hudapp.prefs.plist"

- (NSDictionary *)extraUserDefaultsDictionary {
static BOOL isJailbroken = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isJailbroken = [[NSFileManager defaultManager]
fileExistsAtPath:ROOT_PATH_NS("/Library/PreferenceBundles/TrollSpeedPrefs.bundle")];
});
if (!isJailbroken) {
return nil;
}
return [NSDictionary dictionaryWithContentsOfFile:ROOT_PATH_NS(PREFS_PATH)];
}

- (BOOL)usesCustomFontSize {
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
if (extraUserDefaults) {
return [extraUserDefaults[HUDUserDefaultsKeyUsesCustomFontSize] boolValue];
}
return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomFontSize];
}

- (CGFloat)realCustomFontSize {
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
if (extraUserDefaults) {
return [extraUserDefaults[HUDUserDefaultsKeyRealCustomFontSize] doubleValue];
}
return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomFontSize];
}

- (BOOL)usesCustomOffset {
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
if (extraUserDefaults) {
return [extraUserDefaults[HUDUserDefaultsKeyUsesCustomOffset] boolValue];
}
return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomOffset];
}

- (CGFloat)realCustomOffsetX {
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
if (extraUserDefaults) {
return [extraUserDefaults[HUDUserDefaultsKeyRealCustomOffsetX] doubleValue];
}
return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetX];
}

- (CGFloat)realCustomOffsetY {
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
if (extraUserDefaults) {
return [extraUserDefaults[HUDUserDefaultsKeyRealCustomOffsetY] doubleValue];
}
return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetY];
}
#else
- (BOOL)usesCustomFontSize { return NO; }
- (CGFloat)realCustomFontSize { return HUD_FONT_SIZE; }
Expand Down

0 comments on commit d152a05

Please sign in to comment.