Files
openchamber-android-native/third_party/mygo/appfile_windows.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

45 lines
1.3 KiB
Go

package mygo
import (
"errors"
"io"
"os"
"path/filepath"
)
// readShared reads the file at path through openShared, which shares its
// deletion: os.ReadFile does not, and while it held the file open, a save
// replacing it was refused ("Access is denied"), so that a goroutine
// reading an app file in a loop could make another's save run out of
// retries.
func readShared(path string) ([]byte, error) {
f, err := openShared(path)
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
}
// renameOver renames from over to, its sibling, with POSIX semantics
// (os.Root.Rename), which replace a file that others hold open sharing its
// deletion, as readShared does. os.Rename's MoveFileEx is refused while
// any handle to the file is open, whatever it shares. The root comes from
// fileWatchOpenRoot, which shares the directory's deletion.
func renameOver(from, to string) error {
dir := filepath.Dir(to)
if filepath.Dir(from) != dir {
return os.Rename(from, to)
}
root, err := fileWatchOpenRoot(dir)
if err != nil {
return err
}
defer root.Close()
err = root.Rename(filepath.Base(from), filepath.Base(to))
if le := (*os.LinkError)(nil); errors.As(err, &le) {
err = &os.LinkError{Op: "rename", Old: from, New: to, Err: le.Err}
}
return err
}