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

Commit 0d89ae9

Browse files
committed
add DNS support
1 parent 12194cb commit 0d89ae9

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

V2RayX/AppDelegate.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ - (NSDictionary*)readDefaultsAsDictionary {
201201
if (dUdpSupport == nil) {
202202
dUdpSupport = [NSNumber numberWithBool:NO];// do not support udp as default
203203
}
204+
NSString *dDnsString = [defaults objectForKey:@"dns"];
205+
if (dDnsString == nil) {
206+
dDnsString = @"";
207+
}
204208
NSMutableArray *dProfilesInPlist = [defaults objectForKey:@"profiles"];
205209
NSMutableArray *dProfiles = [[NSMutableArray alloc] init];
206210
NSNumber *dServerIndex;
@@ -231,7 +235,8 @@ - (NSDictionary*)readDefaultsAsDictionary {
231235
@"localPort": dLocalPort,
232236
@"udpSupport": dUdpSupport,
233237
@"profiles": dProfiles,
234-
@"selectedServerIndex": dServerIndex };
238+
@"selectedServerIndex": dServerIndex,
239+
@"dns":dDnsString};
235240
}
236241

237242

V2RayX/ConfigWindow.xib

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<connections>
1111
<outlet property="addRemoveButton" destination="Pgq-bB-pvc" id="m1r-QX-zw6"/>
1212
<outlet property="alterIdField" destination="0MA-zS-uMD" id="Fgh-F0-USD"/>
13+
<outlet property="dnsField" destination="mXE-pr-Ddc" id="Eap-sE-WYI"/>
1314
<outlet property="globalTransportButton" destination="L0C-0n-d5i" id="GRx-qD-mvf"/>
1415
<outlet property="localPortField" destination="2do-qQ-ANK" id="OIL-pR-1TG"/>
1516
<outlet property="portField" destination="vAX-58-HRK" id="l6R-dx-TNq"/>
@@ -22,14 +23,14 @@
2223
<window title="V2RayX" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" animationBehavior="default" id="QvC-M9-y7g">
2324
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
2425
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
25-
<rect key="contentRect" x="196" y="240" width="480" height="344"/>
26+
<rect key="contentRect" x="196" y="240" width="480" height="394"/>
2627
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
2728
<view key="contentView" id="EiT-Mj-1SZ">
28-
<rect key="frame" x="0.0" y="0.0" width="480" height="344"/>
29+
<rect key="frame" x="0.0" y="0.0" width="480" height="394"/>
2930
<autoresizingMask key="autoresizingMask"/>
3031
<subviews>
3132
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HKJ-PD-NRo">
32-
<rect key="frame" x="18" y="305" width="69" height="17"/>
33+
<rect key="frame" x="18" y="355" width="69" height="17"/>
3334
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
3435
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Local Port:" id="FRd-8H-tqe">
3536
<font key="font" metaFont="system"/>
@@ -38,7 +39,7 @@
3839
</textFieldCell>
3940
</textField>
4041
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2do-qQ-ANK">
41-
<rect key="frame" x="93" y="302" width="96" height="22"/>
42+
<rect key="frame" x="93" y="352" width="96" height="22"/>
4243
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
4344
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="jN0-7e-Eex">
4445
<numberFormatter key="formatter" formatterBehavior="default10_4" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="42" id="mKI-i3-kT1"/>
@@ -56,7 +57,7 @@
5657
</connections>
5758
</textField>
5859
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZkQ-S8-swW">
59-
<rect key="frame" x="210" y="304" width="102" height="18"/>
60+
<rect key="frame" x="210" y="354" width="102" height="18"/>
6061
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
6162
<buttonCell key="cell" type="check" title="Support UDP" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="pEW-Gw-3ph">
6263
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -67,7 +68,7 @@
6768
</connections>
6869
</button>
6970
<textField horizontalHuggingPriority="251" verticalHuggingPriority="749" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="reb-n0-jKg">
70-
<rect key="frame" x="18" y="281" width="382" height="17"/>
71+
<rect key="frame" x="18" y="331" width="382" height="17"/>
7172
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
7273
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="If the local port is changed, the pac file also needs manual modification." id="nRL-kf-uam">
7374
<font key="font" metaFont="smallSystem"/>
@@ -76,9 +77,48 @@
7677
</textFieldCell>
7778
</textField>
7879
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="dbj-78-WGX">
79-
<rect key="frame" x="12" y="270" width="456" height="5"/>
80+
<rect key="frame" x="20" y="270" width="440" height="5"/>
8081
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
8182
</box>
83+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lgk-bl-Vga">
84+
<rect key="frame" x="18" y="306" width="35" height="17"/>
85+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
86+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="DNS:" id="sKs-KL-14B">
87+
<font key="font" metaFont="system"/>
88+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
89+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
90+
</textFieldCell>
91+
</textField>
92+
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mXE-pr-Ddc">
93+
<rect key="frame" x="59" y="304" width="401" height="22"/>
94+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
95+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="jCM-1U-byE">
96+
<font key="font" metaFont="system"/>
97+
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
98+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
99+
</textFieldCell>
100+
<connections>
101+
<binding destination="-2" name="value" keyPath="self.dnsString" id="Y1a-JG-9Wu"/>
102+
</connections>
103+
</textField>
104+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="749" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ecy-ho-llN">
105+
<rect key="frame" x="18" y="281" width="382" height="17"/>
106+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
107+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="seperated by comma(,)" id="5N8-C0-QJV">
108+
<font key="font" metaFont="smallSystem"/>
109+
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
110+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
111+
</textFieldCell>
112+
</textField>
113+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tIh-r8-4RU">
114+
<rect key="frame" x="18" y="247" width="93" height="17"/>
115+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
116+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="V2Ray Servers" id="UpZ-NV-drp">
117+
<font key="font" metaFont="system"/>
118+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
119+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
120+
</textFieldCell>
121+
</textField>
82122
<scrollView fixedFrame="YES" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="18l-QB-TVo">
83123
<rect key="frame" x="20" y="80" width="140" height="159"/>
84124
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -325,15 +365,6 @@ Gw
325365
<action selector="cancel:" target="-2" id="blN-np-Jtr"/>
326366
</connections>
327367
</button>
328-
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tIh-r8-4RU">
329-
<rect key="frame" x="18" y="247" width="93" height="17"/>
330-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
331-
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="V2Ray Servers" id="UpZ-NV-drp">
332-
<font key="font" metaFont="system"/>
333-
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
334-
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
335-
</textFieldCell>
336-
</textField>
337368
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Pgq-bB-pvc">
338369
<rect key="frame" x="20" y="60" width="140" height="23"/>
339370
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -368,7 +399,7 @@ Gw
368399
</button>
369400
</subviews>
370401
</view>
371-
<point key="canvasLocation" x="127" y="275"/>
402+
<point key="canvasLocation" x="127" y="300"/>
372403
</window>
373404
</objects>
374405
<resources>

V2RayX/ConfigWindowController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@property (weak) IBOutlet NSTextField *portField;
2727
@property (weak) IBOutlet NSTextField *alterIdField;
2828
@property (weak) IBOutlet NSButton *globalTransportButton;
29+
@property (weak) IBOutlet NSTextField *dnsField;
2930

3031
@property (weak) IBOutlet NSWindow* transportWindow;
3132
//kcp fields
@@ -44,9 +45,10 @@
4445
@property (weak) IBOutlet NSTextField *wsPathField;
4546

4647

47-
@property (nonatomic, strong) ServerProfile* selectedProfile;
48+
@property (nonatomic, weak) ServerProfile* selectedProfile;
4849
@property NSInteger selectedServerIndex;
4950
@property NSInteger localPort;
5051
@property BOOL udpSupport;
52+
@property (nonatomic, weak) NSString* dnsString;
5153
@property (nonatomic, weak) id<ConfigWindowControllerDelegate> delegate;
5254
@end

V2RayX/ConfigWindowController.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ - (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"]];
3233
profiles = defaultsDic[@"profiles"];
3334
[_profileTable reloadData];
3435
_selectedServerIndex = [defaultsDic[@"selectedServerIndex"] integerValue];
@@ -109,7 +110,7 @@ - (IBAction)okSave:(id)sender {
109110
}
110111
[defaults setObject:profileDicArray forKey:@"profiles"];
111112
[defaults setObject:[NSNumber numberWithInteger:_selectedServerIndex] forKey:@"selectedServerIndex"];
112-
113+
[defaults setObject:[[_dnsField stringValue] stringByReplacingOccurrencesOfString:@" " withString:@""] forKey:@"dns"];
113114
[[self delegate] configurationDidChange];
114115
[[self window] close];
115116
}
@@ -199,4 +200,5 @@ - (IBAction)transportHelp:(id)sender {
199200
@synthesize selectedProfile;
200201
@synthesize localPort;
201202
@synthesize udpSupport;
203+
@synthesize dnsString;
202204
@end

V2RayX/ServerProfile.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ - (NSDictionary*)v2rayConfigWithLocalPort:(NSInteger)localPort
6060
if ([self.useMkcp boolValue] == true) {
6161
config[@"outbound"][@"streamSettings"] = @{@"network": @"kcp"};
6262
}
63+
config[@"dns"][@"servers"] = [[[NSUserDefaults standardUserDefaults] objectForKey:@"dns"] componentsSeparatedByString:@","];
6364
return config;
6465
}
6566

0 commit comments

Comments
 (0)