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

Commit

Permalink
refactor user defaults keys
Browse files Browse the repository at this point in the history
Signed-off-by: 82Flex <[email protected]>
  • Loading branch information
Lessica committed Jan 25, 2024
1 parent 6fc7fe3 commit 44441a5
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 151 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ TrollSpeed_CFLAGS += -Isources/KIF
TrollSpeed_CFLAGS += -include supports/hudapp-prefix.pch
MainApplication.mm_CCFLAGS += -std=c++14

TrollSpeed_SWIFT_BRIDGING_HEADER += supports/hudapp-bridging-header.h

TrollSpeed_LDFLAGS += -Flibraries

TrollSpeed_FRAMEWORKS += CoreGraphics CoreServices QuartzCore IOKit UIKit
Expand Down
12 changes: 12 additions & 0 deletions TrollSpeed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
CC91309F2B616541006E3280 /* HUDBackdropLabel.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC91309D2B616541006E3280 /* HUDBackdropLabel.mm */; };
CC9130A32B616C18006E3280 /* HUDBackdropView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC9130A22B616C18006E3280 /* HUDBackdropView.mm */; };
CC9130A42B616C18006E3280 /* HUDBackdropView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CC9130A22B616C18006E3280 /* HUDBackdropView.mm */; };
CC9130A72B62A33A006E3280 /* TSSettingsIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC9130A62B62A33A006E3280 /* TSSettingsIndex.swift */; };
CC9130A82B62A33A006E3280 /* TSSettingsIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC9130A62B62A33A006E3280 /* TSSettingsIndex.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -163,6 +165,8 @@
CC9130A02B616BBF006E3280 /* CAFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CAFilter.h; sourceTree = "<group>"; };
CC9130A12B616C18006E3280 /* HUDBackdropView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HUDBackdropView.h; sourceTree = "<group>"; };
CC9130A22B616C18006E3280 /* HUDBackdropView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = HUDBackdropView.mm; sourceTree = "<group>"; };
CC9130A52B62A262006E3280 /* hudapp-bridging-header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "hudapp-bridging-header.h"; sourceTree = "<group>"; };
CC9130A62B62A33A006E3280 /* TSSettingsIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSSettingsIndex.swift; sourceTree = "<group>"; };
CCB6B6FA2B5C06DD00AD2A89 /* NSUserDefaults+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSUserDefaults+Private.h"; sourceTree = "<group>"; };
CCB6B6FB2B5C074F00AD2A89 /* rootless.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = rootless.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -217,6 +221,7 @@
CC711D922B5BFE66007235A6 /* icon.png */,
CC711D7F2B5BF772007235A6 /* entitlements.plist */,
CC711D7E2B5BF772007235A6 /* hudapp-prefix.pch */,
CC9130A52B62A262006E3280 /* hudapp-bridging-header.h */,
CC711D812B5BFA64007235A6 /* Info.plist */,
CC2BAFE42B5CAF2200A429D1 /* Sandbox-Info.plist */,
CC711D872B5BFCC4007235A6 /* Localizable.strings */,
Expand Down Expand Up @@ -258,6 +263,7 @@
CC711D1F2B5BF5C6007235A6 /* RootViewController.mm */,
CC711D232B5BF5C6007235A6 /* TSEventFetcher.h */,
CC711D472B5BF5C6007235A6 /* TSEventFetcher.mm */,
CC9130A62B62A33A006E3280 /* TSSettingsIndex.swift */,
CC711D462B5BF5C6007235A6 /* TSSettingsController.swift */,
);
path = sources;
Expand Down Expand Up @@ -465,6 +471,7 @@
CC2BAFC82B5CA9DD00A429D1 /* SPLarkController.swift in Sources */,
CC2BAFC92B5CA9DD00A429D1 /* HUDApp.mm in Sources */,
CC2BAFCB2B5CA9DD00A429D1 /* SPLarkSettingsCollectionView.swift in Sources */,
CC9130A82B62A33A006E3280 /* TSSettingsIndex.swift in Sources */,
CC2BAFCC2B5CA9DD00A429D1 /* SPLarkSettingsController.swift in Sources */,
CC2BAFCD2B5CA9DD00A429D1 /* SPLarkControllerExtension.swift in Sources */,
CC2BAFCE2B5CA9DD00A429D1 /* MainApplicationDelegate.mm in Sources */,
Expand All @@ -478,6 +485,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CC9130A72B62A33A006E3280 /* TSSettingsIndex.swift in Sources */,
CC711D4A2B5BF5C6007235A6 /* HUDHelper.mm in Sources */,
CC711D532B5BF5C6007235A6 /* SPLarkPresentingAnimationController.swift in Sources */,
CC711D592B5BF5C6007235A6 /* SPLarkDismissingAnimationController.swift in Sources */,
Expand Down Expand Up @@ -572,6 +580,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "supports/hudapp-bridging-header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -613,6 +622,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "supports/hudapp-bridging-header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -781,6 +791,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "supports/hudapp-bridging-header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -823,6 +834,7 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "supports/hudapp-bridging-header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
87 changes: 42 additions & 45 deletions sources/HUDRootViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -389,48 +389,44 @@ - (void)reloadUserDefaults

HUDPresetPosition selectedMode = [self selectedMode];
BOOL isCentered = (selectedMode == HUDPresetPositionTopCenter || selectedMode == HUDPresetPositionTopCenterMost);
BOOL isCenteredMost = (selectedMode == HUDPresetPositionTopCenterMost);
HUD_SHOW_DOWNLOAD_SPEED_FIRST = isCentered;
HUD_SHOW_SECOND_SPEED_IN_NEW_LINE = !isCentered;
[_speedLabel setTextAlignment:(isCentered ? NSTextAlignmentCenter : NSTextAlignmentLeft)];
[_lockedView setImage:[UIImage systemImageNamed:(isCentered ? @"hand.raised.slash.fill" : @"lock.fill")]];

BOOL singleLineMode = [self singleLineMode];
BOOL usesBitrate = [self usesBitrate];
BOOL usesArrowPrefixes = [self usesArrowPrefixes];
BOOL usesLargeFont = [self usesLargeFont] && !isCenteredMost;
BOOL usesInvertedColor = [self usesInvertedColor];
BOOL hideAtSnapshot = [self hideAtSnapshot];

[_blurView.layer setCornerRadius:(usesLargeFont ? 4.5 : 4.0)];
[_blurView setEffect:(usesInvertedColor ? nil : _blurEffect)];
[_speedLabel setTextAlignment:(isCentered ? NSTextAlignmentCenter : NSTextAlignmentLeft)];
[_speedLabel setColorInvertEnabled:usesInvertedColor];
if (isCentered) {
[_lockedView setImage:[UIImage systemImageNamed:@"hand.raised.slash.fill"]];
} else {
[_lockedView setImage:[UIImage systemImageNamed:@"lock.fill"]];
}
HUD_SHOW_UPLOAD_SPEED = !singleLineMode;

BOOL usesBitrate = [self usesBitrate];
HUD_DATA_UNIT = usesBitrate;
HUD_SHOW_UPLOAD_SPEED = !singleLineMode;
HUD_SHOW_DOWNLOAD_SPEED_FIRST = isCentered;
HUD_SHOW_SECOND_SPEED_IN_NEW_LINE = !isCentered;
HUD_FONT_SIZE = (usesLargeFont ? 9.0 : 8.0);
HUD_FONT_WEIGHT = (usesInvertedColor ? UIFontWeightSemibold : UIFontWeightRegular);
HUD_INACTIVE_OPACITY = (usesInvertedColor ? 1.0 : 0.667);

BOOL usesArrowPrefixes = [self usesArrowPrefixes];
HUD_UPLOAD_PREFIX = (usesArrowPrefixes ? "" : "");
HUD_DOWNLOAD_PREFIX = (usesArrowPrefixes ? "" : "");

prevInputBytes = 0;
prevOutputBytes = 0;
BOOL usesLargeFont = [self usesLargeFont];
HUD_FONT_SIZE = (usesLargeFont ? 9.0 : 8.0);
[_blurView.layer setCornerRadius:(usesLargeFont ? 4.5 : 4.0)];

attributedUploadPrefix = nil;
attributedDownloadPrefix = nil;
BOOL usesInvertedColor = [self usesInvertedColor];
HUD_FONT_WEIGHT = (usesInvertedColor ? UIFontWeightSemibold : UIFontWeightRegular);
HUD_INACTIVE_OPACITY = (usesInvertedColor ? 1.0 : 0.667);
[_blurView setEffect:(usesInvertedColor ? nil : _blurEffect)];
[_speedLabel setColorInvertEnabled:usesInvertedColor];
[_lockedView setHidden:usesInvertedColor];

BOOL hideAtSnapshot = [self hideAtSnapshot];
if (hideAtSnapshot) {
[_containerView setupContainerAsHideContentInScreenshots];
} else {
[_containerView setupContainerAsDisplayContentInScreenshots];
}

prevInputBytes = 0;
prevOutputBytes = 0;
attributedUploadPrefix = nil;
attributedDownloadPrefix = nil;

[self removeAllAnimations];
[self resetGestureRecognizers];
[self updateViewConstraints];
Expand All @@ -446,97 +442,97 @@ - (void)reloadUserDefaults

+ (BOOL)passthroughMode
{
return [[[NSDictionary dictionaryWithContentsOfFile:(ROOT_PATH_NS_VAR(USER_DEFAULTS_PATH))] objectForKey:@"passthroughMode"] boolValue];
return [[[NSDictionary dictionaryWithContentsOfFile:(ROOT_PATH_NS_VAR(USER_DEFAULTS_PATH))] objectForKey:HUDUserDefaultsKeyPassthroughMode] boolValue];
}

- (HUDPresetPosition)selectedMode
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"selectedMode"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeySelectedMode];
return mode != nil ? (HUDPresetPosition)[mode integerValue] : HUDPresetPositionTopCenter;
}

- (BOOL)singleLineMode
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"singleLineMode"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeySingleLineMode];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)usesBitrate
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"usesBitrate"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyUsesBitrate];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)usesArrowPrefixes
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"usesArrowPrefixes"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyUsesArrowPrefixes];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)usesLargeFont
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"usesLargeFont"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyUsesLargeFont];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)usesRotation
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"usesRotation"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyUsesRotation];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)usesInvertedColor
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"usesInvertedColor"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyUsesInvertedColor];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)keepInPlace
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"keepInPlace"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyKeepInPlace];
return mode != nil ? [mode boolValue] : NO;
}

- (BOOL)hideAtSnapshot
{
[self loadUserDefaults:NO];
NSNumber *mode = [_userDefaults objectForKey:@"hideAtSnapshot"];
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyHideAtSnapshot];
return mode != nil ? [mode boolValue] : NO;
}

- (CGFloat)currentPositionY
{
[self loadUserDefaults:NO];
NSNumber *positionY = [_userDefaults objectForKey:@"currentPositionY"];
NSNumber *positionY = [_userDefaults objectForKey:HUDUserDefaultsKeyCurrentPositionY];
return positionY != nil ? [positionY doubleValue] : CGFLOAT_MAX;
}

- (void)setCurrentPositionY:(CGFloat)positionY
{
[self loadUserDefaults:NO];
[_userDefaults setObject:[NSNumber numberWithDouble:positionY] forKey:@"currentPositionY"];
[_userDefaults setObject:[NSNumber numberWithDouble:positionY] forKey:HUDUserDefaultsKeyCurrentPositionY];
[self saveUserDefaults];
}

- (CGFloat)currentLandscapePositionY
{
[self loadUserDefaults:NO];
NSNumber *positionY = [_userDefaults objectForKey:@"currentLandscapePositionY"];
NSNumber *positionY = [_userDefaults objectForKey:HUDUserDefaultsKeyCurrentLandscapePositionY];
return positionY != nil ? [positionY doubleValue] : CGFLOAT_MAX;
}

- (void)setCurrentLandscapePositionY:(CGFloat)positionY
{
[self loadUserDefaults:NO];
[_userDefaults setObject:[NSNumber numberWithDouble:positionY] forKey:@"currentLandscapePositionY"];
[_userDefaults setObject:[NSNumber numberWithDouble:positionY] forKey:HUDUserDefaultsKeyCurrentLandscapePositionY];
[self saveUserDefaults];
}

Expand Down Expand Up @@ -659,11 +655,6 @@ - (void)updateViewConstraints
[NSLayoutConstraint deactivateConstraints:_constraints];
[_constraints removeAllObjects];

HUDPresetPosition selectedMode = [self selectedMode];
BOOL isCentered = (selectedMode == HUDPresetPositionTopCenter || selectedMode == HUDPresetPositionTopCenterMost);
BOOL isCenteredMost = (selectedMode == HUDPresetPositionTopCenterMost);
BOOL isPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);

#if !NO_TROLL
UIInterfaceOrientation orientation = _remoteOrientation;
#else
Expand All @@ -677,6 +668,12 @@ - (void)updateViewConstraints
} else {
isLandscape = UIInterfaceOrientationIsLandscape(orientation);
}

HUDPresetPosition selectedMode = [self selectedMode];
BOOL isCentered = (selectedMode == HUDPresetPositionTopCenter || selectedMode == HUDPresetPositionTopCenterMost);
BOOL isCenteredMost = (selectedMode == HUDPresetPositionTopCenterMost);
BOOL isPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);

_blurView.layer.maskedCorners = (isCenteredMost && !isLandscape) ? kCornerMaskBottom : kCornerMaskAll;

UILayoutGuide *layoutGuide = self.view.safeAreaLayoutGuide;
Expand Down
Loading

0 comments on commit 44441a5

Please sign in to comment.