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

71 lines
2.4 KiB
Go

package platform
import (
"errors"
"io/fs"
)
// FileWatchTarget is a file or directory the core enrolls in a FileWatch.
// IDs are never reused within a FileWatch.
type FileWatchTarget struct {
ID uint64
Path string
// Directory says the target is a directory. A backend that watches a
// file only through its directory, which the core enrolls before it
// lists it, returns ErrUnsupported for a target that isn't one, and
// the core enrolls no more files.
Directory bool
// Info is what the core's scan saw at Path. Backends open the target
// and check it is still the same file, so that a replacement racing
// the enrollment is not watched in its place.
Info fs.FileInfo
// Subtree asks to watch everything beneath the directory with this one
// target, and to name what changes deeper down by its slash-separated
// path relative to it. A backend that can't returns ErrUnsupported,
// and the core enrolls every directory instead.
Subtree bool
}
// FileWatchKind says what changed. Backends report what the system tells
// them; the core rescans what a notice names, so a kind is only a hint.
type FileWatchKind uint8
const (
// FileWatchDirty means something about the target or its child changed.
FileWatchDirty FileWatchKind = iota
FileWatchWrite
FileWatchCreate
FileWatchRemove
FileWatchMoveFrom
FileWatchMoveTo
// FileWatchLost means the system stopped watching the target, for
// example because it was deleted; the core enrolls it again if it
// still exists.
FileWatchLost
)
// FileWatchNotice reports a change to a target (Name empty) or to one of
// the immediate children of a directory target (Name its name; a path for
// a Subtree target). A notice with Err set ends the watch, except
// ErrFileWatchOverflow, after which the core rescans everything.
type FileWatchNotice struct {
Target uint64
Kind FileWatchKind
Name string
Err error
}
// ErrFileWatchOverflow is the Err of a notice when the system dropped
// changes, for example because its queue overflowed.
var ErrFileWatchOverflow = errors.New("file watch queue overflow")
// FileWatch watches the targets the core adds. Its methods may be called
// from any goroutine, one at a time. Close stops the watch and waits until
// every handle is released and notify will not be called again; it must
// not be called from notify.
type FileWatch interface {
Add(target FileWatchTarget) error
Remove(id uint64)
Close()
}