Browse Source

增加脚本处理

master
VIVIMAN 3 years ago
parent
commit
f351a75649
  1. 2
      golang_learn/data_func/go_to_tray/demo03/build.bat
  2. 70
      golang_learn/data_func/go_to_tray/demo03/main.go
  3. 7
      golang_learn/data_func/go_to_tray/demo03/run.bat
  4. 1
      golang_learn/data_func/go_to_tray/demo03/shell/closeCX.bat
  5. 1
      golang_learn/data_func/go_to_tray/demo03/shell/closeCX.sh
  6. 1
      golang_learn/data_func/go_to_tray/demo03/shell/closeDB.bat
  7. 1
      golang_learn/data_func/go_to_tray/demo03/shell/closeDB.sh
  8. 1
      golang_learn/data_func/go_to_tray/demo03/shell/startCX.bat
  9. 1
      golang_learn/data_func/go_to_tray/demo03/shell/startCX.sh
  10. 1
      golang_learn/data_func/go_to_tray/demo03/shell/startDB.bat
  11. 1
      golang_learn/data_func/go_to_tray/demo03/shell/startDB.sh

2
golang_learn/data_func/go_to_tray/demo03/build.bat

@ -1,5 +1,7 @@
set GO111MODULE=on
SET CGO_ENABLED=0
set GOARCH=386
set GOOS=windows
rsrc -manifest main.manifest -ico main.ico -o main.syso
go generate
go build -ldflags="-s -w -H=windowsgui" -o 꽉데으-頓契솰왠.exe

70
golang_learn/data_func/go_to_tray/demo03/main.go

@ -44,7 +44,6 @@ func (mw *MyWindow) AddNotifyIcon() {
// 其他快捷键
mw.addOther()
}
func init() {
@ -63,7 +62,63 @@ func checkError(err error) {
}
}
// open opens the specified URL in the default browser of the user.
// 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()
}
// OpenUrl 按照地址打开浏览器,进行请求。
func OpenUrl(url string) error {
var cmd string
var args []string
@ -72,9 +127,7 @@ func OpenUrl(url string) error {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
default: // "linux", "freebsd", "openbsd", "netbsd", "mac"
cmd = "xdg-open"
}
args = append(args, url)
@ -172,11 +225,7 @@ func (mw *MyWindow) addCxMenu() {
// AddListen 增加服务监听,控制按钮状态
func AddListen(startAction *walk.Action, stopAction *walk.Action, address string, timeout time.Duration) {
conn, err := net.DialTimeout("tcp", address, timeout)
if err != nil {
// fmt.Println("["+now+"]", ipPort, "端口未开启(fail)!")
setEnableAndCheck(startAction, stopAction, false, false)
} else {
if conn != nil {
if err == nil && conn != nil {
// fmt.Println("["+now+"]", ipPort, "端口已开启(success)!")
setEnableAndCheck(startAction, stopAction, false, true)
_ = conn.Close()
@ -184,7 +233,6 @@ func AddListen(startAction *walk.Action, stopAction *walk.Action, address string
// fmt.Println("["+now+"]", ipPort, "端口未开启(fail)!")
setEnableAndCheck(startAction, stopAction, true, false)
}
}
}
// setEnableAndCheck 设置按钮状态

7
golang_learn/data_func/go_to_tray/demo03/run.bat

@ -0,0 +1,7 @@
set GO111MODULE=on
SET CGO_ENABLED=0
set GOARCH=arm
set GOOS=linux
rsrc -manifest main.manifest -ico main.ico -o main.syso
go generate
go build main.go

1
golang_learn/data_func/go_to_tray/demo03/shell/closeCX.bat

@ -0,0 +1 @@
net stop GWY20_Tomcat

1
golang_learn/data_func/go_to_tray/demo03/shell/closeCX.sh

@ -0,0 +1 @@
net start GWY20_Mysql

1
golang_learn/data_func/go_to_tray/demo03/shell/closeDB.bat

@ -0,0 +1 @@
net stop GWY20_Mysql

1
golang_learn/data_func/go_to_tray/demo03/shell/closeDB.sh

@ -0,0 +1 @@
net start GWY20_Mysql

1
golang_learn/data_func/go_to_tray/demo03/shell/startCX.bat

@ -0,0 +1 @@
net start GWY20_Tomcat

1
golang_learn/data_func/go_to_tray/demo03/shell/startCX.sh

@ -0,0 +1 @@
net start GWY20_Mysql

1
golang_learn/data_func/go_to_tray/demo03/shell/startDB.bat

@ -0,0 +1 @@
net start GWY20_Mysql

1
golang_learn/data_func/go_to_tray/demo03/shell/startDB.sh

@ -0,0 +1 @@
net start GWY20_Mysql
Loading…
Cancel
Save