|
|
@ -1,30 +1,36 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"github.com/riftbit/go-systray" |
|
|
|
"io/ioutil" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
|
timezone string |
|
|
|
"log" |
|
|
|
"os/exec" |
|
|
|
"runtime" |
|
|
|
"syscall" |
|
|
|
) |
|
|
|
|
|
|
|
func main() { |
|
|
|
systray.Run(onReady, onExit) |
|
|
|
_ = systray.Run(onReady, onExit) |
|
|
|
} |
|
|
|
|
|
|
|
func onReady() { |
|
|
|
timezone = "公务员" |
|
|
|
_ = systray.SetIcon(getIcon("/Users/zhangxianwei/GolandProjects/golangs_learn/golang_learn/data_func/go_to_tray/demo01/icon.ico")) |
|
|
|
timezone := "公务员" |
|
|
|
_ = systray.SetTitle(timezone) |
|
|
|
_ = systray.SetTooltip(timezone) |
|
|
|
_ = systray.SetIcon(getIcon("D:\\ViviCode\\golangs_learn\\golang_learn\\data_func\\go_to_tray\\demo04\\main.ico")) |
|
|
|
|
|
|
|
submenu := systray.AddSubMenu("子菜单") |
|
|
|
_ = submenu.AddSubMenuItem("开始", "", 0) |
|
|
|
_ = submenu.AddSubMenuItem("结束", "", 0) |
|
|
|
dbMenu := systray.AddSubMenu("数据服务") |
|
|
|
startDbMenu := dbMenu.AddSubMenuItem("启动", "启动 - 数据库服务", 0) |
|
|
|
stopDbMenu := dbMenu.AddSubMenuItem("停止", "停止 - 数据库服务", 0) |
|
|
|
cxMenu := systray.AddSubMenu("应用服务") |
|
|
|
startCxMenu := cxMenu.AddSubMenuItem("启动", "启动 - 应用服务", 0) |
|
|
|
stopCxMenu := cxMenu.AddSubMenuItem("停止", "停止 - 应用服务", 0) |
|
|
|
|
|
|
|
localTime := systray.AddMenuItem("炎龙", "炎龙", 0) |
|
|
|
openMenu := systray.AddMenuItem("打开应用", "打开应用", 0) |
|
|
|
|
|
|
|
fmt.Printf("%#v", localTime) |
|
|
|
submenu := systray.AddSubMenu("帮助") |
|
|
|
upCxMenu := submenu.AddSubMenuItem("升级", "进行下载安装组工软件", 0) |
|
|
|
infoMenu := submenu.AddSubMenuItem("关于", "辅助使用公务员系统服务", 0) |
|
|
|
|
|
|
|
systray.AddSeparator() |
|
|
|
mQuit := systray.AddMenuItem("退出", "退出", 0) |
|
|
@ -32,10 +38,29 @@ func onReady() { |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
select { |
|
|
|
case <-localTime.OnClickCh(): |
|
|
|
timezone = "炎龙" |
|
|
|
case <-startDbMenu.OnClickCh(): |
|
|
|
_ = OpenServe(true) |
|
|
|
return |
|
|
|
case <-stopDbMenu.OnClickCh(): |
|
|
|
_ = CloseServe(true) |
|
|
|
return |
|
|
|
case <-startCxMenu.OnClickCh(): |
|
|
|
_ = OpenServe(false) |
|
|
|
return |
|
|
|
case <-stopCxMenu.OnClickCh(): |
|
|
|
_ = CloseServe(false) |
|
|
|
return |
|
|
|
case <-openMenu.OnClickCh(): |
|
|
|
_ = OpenUrl("http://localhost:54022/qggwy") |
|
|
|
return |
|
|
|
case <-upCxMenu.OnClickCh(): |
|
|
|
_ = OpenUrl("https://www.12371.cn/zgrjxz/gwywx/") |
|
|
|
return |
|
|
|
case <-infoMenu.OnClickCh(): |
|
|
|
_ = OpenUrl("https://www.12371.cn/zgrjxz/gwywx/") |
|
|
|
return |
|
|
|
case <-mQuit.OnClickCh(): |
|
|
|
systray.Quit() |
|
|
|
_ = systray.Quit() |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -49,7 +74,83 @@ func onExit() { |
|
|
|
func getIcon(s string) []byte { |
|
|
|
b, err := ioutil.ReadFile(s) |
|
|
|
if err != nil { |
|
|
|
fmt.Print(err) |
|
|
|
log.Println(err) |
|
|
|
} |
|
|
|
return b |
|
|
|
} |
|
|
|
|
|
|
|
// OpenUrl 按照地址打开浏览器,进行请求。
|
|
|
|
func OpenUrl(url string) error { |
|
|
|
var cmd string |
|
|
|
var args []string |
|
|
|
|
|
|
|
switch runtime.GOOS { |
|
|
|
case "windows": |
|
|
|
cmd = "cmd" |
|
|
|
args = []string{"/c", "start"} |
|
|
|
case "darwin": |
|
|
|
cmd = "open" |
|
|
|
default: // "linux", "freebsd", "openbsd", "netbsd"
|
|
|
|
cmd = "xdg-open" |
|
|
|
} |
|
|
|
args = append(args, url) |
|
|
|
c := exec.Command(cmd, args...) |
|
|
|
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} |
|
|
|
return c.Start() |
|
|
|
} |
|
|
|
|
|
|
|
// OpenServe 打开服务
|
|
|
|
func OpenServe(isDb bool) error { |
|
|
|
var cmd string |
|
|
|
var args []string |
|
|
|
|
|
|
|
switch runtime.GOOS { |
|
|
|
case "windows": |
|
|
|
if isDb { |
|
|
|
cmd = "cmd" |
|
|
|
args = []string{"/c", "./shell/startDB.bat"} |
|
|
|
} else { |
|
|
|
cmd = "/bin/sh" |
|
|
|
args = []string{"-c", "./shell/startDB.sh"} |
|
|
|
} |
|
|
|
default: // "linux", "freebsd", "openbsd", "netbsd", "mac"
|
|
|
|
if isDb { |
|
|
|
cmd = "cmd" |
|
|
|
args = []string{"/c", "./shell/startCX.bat"} |
|
|
|
} else { |
|
|
|
cmd = "/bin/sh" |
|
|
|
args = []string{"-c", "./shell/startCX.sh"} |
|
|
|
} |
|
|
|
} |
|
|
|
c := exec.Command(cmd, args...) |
|
|
|
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} |
|
|
|
return c.Start() |
|
|
|
} |
|
|
|
|
|
|
|
// CloseServe 停止服务
|
|
|
|
func CloseServe(isDb bool) error { |
|
|
|
var cmd string |
|
|
|
var args []string |
|
|
|
|
|
|
|
switch runtime.GOOS { |
|
|
|
case "windows": |
|
|
|
if isDb { |
|
|
|
cmd = "cmd" |
|
|
|
args = []string{"/c", "./shell/stopDB.bat"} |
|
|
|
} else { |
|
|
|
cmd = "/bin/sh" |
|
|
|
args = []string{"-c", "./shell/stopDB.sh"} |
|
|
|
} |
|
|
|
default: // "linux", "freebsd", "openbsd", "netbsd", "mac"
|
|
|
|
if isDb { |
|
|
|
cmd = "cmd" |
|
|
|
args = []string{"/c", "./shell/stopCX.bat"} |
|
|
|
} else { |
|
|
|
cmd = "/bin/sh" |
|
|
|
args = []string{"-c", "./shell/stopCX.sh"} |
|
|
|
} |
|
|
|
} |
|
|
|
c := exec.Command(cmd, args...) |
|
|
|
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} |
|
|
|
return c.Start() |
|
|
|
} |
|
|
|