Skip to content

Commit c073053

Browse files
author
xVanTuring
authored
Merge pull request shadowsocksrr#64 from xVanTuring/v0.3.0
0.3.0-alpha.3
2 parents 4860205 + ca021b9 commit c073053

File tree

22 files changed

+11131
-11303
lines changed

22 files changed

+11131
-11303
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@ dist_electron
136136

137137
src/lib/*
138138
!src/lib/mac_service.sh
139-
!src/lib/proxy_conf_helper
139+
!src/lib/proxy_conf_helper
140+
!src/lib/LICENSE

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-ssr",
3-
"version": "0.3.0",
3+
"version": "0.3.0-alpha.3",
44
"description": "Cross platform ShadowsocksR GUI client built with electron",
55
"author": {
66
"name": "The Electron-SSR Authors",
@@ -26,7 +26,6 @@
2626
"iview": "^3.5.4",
2727
"mousetrap": "^1.6.3",
2828
"qr-image": "^3.2.0",
29-
"rxjs": "^6.5.4",
3029
"sudo-prompt": "^9.1.1",
3130
"urlsafe-base64": "^1.0.0",
3231
"vue": "^2.6.10",

src/lib/LICENSE

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
libsodium.dll
2+
3+
/*
4+
* ISC License
5+
*
6+
* Copyright (c) 2013-2020
7+
* Frank Denis <j at pureftpd dot org>
8+
*
9+
* Permission to use, copy, modify, and/or distribute this software for any
10+
* purpose with or without fee is hereby granted, provided that the above
11+
* copyright notice and this permission notice appear in all copies.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20+
*/
21+
22+
socks2http
23+
24+
The MIT License (MIT)
25+
26+
Copyright (c) 2020 xVanTuring <xVanTuring@outlook.com>
27+
28+
Permission is hereby granted, free of charge, to any person obtaining a copy of
29+
this software and associated documentation files (the "Software"), to deal in
30+
the Software without restriction, including without limitation the rights to
31+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
32+
the Software, and to permit persons to whom the Software is furnished to do so,
33+
subject to the following conditions:
34+
35+
The above copyright notice and this permission notice shall be included in all
36+
copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
40+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
41+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
42+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44+
45+
46+
The MIT License (MIT)
47+
48+
Copyright (c) 2017 Y. T. CHUNG <zonyitoo@gmail.com>
49+
50+
Permission is hereby granted, free of charge, to any person obtaining a copy of
51+
this software and associated documentation files (the "Software"), to deal in
52+
the Software without restriction, including without limitation the rights to
53+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
54+
the Software, and to permit persons to whom the Software is furnished to do so,
55+
subject to the following conditions:
56+
57+
The above copyright notice and this permission notice shall be included in all
58+
copies or substantial portions of the Software.
59+
60+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
61+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
62+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
63+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
64+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
65+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66+
© 2020 GitHub, Inc.
67+
68+
windows-kill.exe
69+
MIT License
70+
71+
Copyright (c) 2017-2018 Alireza Dabiri Nejad <alireza.dabirinejad@live.com>
72+
73+
Permission is hereby granted, free of charge, to any person obtaining a copy
74+
of this software and associated documentation files (the "Software"), to deal
75+
in the Software without restriction, including without limitation the rights
76+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77+
copies of the Software, and to permit persons to whom the Software is
78+
furnished to do so, subject to the following conditions:
79+
80+
The above copyright notice and this permission notice shall be included in all
81+
copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89+
SOFTWARE.
90+
91+
sysproxy
92+
93+
Copyright 2020 xVanTuring
94+
95+
Licensed under the Apache License, Version 2.0 (the "License");
96+
you may not use this file except in compliance with the License.
97+
You may obtain a copy of the License at
98+
99+
http://www.apache.org/licenses/LICENSE-2.0
100+
101+
Unless required by applicable law or agreed to in writing, software
102+
distributed under the License is distributed on an "AS IS" BASIS,
103+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104+
See the License for the specific language governing permissions and
105+
limitations under the License.
106+
107+
Copyright 2016-2019 Noisyfox
108+
109+
Licensed under the Apache License, Version 2.0 (the "License");
110+
you may not use this file except in compliance with the License.
111+
You may obtain a copy of the License at
112+
113+
http://www.apache.org/licenses/LICENSE-2.0
114+
115+
Unless required by applicable law or agreed to in writing, software
116+
distributed under the License is distributed on an "AS IS" BASIS,
117+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
118+
See the License for the specific language governing permissions and
119+
limitations under the License.

src/main/bootstrap.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ export const readyPromise = new Promise(resolve => {
1717
app.once('ready', resolve)
1818
}
1919
})
20-
isPythonInstalled.then(async (value) => {
21-
// 检查python是否安装
22-
if (!value) {
23-
await readyPromise
24-
dialog.showErrorBox($t('NOTI_PYTHON_MISSING_TITLE'), $t('NOTI_PYTHON_MISSING_DETAIL'))
25-
}
26-
})
2720

2821
// 未捕获的rejections
2922
process.on('unhandledRejection', (reason) => {
@@ -67,6 +60,9 @@ if (isWin) {
6760
_s2hPath = path.resolve(__dirname, '../src/lib/socks2http')
6861
} else {
6962
_s2hPath = path.join(path.dirname(exePath), './3rdparty/socks2http')
63+
if (isMac) {
64+
_s2hPath = path.join(path.dirname(exePath), '../3rdparty/socks2http')
65+
}
7066
}
7167
}
7268
export const winToolPath = _winToolPath
@@ -85,10 +81,13 @@ async function init () {
8581
// 判断配置文件是否存在,不存在用默认数据写入
8682
const configFileExists = await pathExists(appConfigPath)
8783
await ensureDir(path.join(appConfigDir, 'logs'))
88-
89-
// 初始化确保文件存在, 10.11版本以下不支持该功能
90-
9184
await readyPromise
85+
isPythonInstalled.then(async (value) => {
86+
// Check Python existence
87+
if (!value) {
88+
dialog.showErrorBox($t('NOTI_PYTHON_MISSING_TITLE'), $t('NOTI_PYTHON_MISSING_DETAIL'))
89+
}
90+
})
9291
if (!configFileExists) {
9392
// todo better locale detect
9493
let config = null

src/main/data.js

Lines changed: 50 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,85 @@
1-
import { Observable, Subject } from 'rxjs'
2-
3-
import { multicast, refCount } from 'rxjs/operators'
4-
import { readJson, writeJson } from 'fs-extra'
1+
import events from 'events'
2+
import fse from 'fs-extra'
53
import bootstrapPromise, { appConfigPath } from './bootstrap'
64
import { sendData } from './window'
7-
import { EVENT_RX_SYNC_MAIN } from '../shared/events'
8-
import { isArray, getUpdatedKeys, configMerge, clone } from '../shared/utils'
9-
import defaultConfig, { mergeConfig } from '../shared/config'
10-
11-
let promise
12-
// 是因为调用app.quit还是手动点击窗口的叉号引起的关闭事件, true表示app.quit
5+
import { EVENT_RX_SYNC_MAIN } from '@/shared/events'
6+
import defaultConfig, { mergeConfig } from '@/shared/config'
7+
import { isArray, getUpdatedKeys, configMerge, clone } from '@/shared/utils'
8+
import logger from './logger'
9+
let currentConfig = null
1310
let _isQuiting = false
14-
// 是否是来自renderer的同步数据
15-
let isFromRenderer = false
16-
// 当前配置
17-
export let currentConfig
11+
let _isFromRenderer = false
12+
class Data {
13+
constructor () {
14+
this.emitter = new events.EventEmitter()
15+
}
16+
async init () {
17+
logger.debug('RX DATA Init')
18+
await bootstrapPromise
19+
const stored = await read()
20+
mergeConfig(stored)
21+
currentConfig = stored
22+
this.next([stored, [], null, isProxyStarted(stored), false])
23+
}
24+
next (data) {
25+
this.emitter.emit('data', data)
26+
}
27+
subscribe (fn) {
28+
this.emitter.on('data', fn)
29+
}
30+
}
1831

19-
// 读取配置
32+
let appConfig$ = new Data()
33+
function isProxyStarted (appConfig) {
34+
return !!(appConfig.enable && appConfig.configs && appConfig.configs[appConfig.index])
35+
}
2036
async function read () {
21-
try {
22-
return await readJson(appConfigPath)
23-
} catch (e) {
37+
let exist = await fse.pathExists(appConfigPath)
38+
if (exist) {
39+
try {
40+
return fse.readJson(appConfigPath)
41+
} catch (error) {
42+
logger.error(`The config: ${appConfigPath} is corrupted, using the default config now!`)
43+
return Promise.resolve(defaultConfig)
44+
}
45+
} else {
2446
return Promise.resolve(defaultConfig)
2547
}
2648
}
2749

28-
// 应用起步后初始化
29-
async function init () {
30-
await bootstrapPromise
31-
const stored = await read()
32-
mergeConfig(stored)
33-
return stored
50+
// appConfig$.init()
51+
export {
52+
currentConfig,
53+
appConfig$
3454
}
35-
36-
// 支持多播
37-
const subject = new Subject()
38-
let _observe
39-
const source = Observable.create(observe => {
40-
_observe = observe
41-
// 初始化数据
42-
promise = init().then(data => {
43-
currentConfig = data
44-
isFromRenderer = false
45-
// 第一个参数为当前配置对象,第二个参数为变更的字段数组,第三个参数为旧配置,第四个参数为当前配置对应是否开启了代理,第五个参数为旧配置对应是否开启了代理
46-
observe.next([data, [], null, isProxyStarted(data), false])
47-
})
48-
})
49-
50-
// 当前是否已选择某节点,即socks代理是否选中并启用
51-
export function isProxyStarted (appConfig) {
52-
return !!(appConfig.enable && appConfig.configs && appConfig.configs[appConfig.index])
53-
}
54-
55-
/**
56-
* 统一使用该接口从外部更新应用配置
57-
* @param {Object} targetConfig 要更新的配置
58-
*/
5955
export function updateAppConfig (targetConfig, fromRenderer = false, forceAppendArray = false) {
6056
const changedKeys = getUpdatedKeys(currentConfig, targetConfig)
6157
// // 只有有数据变更才更新配置
6258
if (changedKeys.length) {
6359
const oldConfig = clone(currentConfig, true)
6460
configMerge(currentConfig, targetConfig, forceAppendArray)
65-
isFromRenderer = fromRenderer
66-
_observe.next([currentConfig, changedKeys, oldConfig, isProxyStarted(currentConfig), isProxyStarted(oldConfig)])
61+
_isFromRenderer = fromRenderer
62+
appConfig$.next([currentConfig, changedKeys, oldConfig, isProxyStarted(currentConfig), isProxyStarted(oldConfig)])
6763
}
6864
}
69-
70-
/**
71-
* 新增单/多个配置
72-
* @param {Array} configs 要添加的配置数组
73-
*/
7465
export function addConfigs (configs) {
7566
updateAppConfig({ configs: currentConfig.configs.concat(isArray(configs) ? configs : [configs]) }, false, true)
7667
}
77-
export const appConfig$ = source.pipe(multicast(subject), refCount())
78-
79-
// 传参用于设定是退出应用还是关闭窗口 不传参表示返回当前状态
8068
export function isQuiting (target) {
8169
if (target !== undefined) {
8270
_isQuiting = target
8371
} else {
8472
return _isQuiting
8573
}
8674
}
87-
88-
// 配置文件变化时
89-
appConfig$.subscribe(data => {
75+
appConfig$.subscribe((data) => {
9076
const [appConfig, changed] = data
9177
if (changed.length) {
92-
// 如果更新则写入配置文件
93-
writeJson(appConfigPath, appConfig, { spaces: '\t' })
78+
fse.writeJson(appConfigPath, appConfig, { spaces: '\t' })
9479
// 如果是从renderer同步过来的数据则不再同步回去,避免重复同步
95-
if (!isFromRenderer) {
80+
// ignore if it came from Renderer
81+
if (!_isFromRenderer) {
9682
sendData(EVENT_RX_SYNC_MAIN, appConfig)
9783
}
9884
}
9985
})
100-
101-
export default promise

0 commit comments

Comments
 (0)