From c2cb52ec4c6496b2563255082a71a70f7011488a Mon Sep 17 00:00:00 2001 From: nange Date: Thu, 21 Mar 2024 12:29:45 +0800 Subject: [PATCH] feat: support cat logs using gnome-terminal --- cmd/easyss/tray.go | 12 +++++++++++- util/sys.go | 14 +++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/easyss/tray.go b/cmd/easyss/tray.go index 25a534d5..d1f40fc5 100644 --- a/cmd/easyss/tray.go +++ b/cmd/easyss/tray.go @@ -309,9 +309,19 @@ func (st *SysTray) catLog() error { win = fmt.Sprintf(win, st.ss.LogFilePath()) } + var linuxCmd []string + if runtime.GOOS == "linux" { + switch { + case util.SysSupportXTerminalEmulator(): + linuxCmd = []string{"x-terminal-emulator", "-e", "tail", "-50f", st.ss.LogFilePath()} + case util.SysSupportGnomeTerminal(): + linuxCmd = []string{"gnome-terminal", "--hide-menubar", "--geometry", "800*600", "--title", "View Easyss Logs", "--", "tail", "-50f", st.ss.LogFilePath()} + } + } + cmdMap := map[string][]string{ "windows": {"powershell", "-Command", "Start-Process", win}, - "linux": {"x-terminal-emulator", "-e", "tail", "-50f", st.ss.LogFilePath()}, + "linux": linuxCmd, "darwin": {"open", "-a", "Console", st.ss.LogFilePath()}, } _, err := util.Command(cmdMap[runtime.GOOS][0], cmdMap[runtime.GOOS][1:]...) diff --git a/util/sys.go b/util/sys.go index 22ede292..89fb42fc 100644 --- a/util/sys.go +++ b/util/sys.go @@ -9,7 +9,19 @@ import ( ) func SysSupportPowershell() bool { - lp, err := exec.LookPath("powershell") + return SysSupport("powershell") +} + +func SysSupportXTerminalEmulator() bool { + return SysSupport("x-terminal-emulator") +} + +func SysSupportGnomeTerminal() bool { + return SysSupport("gnome-terminal") +} + +func SysSupport(bin string) bool { + lp, err := exec.LookPath(bin) if lp != "" && err == nil { return true }