config

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

func DirFrom

func DirFrom(baseDir string) string

func EnsureDir

func EnsureDir() error

func Load

func Load(identity func(string) string) (*Config, Result, error)

func LoadFrom

func LoadFrom(baseDir string, identity func(string) string) (*Config, Result, error)

func Path

func Path() (string, error)

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

func (c *Config) AddTrustedFolder(dir, identity string) bool

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) RememberSitePort added in v1.2.0

func (c *Config) RememberSitePort(anchor string, port int)

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) bool

RemoveTrustedFolder drops dir from the list, returning whether it was present.

func (*Config) Save

func (c *Config) Save() error

func (*Config) SetStartOnLogin added in v1.2.0

func (c *Config) SetStartOnLogin(v bool)

SetStartOnLogin sets the start-on-login preference under the lock.

func (*Config) SetTrustedIdentity added in v1.3.0

func (c *Config) SetTrustedIdentity(dir, identity string) (previous string, ok bool)

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

func (c *Config) SitePort(anchor string) int

SitePort returns the port previously used for an anchor, or 0 if there is none.

func (*Config) SitePortList added in v1.3.0

func (c *Config) SitePortList() map[string]int

SitePortList returns a copy of the remembered ports for startup planning.

func (*Config) StartOnLoginEnabled added in v1.2.0

func (c *Config) StartOnLoginEnabled() bool

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

type TrustedFolder struct {
	Path     string `json:"path"`
	Identity string `json:"identity,omitempty"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL