Files
Reims-Go/internal/app/application_menu.go
T
千川白浪 e0ff794b0e feat: add experimental macOS desktop support on Apple Silicon (#207)
* feat: add experimental Apple Silicon support with Nivfold

Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent.

* fix: open QQ invites and VM SSH on macOS

* fix: move VM, View and Help to the macOS menu bar

* feat(macos): add resumable Apple restore image downloads

Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering.

* fix(macos): localize the native application menu

* fix(macos): address native desktop review findings
2026-12-06 00:47:07 +08:00

73 lines
2.1 KiB
Go

package app
import (
"encoding/json"
"errors"
"strings"
)
type applicationMenuSnapshot struct {
Groups []applicationMenuGroup `json:"groups"`
Standard map[string]string `json:"standard"`
}
type applicationMenuGroup struct {
Label string `json:"label"`
Rows []applicationMenuRow `json:"rows"`
}
type applicationMenuRow struct {
Label string `json:"label,omitempty"`
Key string `json:"key,omitempty"`
Token int32 `json:"token,omitempty"`
Checked bool `json:"checked,omitempty"`
}
func parseApplicationMenu(raw string) (applicationMenuSnapshot, error) {
var snapshot applicationMenuSnapshot
if err := json.Unmarshal([]byte(raw), &snapshot); err != nil || len(snapshot.Groups) != 3 {
return snapshot, errors.New("invalid application menu groups")
}
for _, key := range []string{"edit", "window", "speech", "hide:", "Quit"} {
if strings.TrimSpace(snapshot.Standard[key]) == "" {
return snapshot, errors.New("missing standard application menu labels")
}
}
tokens := make(map[int32]bool)
for _, group := range snapshot.Groups {
if strings.TrimSpace(group.Label) == "" || len(group.Rows) == 0 || len(group.Rows) > 40 {
return snapshot, errors.New("invalid application menu group")
}
for _, row := range group.Rows {
switch row.Key {
case "", "n", "b", "l", ",", "\r":
default:
return snapshot, errors.New("invalid application menu shortcut")
}
if row.Token < 0 || (row.Token > 0 && (row.Label == "" || tokens[row.Token])) {
return snapshot, errors.New("invalid application menu action")
}
if row.Token > 0 {
tokens[row.Token] = true
}
}
}
return snapshot, nil
}
// SyncApplicationMenu publishes the renderer's localized menu and current
// action availability to the host's native menu bar.
func (a *App) SyncApplicationMenu(raw string) error {
if a.ctx == nil {
return errors.New("application menu is not ready")
}
if len(raw) > 32<<10 {
return errors.New("application menu snapshot is too large")
}
snapshot, err := parseApplicationMenu(raw)
if err != nil {
return err
}
return a.syncApplicationMenu(snapshot)
}