Skip to content

Commit

Permalink
Add VLESS/XTLS support in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Narakuku committed Jul 31, 2022
1 parent e29cc5e commit f3becd1
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 195 deletions.
12 changes: 6 additions & 6 deletions V2RayX/AdvancedWindow.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19455" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19455"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -62,7 +62,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="540" height="455"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1025"/>
<rect key="screenRect" x="0.0" y="0.0" width="2240" height="1235"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="540" height="455"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -247,7 +247,7 @@ Gw
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="Foc-Ri-DSS">
<rect key="frame" x="1" y="-15" width="0.0" height="16"/>
<rect key="frame" x="1" y="251" width="420" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="ebi-F0-0yH">
Expand Down Expand Up @@ -1063,7 +1063,7 @@ will match all private IPs.</string>
<autoresizingMask key="autoresizingMask"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="RDn-zh-dIS">
<rect key="frame" x="0.0" y="0.0" width="260" height="133"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textView importsGraphics="NO" richText="NO" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="1mD-il-bEM">
<rect key="frame" x="0.0" y="0.0" width="260" height="133"/>
Expand Down Expand Up @@ -1131,7 +1131,7 @@ Gw
<autoresizingMask key="autoresizingMask"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="jPy-Y0-jqx">
<rect key="frame" x="0.0" y="0.0" width="260" height="133"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textView importsGraphics="NO" richText="NO" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="3kN-VI-6Jc">
<rect key="frame" x="0.0" y="0.0" width="260" height="133"/>
Expand Down
2 changes: 1 addition & 1 deletion V2RayX/ConfigImporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ + (ServerProfile*)importFromVLESSOfXray:(NSString*)vlessStr {
// }

ServerProfile* newProfile = [[ServerProfile alloc] init];
newProfile.protocol = @"vless";
newProfile.protocol = vless;
newProfile.outboundTag = nilCoalescing([url fragment], @"VLESS");
newProfile.address = nilCoalescing([url host], @"");
newProfile.port = [nilCoalescing([url port], @0) intValue];
Expand Down
307 changes: 181 additions & 126 deletions V2RayX/ConfigWindow.xib

Large diffs are not rendered by default.

44 changes: 30 additions & 14 deletions V2RayX/ServerProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,28 @@
#import "AppDelegate.h"
#import "utilities.h"

typedef enum ProtocolType : NSUInteger {
vmess,
vless
} ProtocolType;

typedef enum SecurityType : NSUInteger {
auto_,
none_security,
auto_security,
aes_128_gcm,
chacha20_poly130,
none
chacha20_poly130
} SecurityType;

typedef enum FlowType : NSUInteger {
none_flow,
xtls_rprx_direct,
xtls_rprx_direct_udp443,
xtls_rprx_origin,
xtls_rprx_origin_udp443,
xtls_rprx_splice,
xtls_rprx_splice_udp443
} FlowType;

typedef enum NetWorkType : NSUInteger {
tcp,
kcp,
Expand All @@ -25,21 +40,22 @@ typedef enum NetWorkType : NSUInteger {
} NetWorkType;

@interface ServerProfile : NSObject
- (NSMutableDictionary*)outboundProfile;
+ (ServerProfile* _Nullable )readFromAnOutboundDic:(NSDictionary*)outDict;
+ (NSArray*)profilesFromJson:(NSDictionary*)outboundJson;
-(ServerProfile*)deepCopy;
- (NSMutableDictionary* _Null_unspecified)outboundProfile;
+ (ServerProfile* _Nullable)readFromAnOutboundDic:(NSDictionary* _Null_unspecified)outDict;
+ (NSArray* _Null_unspecified)profilesFromJson:(NSDictionary* _Null_unspecified)outboundJson;
-(ServerProfile* _Null_unspecified)deepCopy;

@property (nonatomic) NSString* address;
@property (nonatomic) NSString* protocol;
@property (nonatomic) NSString* _Null_unspecified address;
@property (nonatomic) ProtocolType protocol;
@property (nonatomic) NSUInteger port;
@property (nonatomic) NSString* userId;
@property (nonatomic) NSString* _Null_unspecified userId;
@property (nonatomic) NSUInteger alterId;
@property (nonatomic) NSUInteger level;
@property (nonatomic) NSString* outboundTag;
@property (nonatomic) NSString* _Null_unspecified outboundTag;
@property (nonatomic) FlowType flow;
@property (nonatomic) SecurityType security;
@property (nonatomic) NetWorkType network;
@property (nonatomic) NSString* sendThrough;
@property (nonatomic) NSDictionary* streamSettings; // except network type.
@property (nonatomic) NSDictionary* muxSettings;
@property (nonatomic) NSString* _Null_unspecified sendThrough;
@property (nonatomic) NSDictionary* _Null_unspecified streamSettings; // except network type.
@property (nonatomic) NSDictionary* _Null_unspecified muxSettings;
@end
18 changes: 13 additions & 5 deletions V2RayX/ServerProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ @implementation ServerProfile
- (ServerProfile*)init {
self = [super init];
if (self) {
[self setProtocol:@"vmess"];
[self setProtocol:vmess];
[self setAddress:@"server.cc"];
[self setPort:10086];
[self setUserId:@"00000000-0000-0000-0000-000000000000"];
[self setAlterId:64];
[self setLevel:0];
[self setOutboundTag:@"test server"];
[self setSecurity:auto_];
[self setFlow:none_flow];
[self setSecurity:none_security];
[self setNetwork:tcp];
[self setSendThrough:@"0.0.0.0"];
[self setStreamSettings:@{
Expand All @@ -30,6 +31,9 @@ - (ServerProfile*)init {
@"allowInsecure": [NSNumber numberWithBool:NO],
@"allowInsecureCiphers": [NSNumber numberWithBool:NO]
},
@"xtlsSettings": @{
@"allowInsecure": [NSNumber numberWithBool:NO]
},
@"tcpSettings": @{
@"header": @{
@"type": @"none"
Expand Down Expand Up @@ -87,7 +91,7 @@ + (NSArray*)profilesFromJson:(NSDictionary*)outboundJson {
}
for (NSDictionary* vnext in [outboundJson valueForKeyPath:@"settings.vnext"]) {
ServerProfile* profile = [[ServerProfile alloc] init];
profile.protocol = nilCoalescing(outboundJson[@"protocol"], @"vmess");
profile.protocol = searchInArray(outboundJson[@"protocol"], PROTOCOL_LIST);
profile.address = nilCoalescing(vnext[@"address"], @"127.0.0.1");
profile.outboundTag = nilCoalescing(outboundJson[@"tag"], @"");
profile.port = [vnext[@"port"] unsignedIntegerValue];
Expand All @@ -97,6 +101,7 @@ + (NSArray*)profilesFromJson:(NSDictionary*)outboundJson {
profile.userId = nilCoalescing(vnext[@"users"][0][@"id"], @"23ad6b10-8d1a-40f7-8ad0-e3e35cd38287");
profile.alterId = [vnext[@"users"][0][@"alterId"] unsignedIntegerValue];
profile.level = [vnext[@"users"][0][@"level"] unsignedIntegerValue];
profile.flow = searchInArray(vnext[@"users"][0][@"flow"], VLESS_FLOW_LIST);
profile.security = searchInArray(vnext[@"users"][0][@"security"], VMESS_SECURITY_LIST);
if (outboundJson[@"streamSettings"] != nil) {
profile.streamSettings = outboundJson[@"streamSettings"];
Expand All @@ -122,13 +127,14 @@ + (ServerProfile* _Nullable )readFromAnOutboundDic:(NSDictionary*)outDict {

-(ServerProfile*)deepCopy {
ServerProfile* aCopy = [[ServerProfile alloc] init];
aCopy.protocol = [NSString stringWithString:nilCoalescing(self.protocol, @"")];
aCopy.protocol = self.protocol;
aCopy.address = [NSString stringWithString:nilCoalescing(self.address, @"")];
aCopy.port = self.port;
aCopy.userId = [NSString stringWithString:nilCoalescing(self.userId, @"")];
aCopy.alterId = self.alterId;
aCopy.level = self.level;
aCopy.outboundTag = [NSString stringWithString:nilCoalescing(self.outboundTag, @"")];
aCopy.flow = self.flow;
aCopy.security = self.security;
aCopy.network = self.network;
aCopy.sendThrough = [NSString stringWithString:nilCoalescing(self.sendThrough, @"")];
Expand All @@ -144,7 +150,7 @@ - (NSMutableDictionary*)outboundProfile {
@{
@"sendThrough": sendThrough,
@"tag": nilCoalescing(outboundTag, @""),
@"protocol": nilCoalescing(protocol, @"vmess"),
@"protocol": PROTOCOL_LIST[protocol],
@"settings": [@{
@"vnext": @[
@{
Expand All @@ -154,6 +160,7 @@ - (NSMutableDictionary*)outboundProfile {
@{
@"id": userId != nil ? [userId stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]: @"",
@"alterId": [NSNumber numberWithUnsignedInteger:alterId],
@"flow": VLESS_FLOW_LIST[flow],
@"security": VMESS_SECURITY_LIST[security],
@"level": [NSNumber numberWithUnsignedInteger:level],
@"encryption": @"none"
Expand Down Expand Up @@ -181,6 +188,7 @@ - (NSMutableDictionary*)outboundProfile {
@synthesize alterId;
@synthesize level;
@synthesize outboundTag;
@synthesize flow;
@synthesize security;
@synthesize network;
@synthesize sendThrough;
Expand Down
Loading

0 comments on commit f3becd1

Please sign in to comment.