Skip to content

Commit

Permalink
Merge pull request ish-app#2451 from saagarjha/master
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Sep 4, 2024
2 parents b8fcb16 + 265a4ff commit 1223ead
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
proc_ish_version = strdup(ishVersion.UTF8String);
// this defaults key is set when taking app store screenshots
extern const char *uname_hostname_override;
NSString *hostnameOverride = [NSUserDefaults.standardUserDefaults stringForKey:@"hostnameOverride"];
NSString *hostnameOverride = UserPreferences.shared._hostnameOverride;
if (@available(iOS 16.0, *)) { // Hostname obfuscation is in effect
hostnameOverride = hostnameOverride ? hostnameOverride : UserPreferences.shared.hostnameOverride;
}
if (hostnameOverride) {
uname_hostname_override = strdup(uname_hostname_override);
uname_hostname_override = strdup(hostnameOverride.UTF8String);
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions app/UserPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ extern NSString *const kThemeBackgroundColor;
@property (readonly) UIStatusBarStyle statusBarStyle;
@property NSArray<NSString *> *launchCommand;
@property NSArray<NSString *> *bootCommand;
@property NSString *hostnameOverride;
// Same as above but returns nil if the user has never set the hostname
@property (readonly) NSString *_hostnameOverride;

+ (instancetype)shared;

Expand All @@ -78,5 +81,6 @@ extern NSString *const kThemeBackgroundColor;

extern NSString *const kPreferenceLaunchCommandKey;
extern NSString *const kPreferenceBootCommandKey;
extern NSString *const kHostnameOverrideKey;

NS_ASSUME_NONNULL_END
28 changes: 27 additions & 1 deletion app/UserPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
static NSString *const kPreferenceBlinkCursorKey = @"Blink Cursor";
NSString *const kPreferenceHideStatusBarKey = @"Status Bar";
static NSString *const kPreferenceColorSchemeKey = @"Color Scheme";
// This key has a different naming scheme because it's used in UI tests as a
// CLI argument.
NSString *const kHostnameOverrideKey = @"hostnameOverride";

NSDictionary<NSString *, NSString *> *friendlyPreferenceMapping;
NSDictionary<NSString *, NSString *> *friendlyPreferenceReverseMapping;
NSDictionary<NSString *, NSString *> *kvoProperties;

static NSString *const kSystemMonospacedFontName = @"ui-monospace";

@interface UserPreferences ()
@interface UserPreferences () {
BOOL _hostnameIsOverridden;
}
- (void)updateTheme;
@end

Expand Down Expand Up @@ -144,6 +149,7 @@ + (instancetype)shared {

- (instancetype)init {
self = [super init];
self->_hostnameIsOverridden = !![NSUserDefaults.standardUserDefaults stringForKey:kHostnameOverrideKey];
if (self) {
_defaults = [NSUserDefaults standardUserDefaults];
[_defaults registerDefaults:@{
Expand All @@ -161,6 +167,7 @@ - (instancetype)init {
kPreferenceHideStatusBarKey: @(NO),
kPreferenceColorSchemeKey: @(ColorSchemeMatchSystem),
kPreferenceThemeKey: @"Default",
kHostnameOverrideKey: UIDevice.currentDevice.name,
}];
// https://webkit.org/blog/10247/new-webkit-features-in-safari-13-1/
if (@available(iOS 13.4, *)) {
Expand Down Expand Up @@ -194,6 +201,7 @@ - (instancetype)init {
@"hide_status_bar": kPreferenceHideStatusBarKey,
@"color_scheme": kPreferenceColorSchemeKey,
@"theme": kPreferenceThemeKey,
@"hostname_override": kHostnameOverrideKey,
};
NSMutableDictionary <NSString *, NSString *> *reverseMapping = [NSMutableDictionary new];
for (NSString *key in friendlyPreferenceMapping) {
Expand Down Expand Up @@ -517,6 +525,7 @@ - (BOOL)validateHideStatusBar:(id *)value error:(NSError **)error {
return [*value isKindOfClass:NSNumber.class];
}

// MARK: colorScheme
- (ColorScheme)colorScheme {
return [_defaults integerForKey:kPreferenceColorSchemeKey];
}
Expand All @@ -533,6 +542,23 @@ - (BOOL)validateColorScheme:(id *)value error:(NSError **)error {
return _value >= __ColorSchemeFirst && _value < __ColorSchemeLast;
}

// MARK: hostnameOverride
- (NSString *)hostnameOverride {
return [_defaults stringForKey:kHostnameOverrideKey];
}

- (void)setHostnameOverride:(NSString *)hostnameOverride {
[_defaults setValue:hostnameOverride forKey:kHostnameOverrideKey];
}

- (BOOL)validateHostnameOverride:(id *)value error:(NSError **)error {
return [*value isKindOfClass:NSString.class];
}

- (NSString *)_hostnameOverride {
return _hostnameIsOverridden ? self.hostnameOverride : nil;
}

+ (BOOL)systemThemeIsDark {
if (@available(iOS 12.0, *)) {
switch (UIScreen.mainScreen.traitCollection.userInterfaceStyle) {
Expand Down

0 comments on commit 1223ead

Please sign in to comment.