Clipboard

backend.Clipboard (Class)
Implements: spec.Clipboard

Clay backend implementation for system clipboard operations.

This class provides cross-platform clipboard text access with support for:

  • Native SDL clipboard on desktop platforms
  • Electron clipboard API when running in Electron
  • Browser clipboard API as a fallback on web
  • Internal text storage as a last resort

Platform-specific behavior:

  • Desktop (SDL): Direct system clipboard access
  • Electron: Uses Electron's clipboard module with retry logic
  • Web Browser: Uses navigator.clipboard API with permission handling
  • Fallback: Internal string storage when system access unavailable

The browser clipboard implementation requires user permission and automatically syncs when the window gains focus.

See: spec.Clipboard The interface this class implements

Instance Members

clay
getText(): String

Gets the current clipboard text content.

Attempts to read from the system clipboard in this order:

  1. Electron clipboard (if available)
  2. SDL system clipboard (on desktop)
  3. Internal clipboard storage (fallback)
Returns Description
String The clipboard text content, or null if empty

clay
setText(text: String): Void

Sets the clipboard text content.

Writes to all available clipboard targets:

  • Internal storage (always)
  • Electron clipboard (if available, with retry)
  • Browser clipboard (if permissions granted)
  • SDL system clipboard (on desktop)

The Electron implementation includes a 100ms delayed retry to work around timing issues with clipboard access.

Name Type Description
text String The text to copy to the clipboard

clay
new(): Void

Creates a new clipboard handler. Automatically detects and initializes the appropriate clipboard API based on the platform and available features.

Private Members

clay
clipboardText: String

Internal clipboard text storage used as fallback