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.
This commit is contained in:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+141
View File
@@ -0,0 +1,141 @@
//go:build ignore
// Gen writes catalog_gen.go, the accessors of MyGo's own strings, with the
// generator of apps' catalogs, messages/en.json, the messages they embed, the languages MyGo is
// translated to, and the package of each translation in
// ../../locales/<tag>, and their imports in ../../cmd/mygo for the Windows
// installer's own strings: `go generate ./internal/l10n`.
package main
import (
"bytes"
"fmt"
"go/format"
"log"
"os"
"path/filepath"
"strings"
"testing/fstest"
"github.com/egoist/mygo/i18n"
"github.com/egoist/mygo/internal/i18ngen"
)
func main() {
log.SetFlags(0)
opts := i18ngen.Options{Dir: "internal/l10n", Source: "en", Namespace: "mygo", Own: true}
c, diags, err := i18ngen.Load(os.DirFS("."), opts)
if err != nil {
log.Fatal(err)
}
check(diags)
src, err := i18ngen.Go(c, "l10n")
if err != nil {
log.Fatal(err)
}
write(i18ngen.GoFile, src)
write(filepath.Join(i18ngen.MessagesDir, "en.json"), i18ngen.MessagesJSON(c.Files["en"]))
// The translations, each with the source to check them against.
all := fstest.MapFS{}
en, err := os.ReadFile("en.json")
if err != nil {
log.Fatal(err)
}
all["en.json"] = &fstest.MapFile{Data: en}
paths, err := filepath.Glob("../../locales/*/*.json")
if err != nil {
log.Fatal(err)
}
var tags []string
for _, p := range paths {
tag := strings.TrimSuffix(filepath.Base(p), ".json")
if filepath.Base(filepath.Dir(p)) != tag {
log.Fatalf("%s: a translation is named after its directory", p)
}
data, err := os.ReadFile(p)
if err != nil {
log.Fatal(err)
}
all[tag+".json"] = &fstest.MapFile{Data: data}
tags = append(tags, tag)
write(filepath.Join(filepath.Dir(p), "locale_gen.go"), localePackage(tag))
}
opts.Dir = "locales"
_, diags, err = i18ngen.Load(all, opts)
if err != nil {
log.Fatal(err)
}
check(diags)
var b bytes.Buffer
b.WriteString("// Code generated by go generate. DO NOT EDIT.\n\npackage l10n\n\n")
b.WriteString("// Languages are those MyGo's own strings are translated to besides\n")
b.WriteString("// English, each in a package an app imports, as\n")
b.WriteString("// github.com/egoist/mygo/locales/zh-Hans.\n")
fmt.Fprintf(&b, "var Languages = %#v\n", tags)
write("languages_gen.go", b.Bytes())
b.Reset()
b.WriteString("// Code generated by go generate ./internal/l10n. DO NOT EDIT.\n\npackage main\n\n")
b.WriteString("// Link every translation of MyGo's strings for the Windows installer.\nimport (\n")
for _, tag := range tags {
fmt.Fprintf(&b, "\t_ %q\n", "github.com/egoist/mygo/locales/"+tag)
}
b.WriteString(")\n")
imports, err := format.Source(b.Bytes())
if err != nil {
log.Fatal(err)
}
write("../../cmd/mygo/locales_gen.go", imports)
}
// localePackage returns the source of the package of the translation to
// tag.
func localePackage(tag string) []byte {
name := strings.ToLower(strings.ReplaceAll(tag, "-", ""))
src := fmt.Sprintf(`// Code generated by go generate ./internal/l10n. DO NOT EDIT.
// Package %[1]s translates MyGo's own strings, those of its controls,
// dialogs and menus, to %[2]s (%[3]s), for apps that ship that
// language. The code mygo generate writes for the catalogs of an app
// imports it for the app's languages; an app without catalogs imports it
// itself:
//
// import _ "github.com/egoist/mygo/locales/%[3]s"
package %[1]s
import (
"embed"
"github.com/egoist/mygo/internal/l10n"
)
//go:embed %[3]s.json
var files embed.FS
func init() { l10n.Add(files) }
`, name, i18n.Autonym(tag), tag)
out, err := format.Source([]byte(src))
if err != nil {
log.Fatal(err)
}
return out
}
func check(diags i18ngen.Diagnostics) {
for _, d := range diags {
log.Print(d)
}
if diags.Errors() > 0 {
os.Exit(1)
}
}
func write(name string, data []byte) {
if old, _ := os.ReadFile(name); !bytes.Equal(old, data) {
if err := os.WriteFile(name, data, 0o644); err != nil {
log.Fatal(err)
}
}
}
+46
View File
@@ -0,0 +1,46 @@
// Package l10n holds MyGo's own strings, those of the controls of package
// ui, of the code editor and the diff viewer, and of the roles of menus,
// in the languages MyGo is translated to: a library's catalog (see
// i18n.NewLibraryCatalog) of the namespace mygo, whose functions say them
// in the language the app shows. An app changes them, or translates them
// to its other languages, with keys "mygo.<key>" in its own catalogs, as
// "mygo.cancel" in its de.json.
//
// en.json, the source, is always linked, as messages/en.json: its
// messages without their descriptions, which only `mygo generate` reads. The translations to the other
// languages (Languages) are packages of their own, in locales/<tag> at the
// root of the module, which an app imports for the languages it ships, as
// the code `mygo generate` writes for its catalogs does: an app does not
// carry the translations to languages it does not show. catalog_gen.go,
// languages_gen.go and the packages of the translations are generated by
// `go generate`, with the code generator of apps' catalogs
// (internal/i18ngen).
package l10n
import (
"embed"
"io/fs"
)
//go:generate go run gen.go
// Namespace is the namespace of the keys with which apps change MyGo's
// strings: "mygo.<key>".
const Namespace = "mygo"
// Add adds the translations of fsys, "<tag>.json", to MyGo's strings: the
// package of each translation adds its own as it is imported.
func Add(fsys fs.FS) {
if err := Catalog.Add(fsys); err != nil {
panic(err)
}
}
// sources are the catalogs as they are written, with their descriptions.
//
//go:embed *.json
var sources embed.FS
// FS returns the catalogs as they are written, which `mygo generate`
// checks the keys "mygo.<key>" of apps against: only it links them.
func FS() fs.FS { return sources }
+136
View File
@@ -0,0 +1,136 @@
package l10n_test
import (
"bytes"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"testing/fstest"
"github.com/egoist/mygo/internal/i18ngen"
. "github.com/egoist/mygo/internal/l10n"
// The translations, which apps import for the languages they ship.
_ "github.com/egoist/mygo/locales/ja"
_ "github.com/egoist/mygo/locales/zh-Hans"
_ "github.com/egoist/mygo/locales/zh-Hant"
)
// TestCatalogs checks the catalogs as `mygo generate` checks an app's: no
// errors, no warnings, every message in every language, and the code
// generated from them: the accessors, the list of the translations and
// their packages.
func TestCatalogs(t *testing.T) {
c, diags, err := i18ngen.Load(FS(), i18ngen.Options{Dir: "internal/l10n", Source: "en", Namespace: Namespace, Own: true})
if err != nil {
t.Fatal(err)
}
for _, d := range diags {
t.Error(d)
}
src, err := i18ngen.Go(c, "l10n")
if err != nil {
t.Fatal(err)
}
if old, _ := os.ReadFile(i18ngen.GoFile); !bytes.Equal(old, src) {
t.Errorf("%s is out of date: go generate ./internal/l10n", i18ngen.GoFile)
}
messages := filepath.Join(i18ngen.MessagesDir, "en.json")
if old, _ := os.ReadFile(messages); !bytes.Equal(old, i18ngen.MessagesJSON(c.Files["en"])) {
t.Errorf("%s is out of date: go generate ./internal/l10n", messages)
}
// The catalog links no formatting of dates (internal/i18nlink).
for _, k := range c.Keys {
for _, p := range k.Params {
if p.Type == "DateTime" {
t.Errorf("%s formats a date, %s, which MyGo's own strings do not link: pass a string", k.Name, p.Name)
}
}
}
all := fstest.MapFS{}
en, _ := os.ReadFile("en.json")
all["en.json"] = &fstest.MapFile{Data: en}
paths, _ := filepath.Glob("../../locales/*/*.json")
var tags []string
for _, p := range paths {
tag := strings.TrimSuffix(filepath.Base(p), ".json")
data, _ := os.ReadFile(p)
all[tag+".json"] = &fstest.MapFile{Data: data}
tags = append(tags, tag)
if _, err := os.Stat(filepath.Join(filepath.Dir(p), "locale_gen.go")); err != nil {
t.Errorf("%s has no package: go generate ./internal/l10n", p)
}
}
if !slices.Equal(tags, Languages) {
t.Errorf("Languages = %v, the translations are %v: go generate ./internal/l10n", Languages, tags)
}
_, diags, err = i18ngen.Load(all, i18ngen.Options{Dir: "locales", Source: "en", Namespace: Namespace})
if err != nil {
t.Fatal(err)
}
for _, d := range diags {
t.Error(d)
}
if got, want := Catalog.Languages(), append([]string{"en"}, tags...); !slices.Equal(got, want) {
t.Errorf("with the translations imported, the catalog has %v, want %v", got, want)
}
}
func TestMessages(t *testing.T) {
for _, c := range []struct{ got, want string }{
{Undo(), "Undo"}, // the source language before package mygo tells the app's
{In("zh-Hans").Undo(), "撤销"},
{In("zh-TW").Undo(), "復原"},
{In("zh-HK").MenuOpenRecent(), "打開最近使用過的檔案"},
{In("de").Undo(), "Undo"},
{In("en").MenuQuitApp("Notes"), "Quit Notes"},
{In("zh-Hans").MenuQuitApp("Notes"), "退出Notes"},
{In("zh-Hant").MenuAbout("Notes"), "關於Notes"},
{In("en").UnmodifiedLines(1), "1 unmodified line"},
{In("en").UnmodifiedLines(4), "4 unmodified lines"},
{In("zh-Hans").UnmodifiedLines(4), "4 行未修改"},
{In("en").Matches(3, 12), "3 of 12"},
{In("zh-Hant").MatchesMore(3, 1000), "第 3 項,共 1,000 項以上"},
{In("en").Line(12345), "Line 12345"},
{In("en").UntitledNumbered(2), "Untitled 2"},
{In("zh-Hans").DocumentFailed("moved", "a.txt"), "无法移动文稿“a.txt”。"},
{In("en").DocumentFailed("saved", "a.txt"), "The document “a.txt” could not be saved."},
{In("en").ColorValue(0.4, 0.755), "40% saturation, 76% brightness"},
{In("en").CurrentLine(3, 120, 5), "Current line 3 of 120, column 5"},
{In("zh-Hans").LineRange(120), "第 1 到 120 行,可加 :列"},
{In("en").RemoveToken("Ada"), "Remove Ada"},
{In("en").HunkAction(In("en").Revert()), "Revert change"},
{In("en-XA").Close(), "[Çļöšé one]"},
} {
if c.got != c.want {
t.Errorf("got %q, want %q", c.got, c.want)
}
}
}
// TestTextsAllocateNothing checks what the controls rely on as they say
// their strings every frame: a string without arguments, said again in
// the same language, allocates nothing.
func TestTextsAllocateNothing(t *testing.T) {
for _, locale := range []string{"", "en", "zh-Hans", "zh-TW", "en-XA"} {
want := In(locale).Undo()
if allocs := testing.AllocsPerRun(100, func() {
if In(locale).Undo() != want {
t.Fatal("the string changed")
}
}); allocs != 0 {
t.Errorf("Undo in %q allocates %v times", locale, allocs)
}
}
}
func BenchmarkText(b *testing.B) {
In("zh-Hans").Undo()
b.ReportAllocs()
for b.Loop() {
_ = In("zh-Hans").Undo()
}
}
+8
View File
@@ -0,0 +1,8 @@
// Code generated by go generate. DO NOT EDIT.
package l10n
// Languages are those MyGo's own strings are translated to besides
// English, each in a package an app imports, as
// github.com/egoist/mygo/locales/zh-Hans.
var Languages = []string{"ja", "zh-Hans", "zh-Hant"}
+212
View File
@@ -0,0 +1,212 @@
{
"previousMonth": "Previous month",
"nextMonth": "Next month",
"undo": "Undo",
"cut": "Cut",
"copy": "Copy",
"paste": "Paste",
"delete": "Delete",
"selectAll": "Select All",
"find": "Find",
"search": "Search",
"clear": "Clear",
"removeToken": "Remove {token}",
"saturation": "Saturation and brightness",
"hex": "Hex",
"divider": "Divider",
"developerTools": "Developer tools",
"elements": "Elements",
"more": "More",
"moreOptions": "More options",
"codeEditor": "Code editor",
"goToDefinition": "Go to Definition",
"toggleComment": "Toggle Comment",
"selection": "Selection",
"transform": "Transform",
"folding": "Folding",
"selectNextOccurrence": "Select Next Occurrence",
"selectAllOccurrences": "Select All Occurrences",
"expandSelection": "Expand Selection",
"splitIntoLines": "Split into Lines",
"upperCase": "Upper Case",
"lowerCase": "Lower Case",
"titleCase": "Title Case",
"snakeCase": "Snake Case",
"kebabCase": "Kebab Case",
"camelCase": "Camel Case",
"pascalCase": "Pascal Case",
"sortLines": "Sort Lines",
"reverseLines": "Reverse Lines",
"uniqueLines": "Unique Lines",
"joinLines": "Join Lines",
"trimTrailingWhitespace": "Trim Trailing Whitespace",
"fold": "Fold",
"unfold": "Unfold",
"foldAll": "Fold All",
"unfoldAll": "Unfold All",
"expandUp": "Expand up",
"expandDown": "Expand down",
"expandAll": "Expand all",
"expand": "Expand {what}",
"unmodifiedLines": "{n, plural, one {# unmodified line} other {# unmodified lines}}",
"unmodifiedLineNumbers": "Lines {from, number, ::group-off} to {to, number, ::group-off}",
"unmodifiedLineNumbersOldNew": "Old lines {oldFrom, number, ::group-off} to {oldTo, number, ::group-off}, new lines {newFrom, number, ::group-off} to {newTo, number, ::group-off}",
"noNewlineAtEnd": "No newline at end of file",
"revert": "Revert",
"keep": "Keep",
"hunkAction": "{action} change",
"line": "Line {n, number, ::group-off}",
"oldLine": "Old line {n, number, ::group-off}",
"newText": "New text",
"oldText": "Old text",
"invalid": "Invalid",
"noResults": "No results",
"matches": "{current} of {total}",
"matchesMore": "{current} of {total}+",
"matchCase": "Match case",
"matchWholeWord": "Match whole word",
"useRegularExpression": "Use regular expression",
"findInSelection": "Find in selection",
"previousMatch": "Previous match",
"nextMatch": "Next match",
"replace": "Replace",
"replaceAll": "Replace All",
"close": "Close",
"goToLine": "Go to line",
"lineRange": "Line 1 to {lines, number, ::group-off}, then :column",
"currentLine": "Current line {line, number, ::group-off} of {lines, number, ::group-off}, column {column, number, ::group-off}",
"completions": "Completions",
"menuUndo": "Undo",
"menuRedo": "Redo",
"menuCut": "Cut",
"menuCopy": "Copy",
"menuPaste": "Paste",
"menuPasteAndMatchStyle": "Paste and Match Style",
"menuDelete": "Delete",
"menuSelectAll": "Select All",
"menuReload": "Reload",
"menuForceReload": "Force Reload",
"menuToggleDevTools": "Toggle Developer Tools",
"menuActualSize": "Actual Size",
"menuZoomIn": "Zoom In",
"menuZoomOut": "Zoom Out",
"menuToggleFullScreen": "Toggle Full Screen",
"menuMinimize": "Minimize",
"menuZoom": "Zoom",
"menuBringAllToFront": "Bring All to Front",
"menuClose": "Close",
"menuCloseWindow": "Close Window",
"menuNew": "New",
"menuOpen": "Open…",
"menuOpenRecent": "Open Recent",
"menuSave": "Save",
"menuSaveAs": "Save As…",
"menuDuplicate": "Duplicate",
"menuRename": "Rename…",
"menuMoveTo": "Move To…",
"menuRevert": "Revert",
"menuRevertToSaved": "Revert to Saved",
"menuQuitApp": "Quit {app}",
"menuAbout": "About {app}",
"menuHide": "Hide {app}",
"menuQuit": "Quit",
"menuExit": "Exit",
"menuHideOthers": "Hide Others",
"menuShowAll": "Show All",
"menuServices": "Services",
"menuStartSpeaking": "Start Speaking",
"menuStopSpeaking": "Stop Speaking",
"menuFile": "File",
"menuEdit": "Edit",
"menuView": "View",
"menuFormat": "Format",
"menuWindow": "Window",
"menuHelp": "Help",
"menuBold": "Bold",
"menuItalic": "Italic",
"menuUnderline": "Underline",
"menuStrikethrough": "Strikethrough",
"menuAlignLeft": "Align Left",
"menuCenter": "Center",
"menuAlignRight": "Align Right",
"noMatches": "No matches",
"previous": "Previous",
"next": "Next",
"done": "Done",
"colorValue": "{saturation, number, percent} saturation, {brightness, number, percent} brightness",
"hours": "hours",
"minutes": "minutes",
"dayPeriod": "AM/PM",
"richText": "Rich text",
"copyCode": "Copy code",
"copied": "Copied",
"copyAsMarkdown": "Copy as Markdown",
"image": "Image",
"menuSpeech": "Speech",
"menuClearRecent": "Clear Menu",
"untitled": "Untitled",
"untitledNumbered": "Untitled {n, number, ::group-off}",
"cancel": "Cancel",
"save": "Save",
"saveEllipsis": "Save…",
"saveAs": "Save As…",
"saveAnyway": "Save Anyway",
"saveAll": "Save All",
"dontSave": "Don’t Save",
"deleteDocument": "Delete",
"revertDocument": "Revert",
"replaceFile": "Replace",
"rename": "Rename",
"renameTo": "Rename To:",
"moveTo": "Move To",
"move": "Move",
"reviewChanges": "Review Changes…",
"discardChanges": "Discard Changes",
"keepNewDocument": "Do you want to keep this new document “{name}”?",
"keepNewDocumentDetail": "You can choose to save your changes, or delete this document immediately. You can’t undo this action.",
"saveChanges": "Do you want to save the changes made to the document “{name}”?",
"changesLost": "Your changes will be lost if you don’t save them.",
"readOnly": "The document “{name}” can’t be saved because its file is read-only.",
"readOnlyDetail": "Save it as another file to keep your changes.",
"changedOnDisk": "The file “{name}” has been changed by another application.",
"changedOnDiskDetail": "Save Anyway replaces it with your version. Revert discards your changes and shows the version on disk.",
"alreadyExists": "An item named “{name}” already exists in this location. Do you want to replace it?",
"alreadyExistsDetail": "Replacing it overwrites its current contents.",
"revertQuestion": "Do you want to revert “{name}” to the last saved version?",
"revertDetail": "Your current changes will be lost.",
"reviewBeforeQuitting": "You have {n} {app} documents with unsaved changes. Do you want to review these changes before quitting?",
"reviewBeforeQuittingDetail": "If you don’t review your documents, all your changes will be lost.",
"saveManyChanges": "Do you want to save the changes to the following {n} documents?",
"documentFailed": "{action, select, opened {The document “{name}” could not be opened.} renamed {The document “{name}” could not be renamed.} moved {The document “{name}” could not be moved.} reverted {The document “{name}” could not be reverted.} other {The document “{name}” could not be saved.}}",
"colorName": "{color, select, red {Red} orange {Orange} yellow {Yellow} green {Green} teal {Teal} blue {Blue} indigo {Indigo} purple {Purple} pink {Pink} brown {Brown} gray {Gray} black {Black} other {{color}}}",
"ok": "OK",
"open": "Open",
"selectFolder": "Select Folder",
"clearTerminal": "Clear",
"clipboardRead": "A program wants to read the clipboard",
"clipboardReadAllow": "Allow",
"clipboardReadDeny": "Deny",
"clipboardReadEmpty": "The clipboard is empty.",
"decimalInvalid": "Enter a number",
"decimalWhole": "Enter a whole number",
"decimalPlaces": "{n, plural, one {Use at most # decimal place} other {Use at most # decimal places}}",
"decimalAtLeast": "Enter {min} or more",
"decimalAtMost": "Enter {max} or less",
"desktopShortcut": "Create a desktop shortcut",
"selected": "selected",
"permissionAccessibility": "Accessibility",
"permissionDeviceControlAndDataAccess": "Device Control and Data Access",
"permissionScreenRecording": "Screen Recording",
"permissionInputMonitoring": "Input Monitoring",
"permissionFullDiskAccess": "Full Disk Access",
"permissionAppManagement": "App Management",
"permissionDeveloperTools": "Developer Tools",
"permissionMicrophone": "Microphone",
"permissionCamera": "Camera",
"permissionCalendars": "Calendars",
"permissionReminders": "Reminders",
"permissionBluetooth": "Bluetooth",
"permissionMediaAppleMusic": "Media \u0026 Apple Music",
"guideDrag": "Drag {app} to the list above to allow {permission}.",
"guideDragHint": "Drag"
}