engine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 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.

Documentation

Overview

Package engine implements the local synchronization pipeline, content hashing, echo loop suppression, and deduplication policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeHash

func ComputeHash(data []byte) string

ComputeHash computes the SHA-256 cryptographic digest of data and returns it formatted as a lowercase hexadecimal string.

Types

type Engine

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

Engine coordinates clipboard change detection, policy filtering, echo loop suppression, and inbound clipboard application.

func New

func New(cfg *config.Config, clip clipboard.Clipboard) *Engine

New constructs an Engine with the provided configuration and clipboard interface.

func (*Engine) ApplyInbound

func (e *Engine) ApplyInbound(item *clipboard.Item, hash string) error

ApplyInbound applies an item received from a remote peer to the local OS clipboard. It records hash as LastReceived BEFORE invoking clipboard.Write, guaranteeing that when the local clipboard watcher fires in response to this write, it is recognized as a self-echo and suppressed.

func (*Engine) Outbound

func (e *Engine) Outbound() <-chan OutboundEvent

Outbound returns the channel emitting validated clipboard events.

func (*Engine) ProcessItem

func (e *Engine) ProcessItem(item *clipboard.Item)

ProcessItem evaluates and dispatches an outbound item (e.g. from local clipboard or the optional screenshot directory watcher).

func (*Engine) ProcessLocalChange

func (e *Engine) ProcessLocalChange()

ProcessLocalChange executes the outbound evaluation pipeline for a local clipboard modification.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

Run executes the engine's main event loop, listening for clipboard change notifications until ctx is cancelled.

func (*Engine) State

func (e *Engine) State() *SyncState

State returns the underlying SyncState instance.

type OutboundEvent

type OutboundEvent struct {
	Item *clipboard.Item
	Hash string
}

OutboundEvent represents a validated, non-echo, non-duplicate clipboard item ready for dispatch to remote peers.

type SyncState

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

SyncState provides thread-safe in-memory tracking of content hashes to enable echo loop elimination and local copy deduplication.

func NewSyncState

func NewSyncState() *SyncState

NewSyncState constructs an empty, initialized SyncState.

func (*SyncState) CurrentLocalHash

func (s *SyncState) CurrentLocalHash() string

CurrentLocalHash returns the SHA-256 hash of the currently active local clipboard content.

func (*SyncState) IsLastReceived

func (s *SyncState) IsLastReceived(hash string) bool

IsLastReceived returns true if hash matches the item most recently applied from a peer. If true, the local clipboard change is a self-echo and must be dropped.

func (*SyncState) IsLastSent

func (s *SyncState) IsLastSent(hash string) bool

IsLastSent returns true if hash matches the item most recently dispatched outbound. If true, the user simply copied the same item again, so it can be safely deduplicated.

func (*SyncState) SetCurrentLocal

func (s *SyncState) SetCurrentLocal(hash string)

SetCurrentLocal records the SHA-256 hash of the currently active local clipboard content.

func (*SyncState) SetLastReceived

func (s *SyncState) SetLastReceived(hash string)

SetLastReceived records the SHA-256 hash of an item received from a remote peer. This must be called BEFORE applying the item to the local operating system clipboard.

func (*SyncState) SetLastSent

func (s *SyncState) SetLastSent(hash string)

SetLastSent records the SHA-256 hash of an item dispatched outbound.

Jump to

Keyboard shortcuts

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