feat: 将"关于"从系统托盘原生对话框迁移到前端页面
移除系统托盘右键菜单中的"关于"选项及各平台原生对话框实现, 在前端新增 /about 路由和关于页面展示品牌信息,侧边栏增加关于导航入口
This commit is contained in:
@@ -18,14 +18,6 @@ func showError(title, message string) {
|
||||
}
|
||||
}
|
||||
|
||||
func showAbout() {
|
||||
script := fmt.Sprintf(`display dialog "%s" buttons {"OK"} default button "OK" with title "%s"`,
|
||||
escapeAppleScript(aboutMessage()), escapeAppleScript(appAboutTitle))
|
||||
if err := exec.Command("osascript", "-e", script).Run(); err != nil {
|
||||
dialogLogger().Warn("显示关于对话框失败", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func escapeAppleScript(s string) string {
|
||||
s = strings.ReplaceAll(s, "\\", "\\\\")
|
||||
s = strings.ReplaceAll(s, "\"", "\\\"")
|
||||
|
||||
@@ -65,21 +65,3 @@ func showError(title, message string) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,6 @@ func showError(title, message string) {
|
||||
messageBox(title, message, MB_ICONERROR)
|
||||
}
|
||||
|
||||
func showAbout() {
|
||||
messageBox(appAboutTitle, aboutMessage(), MB_ICONINFORMATION)
|
||||
}
|
||||
|
||||
func messageBox(title, message string, flags uint) {
|
||||
titlePtr, _ := syscall.UTF16PtrFromString(title)
|
||||
messagePtr, _ := syscall.UTF16PtrFromString(message)
|
||||
|
||||
@@ -287,8 +287,6 @@ func setupSystray(port int) {
|
||||
mPort := systray.AddMenuItem(fmt.Sprintf("端口: %d", port), "")
|
||||
mPort.Disable()
|
||||
systray.AddSeparator()
|
||||
mAbout := systray.AddMenuItem("关于", "")
|
||||
systray.AddSeparator()
|
||||
mQuit := systray.AddMenuItem("退出", "停止服务并退出")
|
||||
|
||||
go func() {
|
||||
@@ -298,8 +296,6 @@ func setupSystray(port int) {
|
||||
if err := openBrowser(fmt.Sprintf("http://localhost:%d", port)); err != nil {
|
||||
zapLogger.Warn("打开浏览器失败", zap.Error(err))
|
||||
}
|
||||
case <-mAbout.ClickedCh:
|
||||
showAbout()
|
||||
case <-mQuit.ClickedCh:
|
||||
doShutdown()
|
||||
systray.Quit()
|
||||
|
||||
@@ -13,7 +13,3 @@ func TestMessageBoxW_WindowsOnly(t *testing.T) {
|
||||
func TestShowError_WindowsBranch(t *testing.T) {
|
||||
showError("测试错误", "这是一条测试错误消息")
|
||||
}
|
||||
|
||||
func TestShowAbout_WindowsBranch(t *testing.T) {
|
||||
showAbout()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@ package main
|
||||
const (
|
||||
appName = "Nex"
|
||||
appTooltip = appName
|
||||
appAboutTitle = "关于 " + appName
|
||||
appDescription = "AI Gateway - 统一的大模型 API 网关"
|
||||
appWebsite = "https://github.com/nex/gateway"
|
||||
)
|
||||
|
||||
func aboutMessage() string {
|
||||
return appName + "\n\n" + appDescription + "\n\n" + appWebsite
|
||||
}
|
||||
|
||||
@@ -2,13 +2,6 @@ package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAboutMessage(t *testing.T) {
|
||||
expected := "Nex\n\nAI Gateway - 统一的大模型 API 网关\n\nhttps://github.com/nex/gateway"
|
||||
if got := aboutMessage(); got != expected {
|
||||
t.Fatalf("aboutMessage() = %q, want %q", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDesktopMetadata(t *testing.T) {
|
||||
if appName != "Nex" {
|
||||
t.Fatalf("appName = %q, want %q", appName, "Nex")
|
||||
@@ -17,8 +10,4 @@ func TestDesktopMetadata(t *testing.T) {
|
||||
if appTooltip != appName {
|
||||
t.Fatalf("appTooltip = %q, want %q", appTooltip, appName)
|
||||
}
|
||||
|
||||
if appAboutTitle != "关于 Nex" {
|
||||
t.Fatalf("appAboutTitle = %q, want %q", appAboutTitle, "关于 Nex")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user