Skip to content

Commit a7c8666

Browse files
author
xVanTuring
authored
Merge pull request shadowsocksrr#55 from xVanTuring/v0.3.0
v0.3.0 update
2 parents 2789ce4 + 944f57b commit a7c8666

File tree

14 files changed

+425
-86
lines changed

14 files changed

+425
-86
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,8 @@ typings/
132132
.next
133133

134134
dist_electron
135-
.electron-vue-rm
135+
.electron-vue-rm
136+
137+
src/lib/*
138+
!src/lib/mac_service.sh
139+
!src/lib/proxy_conf_helper

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ install:
5555
fi
5656
5757
script:
58-
- yarn run electron:build
58+
- yarn fetch-dep && yarn run electron:build

appveyor.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
# Commented sections below can be used to run tests on the CI server
22
# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing
33
# https://www.appveyor.com/docs/appveyor-yml/
4-
version: 0.1.{build}
5-
6-
branches:
7-
only:
8-
- master
9-
10-
# skip_non_tags: true
11-
only_commits:
12-
message: /^trigger ci$/
4+
version: 0.3.0.{build}
135

146
image: Visual Studio 2017
157
platform:
@@ -27,15 +19,11 @@ init:
2719
- git config --global core.autocrlf input
2820

2921
install:
30-
- ps: Install-Product node 8 x64
31-
# - choco install yarn --ignore-dependencies
32-
- git reset --hard HEAD
22+
- ps: Install-Product node 10 x64
3323
- yarn
34-
- node --version
3524

3625
build_script:
37-
#- yarn test
38-
- yarn build
26+
- yarn fetch-dep && yarn electron:build
3927

4028
test: off
4129

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"electron:serve": "vue-cli-service electron:serve",
1313
"i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'",
1414
"postinstall": "electron-builder install-app-deps",
15-
"postuninstall": "electron-builder install-app-deps"
15+
"postuninstall": "electron-builder install-app-deps",
16+
"fetch-dep": "node scripts/fetch_deps.js"
1617
},
1718
"main": "background.js",
1819
"dependencies": {
@@ -44,9 +45,11 @@
4445
"electron": "^6.0.0",
4546
"eslint": "^5.16.0",
4647
"eslint-plugin-vue": "^5.0.0",
48+
"socks5-https-client": "^1.2.1",
4749
"stylus": "^0.54.7",
4850
"stylus-loader": "^3.0.2",
4951
"svg-to-vue-component": "^0.3.8",
52+
"unzipper": "^0.10.8",
5053
"vue-cli-plugin-electron-builder": "^1.4.4",
5154
"vue-cli-plugin-i18n": "^0.6.1",
5255
"vue-template-compiler": "^2.6.10"

scripts/fetch_deps.js

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
const request = require('request')
2+
const os = require('os')
3+
const path = require('path')
4+
const fs = require('fs')
5+
const { ensureDir, copy, readdir } = require('fs-extra')
6+
const { exec } = require('child_process')
7+
const unzipper = require('unzipper')
8+
const Socks5ClientHttpsAgent = require('socks5-https-client/lib/Agent')
9+
const tmpDir = path.join(os.tmpdir(), 'electron-ssr-deps-fetch')
10+
const copyDir = path.join(process.cwd(), 'src', 'lib')
11+
console.log(`tmpDir: ${tmpDir}`)
12+
console.log(`copyDir: ${copyDir}`)
13+
function fetchIndex (url) {
14+
return new Promise((resolve, reject) => {
15+
console.log(`Start Fetching: ${url}`)
16+
let option = {
17+
url: url,
18+
headers: {
19+
'User-Agent': 'electron-ssr'
20+
}
21+
}
22+
withProxy(option)
23+
withGHToken(option)
24+
request(option, (err, resp, body) => {
25+
if (err) {
26+
reject(err)
27+
} else {
28+
console.log('Response Headers')
29+
console.log(resp.headers)
30+
try {
31+
resolve(JSON.parse(body))
32+
} catch (error) {
33+
console.error(`Failed to parse: ${body} err: ${error}`)
34+
reject(error)
35+
}
36+
}
37+
})
38+
})
39+
}
40+
async function getSocks2http () {
41+
const releaseIndex = 'https://api.github.com/repos/xVanTuring/socks2http-rs/releases/latest'
42+
let index = await fetchIndex(releaseIndex)
43+
let assets = index['assets']
44+
if (!(assets && assets.length && assets.length !== 0)) {
45+
console.error('assets is invalid')
46+
console.log(assets)
47+
console.log(index)
48+
index = await fetchIndex(releaseIndex)
49+
assets = index['assets']
50+
}
51+
let withName = 'linux'
52+
switch (process.platform) {
53+
case 'win32':
54+
withName = 'windows'
55+
break
56+
case 'linux':
57+
break
58+
case 'darwin':
59+
withName = 'osx'
60+
break
61+
default:
62+
console.error('Unsupported system')
63+
return
64+
}
65+
let downloadPath = path.join(tmpDir, 'socks2http.zip')
66+
for (const asset of assets) {
67+
if (asset['name'].indexOf(withName) >= 0) {
68+
await downloadFile(asset['browser_download_url'], downloadPath)
69+
break
70+
}
71+
}
72+
await extractFile(downloadPath)
73+
let socks2httpName = 'socks2http'
74+
if (process.platform === 'win32') {
75+
socks2httpName += '.exe'
76+
}
77+
let copiedPath = path.join(copyDir, socks2httpName)
78+
await copy(path.join(tmpDir, socks2httpName), copiedPath)
79+
if (process.platform !== 'win32') {
80+
await new Promise((resolve, reject) => {
81+
console.log(`executing chmod +x ${copiedPath}`)
82+
exec(['chmod', '+x', copiedPath].join(' '), (err) => {
83+
if (err) {
84+
reject(err)
85+
} else {
86+
resolve()
87+
}
88+
})
89+
})
90+
}
91+
}
92+
async function getSysProxy () {
93+
const releaseIndex = 'https://api.github.com/repos/xVanTuring/sysproxy/releases/latest'
94+
let index = await fetchIndex(releaseIndex)
95+
const assets = index['assets']
96+
let downloadPath = path.join(tmpDir, 'sysproxy.exe')
97+
for (const asset of assets) {
98+
if (asset['name'].indexOf('64') >= 0) {
99+
await downloadFile(asset['browser_download_url'], downloadPath)
100+
break
101+
}
102+
}
103+
let copiedPath = path.join(copyDir, 'sysproxy.exe')
104+
await copy(downloadPath, copiedPath)
105+
}
106+
async function getWindowsKill () {
107+
const releaseIndex = 'https://api.github.com/repos/alirdn/windows-kill/releases/latest'
108+
let index = await fetchIndex(releaseIndex)
109+
const assets = index['assets']
110+
let downloadPath = path.join(tmpDir, 'windows-kill.zip')
111+
let folderName = ''
112+
for (const asset of assets) {
113+
if (asset['name'].startsWith('windows-kill_x64')) {
114+
folderName = asset['name'].replace('.zip', '')
115+
await downloadFile(asset['browser_download_url'], downloadPath)
116+
break
117+
}
118+
}
119+
await extractFile(downloadPath)
120+
await copy(path.join(tmpDir, folderName, 'windows-kill.exe'), path.join(copyDir, 'windows-kill.exe'))
121+
}
122+
function downloadFile (url, path) {
123+
return new Promise((resolve, reject) => {
124+
console.log(`Start Downloading: ${url}`)
125+
const file = fs.createWriteStream(path)
126+
let option = {
127+
url: url,
128+
header: {
129+
'User-Agent': 'request'
130+
}
131+
}
132+
withProxy(option)
133+
withGHToken(option)
134+
request(option).on('error', reject).pipe(file)
135+
file.on('close', () => {
136+
console.log('WRITE DONE!')
137+
resolve()
138+
})
139+
})
140+
}
141+
async function getLibsodium () {
142+
const releaseIndex = 'https://api.github.com/repos/xVanTuring/libsodium-msvc-release/releases/latest'
143+
let index = await fetchIndex(releaseIndex)
144+
const assets = index['assets']
145+
const libsodiumName = 'libsodium.dll'
146+
let downloadPath = path.join(tmpDir, libsodiumName)
147+
for (const asset of assets) {
148+
if (asset['name'] === 'libsodium.dll') {
149+
await downloadFile(asset['browser_download_url'], downloadPath)
150+
break
151+
}
152+
}
153+
let copiedPath = path.join(copyDir, libsodiumName)
154+
console.log(`Copy File to ${copiedPath}`)
155+
await copy(downloadPath, copiedPath)
156+
}
157+
function extractFile (zipPath) {
158+
return new Promise((resolve, reject) => {
159+
console.log(`Start Unzipping ${zipPath}`)
160+
fs.createReadStream(zipPath).pipe(unzipper.Extract({ path: tmpDir }))
161+
.on('finish', resolve)
162+
.on('error', reject)
163+
})
164+
}
165+
let agent = null
166+
function withProxy (option) {
167+
let proxy = process.env.http_proxy || process.env.all_proxy || process.env.fetch_proxy
168+
if (proxy) {
169+
if (proxy.startsWith('socks5://')) {
170+
console.log(`Using Socks5 Proxy ${proxy}`)
171+
if (agent == null) {
172+
let url = new (require('url').URL)(proxy)
173+
agent = new Socks5ClientHttpsAgent({
174+
socksHost: url.hostname,
175+
socksPort: parseInt(url.port, 10)
176+
})
177+
}
178+
option['agent'] = agent
179+
return
180+
}
181+
console.log(`Using proxy: ${proxy}`)
182+
option['proxy'] = proxy
183+
}
184+
}
185+
function withGHToken (option) {
186+
if (process.env.GH_TOKEN) {
187+
console.log(`Find GH_TOKE ${process.env.GH_TOKEN.substr(0, 10)}...`)
188+
if (!option['headers']) {
189+
option['headers'] = {}
190+
}
191+
option['headers']['Authorization'] = `token ${process.env.GH_TOKEN}`
192+
}
193+
}
194+
195+
async function main () {
196+
await ensureDir(tmpDir)
197+
await getSocks2http()
198+
if (process.platform === 'win32') {
199+
await getSysProxy()
200+
await getLibsodium()
201+
await getWindowsKill()
202+
}
203+
await printLib()
204+
}
205+
async function printLib () {
206+
console.log('---LISTING LIB DIR---')
207+
let result = await readdir(copyDir)
208+
for (const fileName of result) {
209+
console.log(path.join(copyDir, fileName))
210+
}
211+
}
212+
try {
213+
main()
214+
} catch (error) {
215+
console.error(error)
216+
}

src/lib/libsodium.dll

-296 KB
Binary file not shown.

src/lib/mgwz.dll

-84.5 KB
Binary file not shown.

src/lib/privoxy.exe

-370 KB
Binary file not shown.

src/lib/sysproxy.exe

-102 KB
Binary file not shown.

src/main/bootstrap.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,31 @@ export const subscribeUpdateFile = path.join(appConfigDir, '.subscribe.update.la
4545
export const exePath = app.getPath('exe')
4646
// windows sysproxy.exe文件的路径
4747
let _winToolPath
48-
let _privoxyPath
48+
let _winKillPath
49+
let _s2hPath
4950
let _libsodiumDir
5051
if (isWin) {
5152
if (process.env.NODE_ENV === 'development') {
5253
_winToolPath = path.resolve(__dirname, '../src/lib/sysproxy.exe')
53-
_privoxyPath = path.resolve(__dirname, '../src/lib/privoxy.exe')
54+
_winKillPath = path.resolve(__dirname, '../src/lib/windows-kill.exe')
55+
_s2hPath = path.resolve(__dirname, '../src/lib/socks2http.exe')
5456
_libsodiumDir = path.resolve(__dirname, '../src/lib/')
5557
} else {
5658
_winToolPath = path.join(path.dirname(exePath), './3rdparty/sysproxy.exe')
57-
_privoxyPath = path.join(path.dirname(exePath), './3rdparty/privoxy.exe')
59+
_winKillPath = path.join(path.dirname(exePath), './3rdparty/windows-kill.exe')
60+
_s2hPath = path.join(path.dirname(exePath), './3rdparty/socks2http.exe')
5861
_libsodiumDir = path.join(path.dirname(exePath), './3rdparty')
5962
}
6063
} else if (isLinux || isMac) {
61-
_privoxyPath = 'privoxy'
64+
if (process.env.NODE_ENV === 'development') {
65+
_s2hPath = path.resolve(__dirname, '../src/lib/socks2http')
66+
} else {
67+
_s2hPath = path.join(path.dirname(exePath), './3rdparty/socks2http')
68+
}
6269
}
6370
export const winToolPath = _winToolPath
64-
export const privoxyPath = _privoxyPath
71+
export const winKillPath = _winKillPath
72+
export const s2hPath = _s2hPath
6573
// mac proxy_conf_helper工具目录
6674
export const macToolPath = path.resolve(appConfigDir, 'proxy_conf_helper')
6775
export const libsodiumDir = _libsodiumDir

src/main/client.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
2-
import { execFile } from 'child_process'
3-
import { libsodiumDir } from './bootstrap'
2+
import { execFile, exec } from 'child_process'
3+
import { libsodiumDir, winKillPath } from './bootstrap'
44
import { dialog } from 'electron'
55
import { appConfig$ } from './data'
66
import { ensureHostPortValid } from './port'
@@ -11,6 +11,7 @@ import { toggleEnable } from './tray-handler'
1111
import * as i18n from './locales'
1212
import { isWin } from '@/shared/env'
1313
const $t = i18n.default
14+
let quitByCommand = false
1415
/**
1516
* @type {import('child_process').ChildProcess|null}
1617
*/
@@ -58,8 +59,10 @@ function runPythonSSR (params) {
5859
})
5960
})
6061
pythonSSRInstance.once('exit', (code) => {
61-
logger.debug(`Python SSR exit with code: ${code}`)
62-
pythonSSRInstance = null
62+
if (!quitByCommand) {
63+
logger.debug(`Python SSR exit with code: ${code}`)
64+
pythonSSRInstance = null
65+
}
6366
})
6467
}
6568

@@ -134,12 +137,16 @@ export function stop (force = false) {
134137
pythonSSRInstance.once('exit', (code) => {
135138
logger.debug(`Python SSR exit with code: ${code}`)
136139
pythonSSRInstance = null
137-
if (timeout) {
138-
clearTimeout(timeout)
139-
}
140+
clearTimeout(timeout)
140141
resolve()
141142
})
142-
pythonSSRInstance.kill()
143+
if (process.platform === 'win32') {
144+
logger.info('Killing Python SSR')
145+
exec([winKillPath, '-2', pythonSSRInstance.pid].join(' '))
146+
} else {
147+
pythonSSRInstance.kill('SIGINT')
148+
}
149+
quitByCommand = true
143150
})
144151
}
145152
return Promise.resolve()

0 commit comments

Comments
 (0)