diff --git a/golang_learn/data_func/go_to_tray/demo00/mac.bat b/golang_learn/data_func/go_to_tray/demo00/mac.bat index 34d3546..348d07a 100644 --- a/golang_learn/data_func/go_to_tray/demo00/mac.bat +++ b/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" . diff --git a/golang_learn/data_func/go_to_tray/demo00/mac.sh b/golang_learn/data_func/go_to_tray/demo00/mac.sh new file mode 100755 index 0000000..348d07a --- /dev/null +++ b/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" . diff --git a/golang_learn/data_func/go_to_tray/demo04/mac.sh b/golang_learn/data_func/go_to_tray/demo04/mac.sh new file mode 100755 index 0000000..348d07a --- /dev/null +++ b/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" . diff --git a/golang_learn/data_func/go_to_tray/demo04/main.go b/golang_learn/data_func/go_to_tray/demo04/main.go index 3bc278a..c5c42a7 100644 --- a/golang_learn/data_func/go_to_tray/demo04/main.go +++ b/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 }