Skip to content

Commit

Permalink
Merge pull request #55 from xVanTuring/v0.3.0
Browse files Browse the repository at this point in the history
v0.3.0 update
  • Loading branch information
xVanTuring authored Feb 20, 2020
2 parents 2789ce4 + 944f57b commit a7c8666
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 86 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,8 @@ typings/
.next

dist_electron
.electron-vue-rm
.electron-vue-rm

src/lib/*
!src/lib/mac_service.sh
!src/lib/proxy_conf_helper
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ install:
fi
script:
- yarn run electron:build
- yarn fetch-dep && yarn run electron:build
18 changes: 3 additions & 15 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# Commented sections below can be used to run tests on the CI server
# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing
# https://www.appveyor.com/docs/appveyor-yml/
version: 0.1.{build}

branches:
only:
- master

# skip_non_tags: true
only_commits:
message: /^trigger ci$/
version: 0.3.0.{build}

image: Visual Studio 2017
platform:
Expand All @@ -27,15 +19,11 @@ init:
- git config --global core.autocrlf input

install:
- ps: Install-Product node 8 x64
# - choco install yarn --ignore-dependencies
- git reset --hard HEAD
- ps: Install-Product node 10 x64
- yarn
- node --version

build_script:
#- yarn test
- yarn build
- yarn fetch-dep && yarn electron:build

test: off

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"electron:serve": "vue-cli-service electron:serve",
"i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
"postuninstall": "electron-builder install-app-deps",
"fetch-dep": "node scripts/fetch_deps.js"
},
"main": "background.js",
"dependencies": {
Expand Down Expand Up @@ -44,9 +45,11 @@
"electron": "^6.0.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"socks5-https-client": "^1.2.1",
"stylus": "^0.54.7",
"stylus-loader": "^3.0.2",
"svg-to-vue-component": "^0.3.8",
"unzipper": "^0.10.8",
"vue-cli-plugin-electron-builder": "^1.4.4",
"vue-cli-plugin-i18n": "^0.6.1",
"vue-template-compiler": "^2.6.10"
Expand Down
216 changes: 216 additions & 0 deletions scripts/fetch_deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
const request = require('request')
const os = require('os')
const path = require('path')
const fs = require('fs')
const { ensureDir, copy, readdir } = require('fs-extra')
const { exec } = require('child_process')
const unzipper = require('unzipper')
const Socks5ClientHttpsAgent = require('socks5-https-client/lib/Agent')
const tmpDir = path.join(os.tmpdir(), 'electron-ssr-deps-fetch')
const copyDir = path.join(process.cwd(), 'src', 'lib')
console.log(`tmpDir: ${tmpDir}`)
console.log(`copyDir: ${copyDir}`)
function fetchIndex (url) {
return new Promise((resolve, reject) => {
console.log(`Start Fetching: ${url}`)
let option = {
url: url,
headers: {
'User-Agent': 'electron-ssr'
}
}
withProxy(option)
withGHToken(option)
request(option, (err, resp, body) => {
if (err) {
reject(err)
} else {
console.log('Response Headers')
console.log(resp.headers)
try {
resolve(JSON.parse(body))
} catch (error) {
console.error(`Failed to parse: ${body} err: ${error}`)
reject(error)
}
}
})
})
}
async function getSocks2http () {
const releaseIndex = 'https://api.github.com/repos/xVanTuring/socks2http-rs/releases/latest'
let index = await fetchIndex(releaseIndex)
let assets = index['assets']
if (!(assets && assets.length && assets.length !== 0)) {
console.error('assets is invalid')
console.log(assets)
console.log(index)
index = await fetchIndex(releaseIndex)
assets = index['assets']
}
let withName = 'linux'
switch (process.platform) {
case 'win32':
withName = 'windows'
break
case 'linux':
break
case 'darwin':
withName = 'osx'
break
default:
console.error('Unsupported system')
return
}
let downloadPath = path.join(tmpDir, 'socks2http.zip')
for (const asset of assets) {
if (asset['name'].indexOf(withName) >= 0) {
await downloadFile(asset['browser_download_url'], downloadPath)
break
}
}
await extractFile(downloadPath)
let socks2httpName = 'socks2http'
if (process.platform === 'win32') {
socks2httpName += '.exe'
}
let copiedPath = path.join(copyDir, socks2httpName)
await copy(path.join(tmpDir, socks2httpName), copiedPath)
if (process.platform !== 'win32') {
await new Promise((resolve, reject) => {
console.log(`executing chmod +x ${copiedPath}`)
exec(['chmod', '+x', copiedPath].join(' '), (err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
}
async function getSysProxy () {
const releaseIndex = 'https://api.github.com/repos/xVanTuring/sysproxy/releases/latest'
let index = await fetchIndex(releaseIndex)
const assets = index['assets']
let downloadPath = path.join(tmpDir, 'sysproxy.exe')
for (const asset of assets) {
if (asset['name'].indexOf('64') >= 0) {
await downloadFile(asset['browser_download_url'], downloadPath)
break
}
}
let copiedPath = path.join(copyDir, 'sysproxy.exe')
await copy(downloadPath, copiedPath)
}
async function getWindowsKill () {
const releaseIndex = 'https://api.github.com/repos/alirdn/windows-kill/releases/latest'
let index = await fetchIndex(releaseIndex)
const assets = index['assets']
let downloadPath = path.join(tmpDir, 'windows-kill.zip')
let folderName = ''
for (const asset of assets) {
if (asset['name'].startsWith('windows-kill_x64')) {
folderName = asset['name'].replace('.zip', '')
await downloadFile(asset['browser_download_url'], downloadPath)
break
}
}
await extractFile(downloadPath)
await copy(path.join(tmpDir, folderName, 'windows-kill.exe'), path.join(copyDir, 'windows-kill.exe'))
}
function downloadFile (url, path) {
return new Promise((resolve, reject) => {
console.log(`Start Downloading: ${url}`)
const file = fs.createWriteStream(path)
let option = {
url: url,
header: {
'User-Agent': 'request'
}
}
withProxy(option)
withGHToken(option)
request(option).on('error', reject).pipe(file)
file.on('close', () => {
console.log('WRITE DONE!')
resolve()
})
})
}
async function getLibsodium () {
const releaseIndex = 'https://api.github.com/repos/xVanTuring/libsodium-msvc-release/releases/latest'
let index = await fetchIndex(releaseIndex)
const assets = index['assets']
const libsodiumName = 'libsodium.dll'
let downloadPath = path.join(tmpDir, libsodiumName)
for (const asset of assets) {
if (asset['name'] === 'libsodium.dll') {
await downloadFile(asset['browser_download_url'], downloadPath)
break
}
}
let copiedPath = path.join(copyDir, libsodiumName)
console.log(`Copy File to ${copiedPath}`)
await copy(downloadPath, copiedPath)
}
function extractFile (zipPath) {
return new Promise((resolve, reject) => {
console.log(`Start Unzipping ${zipPath}`)
fs.createReadStream(zipPath).pipe(unzipper.Extract({ path: tmpDir }))
.on('finish', resolve)
.on('error', reject)
})
}
let agent = null
function withProxy (option) {
let proxy = process.env.http_proxy || process.env.all_proxy || process.env.fetch_proxy
if (proxy) {
if (proxy.startsWith('socks5://')) {
console.log(`Using Socks5 Proxy ${proxy}`)
if (agent == null) {
let url = new (require('url').URL)(proxy)
agent = new Socks5ClientHttpsAgent({
socksHost: url.hostname,
socksPort: parseInt(url.port, 10)
})
}
option['agent'] = agent
return
}
console.log(`Using proxy: ${proxy}`)
option['proxy'] = proxy
}
}
function withGHToken (option) {
if (process.env.GH_TOKEN) {
console.log(`Find GH_TOKE ${process.env.GH_TOKEN.substr(0, 10)}...`)
if (!option['headers']) {
option['headers'] = {}
}
option['headers']['Authorization'] = `token ${process.env.GH_TOKEN}`
}
}

async function main () {
await ensureDir(tmpDir)
await getSocks2http()
if (process.platform === 'win32') {
await getSysProxy()
await getLibsodium()
await getWindowsKill()
}
await printLib()
}
async function printLib () {
console.log('---LISTING LIB DIR---')
let result = await readdir(copyDir)
for (const fileName of result) {
console.log(path.join(copyDir, fileName))
}
}
try {
main()
} catch (error) {
console.error(error)
}
Binary file removed src/lib/libsodium.dll
Binary file not shown.
Binary file removed src/lib/mgwz.dll
Binary file not shown.
Binary file removed src/lib/privoxy.exe
Binary file not shown.
Binary file removed src/lib/sysproxy.exe
Binary file not shown.
18 changes: 13 additions & 5 deletions src/main/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,31 @@ export const subscribeUpdateFile = path.join(appConfigDir, '.subscribe.update.la
export const exePath = app.getPath('exe')
// windows sysproxy.exe文件的路径
let _winToolPath
let _privoxyPath
let _winKillPath
let _s2hPath
let _libsodiumDir
if (isWin) {
if (process.env.NODE_ENV === 'development') {
_winToolPath = path.resolve(__dirname, '../src/lib/sysproxy.exe')
_privoxyPath = path.resolve(__dirname, '../src/lib/privoxy.exe')
_winKillPath = path.resolve(__dirname, '../src/lib/windows-kill.exe')
_s2hPath = path.resolve(__dirname, '../src/lib/socks2http.exe')
_libsodiumDir = path.resolve(__dirname, '../src/lib/')
} else {
_winToolPath = path.join(path.dirname(exePath), './3rdparty/sysproxy.exe')
_privoxyPath = path.join(path.dirname(exePath), './3rdparty/privoxy.exe')
_winKillPath = path.join(path.dirname(exePath), './3rdparty/windows-kill.exe')
_s2hPath = path.join(path.dirname(exePath), './3rdparty/socks2http.exe')
_libsodiumDir = path.join(path.dirname(exePath), './3rdparty')
}
} else if (isLinux || isMac) {
_privoxyPath = 'privoxy'
if (process.env.NODE_ENV === 'development') {
_s2hPath = path.resolve(__dirname, '../src/lib/socks2http')
} else {
_s2hPath = path.join(path.dirname(exePath), './3rdparty/socks2http')
}
}
export const winToolPath = _winToolPath
export const privoxyPath = _privoxyPath
export const winKillPath = _winKillPath
export const s2hPath = _s2hPath
// mac proxy_conf_helper工具目录
export const macToolPath = path.resolve(appConfigDir, 'proxy_conf_helper')
export const libsodiumDir = _libsodiumDir
Expand Down
23 changes: 15 additions & 8 deletions src/main/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import { execFile } from 'child_process'
import { libsodiumDir } from './bootstrap'
import { execFile, exec } from 'child_process'
import { libsodiumDir, winKillPath } from './bootstrap'
import { dialog } from 'electron'
import { appConfig$ } from './data'
import { ensureHostPortValid } from './port'
Expand All @@ -11,6 +11,7 @@ import { toggleEnable } from './tray-handler'
import * as i18n from './locales'
import { isWin } from '@/shared/env'
const $t = i18n.default
let quitByCommand = false
/**
* @type {import('child_process').ChildProcess|null}
*/
Expand Down Expand Up @@ -58,8 +59,10 @@ function runPythonSSR (params) {
})
})
pythonSSRInstance.once('exit', (code) => {
logger.debug(`Python SSR exit with code: ${code}`)
pythonSSRInstance = null
if (!quitByCommand) {
logger.debug(`Python SSR exit with code: ${code}`)
pythonSSRInstance = null
}
})
}

Expand Down Expand Up @@ -134,12 +137,16 @@ export function stop (force = false) {
pythonSSRInstance.once('exit', (code) => {
logger.debug(`Python SSR exit with code: ${code}`)
pythonSSRInstance = null
if (timeout) {
clearTimeout(timeout)
}
clearTimeout(timeout)
resolve()
})
pythonSSRInstance.kill()
if (process.platform === 'win32') {
logger.info('Killing Python SSR')
exec([winKillPath, '-2', pythonSSRInstance.pid].join(' '))
} else {
pythonSSRInstance.kill('SIGINT')
}
quitByCommand = true
})
}
return Promise.resolve()
Expand Down
Loading

0 comments on commit a7c8666

Please sign in to comment.