8000 the default proxy is kind of useless feature (who will use more than … · ThinkCode/iProxy@17d1443 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17d1443

Browse files
author
Jérôme Lebel
committed
the default proxy is kind of useless feature (who will use more than one proxy on the same network), and implementing the automatic button
1 parent a192f34 commit 17d1443

File tree

3 files changed

+67
-42
lines changed

3 files changed

+67
-42
lines changed

iProxyMacSetup/Classes/PMUIController.m

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,26 @@ - (void)awakeFromNib
2828

2929
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
3030
{
31-
if ([keyPath isEqualToString:@"browsing"]) {
32-
[self updateProgressIndicator];
33-
} else if ([keyPath isEqualToString:@"resolvingServiceCount"]) {
34-
[self updateProgressIndicator];
35-
} else if ([keyPath isEqualToString:@"proxyServiceList"]) {
36-
[self updateStartButton];
37-
[self updateProxyPopUpButton];
38-
} else if ([keyPath isEqualToString:@"interfaceList"]) {
39-
[self updateStartButton];
40-
[self updateInterfacePopUpButton];
41-
} else if ([keyPath isEqualToString:@"proxyEnabled"]) {
42-
[self updateStartButton];
43-
[self updateInterfacePopUpButton];
44-
[self updateProxyPopUpButton];
45-
} else if ([keyPath isEqualToString:@"automatic"]) {
46-
[self updateStartButton];
47-
[self updateInterfacePopUpButton];
48-
[self updateProxyPopUpButton];
31+
if (object == appDelegate) {
32+
if ([keyPath isEqualToString:@"browsing"]) {
33+
[self updateProgressIndicator];
34+
} else if ([keyPath isEqualToString:@"resolvingServiceCount"]) {
35+
[self updateProgressIndicator];
36+
} else if ([keyPath isEqualToString:@"proxyServiceList"]) {
37+
[self updateStartButton];
38+
[self updateProxyPopUpButton];
39+
} else if ([keyPath isEqualToString:@"interfaceList"]) {
40+
[self updateStartButton];
41+
[self updateInterfacePopUpButton];
42+
} else if ([keyPath isEqualToString:@"proxyEnabled"]) {
43+
[self updateStartButton];
44+
[self updateInterfacePopUpButton];
45+
[self updateProxyPopUpButton];
46+
} else if ([keyPath isEqualToString:@"automatic"]) {
47+
[self updateStartButton];
48+
[self updateInterfacePopUpButton];
49+
[self updateProxyPopUpButton];
50+
}
4951
}
5052
}
5153

@@ -74,8 +76,6 @@ - (void)updateStartButton
7476

7577
- (void)updateProxyPopUpButton
7678
{
77-
NSString *defaultProxy = appDelegate.defaultProxy;
78-
7979
[proxyPopUpButton removeAllItems];
8080
for (NSNetService *service in appDelegate.proxyServiceList) {
8181
NSString *title;
@@ -86,9 +86,6 @@ - (void)updateProxyPopUpButton
8686
} else {
8787
[proxyPopUpButton addItemWithTitle:[NSString stringWithFormat:@"%@ (disabled)", title]];
8888
}
89-
if ([defaultProxy isEqualToString:title]) {
90-
[proxyPopUpButton selectItem:[proxyPopUpButton lastItem]];
91-
}
9289
[title release];
9390
}
9491
[proxyPopUpButton setEnabled:!appDelegate.proxyEnabled && !appDelegate.automatic];
@@ -137,7 +134,6 @@ - (IBAction)interfacePopUpButtonAction:(id)sender
137134

138135
- (IBAction)proxyPopUpButtonAction:(id)sender
139136
{
140-
appDelegate.defaultProxy = [appDelegate.proxyServiceList objectAtIndex:[proxyPopUpButton indexOfSelectedItem]];
141137
}
142138

143139
@end

iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
NSUInteger resolvingServiceCount;
2222

2323
NSString *defaultInterface;
24-
NSString *defaultProxy;
2524
NSString *proxyEnabledInterfaceName;
25+
BOOL proxyEnabled;
2626
}
2727

2828
@property(readonly) BOOL browsing;
@@ -32,7 +32,6 @@
3232
@property(readonly) NSArray *proxyServiceList;
3333
@property(readonly) NSArray *interfaceList;
3434
@property(retain, nonatomic) NSString *defaultInterface;
35-
@property(retain, nonatomic) NSString *defaultProxy;
3635

3736
- (void)startBrowsingServices;
3837
- (void)enableForInterface:(NSString *)interfaceName withProxy:(NSNetService *)proxy;

iProxyMacSetup/Classes/iProxyMacSetupAppDelegate.m

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
2929
self.automatic = [[[NSUserDefaults standardUserDefaults] valueForKey:@"AUTOMATIC"] boolValue];
3030
[self fetchInterfaceList];
3131
[self startBrowsingServices];
32+
[self addObserver:self forKeyPath:@"proxyServiceList" options:NSKeyValueObservingOptionNew context:nil];
33+
[self addObserver:self forKeyPath:@"interfaceList" options:NSKeyValueObservingOptionNew context:nil];
3234
}
3335

3436
- (void)applicationWillTerminate:(NSNotification *)notification
@@ -38,6 +40,43 @@ - (void)applicationWillTerminate:(NSNotification *)notification
3840
}
3941
}
4042

43+
- (void)_updateAutomatic
44+
{
45+
if (automatic) {
46+
NSNetService *proxy = nil;
47+
NSDictionary *currentInterface = nil;
48+
NSUInteger ii, count = [proxyServiceList count];
49+
50+
for (ii = 0; ii < count; ii++) {
51+
if ([(NSNetService *)[proxyServiceList objectAtIndex:ii] port] != -1) {
52+
proxy = [proxyServiceList objectAtIndex:ii];
53+
break;
54+
}
55+
}
56+
for (NSDictionary *interface in interfaceList) {
57+
if ([self.defaultInterface isEqualToString:[interface objectForKey:INTERFACE_NAME]]) {
58+
currentInterface = interface;
59+
break;
60+
}
61+
}
62+
if ((!proxy || !currentInterface) && self.proxyEnabled) {
63+
[self disableProxyForInterface:proxyEnabledInterfaceName];
64+
}
65+
if (proxy && currentInterface && !self.proxyEnabled) {
66+
[self enableForInterface:[currentInterface objectForKey:INTERFACE_NAME] withProxy:proxy];
67+
}
68+
}
69+
}
70+
71+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
72+
{
73+
if (object == self) {
74+
if ([keyPath isEqualToString:@"proxyServiceList"] || [keyPath isEqualToString:@"interfaceList"]) {
75+
[self _updateAutomatic];
76+
}
77+
}
78+
}
79+
4180
- (BOOL)automatic
4281
{
4382
return automatic;
@@ -46,11 +85,18 @@ - (BOOL)automatic
4685
- (void)setAutomatic:(BOOL)value
4786
{
4887
if (automatic != value) {
88+
BOOL shouldStop = automatic;
89+
4990
[self willChangeValueForKey:@"automatic"];
5091
automatic = value;
5192
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:automatic] forKey:@"AUTOMATIC"];
5293
[[NSUserDefaults standardUserDefaults] synchronize];
5394
[self didChangeValueForKey:@"automatic"];
95+
96+
if (shouldStop && self.proxyEnabled) {
97+
[self disableProxyForInterface:proxyEnabledInterfaceName];
98+
}
99+
[self _updateAutomatic];
54100
}
55101
}
56102

@@ -225,22 +271,6 @@ - (void)setDefaultInterface:(NSString *)interface
225271
[[NSUserDefaults standardUserDefaults] synchronize];
226272
}
227273

228-
- (NSString *)defaultProxy
229-
{
230-
if (!defaultProxy) {
231-
defaultProxy = [[[NSUserDefaults standardUserDefaults] objectForKey:@"DEFAULT_PROXY"] retain];
232-
}
233-
return defaultProxy;
234-
}
235-
236-
- (void)setDefaultProxy:(NSString *)proxy
237-
{
238-
[defaultProxy release];
239-
defaultProxy = [proxy retain];
240-
[[NSUserDefaults standardUserDefaults] setObject:defaultProxy forKey:@"DEFAULT_PROXY"];
241-
[[NSUserDefaults standardUserDefaults] synchronize];
242-
}
243-
244274
- (void)_enableProxyForInterface:(NSString *)interface server:(NSString *)server port:(NSUInteger)port
245275
{
246276
NSTask *task;

0 commit comments

Comments
 (0)
0