xfuture 1.9.2 → 1.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,139 @@
1
+ let os = require("os");
2
+ const { spawn } = require('child_process')
3
+ var isMac = false;
4
+ const parser = require('./parser');
5
+ const fs = require('fs');
6
+ parser.isGlobalMode = false;
7
+
8
+ class xFuture {
9
+
10
+ init(){
11
+ this.driver = "";
12
+ this.isTunMode = true;
13
+ }
14
+
15
+ SetEventCallback(name, func){
16
+
17
+ }
18
+
19
+ GetSingBoxDuraion(){
20
+ return 0;
21
+ }
22
+
23
+ GetXrayDuration(){
24
+ return 0;
25
+ }
26
+
27
+ SetPassword(password) {
28
+
29
+ }
30
+
31
+ SetTunModeEnable(enable, workingDir){
32
+ this.isTunMode = enable;
33
+ this.workingDir = workingDir;
34
+ }
35
+
36
+ SetWorkingDir(workingDir){
37
+ this.workingDir = workingDir
38
+ }
39
+
40
+ StartTunnel(url){
41
+ if(this.driver.length == 0) return false;
42
+ this.currentURI = url;
43
+ var json = parser.parse(url);
44
+ var xray_json = JSON.stringify(json);
45
+ console.log("address:", json.address);
46
+ var ok = this.startTunnelPrivate(xray_json, url);
47
+ if (ok) {
48
+ ok = this.StartProxy();
49
+ }
50
+ return ok;
51
+ }
52
+
53
+ startTunnelPrivate(json, url){
54
+
55
+ try {
56
+ // 同步写入文件
57
+ var filePath = this.workingDir + "\\configuration.json";
58
+ fs.writeFileSync(filePath, json, 'utf8');
59
+ console.log('File has been written successfully!');
60
+ var driver = this.workingDir + "\\mao-dou-xray-vpn-driver.exe";
61
+ spawn(driver, ["run", this.workingDir, filePath, url]);
62
+ return true;
63
+ } catch (err) {
64
+ console.error('An error occurred while writing to the file:', err);
65
+ return false;
66
+ }
67
+ }
68
+
69
+ stopTunnelPrivate() {
70
+ var driver = this.workingDir + "\\mao-dou-xray-vpn-driver.exe";
71
+ spawn(driver, ["kill"]);
72
+ }
73
+
74
+ StopTunnel(){
75
+ this.stopTunnelPrivate();
76
+ this.StopProxy();
77
+ }
78
+
79
+ SetVlessEncoding(version){
80
+
81
+ }
82
+
83
+ StartProxy(){
84
+ var ret = true;
85
+ try {
86
+ let process = spawn(this.driver, ["global", "socks=127.0.0.1:40008"])
87
+ process.on('close', (code) => {
88
+ console.info('[sysproxy open]:', code)
89
+ });
90
+ } catch(err) {
91
+ console.warn('[sysproxy open] failed:', err)
92
+ this.stopTunnelPrivate();
93
+ ret = false;
94
+ }
95
+ return ret;
96
+ }
97
+
98
+ // App 进程退出时调用该接口,否则会导致电脑出现断网情况
99
+ StopProxy(){
100
+ if (!isMac) {
101
+ try {
102
+ let process = spawn(this.driver, ["off"])
103
+ process.on('close', function (code) {
104
+ console.info('[sysproxy stop]:', code)
105
+ });
106
+ } catch(err) {
107
+ console.warn('[sysproxy stop] failed:', err)
108
+ }
109
+ }
110
+ }
111
+
112
+ SetGlobalMode(isGlobalMode, ipdir){
113
+ console.log("isGlobalMode:", isGlobalMode, " dir:", ipdir);
114
+ parser.workingDir = ipdir;
115
+ parser.isGlobalMode = isGlobalMode;
116
+ }
117
+
118
+ // 1. Mac 请传 install_helper.sh 和 xfuture_helper 的绝对路径
119
+ // 2. Windows 请传 "maodou" 固定字符串 和 sysproxy.exe 的绝对路径
120
+ InstallDriver(shell_path, helper_path){
121
+ this.driver = helper_path;
122
+ }
123
+
124
+ GetCurrentStatus(){
125
+ return 0;
126
+ }
127
+
128
+ GetCurrentURI(){
129
+ return this.currentURI;
130
+ }
131
+
132
+ GetStatistics(){
133
+ return {"downloadlink":0, "mdownloadlink":0, "muploadlink":0, "uploadlink":0};
134
+ }
135
+ }
136
+
137
+ const xFutureInstance = new xFuture;
138
+ xFutureInstance.init();
139
+ module.exports = xFutureInstance;
package/index.js CHANGED
@@ -32,6 +32,10 @@ class xFuture {
32
32
  ff.SetTunModeEnable(enable, workingDir);
33
33
  }
34
34
 
35
+ SetWorkingDir(workingDir){
36
+ this.workingDir = workingDir
37
+ }
38
+
35
39
  StartTunnel(url){
36
40
  if(this.driver.length == 0) return false;
37
41
  var json = parser.parse(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xfuture",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
4
4
  "description": "electron vpn sdk",
5
5
  "main": "x.js",
6
6
  "scripts": {
@@ -21,6 +21,7 @@
21
21
  },
22
22
  "files": [
23
23
  "index.js",
24
+ "index-for-win32-ia32.js",
24
25
  "parser.js",
25
26
  "package.json",
26
27
  "package/darwin/xFuture.node",