//go:build linux package main import ( "fmt" "os" "os/exec" "sync" ) type dialogToolType int const ( toolNone dialogToolType = iota toolZenity toolKdialog toolNotifySend toolXmessage ) var ( dialogTool dialogToolType dialogToolOnce sync.Once ) func init() { dialogToolOnce.Do(detectDialogTool) } func detectDialogTool() { tools := []struct { name string typ dialogToolType }{ {"zenity", toolZenity}, {"kdialog", toolKdialog}, {"notify-send", toolNotifySend}, {"xmessage", toolXmessage}, } for _, tool := range tools { if _, err := exec.LookPath(tool.name); err == nil { dialogTool = tool.typ return } } dialogTool = toolNone } func showError(title, message string) { switch dialogTool { case toolZenity: exec.Command("zenity", "--error", fmt.Sprintf("--title=%s", title), fmt.Sprintf("--text=%s", message)).Run() case toolKdialog: exec.Command("kdialog", "--error", message, "--title", title).Run() case toolNotifySend: exec.Command("notify-send", "-u", "critical", title, message).Run() case toolXmessage: exec.Command("xmessage", "-center", fmt.Sprintf("%s: %s", title, message)).Run() default: fmt.Fprintf(os.Stderr, "错误: %s: %s\n", title, message) } } func showAbout() { message := "Nex Gateway\n\nAI Gateway - 统一的大模型 API 网关\n\nhttps://github.com/nex/gateway" switch dialogTool { case toolZenity: exec.Command("zenity", "--info", "--title=关于 Nex Gateway", fmt.Sprintf("--text=%s", message)).Run() case toolKdialog: exec.Command("kdialog", "--msgbox", message, "--title", "关于 Nex Gateway").Run() case toolNotifySend: exec.Command("notify-send", "关于 Nex Gateway", message).Run() case toolXmessage: exec.Command("xmessage", "-center", fmt.Sprintf("关于 Nex Gateway: %s", message)).Run() default: fmt.Fprintf(os.Stderr, "关于 Nex Gateway: %s\n", message) } }