Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
fix ping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wk989898 committed May 14, 2020
1 parent e68e4a5 commit 35928b0
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 53 deletions.
66 changes: 35 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
# Vtro ![Vtro](./tray.ico)

[![GitHub license](https://img.shields.io/github/license/wk989898/Vtro)](https://github.com/wk989898/Vtro/blob/master/LICENSE)

## 介绍

trojan 的 windows 图形界面

## 注意

- 可以订阅和添加节点
- 默认[配置](extra-trojan/config.json) ssl验证为`false` 其它保持默认,如有需要请自行更改
- 可以订阅和添加节点,更新订阅时会删除原有所有节点
- 默认[配置](extra-trojan/config.json) ssl 验证为`false` 其它保持默认,如有需要请自行更改
- ~~暂时无法更改节点选项,可以删除后再添加~~
- 支持 ping,tcp-ping
- 根据时间改变节点 ( 适用于晚上自动更改连接节点,如果节点质量不好 [try it](https://github.com/wk989898/Vtro/releases/) )
`开始结束时间相同视为关闭 默认:'19:30'-'00:30',`
- [Conf 配置](./extra-trojan/conf.json)

- nodes `array<node>` 节点列表
- sub `array` 订阅组
- config `object` 配置

### config

- mode `string` default: `day`
&nbsp;&nbsp;`night | day`
- proxy `string` default: `pac`
&nbsp;&nbsp;`pac | global | off`
|type|host|port|
|---|----|----|
|pac|localhost|1082/pac|
|http|-|1081|
|socks5|-|1080|
> 设置 off 后只会开启 socks5 端口 !
- time `object`
- startTime default: `'17:30'`

## Feature

### 根据时间改变节点 , 适用于晚上自动更改连接节点(如果节点质量不好)

`开始结束时间相同视为关闭 默认:'19:30'-'00:30',`

## [Conf 配置](./extra-trojan/conf.json)

- nodes `array<node>` 节点列表
- sub `array` 订阅组
- config `object` 配置
- mode `string` default: `day`
&nbsp;&nbsp;`night | day`
- proxy `string` default: `pac`
&nbsp;&nbsp;`pac | global | off`
|type|host|port|
|---|----|----|
|pac|localhost|1082/pac|
|http|-|1081|
|socks5|-|1080|
> 设置 off 后只会开启 socks5 端口 !
- time `object`
- startTime default: `'19:30'`
- endTime default: `'00:30'`
- day `node` 白天节点
- night `node` 夜间节点
- day `node` 白天节点
- night `node` 夜间节点

## 运行

Expand All @@ -49,11 +53,11 @@ cd dist

## Todo

* [x] 更改单个节点
* [x] 新的交互设计
* [x] 分享节点
* [ ] 更改监听端口
* [ ] 统计流量
- [x] 更改单个节点
- [x] 新的交互设计
- [x] 分享节点
- [ ] 更改监听端口
- [ ] 统计流量

## Credits

Expand Down
4 changes: 2 additions & 2 deletions lib/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/bundle.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ ipcMain.on('get-sub', e => {
})
}).on('update', (e, r) => {
addfile('nodes', r.nodes, res => {
// clear nodes
res.nodes.length = 0
}).finally(e => {
// 防止写入数据出错
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vtro",
"version": "0.1.2",
"version": "0.1.3",
"description": "A simple trojan GUI",
"main": "main.js",
"build": {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
allow: 1,
addr: form.addr,
name: form.name,
ping: 0
// ping: 0
}
if (form.addr && typeof form.addr == 'string' && form.port && typeof form.port == 'number' &&
form.name && form.password)
Expand Down
21 changes: 12 additions & 9 deletions src/pages/nodes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
ipc.on('update-nodes', (e, arg) => {
console.log('update-nodes')
this.nodes = this.$global.nodes = arg
this.$forceUpdate()
if (!this.nodes[0].ping) this.nodes.forEach(v => {
this.$set(v, 'ping', 0)
})
// this.$forceUpdate()
}).on('ping', e => {
makeping(this.nodes)
}).on('tcp-ping', e => {
Expand Down Expand Up @@ -110,7 +113,7 @@
})
})
} else if (type === 'ping') {
_tcping(node, res => {
_ping(node, res => {
let result = parseInt(res.avg) || parseInt(res.min) || -1
self.nodes.forEach((v, i) => {
if (v === node) v.ping = result
Expand All @@ -124,15 +127,15 @@
title: '成功',
message: '复制成功',
type: 'success',
duration:1000,
duration: 1000,
showClose: false
})
).catch(()=>this.$notify.error({
title: '失败',
message: '复制失败',
duration:1000,
showClose: false
}))
).catch(() => this.$notify.error({
title: '失败',
message: '复制失败',
duration: 1000,
showClose: false
}))
}
this.$refs.meun.style.height = '0'
},
Expand Down
11 changes: 6 additions & 5 deletions src/utils/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getTcping(hosts) {
})
}
*/

export function _ping(host, cb) {
ping.promise.probe(host.addr, {
timeout: 10
Expand All @@ -44,18 +45,18 @@ export function _tcping(host, cb) {
}).then(cb)
}
export function makeping(lists) {
lists.map(list => {
list.ping = 'wait'
lists.forEach(list => {
// list.ping = 'wait'
_ping(list, res => {
list.ping = parseInt(res.avg) || parseInt(res.min) || -1
list.ping = parseInt(res.avg) || parseInt(res.min) || 'fail'
})
})
}
export function maketcping(lists) {
lists.map(list => {
lists.forEach(list => {
list.ping = 'wait'
_tcping(list, res => {
list.ping = parseInt(res.avg) || parseInt(res.min) || -1
list.ping = parseInt(res.avg) || parseInt(res.min) || 'fail'
})
})
}
Expand Down
4 changes: 1 addition & 3 deletions src/utils/trojan.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class Trojan {
json.allow = arr[3]
json.addr = arr[4]
json.name = decodeURI(arr[5])
// 必须存在 否则会影响 nodes.ping 刷新
// 可能是vue的bug
json.ping = 0
// json.ping = 0
return json
}
subscribe(txt) {
Expand Down

0 comments on commit 35928b0

Please sign in to comment.