Skip to content

Commit 8f8320c

Browse files
committed
oh my 5ga
Signed-off-by: 82Flex <82flex@gmail.com>
1 parent d7bafd0 commit 8f8320c

6 files changed

Lines changed: 73 additions & 7 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export PACKAGE_VERSION := 2.0
1+
export PACKAGE_VERSION := 2.1
22

33
ifeq ($(THEOS_DEVICE_SIMULATOR),1)
44
TARGET := simulator:clang:latest:14.0

SingleVPN.x

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
@property (nonatomic, copy) UIColor *textColor;
3838
@property (nonatomic, copy) UIColor *imageDimmedTintColor;
3939
@property (nonatomic, copy) UIColor *imageTintColor;
40+
@property (nonatomic, copy) UIFont *font;
4041
@end
4142

4243
@interface STUIStatusBarStringView : UIView
@@ -47,6 +48,7 @@
4748

4849
@interface STUIStatusBarCellularNetworkTypeView : UIView
4950
@property (nonatomic, strong) STUIStatusBarStringView *stringView;
51+
@property (nonatomic, strong) NSLayoutConstraint *widthConstraint;
5052
@end
5153

5254
@interface STUIStatusBarWifiSignalView : UIView
@@ -57,6 +59,8 @@
5759
static BOOL _isEnabled = NO;
5860
static BOOL _isVPNEnabled = NO;
5961
static BOOL _isEnabledReversed = NO;
62+
static BOOL _isForce5GAEnabled = NO;
63+
6064
static UIColor *_darkReplacementColor = nil;
6165
static UIColor *_lightReplacementColor = nil;
6266

@@ -80,6 +84,7 @@ static void ReloadPrefs() {
8084
NSDictionary *settings = [prefs dictionaryRepresentation];
8185
_isEnabled = settings[@"IsEnabled"] ? [settings[@"IsEnabled"] boolValue] : YES;
8286
_isEnabledReversed = settings[@"IsEnabledReversed"] ? [settings[@"IsEnabledReversed"] boolValue] : NO;
87+
_isForce5GAEnabled = settings[@"IsForce5GAEnabled"] ? [settings[@"IsForce5GAEnabled"] boolValue] : NO;
8388

8489
_lightReplacementColor = svpnColorWithHexString(settings[@"ForegroundColorLight"]) ?: [UIColor colorWithRed:0.19607843137254902 green:0.7803921568627451 blue:0.34901960784313724 alpha:1];
8590
_darkReplacementColor = svpnColorWithHexString(settings[@"ForegroundColorDark"]) ?: [UIColor colorWithRed:0.17254901960784313 green:0.8156862745098039 blue:0.3411764705882353 alpha:1];
@@ -230,7 +235,42 @@ static void ReloadPrefs() {
230235
[styleAttrs setTextColor:svpnColorWithTextColor(styleAttrs.textColor)];
231236
}
232237

233-
%orig;
238+
if (![text hasPrefix:@"5G"] || !_isForce5GAEnabled) {
239+
%orig;
240+
return;
241+
}
242+
243+
if (@available(iOS 16, *)) {
244+
text = @"5GA";
245+
prefixLength = 2;
246+
%orig;
247+
248+
NSMutableAttributedString *attributedText = [self.stringView.attributedText mutableCopy];
249+
UIFont *font = styleAttrs.font;
250+
251+
NSMutableDictionary *traits = [[font.fontDescriptor objectForKey:UIFontDescriptorTraitsAttribute] mutableCopy] ?: [NSMutableDictionary dictionary];
252+
traits[UIFontWidthTrait] = @(UIFontWidthCondensed / 1.5);
253+
traits[UIFontWeightTrait] = @(UIFontWeightSemibold);
254+
UIFontDescriptor *condensedDescriptor = [font.fontDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorTraitsAttribute: traits}];
255+
UIFont *condensedFont = [UIFont fontWithDescriptor:condensedDescriptor size:0];
256+
UIFont *smallerCondensedFont = [condensedFont fontWithSize:condensedFont.pointSize * 0.7];
257+
258+
[attributedText addAttribute:NSFontAttributeName value:condensedFont range:NSMakeRange(0, prefixLength)];
259+
[attributedText addAttribute:NSFontAttributeName value:smallerCondensedFont range:NSMakeRange(prefixLength, attributedText.length - prefixLength)];
260+
261+
self.stringView.attributedText = attributedText;
262+
self.widthConstraint.active = NO;
263+
264+
NSLayoutConstraint *newWidthConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0];
265+
newWidthConstraint.constant = [attributedText size].width * 0.9;
266+
newWidthConstraint.priority = UILayoutPriorityRequired;
267+
newWidthConstraint.active = YES;
268+
269+
objc_setAssociatedObject(self, @selector(widthConstraint), newWidthConstraint, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
270+
} else {
271+
%orig;
272+
return;
273+
}
234274
}
235275

236276
- (void)setAttributedText:(NSAttributedString *)attributedText prefixLength:(NSInteger)prefixLength forType:(NSInteger)type animated:(BOOL)animated {

SingleVPNPrefs/Resources/Root.plist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@
7878
<key>PostNotification</key>
7979
<string>com.82flex.singlevpnprefs/saved</string>
8080
</dict>
81+
<dict>
82+
<key>cell</key>
83+
<string>PSSwitchCell</string>
84+
<key>default</key>
85+
<false/>
86+
<key>defaults</key>
87+
<string>com.82flex.singlevpnprefs</string>
88+
<key>key</key>
89+
<string>IsForce5GAEnabled</string>
90+
<key>label</key>
91+
<string>Show 5G as 5G Advanced</string>
92+
<key>PostNotification</key>
93+
<string>com.82flex.singlevpnprefs/saved</string>
94+
</dict>
8195
<dict>
8296
<key>cell</key>
8397
<string>PSButtonCell</string>

SingleVPNPrefs/Resources/en.lproj/Root.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
"Made with ♥ by OwnGoal Studio" = "Made with ♥ by OwnGoal Studio";
1414
"Please support our paid works, thank you!" = "Please support our paid works, thank you!";
1515
"“Reverse Indicator” will change the appearance of the VPN indicator when the VPN is NOT connected." = "“Reverse Indicator” will change the appearance of the VPN indicator when the VPN is NOT connected.";
16+
"Show 5G as 5G Advanced" = "Show 5G as 5G Advanced";

SingleVPNPrefs/Resources/zh-Hans.lproj/Root.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
"Made with ♥ by OwnGoal Studio" = "「乌龙工作室」倾情献制";
1414
"Please support our paid works, thank you!" = "请支持我们的其他付费作品,谢谢!";
1515
"“Reverse Indicator” will change the appearance of the VPN indicator when the VPN is NOT connected." = "在 VPN 连接时改变网络状态指示器的外观。若打开 “反转指示”,将在未连接时改变其外观。";
16+
"Show 5G as 5G Advanced" = "将 5G 显示为 5G Advanced";

SingleVPNPrefs/SingleVPNRootListController.m

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,31 @@ @implementation SingleVPNRootListController
9595

9696
- (NSArray *)specifiers {
9797
if (!_specifiers) {
98-
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
99-
for (PSSpecifier *specifier in _specifiers) {
100-
NSString *cellClassName = [specifier propertyForKey:@"cellClass"];
98+
NSArray *specs = [self loadSpecifiersFromPlistName:@"Root" target:self];
99+
NSMutableArray *mSpecs = [NSMutableArray arrayWithCapacity:specs.count];
100+
for (PSSpecifier *spec in specs) {
101+
NSString *cellClassName = [spec propertyForKey:@"cellClass"];
101102
if ([cellClassName isKindOfClass:[NSString class]]) {
102-
[specifier setProperty:NSClassFromString(cellClassName) forKey:@"cellClass"];
103+
[spec setProperty:NSClassFromString(cellClassName) forKey:@"cellClass"];
103104
}
105+
if (@available(iOS 17, *)) {
106+
} else {
107+
NSString *key = [spec propertyForKey:@"key"];
108+
if ([key isEqualToString:@"IsForce5GAEnabled"]) {
109+
continue;
110+
}
111+
}
112+
[mSpecs addObject:spec];
104113
}
114+
_specifiers = mSpecs;
105115
}
106116
return _specifiers;
107117
}
108118

109119
- (void)resetAppearance {
110120
for (PSSpecifier *specifier in self.specifiers) {
111121
NSString *key = [specifier propertyForKey:@"key"];
112-
if ([key hasPrefix:@"ForegroundColor"]) {
122+
if ([key hasPrefix:@"ForegroundColor"] || [key isEqualToString:@"IsForce5GAEnabled"]) {
113123
id defaultValue = [specifier propertyForKey:@"default"];
114124
[self setPreferenceValue:defaultValue specifier:specifier];
115125
[self reloadSpecifier:specifier animated:YES];

0 commit comments

Comments
 (0)