Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit d152a05

Browse files
committed
feat: add optional prefs
Signed-off-by: 82Flex <82flex@gmail.com>
1 parent e8a8534 commit d152a05

File tree

14 files changed

+332
-6
lines changed

14 files changed

+332
-6
lines changed

.clang-format

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# clang-format
2+
BasedOnStyle: LLVM
3+
IndentWidth: 4
4+
AccessModifierOffset: -4
5+
ContinuationIndentWidth: 4
6+
ColumnLimit: 120

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ TrollSpeed_CODESIGN_FLAGS += -Ssupports/entitlements.plist
3636

3737
include $(THEOS_MAKE_PATH)/application.mk
3838

39+
SUBPROJECTS += prefs
3940
ifneq ($(FINALPACKAGE),1)
4041
SUBPROJECTS += memory_pressure
41-
include $(THEOS_MAKE_PATH)/aggregate.mk
4242
endif
4343

44+
include $(THEOS_MAKE_PATH)/aggregate.mk
45+
4446
before-all::
4547
$(ECHO_NOTHING)defaults write $(LAUNCHD_PLIST) ProgramArguments -array "$(THEOS_PACKAGE_INSTALL_PREFIX)/Applications/TrollSpeed.app/TrollSpeed" "-hud" || true$(ECHO_END)
4648
$(ECHO_NOTHING)plutil -convert xml1 $(LAUNCHD_PLIST)$(ECHO_END)

prefs/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARCHS := arm64 arm64e
2+
TARGET := iphone:clang:15.6:14.0
3+
INSTALL_TARGET_PROCESSES := Preferences
4+
5+
include $(THEOS)/makefiles/common.mk
6+
7+
BUNDLE_NAME += TrollSpeedPrefs
8+
9+
TrollSpeedPrefs_FILES += TSPrefsRootListController.m
10+
TrollSpeedPrefs_FRAMEWORKS += UIKit
11+
TrollSpeedPrefs_PRIVATE_FRAMEWORKS += Preferences
12+
TrollSpeedPrefs_INSTALL_PATH += /Library/PreferenceBundles
13+
TrollSpeedPrefs_CFLAGS += -fobjc-arc
14+
TrollSpeedPrefs_CFLAGS += -I../supports/
15+
16+
include $(THEOS_MAKE_PATH)/bundle.mk

prefs/Resources/Info.plist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>TrollSpeedPrefs</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>ch.xxtou.hudapp.prefs</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundlePackageType</key>
14+
<string>BNDL</string>
15+
<key>CFBundleShortVersionString</key>
16+
<string>1.0.0</string>
17+
<key>CFBundleSignature</key>
18+
<string>????</string>
19+
<key>CFBundleVersion</key>
20+
<string>1.0</string>
21+
<key>NSPrincipalClass</key>
22+
<string>TSPrefsRootListController</string>
23+
</dict>
24+
</plist>

prefs/Resources/Root.plist

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>items</key>
6+
<array>
7+
<dict>
8+
<key>cell</key>
9+
<string>PSGroupCell</string>
10+
<key>label</key>
11+
<string>Custom Font Size</string>
12+
</dict>
13+
<dict>
14+
<key>cell</key>
15+
<string>PSSwitchCell</string>
16+
<key>default</key>
17+
<false/>
18+
<key>defaults</key>
19+
<string>ch.xxtou.hudapp.prefs</string>
20+
<key>key</key>
21+
<string>usesCustomFontSize</string>
22+
<key>label</key>
23+
<string>Uses Custom Font Size</string>
24+
<key>PostNotification</key>
25+
<string>ch.xxtou.notification.hud.reload</string>
26+
</dict>
27+
<dict>
28+
<key>cell</key>
29+
<string>PSSliderCell</string>
30+
<key>default</key>
31+
<real>9</real>
32+
<key>defaults</key>
33+
<string>ch.xxtou.hudapp.prefs</string>
34+
<key>key</key>
35+
<string>realCustomFontSize</string>
36+
<key>label</key>
37+
<string>Custom Font Size</string>
38+
<key>max</key>
39+
<real>12</real>
40+
<key>min</key>
41+
<real>8</real>
42+
<key>showValue</key>
43+
<true/>
44+
<key>PostNotification</key>
45+
<string>ch.xxtou.notification.hud.reload</string>
46+
</dict>
47+
<dict>
48+
<key>cell</key>
49+
<string>PSGroupCell</string>
50+
<key>label</key>
51+
<string>Custom Offset</string>
52+
</dict>
53+
<dict>
54+
<key>cell</key>
55+
<string>PSSwitchCell</string>
56+
<key>default</key>
57+
<false/>
58+
<key>defaults</key>
59+
<string>ch.xxtou.hudapp.prefs</string>
60+
<key>key</key>
61+
<string>usesCustomOffset</string>
62+
<key>label</key>
63+
<string>Uses Custom Offset</string>
64+
<key>PostNotification</key>
65+
<string>ch.xxtou.notification.hud.reload</string>
66+
</dict>
67+
<dict>
68+
<key>cell</key>
69+
<string>PSSliderCell</string>
70+
<key>default</key>
71+
<real>0</real>
72+
<key>defaults</key>
73+
<string>ch.xxtou.hudapp.prefs</string>
74+
<key>key</key>
75+
<string>realCustomOffsetX</string>
76+
<key>label</key>
77+
<string>Custom Offset X</string>
78+
<key>max</key>
79+
<real>100</real>
80+
<key>min</key>
81+
<real>-100</real>
82+
<key>showValue</key>
83+
<true/>
84+
<key>PostNotification</key>
85+
<string>ch.xxtou.notification.hud.reload</string>
86+
</dict>
87+
<dict>
88+
<key>cell</key>
89+
<string>PSSliderCell</string>
90+
<key>default</key>
91+
<real>0</real>
92+
<key>defaults</key>
93+
<string>ch.xxtou.hudapp.prefs</string>
94+
<key>key</key>
95+
<string>realCustomOffsetY</string>
96+
<key>label</key>
97+
<string>Custom Offset Y</string>
98+
<key>max</key>
99+
<real>100</real>
100+
<key>min</key>
101+
<real>-100</real>
102+
<key>showValue</key>
103+
<true/>
104+
<key>PostNotification</key>
105+
<string>ch.xxtou.notification.hud.reload</string>
106+
</dict>
107+
<dict>
108+
<key>cell</key>
109+
<string>PSGroupCell</string>
110+
<key>label</key>
111+
<string></string>
112+
<key>footerText</key>
113+
<string>Made with ♥ by @Lessica and @jmpews</string>
114+
</dict>
115+
<dict>
116+
<key>cell</key>
117+
<string>PSButtonCell</string>
118+
<key>label</key>
119+
<string>Reset to Default</string>
120+
<key>action</key>
121+
<string>resetToDefaults:</string>
122+
<key>defaults</key>
123+
<string>ch.xxtou.hudapp.prefs</string>
124+
<key>PostNotification</key>
125+
<string>ch.xxtou.notification.hud.reload</string>
126+
</dict>
127+
</array>
128+
<key>title</key>
129+
<string>TrollSpeed</string>
130+
</dict>
131+
</plist>

Resources/Settings.bundle/es.lproj/Root.strings renamed to prefs/Resources/en.lproj/Root.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
"Custom Offset" = "Custom Offset";
88

99
"Uses Custom Offset" = "Uses Custom Offset";
10+
11+
"Reset to Default" = "Reset to Default";

prefs/Resources/icon.png

2.99 KB
Loading

prefs/Resources/icon@2x.png

7.88 KB
Loading

prefs/Resources/icon@3x.png

14.8 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"Appearance" = "外观";
2+
3+
"Custom Font Size" = "自定义字体大小";
4+
5+
"Uses Custom Font Size" = "使用自定义字体大小";
6+
7+
"Custom Offset" = "自定义偏移位置";
8+
9+
"Uses Custom Offset" = "使用自定义偏移位置";
10+
11+
"Reset to Default" = "重置为默认值";

prefs/TSPrefsRootListController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Preferences/PSListController.h>
2+
3+
@interface TSPrefsRootListController : PSListController
4+
5+
@end

prefs/TSPrefsRootListController.m

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#import <Foundation/Foundation.h>
2+
#import <Preferences/PSSpecifier.h>
3+
4+
#import <rootless.h>
5+
6+
#import "TSPrefsRootListController.h"
7+
8+
@implementation TSPrefsRootListController
9+
10+
- (NSArray *)specifiers {
11+
if (!_specifiers) {
12+
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
13+
}
14+
return _specifiers;
15+
}
16+
17+
- (id)readPreferenceValue:(PSSpecifier *)specifier {
18+
NSString *containerPath =
19+
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
20+
NSString *path = [NSString
21+
stringWithFormat:ROOT_PATH_NS("%@/Preferences/%@.plist"), containerPath, specifier.properties[@"defaults"]];
22+
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
23+
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
24+
return (settings[specifier.properties[@"key"]]) ?: specifier.properties[@"default"];
25+
}
26+
27+
- (void)setPreferenceValue:(id)value specifier:(PSSpecifier *)specifier {
28+
NSString *containerPath =
29+
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
30+
NSString *path = [NSString
31+
stringWithFormat:ROOT_PATH_NS("%@/Preferences/%@.plist"), containerPath, specifier.properties[@"defaults"]];
32+
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
33+
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
34+
[settings setObject:value forKey:specifier.properties[@"key"]];
35+
[settings writeToFile:path atomically:YES];
36+
CFStringRef notificationName = (__bridge CFStringRef)specifier.properties[@"PostNotification"];
37+
if (notificationName) {
38+
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL,
39+
YES);
40+
}
41+
}
42+
43+
- (void)resetToDefaults:(PSSpecifier *)specifier {
44+
NSString *containerPath =
45+
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
46+
NSString *path = [NSString
47+
stringWithFormat:ROOT_PATH_NS("%@/Preferences/%@.plist"), containerPath, specifier.properties[@"defaults"]];
48+
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
49+
[settings writeToFile:path atomically:YES];
50+
CFStringRef notificationName = (__bridge CFStringRef)specifier.properties[@"PostNotification"];
51+
if (notificationName) {
52+
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL,
53+
YES);
54+
}
55+
[self reloadSpecifiers];
56+
}
57+
58+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>entry</key>
6+
<dict>
7+
<key>bundle</key>
8+
<string>TrollSpeedPrefs</string>
9+
<key>cell</key>
10+
<string>PSLinkCell</string>
11+
<key>detail</key>
12+
<string>TSPrefsRootListController</string>
13+
<key>icon</key>
14+
<string>icon.png</string>
15+
<key>isController</key>
16+
<true/>
17+
<key>label</key>
18+
<string>TrollSpeed</string>
19+
</dict>
20+
</dict>
21+
</plist>

sources/HUDRootViewController.mm

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <ifaddrs.h>
1111
#import <objc/runtime.h>
1212
#import <mach/vm_param.h>
13+
#import <Foundation/Foundation.h>
1314

1415
#import "HUDPresetPosition.h"
1516
#import "HUDRootViewController.h"
@@ -686,11 +687,60 @@ - (void)setCurrentLandscapePositionY:(CGFloat)positionY
686687
}
687688

688689
#if !NO_TROLL
689-
- (BOOL)usesCustomFontSize { return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomFontSize]; }
690-
- (CGFloat)realCustomFontSize { return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomFontSize]; }
691-
- (BOOL)usesCustomOffset { return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomOffset]; }
692-
- (CGFloat)realCustomOffsetX { return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetX]; }
693-
- (CGFloat)realCustomOffsetY { return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetY]; }
690+
#define PREFS_PATH "/var/mobile/Library/Preferences/ch.xxtou.hudapp.prefs.plist"
691+
692+
- (NSDictionary *)extraUserDefaultsDictionary {
693+
static BOOL isJailbroken = NO;
694+
static dispatch_once_t onceToken;
695+
dispatch_once(&onceToken, ^{
696+
isJailbroken = [[NSFileManager defaultManager]
697+
fileExistsAtPath:ROOT_PATH_NS("/Library/PreferenceBundles/TrollSpeedPrefs.bundle")];
698+
});
699+
if (!isJailbroken) {
700+
return nil;
701+
}
702+
return [NSDictionary dictionaryWithContentsOfFile:ROOT_PATH_NS(PREFS_PATH)];
703+
}
704+
705+
- (BOOL)usesCustomFontSize {
706+
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
707+
if (extraUserDefaults) {
708+
return [extraUserDefaults[HUDUserDefaultsKeyUsesCustomFontSize] boolValue];
709+
}
710+
return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomFontSize];
711+
}
712+
713+
- (CGFloat)realCustomFontSize {
714+
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
715+
if (extraUserDefaults) {
716+
return [extraUserDefaults[HUDUserDefaultsKeyRealCustomFontSize] doubleValue];
717+
}
718+
return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomFontSize];
719+
}
720+
721+
- (BOOL)usesCustomOffset {
722+
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
723+
if (extraUserDefaults) {
724+
return [extraUserDefaults[HUDUserDefaultsKeyUsesCustomOffset] boolValue];
725+
}
726+
return [GetStandardUserDefaults() boolForKey:HUDUserDefaultsKeyUsesCustomOffset];
727+
}
728+
729+
- (CGFloat)realCustomOffsetX {
730+
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
731+
if (extraUserDefaults) {
732+
return [extraUserDefaults[HUDUserDefaultsKeyRealCustomOffsetX] doubleValue];
733+
}
734+
return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetX];
735+
}
736+
737+
- (CGFloat)realCustomOffsetY {
738+
NSDictionary *extraUserDefaults = [self extraUserDefaultsDictionary];
739+
if (extraUserDefaults) {
740+
return [extraUserDefaults[HUDUserDefaultsKeyRealCustomOffsetY] doubleValue];
741+
}
742+
return [GetStandardUserDefaults() doubleForKey:HUDUserDefaultsKeyRealCustomOffsetY];
743+
}
694744
#else
695745
- (BOOL)usesCustomFontSize { return NO; }
696746
- (CGFloat)realCustomFontSize { return HUD_FONT_SIZE; }

0 commit comments

Comments
 (0)