forked from Akkariiin/electron-ssr
-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from xVanTuring/v0.3.0
0.3.0-alpha.3
- Loading branch information
Showing
22 changed files
with
11,131 additions
and
11,303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.