diff --git a/iProxyMacSetup/Classes/PMUIController.m b/iProxyMacSetup/Classes/PMUIController.m index a73ebc9..1b00c6b 100644 --- a/iProxyMacSetup/Classes/PMUIController.m +++ b/iProxyMacSetup/Classes/PMUIController.m @@ -77,11 +77,13 @@ - (void)updateStartButton - (void)updateProxyPopUpButton { [proxyPopUpButton removeAllItems]; - for (NSNetService *service in appDelegate.proxyServiceList) { + for (NSDictionary *proxy in appDelegate.proxyServiceList) { NSString *title; + NSNetService *proxyService; - title = [[NSString alloc] initWithFormat:@"%@.%@", [service name], [service domain]]; - if ([service port] != -1) { + proxyService = [proxy objectForKey:PROXY_SERVICE_KEY]; + title = [[NSString alloc] initWithFormat:@"%@.%@", [proxyService name], [proxyService domain]]; + if ([proxyService port] != -1 || [proxyService port] != 0) { [proxyPopUpButton addItemWithTitle:title]; } else { [proxyPopUpButton addItemWithTitle:[NSString stringWithFormat:@"%@ (disabled)", title]]; @@ -114,7 +116,7 @@ - (void)updateInterfacePopUpButton - (IBAction)startButtonAction:(id)sender { NSDictionary *interfaceInfo; - NSNetService *proxy; + NSDictionary *proxy; [self updateProxyPopUpButton]; [self updateInterfacePopUpButton]; diff --git a/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.h b/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.h index 2bd5ceb..a2e4c40 100644 --- a/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.h +++ b/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.h @@ -11,6 +11,8 @@ #define INTERFACE_NAME @"name" #define INTERFACE_ENABLED @"enabled" +#define PROXY_SERVICE_KEY @"service" + @interface iProxyMacSetupAppDelegate : NSObject { NSMutableArray *proxyServiceList; @@ -34,7 +36,7 @@ @property(retain, nonatomic) NSString *defaultInterface; - (void)startBrowsingServices; -- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSNetService *)proxy; +- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSDictionary *)proxy; - (void)disableProxyForInterface:(NSString *)interface; @end diff --git a/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.m b/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.m index 3d65580..8a406e0 100644 --- a/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.m +++ b/iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.m @@ -45,12 +45,15 @@ - (void)applicationWillTerminate:(NSNotification *)notification - (void)_updateAutomatic { if (automatic) { - NSNetService *proxy = nil; + NSDictionary *proxy = nil; NSDictionary *currentInterface = nil; NSUInteger ii, count = [proxyServiceList count]; for (ii = 0; ii < count; ii++) { - if ([(NSNetService *)[proxyServiceList objectAtIndex:ii] port] != -1 && [(NSNetService *)[proxyServiceList objectAtIndex:ii] port] != 0) { + NSNetService *proxyService; + + proxyService = [[proxyServiceList objectAtIndex:ii] objectForKey:PROXY_SERVICE_KEY]; + if ([proxyService port] != -1 && [proxyService port] != 0) { proxy = [proxyServiceList objectAtIndex:ii]; break; } @@ -222,7 +225,10 @@ - (NSInteger)indexForDomain:(NSString *)domain name:(NSString *)name type:(NSStr - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing { [self willChangeValueForKey:@"proxyServiceList"]; - [proxyServiceList addObject:aNetService]; + NSMutableDictionary *proxy = [[NSMutableDictionary alloc] init]; + [proxy setObject:aNetService forKey:PROXY_SERVICE_KEY]; + [proxyServiceList addObject:proxy]; + [proxy release]; [self didChangeValueForKey:@"proxyServiceList"]; [aNetService setDelegate:self]; [aNetService resolveWithTimeout:20.0]; @@ -286,12 +292,15 @@ - (void)_enableProxyForInterface:(NSString *)interface server:(NSString *)server [task waitUntilExit]; } -- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSNetService *)proxy +- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSDictionary *)proxy { if (!proxyEnabled) { + NSNetService *proxyService; + [self willChangeValueForKey:@"proxyEnabled"]; - if ([proxy port] != -1) { - [self _enableProxyForInterface:interfaceName server:[NSString stringWithFormat:@"%@.%@", [proxy name], [proxy domain]] port:[proxy port]]; + proxyService = [proxy objectForKey:PROXY_SERVICE_KEY]; + if ([proxyService port] != -1) { + [self _enableProxyForInterface:interfaceName server:[NSString stringWithFormat:@"%@.%@", [proxyService name], [proxyService domain]] port:[proxyService port]]; proxyEnabled = YES; proxyEnabledInterfaceName = [interfaceName retain]; }