clipboard

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

clipboard

github.com/webong/ext/res/system/capture/clipboard is the reusable, transport-free system clipboard package inside the system shell module. It defines bounded multi-format snapshots, opaque generations, and conditional write and clear operations. The embedding application supplies a policy and native backend.

Generation metadata can be queried without reading clipboard contents, so an application can grant write-only access while retaining stale-write protection.

The library does not define grants, approval UI, remote request routing, implicit restoration, or permission onboarding. A native mutation receipt reports dispatch separately from later verification because operating-system clipboard APIs do not provide a cross-process transaction.

Apple implementations live in ios/Sources/ExtClipboard; Android implementations live in android/src/android. They are shipped by pkg/ext-ios and pkg/ext-android respectively.

Documentation

Overview

Package clipboard defines bounded, transport-free access to a native system clipboard. Hosts choose a backend and policy; this package performs no remote routing, approval UI, permission prompting, or implicit restoration.

Index

Constants

View Source
const (
	MaxPolicyBytes = 16 << 20
	MaxItems       = 64
	MaxFormats     = 32
)

Variables

View Source
var (
	ErrChanged = errors.New("clipboard generation changed")
	ErrDenied  = errors.New("clipboard operation denied")
	ErrInvalid = errors.New("invalid clipboard value")
	ErrLimit   = errors.New("clipboard limit exceeded")
)

Functions

func ValidateItems

func ValidateItems(items []Item, maxBytes int64, formats []string) error

func ValidatePolicy

func ValidatePolicy(policy Policy) error

func ValidateSnapshot

func ValidateSnapshot(snapshot Snapshot, maxBytes int64, formats []string) error

Types

type Backend

type Backend interface {
	Generation(context.Context) (string, error)
	Read(context.Context, int64, []string) (Snapshot, error)
	Write(context.Context, WriteRequest, int64, []string) (Receipt, error)
}

Backend serializes operations and compares ExpectedGeneration immediately before mutation. Native clipboard APIs may still lack cross-process atomicity.

type Clipboard

type Clipboard struct {
	// contains filtered or unexported fields
}

func New

func New(backend Backend, policy Policy) (*Clipboard, error)

func (*Clipboard) Clear

func (c *Clipboard) Clear(ctx context.Context, expectedGeneration string) (Receipt, error)

func (*Clipboard) Generation

func (c *Clipboard) Generation(ctx context.Context) (string, error)

Generation returns mutation metadata without reading clipboard contents. It lets a write-only client perform a conditional write without gaining read access.

func (*Clipboard) Read

func (c *Clipboard) Read(ctx context.Context) (Snapshot, error)

func (*Clipboard) Write

func (c *Clipboard) Write(ctx context.Context, request WriteRequest) (Receipt, error)

type Item

type Item struct {
	Representations []Representation `json:"representations"`
}

type Policy

type Policy struct {
	MaxBytes       int64    `json:"maxBytes"`
	AllowedFormats []string `json:"allowedFormats"`
	AllowRead      bool     `json:"allowRead"`
	AllowWrite     bool     `json:"allowWrite"`
}

Policy is fixed by the embedding application before native access begins.

type Receipt

type Receipt struct {
	Generation string `json:"generation"`
	Dispatch   string `json:"dispatch"`
}

Receipt distinguishes a dispatched native mutation from later verification.

type Representation

type Representation struct {
	Format string `json:"format"`
	Data   []byte `json:"data"`
}

type Snapshot

type Snapshot struct {
	Generation string `json:"generation"`
	Items      []Item `json:"items"`
}

Snapshot is a finite copy. Generation is opaque and is only meaningful to the backend instance that produced it.

type WriteRequest

type WriteRequest struct {
	ExpectedGeneration string `json:"expectedGeneration"`
	Items              []Item `json:"items"`
}

Jump to

Keyboard shortcuts

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