Skip to content

Commit

Permalink
Merge pull request #64 from xVanTuring/v0.3.0
Browse files Browse the repository at this point in the history
0.3.0-alpha.3
  • Loading branch information
xVanTuring authored Feb 27, 2020
2 parents 4860205 + ca021b9 commit c073053
Show file tree
Hide file tree
Showing 22 changed files with 11,131 additions and 11,303 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ dist_electron

src/lib/*
!src/lib/mac_service.sh
!src/lib/proxy_conf_helper
!src/lib/proxy_conf_helper
!src/lib/LICENSE
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-ssr",
"version": "0.3.0",
"version": "0.3.0-alpha.3",
"description": "Cross platform ShadowsocksR GUI client built with electron",
"author": {
"name": "The Electron-SSR Authors",
Expand All @@ -26,7 +26,6 @@
"iview": "^3.5.4",
"mousetrap": "^1.6.3",
"qr-image": "^3.2.0",
"rxjs": "^6.5.4",
"sudo-prompt": "^9.1.1",
"urlsafe-base64": "^1.0.0",
"vue": "^2.6.10",
Expand Down
119 changes: 119 additions & 0 deletions src/lib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
libsodium.dll

/*
* ISC License
*
* Copyright (c) 2013-2020
* Frank Denis <j at pureftpd dot org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

socks2http

The MIT License (MIT)

Copyright (c) 2020 xVanTuring <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


The MIT License (MIT)

Copyright (c) 2017 Y. T. CHUNG <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
© 2020 GitHub, Inc.

windows-kill.exe
MIT License

Copyright (c) 2017-2018 Alireza Dabiri Nejad <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

sysproxy

Copyright 2020 xVanTuring

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2016-2019 Noisyfox

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
19 changes: 9 additions & 10 deletions src/main/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ export const readyPromise = new Promise(resolve => {
app.once('ready', resolve)
}
})
isPythonInstalled.then(async (value) => {
// 检查python是否安装
if (!value) {
await readyPromise
dialog.showErrorBox($t('NOTI_PYTHON_MISSING_TITLE'), $t('NOTI_PYTHON_MISSING_DETAIL'))
}
})

// 未捕获的rejections
process.on('unhandledRejection', (reason) => {
Expand Down Expand Up @@ -67,6 +60,9 @@ if (isWin) {
_s2hPath = path.resolve(__dirname, '../src/lib/socks2http')
} else {
_s2hPath = path.join(path.dirname(exePath), './3rdparty/socks2http')
if (isMac) {
_s2hPath = path.join(path.dirname(exePath), '../3rdparty/socks2http')
}
}
}
export const winToolPath = _winToolPath
Expand All @@ -85,10 +81,13 @@ async function init () {
// 判断配置文件是否存在,不存在用默认数据写入
const configFileExists = await pathExists(appConfigPath)
await ensureDir(path.join(appConfigDir, 'logs'))

// 初始化确保文件存在, 10.11版本以下不支持该功能

await readyPromise
isPythonInstalled.then(async (value) => {
// Check Python existence
if (!value) {
dialog.showErrorBox($t('NOTI_PYTHON_MISSING_TITLE'), $t('NOTI_PYTHON_MISSING_DETAIL'))
}
})
if (!configFileExists) {
// todo better locale detect
let config = null
Expand Down
116 changes: 50 additions & 66 deletions src/main/data.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,85 @@
import { Observable, Subject } from 'rxjs'

import { multicast, refCount } from 'rxjs/operators'
import { readJson, writeJson } from 'fs-extra'
import events from 'events'
import fse from 'fs-extra'
import bootstrapPromise, { appConfigPath } from './bootstrap'
import { sendData } from './window'
import { EVENT_RX_SYNC_MAIN } from '../shared/events'
import { isArray, getUpdatedKeys, configMerge, clone } from '../shared/utils'
import defaultConfig, { mergeConfig } from '../shared/config'

let promise
// 是因为调用app.quit还是手动点击窗口的叉号引起的关闭事件, true表示app.quit
import { EVENT_RX_SYNC_MAIN } from '@/shared/events'
import defaultConfig, { mergeConfig } from '@/shared/config'
import { isArray, getUpdatedKeys, configMerge, clone } from '@/shared/utils'
import logger from './logger'
let currentConfig = null
let _isQuiting = false
// 是否是来自renderer的同步数据
let isFromRenderer = false
// 当前配置
export let currentConfig
let _isFromRenderer = false
class Data {
constructor () {
this.emitter = new events.EventEmitter()
}
async init () {
logger.debug('RX DATA Init')
await bootstrapPromise
const stored = await read()
mergeConfig(stored)
currentConfig = stored
this.next([stored, [], null, isProxyStarted(stored), false])
}
next (data) {
this.emitter.emit('data', data)
}
subscribe (fn) {
this.emitter.on('data', fn)
}
}

// 读取配置
let appConfig$ = new Data()
function isProxyStarted (appConfig) {
return !!(appConfig.enable && appConfig.configs && appConfig.configs[appConfig.index])
}
async function read () {
try {
return await readJson(appConfigPath)
} catch (e) {
let exist = await fse.pathExists(appConfigPath)
if (exist) {
try {
return fse.readJson(appConfigPath)
} catch (error) {
logger.error(`The config: ${appConfigPath} is corrupted, using the default config now!`)
return Promise.resolve(defaultConfig)
}
} else {
return Promise.resolve(defaultConfig)
}
}

// 应用起步后初始化
async function init () {
await bootstrapPromise
const stored = await read()
mergeConfig(stored)
return stored
// appConfig$.init()
export {
currentConfig,
appConfig$
}

// 支持多播
const subject = new Subject()
let _observe
const source = Observable.create(observe => {
_observe = observe
// 初始化数据
promise = init().then(data => {
currentConfig = data
isFromRenderer = false
// 第一个参数为当前配置对象,第二个参数为变更的字段数组,第三个参数为旧配置,第四个参数为当前配置对应是否开启了代理,第五个参数为旧配置对应是否开启了代理
observe.next([data, [], null, isProxyStarted(data), false])
})
})

// 当前是否已选择某节点,即socks代理是否选中并启用
export function isProxyStarted (appConfig) {
return !!(appConfig.enable && appConfig.configs && appConfig.configs[appConfig.index])
}

/**
* 统一使用该接口从外部更新应用配置
* @param {Object} targetConfig 要更新的配置
*/
export function updateAppConfig (targetConfig, fromRenderer = false, forceAppendArray = false) {
const changedKeys = getUpdatedKeys(currentConfig, targetConfig)
// // 只有有数据变更才更新配置
if (changedKeys.length) {
const oldConfig = clone(currentConfig, true)
configMerge(currentConfig, targetConfig, forceAppendArray)
isFromRenderer = fromRenderer
_observe.next([currentConfig, changedKeys, oldConfig, isProxyStarted(currentConfig), isProxyStarted(oldConfig)])
_isFromRenderer = fromRenderer
appConfig$.next([currentConfig, changedKeys, oldConfig, isProxyStarted(currentConfig), isProxyStarted(oldConfig)])
}
}

/**
* 新增单/多个配置
* @param {Array} configs 要添加的配置数组
*/
export function addConfigs (configs) {
updateAppConfig({ configs: currentConfig.configs.concat(isArray(configs) ? configs : [configs]) }, false, true)
}
export const appConfig$ = source.pipe(multicast(subject), refCount())

// 传参用于设定是退出应用还是关闭窗口 不传参表示返回当前状态
export function isQuiting (target) {
if (target !== undefined) {
_isQuiting = target
} else {
return _isQuiting
}
}

// 配置文件变化时
appConfig$.subscribe(data => {
appConfig$.subscribe((data) => {
const [appConfig, changed] = data
if (changed.length) {
// 如果更新则写入配置文件
writeJson(appConfigPath, appConfig, { spaces: '\t' })
fse.writeJson(appConfigPath, appConfig, { spaces: '\t' })
// 如果是从renderer同步过来的数据则不再同步回去,避免重复同步
if (!isFromRenderer) {
// ignore if it came from Renderer
if (!_isFromRenderer) {
sendData(EVENT_RX_SYNC_MAIN, appConfig)
}
}
})

export default promise
Loading

0 comments on commit c073053

Please sign in to comment.