Files
openchamber-android-native/third_party/mygo/menu_text.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

67 lines
2.1 KiB
Go

package mygo
import (
"github.com/egoist/mygo/internal/l10n"
"github.com/egoist/mygo/internal/platform"
)
// The labels menu items take from their role (MenuItem.Role) are MyGo's
// own strings: they say the language the app shows (App.Locale), and an
// item whose label is its role's says the new language's when it changes.
// menuMessages returns MyGo's own strings, which the labels of roles are,
// in the language the app shows; in its own language before it worked out
// which (App.Locale).
func menuMessages() l10n.Messages { return l10n.In(appLanguage()) }
// appLanguage returns the language the app shows, or "" before it worked
// out which.
func appLanguage() string {
if s := locales.shown.Load(); s != nil {
return s.locale
}
return ""
}
// platformTexts returns the words the backends say of their own in a
// language (platform.Texts).
func platformTexts(locale string) platform.Texts {
tx := l10n.In(locale)
return platform.Texts{OK: tx.Ok(), Cancel: tx.Cancel(), Open: tx.Open(), Save: tx.Save(),
SelectFolder: tx.SelectFolder(), About: tx.MenuAbout("\x00")}
}
// relabelMenus gives the items whose label is their role's the role's
// label now, as the language the app shows changed, and shows the menus
// in use with them: the menus of the app and of windows anew, and the
// others, as those of trays and the Dock, item by item. Main thread only.
func relabelMenus() {
menuMu.Lock()
var changed []*platform.MenuItem
for _, wp := range menuItems.byID {
it := wp.Value()
if it == nil || it.Role == "" || it.roleLabel == "" || it.Label != it.roleLabel {
continue
}
if label, _ := roleDefaults(it.Role); label != it.Label {
it.Label, it.roleLabel = label, label
changed = append(changed, it.snapshotLocked())
}
}
menuMu.Unlock()
if len(changed) == 0 || !App.IsReady() {
return // menus take their labels as Run installs them
}
if m := App.Menu(); m != nil {
backend().SetApplicationMenu(m.snapshot())
}
for _, w := range Windows() {
if w.menu != nil && w.native != nil {
w.native.SetMenu(w.menu.snapshot())
}
}
for _, it := range changed {
backend().UpdateMenuItem(it)
}
}