refactor: 桌面应用对话框代码拆分为平台专用文件
- 新增 dialog_windows.go、dialog_darwin.go、dialog_linux.go - 使用 Go 构建标签实现条件编译 - 修复跨平台编译错误(syscall.NewLazyDLL 在 macOS/Linux 未定义) - 实现 Linux 多工具降级策略(zenity → kdialog → notify-send → xmessage → stderr) - 实现 macOS AppleScript 字符转义 - 更新 messagebox_test.go 构建标签 - 更新 desktop-app spec 新增 Linux 降级策略和 macOS 字符转义规范
This commit is contained in:
28
backend/cmd/desktop/dialog_darwin.go
Normal file
28
backend/cmd/desktop/dialog_darwin.go
Normal file
@@ -0,0 +1,28 @@
|
||||
//go:build darwin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func showError(title, message string) {
|
||||
script := fmt.Sprintf(`display dialog "%s" buttons {"OK"} default button "OK" with title "%s"`,
|
||||
escapeAppleScript(message), escapeAppleScript(title))
|
||||
exec.Command("osascript", "-e", script).Run()
|
||||
}
|
||||
|
||||
func showAbout() {
|
||||
message := "Nex Gateway\n\nAI Gateway - 统一的大模型 API 网关\n\nhttps://github.com/nex/gateway"
|
||||
script := fmt.Sprintf(`display dialog "%s" buttons {"OK"} default button "OK" with title "关于 Nex Gateway"`,
|
||||
escapeAppleScript(message))
|
||||
exec.Command("osascript", "-e", script).Run()
|
||||
}
|
||||
|
||||
func escapeAppleScript(s string) string {
|
||||
s = strings.ReplaceAll(s, "\\", "\\\\")
|
||||
s = strings.ReplaceAll(s, "\"", "\\\"")
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user