From ab88e1b65c76141f1b0503a8b1304476a1c4224f Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Mon, 25 Jan 2021 06:23:48 +0300 Subject: [PATCH] Use NSSet for broken feed URL lookup. --- Application/AppController.m | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Application/AppController.m b/Application/AppController.m index d2f161728..2de63b559 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -372,12 +372,8 @@ [userDefaultsValuesDict setObject:[NSNumber numberWithInt:8] forKey:@"hotKeySpamKeyCode"]; [userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSEventModifierFlagControl|NSEventModifierFlagCommand)] forKey:@"hotKeySpamModifiers"]; - NSString * feedURLdefault = @"https://f.losno.co/cog/mercury.xml"; - NSString * feedURLbroken = @"https://kode54.net/cog/stable.xml"; - NSString * feedURLbroken2 = @"https://kode54.net/cog/mercury.xml"; - NSString * feedURLbroken3 = @"https://www.kode54.net/cog/mercury.xml"; - [userDefaultsValuesDict setObject:feedURLdefault forKey:@"SUFeedURL"]; - + NSString *feedURLdefault = @"https://f.losno.co/cog/mercury.xml"; + [userDefaultsValuesDict setObject:feedURLdefault forKey:@"SUFeedURL"]; [userDefaultsValuesDict setObject:@"clearAndPlay" forKey:@"openingFilesBehavior"]; [userDefaultsValuesDict setObject:@"enqueue" forKey:@"openingFilesAlteredBehavior"]; @@ -399,13 +395,18 @@ //Register and sync defaults [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; [[NSUserDefaults standardUserDefaults] synchronize]; - + //And if the existing feed URL is broken due to my ineptitude with the above defaults, fix it - if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"] isEqualToString:feedURLbroken] || - [[[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"] isEqualToString:feedURLbroken2] || - [[[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"] isEqualToString:feedURLbroken3]) + NSSet *brokenFeedURLs = [NSSet setWithObjects: + @"https://kode54.net/cog/stable.xml", + @"https://kode54.net/cog/mercury.xml" + @"https://www.kode54.net/cog/mercury.xml", + nil]; + NSString *feedURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"]; + if ([brokenFeedURLs containsObject:feedURL]) { [[NSUserDefaults standardUserDefaults] setValue:feedURLdefault forKey:@"SUFeedURL"]; - + } + //Add observers [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyPlayKeyCode" options:0 context:nil]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyPreviousKeyCode" options:0 context:nil];