Skip to content

Commit

Permalink
feat:进度条、支持32位系统
Browse files Browse the repository at this point in the history
  • Loading branch information
UlinoyaPed committed Mar 16, 2024
1 parent 3561c53 commit 0057716
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 21 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# QuickClash

QuickClash是一个用于快速启动Clash的工具,适用于临时设备,并且仅支持Windows操作系统。

## 功能特点

### 程序流程:
1. 下载配置文件和WebUI资源文件。
2. 加载和解析配置文件。
3. 启动一个Gin实例,用于提供Web界面。
4. 检查订阅文件是否需要更新,并在需要时更新订阅。
5. 检查所需的Clash内核文件是否存在,并在需要时下载。
6. 启动Clash,并使用配置文件运行。
7. 设置系统代理,将流量导向Clash。
8. 在程序终止时自动取消代理。
9. 打印相关提示信息。

### 特点:
1. 支持多语言功能。
2. 通过配置文件选择使用的Clash内核(Clash或ClashMeta)。
3. 支持下载和解压WebUI资源文件。
4. 支持自动检查和下载新的配置文件。
5. 在启动Clash之后设置系统代理。
6. 使用Gin作为Web界面的服务器。

### NEW:
- 进度条
- 支持32位系统

## 使用方法

1. 下载最新版本的QuickClash工具。
2. 解压缩下载的文件到你想要存放的目录。
3. 双击运行QuickClash.exe文件。
4. Clash将会启动。

## 注意事项

- 本工具仅适用于Windows操作系统。

## 许可证

本项目使用GPL-3.0许可证。有关详细信息,请参阅 [LICENSE](LICENSE) 文件。
6 changes: 5 additions & 1 deletion config/QuickClash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ quickclash:
#"zh-CN": "简体中文"
#"zh-TW": "繁體中文"
lang: zh-CN

#sublink可留空,但需要在程序运行时手动输入
sublink:
#WebUI的端口
port: 80
#secret可为空
secret: 123456
#填写 clash 或 clash.meta
#如果订阅文件不存在或超过多少小时则下载
duration: 6
#填写 clash clash.meta clash.metax86
#32位系统无论填什么都只能用metax86
core: clash.meta
36 changes: 36 additions & 0 deletions download.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
package main

import (
"io"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/gookit/color"
"github.com/schollz/progressbar/v3"
)

func DownloadWithBar(url string, filepath string) error {
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()

// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// Create our progress bar
bar := progressbar.Default(resp.ContentLength)

// Create our reader and stat the size of our file
reader := io.TeeReader(resp.Body, bar)

// Write the body to file
_, err = io.Copy(out, reader)
if err != nil {
return err
}

bar.Add(int(resp.ContentLength))
bar.Finish()

return nil
}

func Download(url string, filepath string) error {
// HTTP GET请求 下载配置文件
resp, err := http.Get(url)
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/gookit/color v1.5.4
github.com/gookit/config/v2 v2.2.3
github.com/gookit/i18n v1.1.4
github.com/schollz/progressbar/v3 v3.14.2
)

require (
Expand All @@ -28,20 +29,22 @@ require (
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/protobuf v1.30.0 // indirect
Expand Down
19 changes: 13 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
Expand All @@ -57,8 +58,10 @@ github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNa
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand All @@ -70,6 +73,10 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/schollz/progressbar/v3 v3.14.2 h1:EducH6uNLIWsr560zSV1KrTeUb/wZGAHqyMFIEa99ks=
github.com/schollz/progressbar/v3 v3.14.2/go.mod h1:aQAZQnhF4JGFtRJiw/eobaXpsqpVQAftEQ+hLGXaRc4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down Expand Up @@ -108,12 +115,12 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28=
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
Expand Down
24 changes: 15 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"time"

"github.com/dablelv/go-huge-util/zip"
Expand Down Expand Up @@ -104,8 +105,8 @@ func main() {
duration = time.Since(modTime)
}

// 如果文件不存在或超过6小时则下载
if errStat != nil || duration.Hours() > 6 {
// 如果文件不存在或超过多少小时则下载
if errStat != nil || duration.Hours() > config.Float("quickclash.duration") {
SubUrl = config.String("quickclash.sublink")
if SubUrl == "" {
color.BgLightBlue.Println(i18n.Dtr("inputSublink"))
Expand All @@ -132,12 +133,17 @@ func main() {
}

//检查内核
if config.String("quickclash.core") == "clash" {
Core = ClashCore
color.BgLightBlue.Println(i18n.Dtr("currentCore", "Clash"))
} else if config.String("quickclash.core") == "clash.meta" {
Core = ClashMetaCore
color.BgLightBlue.Println(i18n.Dtr("currentCore", "ClashMeta"))
if runtime.GOARCH == "386" || config.String("quickclash.core") == "clash.metax86" {
Core = ClashMetaCorex86
color.BgLightBlue.Println(i18n.Dtr("currentCore", "ClashMeta X86"))
} else if runtime.GOARCH == "amd64" {
if config.String("quickclash.core") == "clash" {
Core = ClashCore
color.BgLightBlue.Println(i18n.Dtr("currentCore", "Clash"))
} else if config.String("quickclash.core") == "clash.meta" {
Core = ClashMetaCore
color.BgLightBlue.Println(i18n.Dtr("currentCore", "ClashMeta"))
}
} else {
panic(color.BgRed.Sprintf(i18n.Dtr("coreSetWrong", QuickClashYml)))
}
Expand All @@ -147,7 +153,7 @@ func main() {
// 如果文件不存在则下载
if err != nil {
color.FgLightBlue.Println(i18n.Dtr("downloading", Core+" Core"))
err = Download(ReleaseBaseUrl+Core, Core)
err = DownloadWithBar(ReleaseBaseUrl+Core, Core)
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

const (
QuickClashYml = "config/QuickClash.yml"
RepoBaseUrl = "https://ghproxy.com/https://github.com/UlinoyaPed/QuickClash/raw/master/"
ReleaseBaseUrl = "https://ghproxy.com/https://github.com/UlinoyaPed/QuickClash/releases/download/v0.1/"
RepoBaseUrl = "https://mirror.ghproxy.com/https://github.com/UlinoyaPed/QuickClash/raw/master/"
ReleaseBaseUrl = "https://mirror.ghproxy.com/https://github.com/UlinoyaPed/QuickClash/releases/download/v0.1/"
QuickClashSubYml = "yaml/QuickClashSub.yaml"
ClashMetaCore = "clash.meta.exe"
ClashMetaCorex86 = "clash.meta_x86.exe"
ClashCore = "clash.exe"
WebUIUrl = "https://ghproxy.com/https://github.com/UlinoyaPed/QuickClash/releases/download/v0.2/web.zip"
)
Expand Down

0 comments on commit 0057716

Please sign in to comment.