diff --git a/Common/ACPreferences.h b/Common/ACPreferences.h index c22424a..403ac64 100644 --- a/Common/ACPreferences.h +++ b/Common/ACPreferences.h @@ -60,6 +60,13 @@ extern NSString * const kACMenuBarImageDidChange; -(void)setDisabledCheckForUpdatesAutomatically:(BOOL)inValue; +/** + Enable auto connecting to max one service. + */ +-(BOOL)singleAutoConnect; +-(void)setSingleAutoConnect:(BOOL)inValue; + + /** Menu Bar Images */ diff --git a/Common/ACPreferences.m b/Common/ACPreferences.m index f2d34de..306d08f 100644 --- a/Common/ACPreferences.m +++ b/Common/ACPreferences.m @@ -20,6 +20,7 @@ NSString * const kAlwaysConnectedRetryDelayPrefKey = @"AlwaysConnectedRetryDelay"; NSString * const kDisabledCheckForUpdatesAutomaticallyPrefKey = @"DisabledCheckForUpdatesAutomatically"; +NSString * const kSingleAutoConnectPrefKey = @"SingleAutoConnect"; NSString * const kMenuBarImageTypePrefKey = @"MenuBarImageType"; NSString * const kACConfigurationDidChange = @"kACConfigurationDidChange"; @@ -68,7 +69,8 @@ -(void)setAlwaysConnected:(BOOL)inAlwaysConnected forServicesIdentifier:(NSStrin services = [[NSMutableArray alloc] init]; } - for(NSDictionary *service in services) + // Use a copy to avoid looping through an array that is being modified during the loop + for(NSDictionary *service in [services copy]) { NSString *serviceIdentifier = service[kServiceIdentifierKey]; if([serviceIdentifier isEqualToString:inServiceIdentifier]) @@ -80,7 +82,14 @@ -(void)setAlwaysConnected:(BOOL)inAlwaysConnected forServicesIdentifier:(NSStrin [services addObject:updatedServiceDictionary]; serviceFound = YES; - break; + } + else if(inAlwaysConnected && [self singleAutoConnect]) + { + NSMutableDictionary *updatedServiceDictionary = [service mutableCopy]; + updatedServiceDictionary[kServiceAlwaysConnectedKey] = [NSNumber numberWithBool:false]; + + [services removeObject:service]; + [services addObject:updatedServiceDictionary]; } } @@ -202,6 +211,16 @@ -(void)setDisabledCheckForUpdatesAutomatically:(BOOL)inValue [[NSUserDefaults standardUserDefaults] setBool:inValue forKey:kDisabledCheckForUpdatesAutomaticallyPrefKey]; } +-(BOOL)singleAutoConnect +{ + return [[NSUserDefaults standardUserDefaults] boolForKey:kSingleAutoConnectPrefKey]; +} + +-(void)setSingleAutoConnect:(BOOL)inValue +{ + [[NSUserDefaults standardUserDefaults] setBool:inValue forKey:kSingleAutoConnectPrefKey]; +} + -(MenuBarImageType)menuBarImageType { return [[NSUserDefaults standardUserDefaults] integerForKey:kMenuBarImageTypePrefKey]; diff --git a/VPNStatus/Base.lproj/ACCrossPromotionWindow.xib b/VPNStatus/Base.lproj/ACCrossPromotionWindow.xib index 57f0d2f..5a0beff 100644 --- a/VPNStatus/Base.lproj/ACCrossPromotionWindow.xib +++ b/VPNStatus/Base.lproj/ACCrossPromotionWindow.xib @@ -1,8 +1,8 @@ - + - + @@ -17,7 +17,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -154,7 +154,7 @@ - + @@ -230,7 +230,7 @@ - + @@ -238,7 +238,7 @@ - + diff --git a/VPNStatus/Base.lproj/ACPreferencesAboutView.xib b/VPNStatus/Base.lproj/ACPreferencesAboutView.xib index c852fb3..7fccd36 100644 --- a/VPNStatus/Base.lproj/ACPreferencesAboutView.xib +++ b/VPNStatus/Base.lproj/ACPreferencesAboutView.xib @@ -1,8 +1,8 @@ - + - + @@ -27,7 +27,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -43,7 +43,7 @@ - + diff --git a/VPNStatus/Base.lproj/ACPreferencesGeneralView.xib b/VPNStatus/Base.lproj/ACPreferencesGeneralView.xib index 332a371..357e7e8 100644 --- a/VPNStatus/Base.lproj/ACPreferencesGeneralView.xib +++ b/VPNStatus/Base.lproj/ACPreferencesGeneralView.xib @@ -1,8 +1,8 @@ - + - + @@ -11,6 +11,7 @@ + @@ -20,15 +21,15 @@ - - + + - + @@ -36,8 +37,8 @@ - - + + @@ -54,16 +55,16 @@ - - + + - - + + @@ -71,7 +72,7 @@ - - + + + - + @@ -111,14 +122,23 @@ - + + + + + + + + + + @@ -128,27 +148,33 @@ + - + + - + + + + + - + diff --git a/VPNStatus/PreferencesUI/ACPreferencesGeneralViewController.m b/VPNStatus/PreferencesUI/ACPreferencesGeneralViewController.m index 7d2f63f..555ed31 100644 --- a/VPNStatus/PreferencesUI/ACPreferencesGeneralViewController.m +++ b/VPNStatus/PreferencesUI/ACPreferencesGeneralViewController.m @@ -13,6 +13,7 @@ @interface ACPreferencesGeneralViewController () @property (weak) IBOutlet NSTextField *retryDelayField; @property (weak) IBOutlet NSButton *automaticCheckForUpdatesButton; +@property (weak) IBOutlet NSButton *singleAutoConnectButton; @property (weak) IBOutlet NSPopUpButton *menuBarImagePopUpButton; @end @@ -47,6 +48,16 @@ - (void)viewDidLoad [self.automaticCheckForUpdatesButton setState:NSControlStateValueOn]; } + BOOL singleAutoConnect = [[ACPreferences sharedPreferences] singleAutoConnect]; + if(singleAutoConnect) + { + [self.singleAutoConnectButton setState:NSControlStateValueOn]; + } + else + { + [self.singleAutoConnectButton setState:NSControlStateValueOff]; + } + NSMenu *theMenu = self.menuBarImagePopUpButton.menu; for(NSInteger menuItemIndex = 0 ; menuItemIndex < theMenu.numberOfItems ; menuItemIndex++) { @@ -94,6 +105,12 @@ - (IBAction)doCheckForUpdatesAutomatically:(id)sender [[ACPreferences sharedPreferences] setDisabledCheckForUpdatesAutomatically:(checkbox.state != NSControlStateValueOn)]; } +- (IBAction)doSingleAutoConnect:(id)sender +{ + NSButton *checkbox = (NSButton *)sender; + [[ACPreferences sharedPreferences] setSingleAutoConnect:(checkbox.state != NSControlStateValueOff)]; +} + - (IBAction)doChangeMenuBarImage:(id)sender { NSInteger menuBarImageType = [sender indexOfSelectedItem];