From 36d097d9b9b4640848f42cc8d050e8ccc49ea830 Mon Sep 17 00:00:00 2001 From: viviman <962464Nas> Date: Mon, 9 May 2022 23:05:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B3=BB=E7=BB=9F=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data_func/go_to_tray/demo00/mac.bat | 8 ----- .../data_func/go_to_tray/demo00/mac.sh | 1 + .../data_func/go_to_tray/demo04/mac.sh | 1 + .../data_func/go_to_tray/demo04/main.go | 32 ++++++------------- 4 files changed, 12 insertions(+), 30 deletions(-) create mode 100755 golang_learn/data_func/go_to_tray/demo00/mac.sh create mode 100755 golang_learn/data_func/go_to_tray/demo04/mac.sh 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 }