From e8053cb41dc21e7e9d3ef01ff3e9f32fcc5cdd39 Mon Sep 17 00:00:00 2001 From: XZB Date: Mon, 21 Mar 2022 21:09:20 +0800 Subject: [PATCH] update CHANGELOG.md and README.md --- CHANGELOG.md | 14 +++++++++++++- README.ZH.md | 26 +++++++++++++------------- README.md | 14 ++++++++------ client/service/terminal/terminal.go | 7 +++---- server/handler/terminal.go | 1 + web/src/components/terminal.js | 21 +++++++++++++-------- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb56461..e868ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ * BREAKING-CHANGE: module `Device` has changed. * THIS RELEASE IS **NOT** COMPATIBLE WITH LAST RELEASE. +* 新增:网络IO速度监控。 +* 新增:客户端自行升级。 +* 修复:在类Unix系统中使用terminal时中文乱码。 +* 破坏性变动:`Device`类型已更改。 +* 本版本**不**兼容上一版本,暂时仍需要手动升级客户端。 + ## v0.0.2 @@ -15,9 +21,15 @@ * BREAKING-CHANGE: module `Device` has changed. * THIS RELEASE IS **NOT** COMPATIBLE WITH LAST RELEASE. +* 新增:网络延迟检测。 +* 新增:CPU使用率进度、内存使用进度、硬盘使用进度。 +* 破坏性变动:`Device`类型已更改。 +* 本版本**不**兼容上一版本,暂时仍需要手动升级客户端。 + ## v0.0.1 * First release. -* \ No newline at end of file + +* 这是第一个发行版。 \ No newline at end of file diff --git a/README.ZH.md b/README.ZH.md index d644b75..b838873 100644 --- a/README.ZH.md +++ b/README.ZH.md @@ -82,40 +82,40 @@ ### 指南 ```bash -# Clone this repository +# Clone该项目 $ git clone https://github.com/XZB-1248/Spark $ cd ./Spark -# Here we're going to build front-end pages. +# 开始编译前端页面 $ cd ./web -# Install all dependencies and build. +# 安装所有的依赖,然后编译。 $ npm install $ npm run build-prod -# Embed all static resources into one single file by using statik. +# 通过statik,将前端文件嵌入到服务端里。 $ cd .. $ go install github.com/rakyll/statik $ statik -m -src="./web/dist" -f -dest="./server/embed" -p web -ns web -# Now we should build client. -$ mkdir ./built -# Use this when you're using windows. -$ ./build.client.bat - -# When you're using unix-like OS, you can use this. +# 开始编译客户端。 +# 在使用类Unix系统时,运行以下命令。 +$ go mod tidy +$ go mod download $ ./build.client.sh +$ statik -m -src="./built" -f -dest="./server/embed" -include=* -p built -ns built -# Finally we're compiling the server side. -$ go build -ldflags "-s -w" -o Spark Spark/Server - +# 最终开始编译服务端。 +$ ./build.server.sh ``` +然后打开`releases`目录,放入上文提到的配置文件,选择对应平台的服务端运行即可。 + --- ## 截图 diff --git a/README.md b/README.md index 8e80fef..72b5b08 100644 --- a/README.md +++ b/README.md @@ -98,19 +98,21 @@ $ statik -m -src="./web/dist" -f -dest="./server/embed" -p web -ns web # Now we should build client. -$ mkdir ./built -# Use this when you're using windows. -$ ./build.client.bat - # When you're using unix-like OS, you can use this. +$ go mod tidy +$ go mod download $ ./build.client.sh +$ statik -m -src="./built" -f -dest="./server/embed" -include=* -p built -ns built # Finally we're compiling the server side. -$ go build -ldflags "-s -w" -o Spark Spark/Server - +$ ./build.server.sh ``` +Then you can find executable files in `releases` directory. + +Copy configuration file mentioned above into this dir, and then you can execute server. + --- ## Screenshots diff --git a/client/service/terminal/terminal.go b/client/service/terminal/terminal.go index 29a1c06..bdf8559 100644 --- a/client/service/terminal/terminal.go +++ b/client/service/terminal/terminal.go @@ -183,11 +183,10 @@ func getTerminal() string { if runtime.GOOS == `windows` { return `cmd.exe` } - sh := []string{`bash`, `zsh`, `sh`} + sh := []string{`/bin/bash`, `/bin/zsh`, `/bin/sh`} for i := 0; i < len(sh); i++ { - f, err := os.Open(sh[i]) - if err == nil { - f.Close() + _, err := os.Stat(sh[i]) + if !errors.Is(err, os.ErrNotExist) { return sh[i] } } diff --git a/server/handler/terminal.go b/server/handler/terminal.go index 1eb3736..69a4bca 100644 --- a/server/handler/terminal.go +++ b/server/handler/terminal.go @@ -146,6 +146,7 @@ func eventWrapper(terminal *terminal) common.EventCallback { simpleSendPack(modules.Packet{Act: `warn`, Msg: msg}, terminal.session) terminals.Remove(terminal.termUUID) common.RemoveEvent(terminal.eventUUID) + terminal.session.Close() } return } diff --git a/web/src/components/terminal.js b/web/src/components/terminal.js index ce2abdf..09a14d2 100644 --- a/web/src/components/terminal.js +++ b/web/src/components/terminal.js @@ -1,5 +1,5 @@ import React, {createRef} from "react"; -import {Modal} from "antd"; +import {message, Modal} from "antd"; import {Terminal} from "xterm"; import {WebLinksAddon} from "xterm-addon-web-links"; import {FitAddon} from "xterm-addon-fit"; @@ -160,15 +160,20 @@ class TerminalModal extends React.Component { let data = this.decrypt(e.data); try { data = JSON.parse(data); - } catch (_) { - } + } catch (_) {} if (this.conn) { - data = ab2str(hex2buf(data?.data?.output)); - if (data === buffer) { - buffer = ''; + if (data?.act === 'outputTerminal') { + data = ab2str(hex2buf(data?.data?.output)); + if (data === buffer) { + buffer = ''; + return; + } + this.term.write(data); return; } - this.term.write(data); + if (data?.act === 'warn') { + message.warn(data.msg??'未知错误'); + } } } this.ws.onclose = (e) => { @@ -230,7 +235,7 @@ class TerminalModal extends React.Component { if (this.conn) { this.ws.close(); } - this.termEv.dispose(); + this?.termEv?.dispose(); this.termEv = null; } else { if (this.props.visible) {