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:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
@@ -0,0 +1,177 @@
|
||||
// Package accelerator parses Electron style keyboard accelerators such as
|
||||
// "CmdOrCtrl+Shift+Z" into a platform neutral representation.
|
||||
package accelerator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Modifiers is a bit set of modifier keys.
|
||||
type Modifiers uint8
|
||||
|
||||
// Modifier keys. Super is Command on macOS and the Windows/Super key
|
||||
// elsewhere.
|
||||
const (
|
||||
Super Modifiers = 1 << iota
|
||||
Ctrl
|
||||
Alt
|
||||
Shift
|
||||
)
|
||||
|
||||
// Accelerator is a parsed accelerator.
|
||||
type Accelerator struct {
|
||||
Modifiers Modifiers
|
||||
// Key is either a single lower case character ("a", "1", ",") or one of
|
||||
// the named keys: F1-F24, Enter, Tab, Space, Backspace, Delete, Insert,
|
||||
// Escape, Up, Down, Left, Right, Home, End, PageUp, PageDown,
|
||||
// VolumeUp, VolumeDown, VolumeMute, MediaNextTrack, MediaPreviousTrack,
|
||||
// MediaStop, MediaPlayPause, PrintScreen, Num0-Num9, NumDec, NumAdd,
|
||||
// NumSub, NumMult, NumDiv, CapsLock, NumLock, ScrollLock.
|
||||
Key string
|
||||
}
|
||||
|
||||
// Has reports whether all modifiers in m are set.
|
||||
func (a Accelerator) Has(m Modifiers) bool { return a.Modifiers&m == m }
|
||||
|
||||
// String formats the accelerator in canonical form.
|
||||
func (a Accelerator) String() string {
|
||||
var parts []string
|
||||
if a.Has(Super) {
|
||||
parts = append(parts, "Super")
|
||||
}
|
||||
if a.Has(Ctrl) {
|
||||
parts = append(parts, "Ctrl")
|
||||
}
|
||||
if a.Has(Alt) {
|
||||
parts = append(parts, "Alt")
|
||||
}
|
||||
if a.Has(Shift) {
|
||||
parts = append(parts, "Shift")
|
||||
}
|
||||
key := a.Key
|
||||
if len(key) == 1 {
|
||||
key = strings.ToUpper(key)
|
||||
}
|
||||
return strings.Join(append(parts, key), "+")
|
||||
}
|
||||
|
||||
var namedKeys = map[string]string{
|
||||
"plus": "+",
|
||||
"space": "Space",
|
||||
"tab": "Tab",
|
||||
"capslock": "CapsLock",
|
||||
"numlock": "NumLock",
|
||||
"scrolllock": "ScrollLock",
|
||||
"backspace": "Backspace",
|
||||
"delete": "Delete",
|
||||
"del": "Delete",
|
||||
"insert": "Insert",
|
||||
"ins": "Insert",
|
||||
"return": "Enter",
|
||||
"enter": "Enter",
|
||||
"up": "Up",
|
||||
"down": "Down",
|
||||
"left": "Left",
|
||||
"right": "Right",
|
||||
"home": "Home",
|
||||
"end": "End",
|
||||
"pageup": "PageUp",
|
||||
"pagedown": "PageDown",
|
||||
"escape": "Escape",
|
||||
"esc": "Escape",
|
||||
"volumeup": "VolumeUp",
|
||||
"volumedown": "VolumeDown",
|
||||
"volumemute": "VolumeMute",
|
||||
"medianexttrack": "MediaNextTrack",
|
||||
"mediaprevioustrack": "MediaPreviousTrack",
|
||||
"mediastop": "MediaStop",
|
||||
"mediaplaypause": "MediaPlayPause",
|
||||
"printscreen": "PrintScreen",
|
||||
"numdec": "NumDec",
|
||||
"numadd": "NumAdd",
|
||||
"numsub": "NumSub",
|
||||
"nummult": "NumMult",
|
||||
"numdiv": "NumDiv",
|
||||
}
|
||||
|
||||
// Parse parses an accelerator for the given GOOS. "CmdOrCtrl" resolves to
|
||||
// Super (Command) on darwin and Ctrl elsewhere.
|
||||
func Parse(s, goos string) (Accelerator, error) {
|
||||
var a Accelerator
|
||||
if strings.TrimSpace(s) == "" {
|
||||
return a, fmt.Errorf("accelerator: empty accelerator")
|
||||
}
|
||||
parts := splitParts(s)
|
||||
for i, raw := range parts {
|
||||
p := strings.TrimSpace(raw)
|
||||
if p == "" {
|
||||
return a, fmt.Errorf("accelerator: invalid accelerator %q", s)
|
||||
}
|
||||
last := i == len(parts)-1
|
||||
if m, ok := modifier(p, goos); ok && !last {
|
||||
a.Modifiers |= m
|
||||
continue
|
||||
}
|
||||
if !last {
|
||||
return a, fmt.Errorf("accelerator: unknown modifier %q in %q", p, s)
|
||||
}
|
||||
key, err := parseKey(p)
|
||||
if err != nil {
|
||||
return a, fmt.Errorf("accelerator: %w in %q", err, s)
|
||||
}
|
||||
a.Key = key
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// splitParts splits on "+" while allowing "+" itself as the key, as in
|
||||
// "CmdOrCtrl++".
|
||||
func splitParts(s string) []string {
|
||||
parts := strings.Split(s, "+")
|
||||
if strings.HasSuffix(s, "++") {
|
||||
parts = append(parts[:len(parts)-2], "+")
|
||||
} else if s == "+" {
|
||||
parts = []string{"+"}
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
func modifier(p, goos string) (Modifiers, bool) {
|
||||
switch strings.ToLower(p) {
|
||||
case "command", "cmd", "super", "meta", "win":
|
||||
return Super, true
|
||||
case "control", "ctrl":
|
||||
return Ctrl, true
|
||||
case "commandorcontrol", "cmdorctrl":
|
||||
if goos == "darwin" {
|
||||
return Super, true
|
||||
}
|
||||
return Ctrl, true
|
||||
case "alt", "option", "altgr":
|
||||
return Alt, true
|
||||
case "shift":
|
||||
return Shift, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func parseKey(p string) (string, error) {
|
||||
lower := strings.ToLower(p)
|
||||
if len([]rune(p)) == 1 {
|
||||
return strings.ToLower(p), nil
|
||||
}
|
||||
if k, ok := namedKeys[lower]; ok {
|
||||
return k, nil
|
||||
}
|
||||
if len(lower) >= 2 && lower[0] == 'f' {
|
||||
var n int
|
||||
if _, err := fmt.Sscanf(lower[1:], "%d", &n); err == nil && n >= 1 && n <= 24 && fmt.Sprint(n) == lower[1:] {
|
||||
return fmt.Sprintf("F%d", n), nil
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(lower, "num") && len(lower) == 4 && lower[3] >= '0' && lower[3] <= '9' {
|
||||
return "Num" + lower[3:], nil
|
||||
}
|
||||
return "", fmt.Errorf("unknown key %q", p)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package accelerator
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
goos string
|
||||
want Accelerator
|
||||
}{
|
||||
{"CmdOrCtrl+Q", "darwin", Accelerator{Super, "q"}},
|
||||
{"CmdOrCtrl+Q", "linux", Accelerator{Ctrl, "q"}},
|
||||
{"CommandOrControl+Shift+Z", "windows", Accelerator{Ctrl | Shift, "z"}},
|
||||
{"Alt+F4", "windows", Accelerator{Alt, "F4"}},
|
||||
{"Option+Cmd+I", "darwin", Accelerator{Alt | Super, "i"}},
|
||||
{"F11", "linux", Accelerator{0, "F11"}},
|
||||
{"Ctrl+Plus", "linux", Accelerator{Ctrl, "+"}},
|
||||
{"CmdOrCtrl++", "darwin", Accelerator{Super, "+"}},
|
||||
{"CmdOrCtrl+=", "darwin", Accelerator{Super, "="}},
|
||||
{"Cmd+,", "darwin", Accelerator{Super, ","}},
|
||||
{"Shift+Return", "darwin", Accelerator{Shift, "Enter"}},
|
||||
{"Esc", "darwin", Accelerator{0, "Escape"}},
|
||||
{"Ctrl+Num5", "linux", Accelerator{Ctrl, "Num5"}},
|
||||
{"Super+Space", "linux", Accelerator{Super, "Space"}},
|
||||
{"ctrl + shift + up", "linux", Accelerator{Ctrl | Shift, "Up"}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got, err := Parse(tt.in, tt.goos)
|
||||
if err != nil {
|
||||
t.Errorf("Parse(%q): %v", tt.in, err)
|
||||
continue
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("Parse(%q, %s) = %+v, want %+v", tt.in, tt.goos, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseErrors(t *testing.T) {
|
||||
for _, in := range []string{"", "Ctrl+", "Hyper+A", "Ctrl+F25", "Ctrl+Foo", "Ctrl+A+B"} {
|
||||
if _, err := Parse(in, "linux"); err == nil {
|
||||
t.Errorf("Parse(%q) succeeded, want error", in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
a, _ := Parse("Shift+CmdOrCtrl+k", "linux")
|
||||
if got := a.String(); got != "Ctrl+Shift+K" {
|
||||
t.Errorf("String() = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGTrigger(t *testing.T) {
|
||||
for in, want := range map[string]string{
|
||||
"Shift+CmdOrCtrl+K": "CTRL+SHIFT+k",
|
||||
"Super+Space": "LOGO+space",
|
||||
"Alt+Shift+Enter": "ALT+SHIFT+Return",
|
||||
"CmdOrCtrl+,": "CTRL+comma",
|
||||
"Ctrl+Plus": "CTRL+plus",
|
||||
"Ctrl+Alt+Super+F12": "CTRL+ALT+LOGO+F12",
|
||||
"Ctrl+Num7": "CTRL+KP_7",
|
||||
"Ctrl+PageDown": "CTRL+Page_Down",
|
||||
"MediaPlayPause": "XF86AudioPlay",
|
||||
"Ctrl+1": "CTRL+1",
|
||||
"Ctrl+é": "CTRL+U00E9",
|
||||
} {
|
||||
a, err := Parse(in, "linux")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := a.XDGTrigger(); got != want {
|
||||
t.Errorf("XDGTrigger(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package accelerator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Keysym returns the XKB (and X11) name of the key, as in "a", "comma",
|
||||
// "Return", "F5" or "KP_Add".
|
||||
func (a Accelerator) Keysym() string {
|
||||
if name, ok := keysyms[a.Key]; ok {
|
||||
return name
|
||||
}
|
||||
if strings.HasPrefix(a.Key, "Num") && len(a.Key) == 4 {
|
||||
return "KP_" + a.Key[3:]
|
||||
}
|
||||
if r := []rune(a.Key); len(r) == 1 && r[0] > '~' {
|
||||
return fmt.Sprintf("U%04X", r[0])
|
||||
}
|
||||
return a.Key // letters, digits and F1-F24
|
||||
}
|
||||
|
||||
// XDGTrigger formats the accelerator as a trigger of the XDG shortcuts
|
||||
// specification, as in "CTRL+SHIFT+k", which desktop portals take.
|
||||
func (a Accelerator) XDGTrigger() string {
|
||||
var parts []string
|
||||
for _, m := range []struct {
|
||||
mod Modifiers
|
||||
name string
|
||||
}{{Ctrl, "CTRL"}, {Alt, "ALT"}, {Shift, "SHIFT"}, {Super, "LOGO"}} {
|
||||
if a.Has(m.mod) {
|
||||
parts = append(parts, m.name)
|
||||
}
|
||||
}
|
||||
return strings.Join(append(parts, a.Keysym()), "+")
|
||||
}
|
||||
|
||||
var keysyms = map[string]string{
|
||||
"!": "exclam", `"`: "quotedbl", "#": "numbersign", "$": "dollar", "%": "percent",
|
||||
"&": "ampersand", "'": "apostrophe", "(": "parenleft", ")": "parenright", "*": "asterisk",
|
||||
"+": "plus", ",": "comma", "-": "minus", ".": "period", "/": "slash", ":": "colon",
|
||||
";": "semicolon", "<": "less", "=": "equal", ">": "greater", "?": "question", "@": "at",
|
||||
"[": "bracketleft", `\`: "backslash", "]": "bracketright", "^": "asciicircum",
|
||||
"_": "underscore", "`": "grave", "{": "braceleft", "|": "bar", "}": "braceright", "~": "asciitilde",
|
||||
"Enter": "Return", "Tab": "Tab", "Space": "space", "Backspace": "BackSpace",
|
||||
"Delete": "Delete", "Insert": "Insert", "Escape": "Escape",
|
||||
"Up": "Up", "Down": "Down", "Left": "Left", "Right": "Right",
|
||||
"Home": "Home", "End": "End", "PageUp": "Page_Up", "PageDown": "Page_Down",
|
||||
"VolumeUp": "XF86AudioRaiseVolume", "VolumeDown": "XF86AudioLowerVolume", "VolumeMute": "XF86AudioMute",
|
||||
"MediaNextTrack": "XF86AudioNext", "MediaPreviousTrack": "XF86AudioPrev",
|
||||
"MediaStop": "XF86AudioStop", "MediaPlayPause": "XF86AudioPlay",
|
||||
"PrintScreen": "Print", "CapsLock": "Caps_Lock", "NumLock": "Num_Lock", "ScrollLock": "Scroll_Lock",
|
||||
"NumDec": "KP_Decimal", "NumAdd": "KP_Add", "NumSub": "KP_Subtract",
|
||||
"NumMult": "KP_Multiply", "NumDiv": "KP_Divide",
|
||||
}
|
||||
Reference in new issue
Block a user