Documentation
¶
Overview ¶
Package applets holds the on-disk catalog of applets: web pages an agent or a user writes, which Hive opens with full access to the machine through window.hive (ADR applets-are-web-pages-with-full-access-to-the-machine).
This package parses and validates. It never executes a command.
Index ¶
- Constants
- Variables
- func BridgeScript() string
- func FreeID(root, id string) (string, error)
- func IsWatchedFile(path string) bool
- func ReadBuiltin(id, name string) ([]byte, error)
- func SetSurface(raw []byte, surface string, on bool) ([]byte, error)
- func SkipsWatch(dir string) bool
- type Applet
- type Archive
- type ArchiveFile
- type Command
- type Entry
- type PackList
- type PackedApplet
- type PackedFile
- type PopupSurface
- type Store
- type Surfaces
- type TabSurface
- type TitlebarSurface
- type UpdateHiveError
Constants ¶
const ( // FileName is the file that makes a directory under the applets root an applet. FileName = "applet.yaml" // DefaultEntry is the page an applet opens on. DefaultEntry = "index.html" // DefaultTitlebarWidth matches the bar's square icon buttons. DefaultTitlebarWidth = 28 )
const ( // ArchiveFormat is the version of the file Pack writes. Unpack refuses any other, so // a later format can be told apart rather than misread. ArchiveFormat = 1 // ArchiveExtension names a shared applet: a zip holding ArchiveManifestName and the // applet's files under files/. ArchiveExtension = ".hiveapplet" // ArchiveManifestName is the one entry outside files/. ArchiveManifestName = "hive-applet.json" MaxArchiveBytes = 32 << 20 MaxArchiveFiles = 500 // MaxUnpackedBytes bounds what an archive may expand to, which its own headers // cannot be trusted to report. MaxUnpackedBytes = 64 << 20 )
const ( SurfaceTab = "tab" SurfacePopup = "popup" SurfaceTitlebar = "titlebar" )
Names of the keys under surfaces: in applet.yaml.
const BuilderID = "applet-builder"
const ( // FormatVersion is the applet.yaml format this Hive reads. It rises only for a change an // older Hive would misread, which is what keeps files working across releases. FormatVersion = 1 )
Variables ¶
var ErrAppletExists = errors.New("an applet with that id already exists")
ErrAppletExists reports that an id is taken. Nothing replaces an applet on import.
Functions ¶
func BridgeScript ¶
func BridgeScript() string
func FreeID ¶
FreeID returns id if nothing holds it, and otherwise the first free id-2, id-3 and so on.
func IsWatchedFile ¶
IsWatchedFile matches what can change the catalog or a page on screen. A shell script is read when it runs and needs no reload, and a data file an applet writes for itself must not restart it.
func ReadBuiltin ¶
ReadBuiltin returns one file of a built-in applet.
func SetSurface ¶
SetSurface returns raw with one surface turned on or off, keeping the file's comments. Off is enabled: false rather than a removed key, so a pop-up keeps its size and a title bar keeps its page for when the surface comes back.
func SkipsWatch ¶
SkipsWatch names a folder that holds no part of a page an edit would change, and can be large enough to run out of file watches.
Types ¶
type Applet ¶
type Applet struct {
ID string `yaml:"-"`
// Dir is the applet's directory, exported to its commands as HIVE_APPLET_DIR. A
// built-in has its page in the binary, and keeps only its saved storage here.
Dir string `yaml:"-"`
// Builtin marks an applet Hive ships. A directory of the same name replaces it.
Builtin bool `yaml:"-"`
// Warnings names what this Hive skipped in the file, such as a key from a later
// release. The applet still runs.
Warnings []string `yaml:"-"`
// Version is the format of this file, not a release of the applet.
Version int `yaml:"version"`
// Hive is the oldest Hive that can run this applet, as ">=0.60".
Hive string `yaml:"hive,omitempty"`
Title string `yaml:"title"`
Icon string `yaml:"icon,omitempty"`
// Cwd pins the applet's commands to one directory. Empty follows the session on
// screen, and the applet's own directory without one.
Cwd string `yaml:"cwd,omitempty"`
// Entry is the page the applet opens on, relative to its directory.
Entry string `yaml:"entry,omitempty"`
// Surfaces says where the applet shows. A file that names none is a pop-up.
Surfaces Surfaces `yaml:"surfaces,omitempty"`
// Commands are the applet's palette rows that a user can bind to a key, as
// applet.<id>.<command>. They carry no default chord, so a file cannot claim a key.
Commands []Command `yaml:"commands,omitempty"`
}
Applet is one applet.yaml. ID is the name of its directory, so an applet can be copied or renamed by moving the directory.
func Parse ¶
Parse decodes one applet.yaml for the Hive at hostVersion. It reads forward: a later release's key or icon is a warning, so an applet written there still opens here. A wrong shape under a key this Hive knows stays an error, and so does a file that says this Hive is too old (ADR applets-are-web-pages-with-full-access-to-the-machine).
type Archive ¶
type Archive struct {
Applet Applet
Files []ArchiveFile
}
Archive is an applet read out of a shared file, checked and still only in memory.
func Unpack ¶
Unpack reads a shared file, which it treats as hostile. It writes nothing, and every problem refuses the whole file. A zip has no hard links, so the entry type check covers symlinks and every other special file. A warning from Parse carries only names it has already reduced to plain text.
func (Archive) Install ¶
Install writes the archive as a new applet under root. The directory appears whole or not at all: it is written beside root, where the catalog does not look, and renamed in. Files get plain permissions, so the archive cannot mark anything executable. A failure from beforeRename, which may be nil, leaves nothing behind.
type ArchiveFile ¶
ArchiveFile is one file of an applet, by its slash-separated path in the directory.
type Command ¶
type Command struct {
// ID is permanent once a user has bound it: it is what settings.yaml names.
ID string `yaml:"id"`
Title string `yaml:"title"`
Icon string `yaml:"icon,omitempty"`
Keywords []string `yaml:"keywords,omitempty"`
}
Command is one thing an applet offers the palette. Running it reaches the page through hive.on('command').
type Entry ¶
type Entry struct {
Applet Applet
Err error
// Revision is the newest change among the applet's watched files, in Unix
// milliseconds. It is what tells a page on screen to load again after an edit,
// without a change to another applet restarting this one.
Revision int64
}
Entry is one directory under the root. A broken file keeps the Applet that last loaded from it, with the problem in Err, so an edit in progress neither removes the applet from the palette nor hides why the edit did not take.
type PackList ¶
type PackList struct {
Files []PackedFile
LeftOut []string
}
PackList is what an export of a directory contains and what it leaves out.
type PackedApplet ¶
PackedApplet is an export, whole in memory, with what it holds.
func Pack ¶
func Pack(applet Applet, hiveVersion string) (PackedApplet, error)
Pack reads one applet's directory into an archive. It records no timestamp, owner or path from this machine: the entries are the relative paths and their contents. It runs the checks an import would, so what cannot be imported fails here, for the person who can fix it. The result is held in memory, so what the user reviews is what gets written.
type PackedFile ¶
PackedFile is one file an export includes.
type PopupSurface ¶
type PopupSurface struct {
Enabled *bool `yaml:"enabled,omitempty"`
Width int `yaml:"width,omitempty"`
Height int `yaml:"height,omitempty"`
}
PopupSurface sizes the pop-up in pixels. Zero fills the window.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the catalog. It reads the disk only in Reload, so opening the palette costs no I/O.
type Surfaces ¶
type Surfaces struct {
// Tab puts the applet in a session's + menu.
Tab *TabSurface `yaml:"tab,omitempty"`
// Popup opens the applet over the app, from the palette or a chord.
Popup *PopupSurface `yaml:"popup,omitempty"`
// Titlebar runs a page in the title bar from the moment the file loads.
Titlebar *TitlebarSurface `yaml:"titlebar,omitempty"`
}
Surfaces is the registration: an applet shows where its file says, and nowhere else. A surface takes a map so a later release can add to it without moving a key.
func (Surfaces) ShowsPopup ¶
func (Surfaces) ShowsTab ¶
ShowsTab, ShowsPopup and ShowsTitlebar say whether the surface is listed and not turned off.
func (Surfaces) ShowsTitlebar ¶
type TabSurface ¶
type TabSurface struct {
// Enabled false turns the surface off and keeps its settings. Unset is on.
Enabled *bool `yaml:"enabled,omitempty"`
}
TabSurface takes its size from its panel.
type TitlebarSurface ¶
type TitlebarSurface struct {
Enabled *bool `yaml:"enabled,omitempty"`
// Entry is relative to the applet's directory. Empty uses the applet's Entry, and
// the page tells the two apart with hive.surface.
Entry string `yaml:"entry,omitempty"`
// Width is the slot's width in pixels until the page asks for another. Zero is
// DefaultTitlebarWidth, one icon button.
Width int `yaml:"width,omitempty"`
}
TitlebarSurface is the page an applet shows in the title bar.
type UpdateHiveError ¶
type UpdateHiveError struct {
// contains filtered or unexported fields
}
UpdateHiveError reports a file this Hive is too old for. It stands on its own, so an import shows it as is rather than calling the file invalid.
func (*UpdateHiveError) Error ¶
func (e *UpdateHiveError) Error() string