Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazeorz committed May 26, 2021
1 parent 2240479 commit 289ecaa
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion controller/ConfigInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path"
"regexp"
"strconv"
"strings"
"time"
)
Expand All @@ -39,8 +40,12 @@ func formatFileSize(fileSize int64) (size string) {
return fmt.Sprintf("%.2fB", float64(fileSize)/float64(1))
} else if fileSize < (1024 * 1024) {
return fmt.Sprintf("%.2fKB", float64(fileSize)/float64(1024))
} else {
} else if fileSize < (1024 * 1024 * 1024) {
return fmt.Sprintf("%.2fMB", float64(fileSize)/float64(1024*1024))
} else if fileSize < (1024 * 1024 * 1024 * 1024) {
return fmt.Sprintf("%.2fGB", float64(fileSize)/float64(1024*1024*1024))
} else {
return fmt.Sprintf("%.2fTB", float64(fileSize)/float64(1024*1024*1024*1024))
}
}

Expand Down Expand Up @@ -250,3 +255,48 @@ func updateConfig(Name, url string) error {
}
return err
}

func UserINFO() (UnUsedINFO, TotalINFO, ExpireINFO string) {
var (
infoURL = ""
)
content, err := os.OpenFile("./config.yaml", os.O_RDWR, 0666)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(content)
Reg := regexp.MustCompile(`# Clash.Mini : (http.*)`)
for scanner.Scan() {
if Reg.MatchString(scanner.Text()) {
infoURL = Reg.FindStringSubmatch(scanner.Text())[1]
break
} else {
infoURL = ""
}
}
defer content.Close()

if infoURL != "" {
client := &http.Client{}
res, _ := http.NewRequest("GET", infoURL, nil)
res.Header.Add("User-Agent", "clash")
resp, _ := client.Do(res)
userinfo := resp.Header.Get("Subscription-Userinfo")
reg := regexp.MustCompile(`=(\d+);\s.*=(\d+);\s.*=(\d+);\s.*=(\d+)`)
info := reg.FindStringSubmatch(userinfo)

Upload, _ := strconv.ParseInt(info[1], 10, 64)
Download, _ := strconv.ParseInt(info[2], 10, 64)
Total, _ := strconv.ParseInt(info[3], 10, 64)
Expire, _ := strconv.ParseInt(info[4], 10, 64)
tm := time.Unix(Expire, 0)
Unused := Total - Upload - Download
UnUsedINFO := formatFileSize(Unused)
TotalINFO := formatFileSize(Total)
ExpireINFO := tm.Format("2006-01-02")
return UnUsedINFO, TotalINFO, ExpireINFO
} else {
return UnUsedINFO, TotalINFO, ExpireINFO
}

}
13 changes: 13 additions & 0 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ func Notify(info string) {
}
}

func NotifyINFO(UnUsedINFO, TotalINFO, ExpireINFO string) {
content = "剩余流量:" + UnUsedINFO + "\n流量额度:" + TotalINFO + "\n到期时间:" + ExpireINFO
notification := toast.Notification{
AppID: "Clash.Mini",
Title: "📢流量信息📢",
Icon: appPath,
Message: content,
}
err := notification.Push()
if err != nil {
}
}

func iconBytesToFilePath(iconBytes []byte) (string, error) {
bh := md5.Sum(iconBytes)
dataHash := hex.EncodeToString(bh[:])
Expand Down
10 changes: 8 additions & 2 deletions systray/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func onReady() {
mURL := systray.AddMenuItem("控制面板", "")
mConfig := systray.AddMenuItem("配置管理", "")
mOther := systray.AddMenuItem("其他设置", "")
mOtherTask := mOther.AddSubMenuItem("设置开机启动(TASK)", "")
mOtherAutosys := mOther.AddSubMenuItem("默认设置代理", "")
mOtherTask := mOther.AddSubMenuItem("设置开机启动", "")
mOtherAutosys := mOther.AddSubMenuItem("设置系统代理", "")
mOtherMMBD := mOther.AddSubMenuItem("设置GeoIP2数据库", "")
MaxMindMMBD := mOtherMMBD.AddSubMenuItem("MaxMind数据库", "")
Hackl0usMMBD := mOtherMMBD.AddSubMenuItem("Hackl0us数据库", "")
Expand Down Expand Up @@ -82,6 +82,12 @@ func onReady() {
mEnabled.Check()
notify.Notify("SysON")
}

UnUsedINFO, TotalINFO, ExpireINFO := controller.UserINFO()
if UnUsedINFO != "" {
notify.NotifyINFO(UnUsedINFO, TotalINFO, ExpireINFO)
}

for {
<-t.C
switch tunnel.Mode() {
Expand Down

0 comments on commit 289ecaa

Please sign in to comment.