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

Commit 6b8b118

Browse files
committed
share over LAN
1 parent b3e0fc7 commit 6b8b118

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

V2RayX/AppDelegate.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ - (void) writeDefaultSettings {
9393
@"selectedServerIndex": [NSNumber numberWithInteger:0],
9494
@"localPort": [NSNumber numberWithInteger:1081],
9595
@"udpSupport": [NSNumber numberWithBool:NO],
96+
@"shareOverLan": [NSNumber numberWithBool:NO],
9697
@"dns": @"localhost",
9798
@"useTLS": [NSNumber numberWithBool:NO],
9899
@"tlsSettings": @{
@@ -254,6 +255,7 @@ - (NSDictionary*)readDefaultsAsDictionary {
254255
NSNumber *dMode = nilCoalescing([defaults objectForKey:@"proxyMode"], @0); // use v2ray rules as defualt mode
255256
NSNumber* dLocalPort = nilCoalescing([defaults objectForKey:@"localPort"], @1081);//use 1081 as default local port
256257
NSNumber* dUdpSupport = nilCoalescing([defaults objectForKey:@"udpSupport"], [NSNumber numberWithBool:NO]);// do not support udp as default
258+
NSNumber* dShareOverLan = nilCoalescing([defaults objectForKey:@"shareOverLan"], [NSNumber numberWithBool:NO]); //do not share over lan as default
257259
NSString *dDnsString = nilCoalescing([defaults objectForKey:@"dns"], @"");
258260
NSMutableArray *dProfilesInPlist = [defaults objectForKey:@"profiles"];
259261
NSMutableArray *dProfiles = [[NSMutableArray alloc] init];
@@ -285,6 +287,7 @@ - (NSDictionary*)readDefaultsAsDictionary {
285287
@"proxyMode": dMode,
286288
@"localPort": dLocalPort,
287289
@"udpSupport": dUdpSupport,
290+
@"shareOverLan": dShareOverLan,
288291
@"profiles": dProfiles,
289292
@"selectedServerIndex": dServerIndex,
290293
@"dns":dDnsString};
@@ -301,7 +304,7 @@ -(void)unloadV2ray {
301304
-(BOOL)loadV2ray {
302305
NSString *configPath = [NSString stringWithFormat:@"%@/Library/Application Support/V2RayX/config.json",NSHomeDirectory()];
303306
printf("proxy mode is %ld\n", (long)proxyMode);
304-
NSDictionary *configDic = [[profiles objectAtIndex:selectedServerIndex] v2rayConfigWithLocalPort:localPort udpSupport:udpSupport v2rayRules:proxyMode == 0];
307+
NSDictionary *configDic = [[profiles objectAtIndex:selectedServerIndex] v2rayConfigWithRules:proxyMode == 0];
305308
NSData* v2rayJSONconfig = [NSJSONSerialization dataWithJSONObject:configDic options:NSJSONWritingPrettyPrinted error:nil];
306309
[v2rayJSONconfig writeToFile:configPath atomically:NO];
307310
[self generateLaunchdPlist:plistPath];

V2RayX/ConfigWindow.xib

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,22 @@ Gw
441441
<action selector="cancel:" target="-2" id="blN-np-Jtr"/>
442442
</connections>
443443
</button>
444+
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HGo-i2-l4d">
445+
<rect key="frame" x="325" y="378" width="119" height="18"/>
446+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
447+
<buttonCell key="cell" type="check" title="Share Over LAN" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="TXX-VD-4P4">
448+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
449+
<font key="font" metaFont="system"/>
450+
</buttonCell>
451+
<connections>
452+
<binding destination="-2" name="value" keyPath="self.shareOverLan" id="eeF-vl-cmx"/>
453+
</connections>
454+
</button>
444455
</subviews>
445456
</view>
446457
<point key="canvasLocation" x="162.5" y="312"/>
447458
</window>
459+
<userDefaultsController representsSharedInstance="YES" id="I7n-bF-Cph"/>
448460
</objects>
449461
<resources>
450462
<image name="NSAddTemplate" width="11" height="11"/>

V2RayX/ConfigWindowController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
@property NSInteger selectedServerIndex;
5454
@property NSInteger localPort;
5555
@property BOOL udpSupport;
56+
@property BOOL shareOverLan;
5657
@property (nonatomic, weak) NSString* dnsString;
5758
@property (nonatomic, weak) id<ConfigWindowControllerDelegate> delegate;
5859
@end

V2RayX/ConfigWindowController.m

Lines changed: 3 additions & 0 deletions
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 setShareOverLan:[defaultsDic[@"shareOverLan"] boolValue]];
3233
if ([defaultsDic[@"dns"] length] > 0) {
3334
[self setDnsString:defaultsDic[@"dns"]];
3435
} else {
@@ -101,6 +102,7 @@ - (IBAction)okSave:(id)sender {
101102
// save settings to file
102103
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
103104
[defaults setObject:[NSNumber numberWithBool:udpSupport] forKey:@"udpSupport"];
105+
[defaults setObject:[NSNumber numberWithBool:shareOverLan] forKey:@"shareOverLan"];
104106
[defaults setObject:[NSNumber numberWithInteger:localPort] forKey:@"localPort"];
105107
NSMutableArray* profileDicArray = [[NSMutableArray alloc] init];
106108
for (ServerProfile *p in profiles) {
@@ -235,5 +237,6 @@ - (IBAction)transportHelp:(id)sender {
235237
@synthesize selectedProfile;
236238
@synthesize localPort;
237239
@synthesize udpSupport;
240+
@synthesize shareOverLan;
238241
@synthesize dnsString;
239242
@end

V2RayX/ServerProfile.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
@interface ServerProfile : NSObject
1111
- (NSDictionary*)dictionaryForm;
12-
- (NSDictionary*)v2rayConfigWithLocalPort:(NSInteger)localPort
13-
udpSupport:(BOOL)udp
14-
v2rayRules:(BOOL)rules;
12+
- (NSDictionary*)v2rayConfigWithRules:(BOOL)rules;
1513
@property (nonatomic) NSString* address;
1614
@property (nonatomic) NSNumber* port;
1715
@property (nonatomic) NSString* userId;

V2RayX/ServerProfile.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,20 @@ - (NSDictionary*)dictionaryForm {
4040
@"network": network != nil ? network : @0};
4141
}
4242

43-
- (NSDictionary*)v2rayConfigWithLocalPort:(NSInteger)localPort
44-
udpSupport:(BOOL)udp
45-
v2rayRules:(BOOL)rules
43+
- (NSDictionary*)v2rayConfigWithRules:(BOOL)rules
4644
{
45+
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
4746
//generate config template
4847
NSMutableDictionary *config = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:rules?@"config-sample-rules":@"config-sample" ofType:@"plist"]];
49-
config[@"inbound"][@"port"] = [NSNumber numberWithInteger:localPort];
50-
config[@"inbound"][@"settings"][@"udp"] = [NSNumber numberWithBool:udp];
48+
config[@"inbound"][@"port"] = [userDefaults objectForKey:@"localPort"];
49+
config[@"inbound"][@"listen"] = [[userDefaults objectForKey:@"shareOverLan"] boolValue] ? @"0.0.0.0" : @"127.0.0.1";
50+
config[@"inbound"][@"settings"][@"udp"] = config[@"udpSupport"];
5151
config[@"inbound"][@"allowPassive"] = [self allowPassive];
5252
config[@"outbound"][@"settings"][@"vnext"][0][@"address"] = self.address;
5353
config[@"outbound"][@"settings"][@"vnext"][0][@"port"] = self.port;
5454
config[@"outbound"][@"settings"][@"vnext"][0][@"users"][0][@"id"] = self.userId;
5555
config[@"outbound"][@"settings"][@"vnext"][0][@"users"][0][@"alterId"] = self.alterId;
5656
config[@"outbound"][@"settings"][@"vnext"][0][@"users"][0][@"security"] = @[@"aes-128-cfb", @"aes-128-gcm", @"chacha20-poly1305"][self.security.integerValue % 3];
57-
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
5857
NSMutableDictionary* streamSettings = [[userDefaults objectForKey:@"transportSettings"] mutableCopy];
5958
streamSettings[@"network"] = @[@"tcp", @"kcp", @"ws"][self.network.integerValue % 3];
6059
streamSettings[@"security"] = [[userDefaults objectForKey:@"useTLS"] boolValue] ? @"tls" : @"none";

0 commit comments

Comments
 (0)