将 macOS 桌面应用改为通用二进制并动态写入最低系统版本,避免 Intel Mac 无法启动。统一桌面应用名称与托盘展示,并补充测试确保相关行为稳定。
86 lines
1.7 KiB
Go
86 lines
1.7 KiB
Go
//go:build linux
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"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:
|
|
dialogLogger().Error("无法显示错误对话框")
|
|
}
|
|
}
|
|
|
|
func showAbout() {
|
|
switch dialogTool {
|
|
case toolZenity:
|
|
exec.Command("zenity", "--info",
|
|
fmt.Sprintf("--title=%s", appAboutTitle),
|
|
fmt.Sprintf("--text=%s", aboutMessage())).Run()
|
|
case toolKdialog:
|
|
exec.Command("kdialog", "--msgbox", aboutMessage(), "--title", appAboutTitle).Run()
|
|
case toolNotifySend:
|
|
exec.Command("notify-send", appAboutTitle, aboutMessage()).Run()
|
|
case toolXmessage:
|
|
exec.Command("xmessage", "-center",
|
|
fmt.Sprintf("%s: %s", appAboutTitle, aboutMessage())).Run()
|
|
default:
|
|
dialogLogger().Info(appAboutTitle)
|
|
}
|
|
}
|