Skip to content

Commit

Permalink
1、任务计划自启
Browse files Browse the repository at this point in the history
2、mmdb切换
3、默认设置系统代理
4、机场信息弹窗显示
  • Loading branch information
Clash-Mini authored and Mazeorz committed May 26, 2021
1 parent 289ecaa commit f1c0c36
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
13 changes: 8 additions & 5 deletions .idea/workspace.xml

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

9 changes: 5 additions & 4 deletions controller/ConfigInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func updateConfig(Name, url string) error {
return err
}

func UserINFO() (UnUsedINFO, TotalINFO, ExpireINFO string) {
func UserINFO() (UsedINFO, UnUsedINFO, ExpireINFO string) {
var (
infoURL = ""
)
Expand Down Expand Up @@ -291,12 +291,13 @@ func UserINFO() (UnUsedINFO, TotalINFO, ExpireINFO string) {
Expire, _ := strconv.ParseInt(info[4], 10, 64)
tm := time.Unix(Expire, 0)
Unused := Total - Upload - Download
Used := Upload + Download
UsedINFO := formatFileSize(Used)
UnUsedINFO := formatFileSize(Unused)
TotalINFO := formatFileSize(Total)
ExpireINFO := tm.Format("2006-01-02")
return UnUsedINFO, TotalINFO, ExpireINFO
return UsedINFO, UnUsedINFO, ExpireINFO
} else {
return UnUsedINFO, TotalINFO, ExpireINFO
return UsedINFO, UnUsedINFO, ExpireINFO
}

}
3 changes: 1 addition & 2 deletions controller/Task.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ func TaskCommand(args string) error {
}

func TaskBuild() (xml []byte) {

taskComName := os.Args[0]
taskWorkingPath, _ := os.Getwd()
doc := etree.NewDocument()
doc.CreateProcInst("xml", `version="1.0" encoding="GBK"`)
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-16"`)
Task := doc.CreateElement(`Task`)
Task.CreateAttr("version", "1.2")
Task.CreateAttr("xmlns", `http://schemas.microsoft.com/windows/2004/02/mit/task`)
Expand Down
26 changes: 13 additions & 13 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ func Notify(info string) {

switch info {
case "SysON":
content = "系统代理:✅"
content = "--------------------\n系统代理:✅"
case "SysOFF":
content = "系统代理:❎"
content = "--------------------\n系统代理:❎"
case "Direct":
content = "已切换为:直连模式-✅"
content = "--------------------\n已切换为:直连模式-✅"
case "Rule":
content = "已切换为:规则模式-✅"
content = "--------------------\n已切换为:规则模式-✅"
case "Global":
content = "已切换为:全局模式-✅"
content = "--------------------\n已切换为:全局模式-✅"
case "Startup":
content = "开机启动:✅"
content = "--------------------\n开机启动:✅"
case "StartupOff":
content = "开机启动:❎"
content = "--------------------\n开机启动:❎"
case "SysAutoON":
content = "默认代理:✅"
content = "--------------------\n默认代理:✅"
case "SysAutoOFF":
content = "默认代理:❎"
content = "--------------------\n默认代理:❎"
case "Max":
content = "成功切换Maxmind数据库"
content = "--------------------\n成功切换:Maxmind数据库"
case "Lite":
content = "成功切换Hackl0us数据库"
content = "--------------------\n成功切换:Hackl0us数据库"
}
notification := toast.Notification{
AppID: "Clash.Mini",
Expand All @@ -52,8 +52,8 @@ func Notify(info string) {
}
}

func NotifyINFO(UnUsedINFO, TotalINFO, ExpireINFO string) {
content = "剩余流量:" + UnUsedINFO + "\n流量额度:" + TotalINFO + "\n到期时间:" + ExpireINFO
func NotifyINFO(UsedINFO, UnUsedINFO, ExpireINFO string) {
content = "--------------------\n已用流量:" + UsedINFO + "\n剩余流量:" + UnUsedINFO + "\n到期时间:" + ExpireINFO
notification := toast.Notification{
AppID: "Clash.Mini",
Title: "📢流量信息📢",
Expand Down
25 changes: 14 additions & 11 deletions systray/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func onReady() {
notify.Notify("SysON")
}

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

for {
<-t.C
switch tunnel.Mode() {
Expand Down Expand Up @@ -188,10 +183,16 @@ func onReady() {
} else {
}
}

}
}()

go func() {
UnUsedINFO, TotalINFO, ExpireINFO := controller.UserINFO()
time.Sleep(2 * time.Second)
if UnUsedINFO != "" {
notify.NotifyINFO(UnUsedINFO, TotalINFO, ExpireINFO)
}
for {
select {
case <-mTitle.ClickedCh:
Expand Down Expand Up @@ -237,27 +238,27 @@ func onReady() {
case <-mOtherAutosys.ClickedCh:
if mOtherAutosys.Checked() {
controller.Regcmd("Sys", "OFF")
time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)
if controller.RegCompare("Sys") == false {
notify.Notify("SysAutoOFF")
}
} else {
controller.Regcmd("Sys", "ON")
time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)
if controller.RegCompare("Sys") == true {
notify.Notify("SysAutoON")
}
}
case <-mOtherTask.ClickedCh:
if mOtherTask.Checked() {
controller.TaskCommand("delete")
time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)
if controller.RegCompare("Task") == false {
notify.Notify("StartupOff")
}
} else {
controller.TaskCommand("create")
time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)
taskFile := filepath.Join(".", "task.xml")
taskPath, _ := os.Getwd()
Filepath := filepath.Join(taskPath, taskFile)
Expand All @@ -271,7 +272,8 @@ func onReady() {
return
} else {
controller.GetMMDB("Max")
if controller.RegCompare("MMBD") == true {
if controller.RegCompare("MMBD") == false {
time.Sleep(2 * time.Second)
notify.Notify("Max")
}
}
Expand All @@ -280,7 +282,8 @@ func onReady() {
return
} else {
controller.GetMMDB("Lite")
if controller.RegCompare("MMBD") == false {
if controller.RegCompare("MMBD") == true {
time.Sleep(2 * time.Second)
notify.Notify("Lite")
}
}
Expand Down

0 comments on commit f1c0c36

Please sign in to comment.