Documentation
¶
Index ¶
- func Dir() (string, error)
- func DirFrom(baseDir string) string
- func EnsureDir() error
- func Load(identity func(string) string) (*Config, Result, error)
- func LoadFrom(baseDir string, identity func(string) string) (*Config, Result, error)
- func Path() (string, error)
- type Config
- func (c *Config) AddTrustedFolder(dir, identity string) bool
- func (c *Config) ForgetSitePort(anchor string) int
- func (c *Config) RememberSitePort(anchor string, port int)
- func (c *Config) RemoveTrustedFolder(dir string) (TrustedFolder, bool)
- func (c *Config) Save() error
- func (c *Config) SetStartOnLogin(v bool)
- func (c *Config) SetTrustedIdentity(dir, identity string) (previous string, ok bool)
- func (c *Config) SitePort(anchor string) int
- func (c *Config) SitePortList() map[string]int
- func (c *Config) StartOnLoginEnabled() bool
- func (c *Config) TrustedFolderList() []TrustedFolder
- type Result
- type TrustedFolder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
StartOnLogin bool `json:"startOnLogin"`
// SitePorts remembers the loopback port each origin was served on.
// Browser storage (localStorage, IndexedDB, cookies) is scoped to an origin,
// and the port is part of the origin, so handing a tree a fresh random port
// on every launch silently orphans whatever the page stored last time.
// Keyed by the origin's anchor: a trusted folder, or an ordinary directory
// for a file opened outside every trusted folder.
SitePorts map[string]int `json:"sitePorts,omitempty"`
// TrustedFolders are folders the user declared theirs. HTML Clay files under
// one open editable with no prompts, including files added later, and any
// file in it can change any other. This is the app's one durable permission
// fact: it grants read and write, it anchors exactly one origin, and it is
// the key that origin's port is remembered under.
//
// These are never pruned on Load: a trusted folder is a standing write
// capability, and a dead or identity-changed entry must surface in the tray
// as dead rather than silently vanish from the record of what the user
// granted.
//
// The on-disk key stays "workspaceFolders" even though the concept is now
// called a trusted folder. Reusing the "trustedFolders" key would make
// json.Unmarshal fail against 1.2.0 configs, where it held a []string, and
// the corrupt-config path would then reset every setting the user has.
TrustedFolders []TrustedFolder `json:"workspaceFolders,omitempty"`
// LegacyTrusted is 1.2.0's read-only trusted folder list. It is promoted to
// TrustedFolders once on Load and cleared on the next Save, which is the
// completion marker. Distinct Go field, distinct JSON key, distinct type, so
// the decoder never sees a shape it does not expect.
LegacyTrusted []string `json:"trustedFolders,omitempty"`
// contains filtered or unexported fields
}
func (*Config) AddTrustedFolder ¶ added in v1.2.0
AddTrustedFolder records dir with its identity fingerprint, returning false if the path was already present. dir must already be canonical (resolved, home-contained); the caller validates before adding, so containment checks here can stay simple.
func (*Config) ForgetSitePort ¶ added in v1.3.1
ForgetSitePort drops the remembered port for anchor and returns it, so a caller whose change fails to reach disk can put it back.
Untrusting a folder forgets its port. Keeping it would hand the folder's exact origin straight back to the first file re-homed out of it: that file's own folder IS the untrusted folder, so it anchors there and binds the same remembered port, leaving the untrusted folder's still-open pages same-origin with a file that has a live save token. "Files you had opened yourself survive, on a new address of their own" is the promise, and the new address is the whole of it.
func (*Config) RememberSitePort ¶ added in v1.2.0
RememberSitePort records the port an origin was served on so the next launch can reuse it and keep the origin stable.
func (*Config) RemoveTrustedFolder ¶ added in v1.2.0
func (c *Config) RemoveTrustedFolder(dir string) (TrustedFolder, bool)
RemoveTrustedFolder drops dir from the list, returning the entry it removed along with whether it was there at all.
The entry comes back so a caller whose removal fails to reach disk can restore exactly what it took out. Re-adding a freshly built entry instead re-pins the folder to whatever is at that path now, which turns a dead entry (folder deleted and replaced, granting nothing) into a live grant over the newcomer — the one thing the identity pin exists to prevent, arrived at through an error path.
func (*Config) SetStartOnLogin ¶ added in v1.2.0
SetStartOnLogin sets the start-on-login preference under the lock.
func (*Config) SetTrustedIdentity ¶ added in v1.3.0
SetTrustedIdentity re-pins an existing entry and returns the pin it replaced, so a caller whose save fails can put it back. ok reports whether there was an entry to re-pin. The pin is what makes a replaced folder stop granting; moving it is how an explicit re-approval of the folder now on disk takes effect.
func (*Config) SitePort ¶ added in v1.2.0
SitePort returns the port previously used for an anchor, or 0 if there is none.
func (*Config) SitePortList ¶ added in v1.3.0
SitePortList returns a copy of the remembered ports for startup planning.
func (*Config) StartOnLoginEnabled ¶ added in v1.2.0
StartOnLoginEnabled reports the start-on-login preference under the lock.
func (*Config) TrustedFolderList ¶ added in v1.2.0
func (c *Config) TrustedFolderList() []TrustedFolder
TrustedFolderList returns a copy of the trusted folders so callers can read the list without touching the field under the lock.
type Result ¶ added in v1.3.0
type Result struct {
// HadAppMode is true when the loaded file still carried App Mode. Startup
// uses it to delete the Chromium profile directory that mode created.
HadAppMode bool
// PromotedLegacy is true when 1.2.0 read-only trusted folders were widened
// into trusted folders.
PromotedLegacy bool
}
Result reports what Load had to do to the file, so startup can act on a one-time migration without a live field for a setting that no longer exists.
type TrustedFolder ¶ added in v1.3.0
TrustedFolder is one declared folder. Identity is the folder's device+inode fingerprint at declaration time ("" where the platform cannot provide one); callers compare it before installing so a directory swapped for a symlink since declaration is refused under the old name instead of granting write over whatever tree the link now points at.