Skip to content

Commit

Permalink
Merge pull request #58 from xVanTuring/v0.3.0
Browse files Browse the repository at this point in the history
...
  • Loading branch information
Akkariiin authored Feb 23, 2020
2 parents a7c8666 + 56d2e23 commit 4860205
Show file tree
Hide file tree
Showing 27 changed files with 1,197 additions and 832 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ install:
fi
script:
- yarn fetch-dep && yarn run electron:build
- yarn fetch-dep && yarn run electron:build
if: tag IS blank
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ build_script:

test: off

skip_tags: true
25 changes: 25 additions & 0 deletions docs/Build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## How to Build

### Req
> You will need these to build Electron-SSR
1. node.js
2. yarn
3. network
4. time
5. love
6. passion
7. family
8. friends
9. ...
> Living in CN? \
> [mirrors for electron](https://npm.taobao.org/mirrors/)
### Build
1. `yarn`
2. `yarn fetch-dep` will fetch 3dparty software like `socks2http`,`windows-kill`
> env variable `http_proxy`, `fetch_proxy` in `socks5`, and `http` will be used as proxy automatically.\
> Or you can try adding argument `-m` which will use a [github-mirror](http://github-mirror.bugkiller.org/) to download files, but it may be insecure.
3. `yarn electron:build` will build available target, make sure edit it as you need in `vue.config.js` if you are in linux

### Extra
N/A
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@
},
"devDependencies": {
"@kazupon/vue-i18n-loader": "^0.3.0",
"@vue/cli-plugin-babel": "^4.1.0",
"@vue/cli-plugin-eslint": "^4.1.0",
"@vue/cli-plugin-vuex": "^4.1.0",
"@vue/cli-service": "^4.1.0",
"@vue/cli-plugin-babel": "^4.2.2",
"@vue/cli-plugin-eslint": "^4.2.2",
"@vue/cli-plugin-vuex": "^4.2.2",
"@vue/cli-service": "^4.2.2",
"@vue/eslint-config-standard": "^4.0.0",
"babel-eslint": "^10.0.3",
"chalk": "^3.0.0",
"cli-progress": "^3.6.0",
"devtron": "^1.4.0",
"electron": "^6.0.0",
"electron": "^6.1.7",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"request": "^2.88.2",
"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-electron-builder": "^1.4.5",
"vue-cli-plugin-i18n": "^0.6.1",
"vue-template-compiler": "^2.6.10"
},
Expand Down
41 changes: 36 additions & 5 deletions scripts/fetch_deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const fs = require('fs')
const { ensureDir, copy, readdir } = require('fs-extra')
const { exec } = require('child_process')
const unzipper = require('unzipper')
const chalk = require('chalk')
const cliProgress = require('cli-progress')
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}`)
Expand Down Expand Up @@ -119,21 +122,49 @@ async function getWindowsKill () {
await extractFile(downloadPath)
await copy(path.join(tmpDir, folderName, 'windows-kill.exe'), path.join(copyDir, 'windows-kill.exe'))
}
/**
*
* @param {string} url
* @param {string} path
*/
function downloadFile (url, path) {
return new Promise((resolve, reject) => {
let useMirror = process.argv.indexOf('-m') >= 0
// let isDebug = process.argv.indexOf('-d') >= 0
if (useMirror) {
const mirrorHost = 'http://github-mirror.bugkiller.org'
console.log(chalk.red(`Using github-mirror from ${mirrorHost}, it may not be safe.`))
url = url.replace('https://github.com', mirrorHost)
}
console.log(`Start Downloading: ${url}`)
const file = fs.createWriteStream(path)
let option = {
url: url,
header: {
'User-Agent': 'request'
'User-Agent': 'electron-ssr'
}
}
withProxy(option)
withGHToken(option)
request(option).on('error', reject).pipe(file)
if (!useMirror) {
withProxy(option)
withGHToken(option)
}
let req = request(option)
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)
req.on('error', (error) => {
reject(error)
bar.stop()
})
req.on('response', (resp) => {
bar.start(parseInt(resp.headers['content-length'], 10), 0)
})
req.pipe(file)
let sum = 0
req.on('data', (chunk) => {
sum += chunk.length
bar.update(sum)
})
file.on('close', () => {
console.log('WRITE DONE!')
bar.stop()
resolve()
})
})
Expand Down
71 changes: 48 additions & 23 deletions src/main/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-unused-vars */
import path from 'path'
import { app, dialog } from 'electron'
import { ensureDir, pathExists, outputJson } from 'fs-extra'
import { ensureDir, pathExists, outputJson, readJson } from 'fs-extra'
import logger from './logger'
import sudo from 'sudo-prompt'
import defaultConfig from '../shared/config'
import { isWin, isMac, isLinux, isOldMacVersion, isPythonInstalled } from '../shared/env'
import { init as initIcon } from '../shared/icon'
import * as i18n from './locales'
import { installMacHelpTool } from './tray-handler'
const $t = i18n.default
// app ready事件
export const readyPromise = new Promise(resolve => {
Expand Down Expand Up @@ -37,6 +38,7 @@ export const appConfigPath = path.join(appConfigDir, 'gui-config.json')
export const defaultSSRDownloadDir = path.join(appConfigDir, 'shadowsocksr')
// pac文件下载目录
export const pacPath = path.join(appConfigDir, 'pac.txt')
export const pacRawPath = path.join(appConfigDir, 'pac.raw.txt')

export const privoxyCfgPath = path.join(appConfigDir, 'privoxy.cfg')
// 记录上次订阅更新时间的文件
Expand Down Expand Up @@ -73,19 +75,7 @@ export const s2hPath = _s2hPath
// mac proxy_conf_helper工具目录
export const macToolPath = path.resolve(appConfigDir, 'proxy_conf_helper')
export const libsodiumDir = _libsodiumDir

// 在mac上执行sudo命令
async function sudoMacCommand (command) {
return new Promise((resolve, reject) => {
sudo.exec(command, { name: 'ShadowsocksR Client' }, (error, stdout, stderr) => {
if (error || stderr) {
reject(error || stderr)
} else {
resolve(stdout)
}
})
})
}
/**
* 确保文件存在,目录正常
*/
Expand All @@ -94,18 +84,53 @@ async function init () {
await ensureDir(appConfigDir)
// 判断配置文件是否存在,不存在用默认数据写入
const configFileExists = await pathExists(appConfigPath)
if (!configFileExists) {
await outputJson(appConfigPath, defaultConfig, { spaces: '\t' })
}
await ensureDir(path.join(appConfigDir, 'logs'))

// 初始化确保文件存在, 10.11版本以下不支持该功能
if (isMac && !isOldMacVersion && !await pathExists(macToolPath)) {
const helperPath = process.env.NODE_ENV === 'development'
? path.join(__dirname, '../lib/proxy_conf_helper')
: path.join(exePath, '../../../Contents/proxy_conf_helper')
await sudoMacCommand(`cp ${helperPath} "${macToolPath}" && chown root:admin "${macToolPath}" && chmod a+rx "${macToolPath}" && chmod +s "${macToolPath}"`)

await readyPromise
if (!configFileExists) {
// todo better locale detect
let config = null
let locale = app.getLocale()
if (locale.startsWith('zh')) {
config = Object.assign({}, { lang: 'zh-CN' }, defaultConfig)
} else {
config = Object.assign({}, { lang: 'en-US' }, defaultConfig)
}
await outputJson(appConfigPath, config, { spaces: 4 })
}
if (isMac) {
let msg = 'Installing macOS Proxy Conf Helper.\n\nWe need install an extra tool to help configuring system proxy.\nYou can always choose to install it in tray menu.'
let config = await readJson(appConfigPath)
if (!await isOldMacVersion) {
if (!await pathExists(macToolPath)) {
if (!config.noMacToolInstall) {
let result = await dialog.showMessageBox(null, {
type: 'question',
buttons: ['Continue', 'No'],
defaultId: 0,
title: 'Installing macOS Proxy Conf Helper.',
message: msg
})
if (result.response === 0) {
try {
await installMacHelpTool()
config['isMacToolInstalled'] = true
} catch (error) {
console.log(error)
logger.error('Failed to install mac proxy_conf_helper')
}
} else {
config['noMacToolInstall'] = true
config['isMacToolInstalled'] = false
}
}
} else {
config['isMacToolInstalled'] = true
}
await outputJson(appConfigPath, config, { spaces: 4 })
}
}
return readyPromise
}
export default init()
2 changes: 1 addition & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (!isPrimaryInstance) {

// 开机自启动配置
const AutoLauncher = new AutoLaunch({
name: 'ShadowsocksR Client',
name: 'Electron SSR',
isHidden: true,
mac: {
useLaunchAgent: true
Expand Down
4 changes: 3 additions & 1 deletion src/main/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
"NOTI_CHECK_PORT":"Please check yout port",
"NOTI_PROCESS_CANT_KILL":"Process {pid} may not be closed, please try close it manually",
"NOTI_PYTHON_MISSING_TITLE": "No python detected",
"NOTI_PYTHON_MISSING_DETAIL": "The backend of this program requires python\n Please Make sure you have it installed"
"NOTI_PYTHON_MISSING_DETAIL": "The backend of this program requires python\n Please Make sure you have it installed",
"NOTI_PAC_UPDATE_SUCC":"PAC File Updated",
"NOTI_PAC_UPDATE_FAILED":"PAC Updating Failed, Please check your network and DNS"
}
2 changes: 1 addition & 1 deletion src/main/locales/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export default function $t (key, format = null) {
}
return raw
}
return dict[key]
return dict[key] || key
}
5 changes: 3 additions & 2 deletions src/main/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"NOTI_CHECK_PORT":"请检查你端口占用",
"NOTI_PROCESS_CANT_KILL":"进程 {pid} 可能无法关闭,尝试手动关闭",
"NOTI_PYTHON_MISSING_TITLE": "未检测到python",
"NOTI_PYTHON_MISSING_DETAIL": "本程序所使用的后端为python版ssr/ssrr\n请确保已安装python且可正常使用,否则软件可能无法正常运行"

"NOTI_PYTHON_MISSING_DETAIL": "本程序所使用的后端为python版ssr/ssrr\n请确保已安装python且可正常使用,否则软件可能无法正常运行",
"NOTI_PAC_UPDATE_SUCC":"PAC文件更新成功",
"NOTI_PAC_UPDATE_FAILED":"PAC文件更新失败, 请检查你的网络和DNS"
}
Loading

0 comments on commit 4860205

Please sign in to comment.