Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit b194d89

Browse files
committed
fix a bug when dns is not specified
1 parent 64272a5 commit b194d89

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

V2RayX/ConfigWindowController.m

+10-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ - (void)windowDidLoad {
2929
NSDictionary *defaultsDic = [[self delegate] readDefaultsAsDictionary];
3030
[self setLocalPort:[defaultsDic[@"localPort"] integerValue]];
3131
[self setUdpSupport:[defaultsDic[@"udpSupport"] boolValue]];
32-
[self setDnsString:defaultsDic[@"dns"]];
32+
if ([defaultsDic[@"dns"] length] > 0) {
33+
[self setDnsString:defaultsDic[@"dns"]];
34+
} else {
35+
[self setDnsString:@"localhost"];
36+
}
3337
profiles = defaultsDic[@"profiles"];
3438
[_profileTable reloadData];
3539
_selectedServerIndex = [defaultsDic[@"selectedServerIndex"] integerValue];
@@ -104,7 +108,11 @@ - (IBAction)okSave:(id)sender {
104108
}
105109
[defaults setObject:profileDicArray forKey:@"profiles"];
106110
[defaults setObject:[NSNumber numberWithInteger:_selectedServerIndex] forKey:@"selectedServerIndex"];
107-
[defaults setObject:[[_dnsField stringValue] stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"dns"];
111+
NSString* dnsStr = [[_dnsField stringValue] stringByReplacingOccurrencesOfString:@" " withString:@""];
112+
if ([dnsStr length] == 0) {
113+
dnsStr = @"localhost";
114+
}
115+
[defaults setObject:dnsStr forKey:@"dns"];
108116
[[self delegate] configurationDidChange];
109117
[[self window] close];
110118
}

V2RayX/ServerProfile.m

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ - (NSDictionary*)v2rayConfigWithLocalPort:(NSInteger)localPort
6363
NSArray* dnsArray = [[[NSUserDefaults standardUserDefaults] objectForKey:@"dns"] componentsSeparatedByString:@","];
6464
if ([dnsArray count] > 0) {
6565
config[@"dns"][@"servers"] = dnsArray;
66+
} else {
67+
config[@"dns"][@"servers"] = @[@"localhost"];
6668
}
6769
return config;
6870
}

0 commit comments

Comments
 (0)