Browse Source

增加系统控制 代码

master
viviman 3 years ago
parent
commit
36d097d9b9
  1. 8
      golang_learn/data_func/go_to_tray/demo00/mac.bat
  2. 1
      golang_learn/data_func/go_to_tray/demo00/mac.sh
  3. 1
      golang_learn/data_func/go_to_tray/demo04/mac.sh
  4. 32
      golang_learn/data_func/go_to_tray/demo04/main.go

8
golang_learn/data_func/go_to_tray/demo00/mac.bat

@ -1,9 +1 @@
SET CC=gcc
SET CGO_ENABLED=1
# shellcheck disable=SC2121
set GOARCH=amd64
# shellcheck disable=SC2121
set GOOS=darwin
rsrc -manifest main.manifest -ico main.ico -o main.syso
go generate
go build -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags="framework=Cocoa" .

1
golang_learn/data_func/go_to_tray/demo00/mac.sh

@ -0,0 +1 @@
go build -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags="framework=Cocoa" .

1
golang_learn/data_func/go_to_tray/demo04/mac.sh

@ -0,0 +1 @@
go build -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags="framework=Cocoa" .

32
golang_learn/data_func/go_to_tray/demo04/main.go

@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"runtime"
"syscall"
)
func main() {
@ -38,23 +37,11 @@ func toFile(fileName, str string) {
_ = sqlObj.Close()
}
// PathExists 判断文件夹是否存在
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func onReady() {
timezone := "公务员"
_ = systray.SetTitle(timezone)
_ = systray.SetTooltip(timezone)
_ = systray.SetIcon(getIcon("D:\\ViviCode\\golangs_learn\\golang_learn\\data_func\\go_to_tray\\demo04\\main.ico"))
_ = systray.SetIcon(getIcon("/Users/zhangxianwei/GolandProjects/golangs_learn/golang_learn/data_func/go_to_tray/demo04/main.ico"))
dbMenu := systray.AddSubMenu("数据服务")
startDbMenu := dbMenu.AddSubMenuItem("启动", "启动 - 数据库服务", 0)
@ -131,9 +118,7 @@ func OpenUrl(url string) error {
cmd = "xdg-open"
}
args = append(args, url)
c := exec.Command(cmd, args...)
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return c.Start()
return runExec(cmd, args...).Start()
}
// OpenServe 打开服务
@ -159,9 +144,7 @@ func OpenServe(isDb bool) error {
args = []string{"-c", "cd", "shell", "&&", "startCX.sh"}
}
}
c := exec.Command(cmd, args...)
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return c.Start()
return runExec(cmd, args...).Start()
}
// CloseServe 停止服务
@ -187,7 +170,12 @@ func CloseServe(isDb bool) error {
args = []string{"-c", "cd", "shell", "&&", "stopCX.sh"}
}
}
return runExec(cmd, args...).Start()
}
func runExec(cmd string, args ...string) *exec.Cmd {
c := exec.Command(cmd, args...)
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return c.Start()
// TODO windows 需要放开,其他系统 需要隐藏
// c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return c
}

Loading…
Cancel
Save