Skip to main content
Clipboard operations handle reading, writing, and syncing clipboard content across devices. These functions manage the core functionality of ClipSync.

updateClipboard

Updates the clipboard content and syncs it to all devices in the session. Source: src/App.jsx:167

Parameters

This function uses component state rather than direct parameters:
string
The text content to be synced. Maximum length of 15,000 characters.
object | null
Optional file attachment object containing url, path, name, and type properties.
boolean
Flag indicating whether the content contains sensitive information that should be hidden.

Behavior

  1. Validates that either text or file content exists
  2. Checks content length (15,000 character limit)
  3. Creates a new session if one doesn’t exist
  4. Inserts clipboard data into the database
  5. Clears the input fields and resets state

fetchClipboardHistory

Retrieves all clipboard entries for the current session. Source: src/App.jsx:31

Parameters

string
required
The session code to fetch clipboard history for (from component state).

Return Value

Returns Promise<void>. Updates component state with the fetched clipboard history.

copyToClipboard

Copies text content to the system clipboard. Source: src/App.jsx:207

Parameters

string
required
The text content to copy to the system clipboard.

Behavior

Uses the browser’s Clipboard API (navigator.clipboard.writeText) to write content to the system clipboard and displays a success notification.

addClipboardText

Reads text from the system clipboard and adds it to the input field. Source: src/App.jsx:212

Behavior

  1. Requests clipboard read permission from the browser
  2. Reads text content from the system clipboard
  3. Updates the input field with the clipboard text
  4. Shows appropriate success or error messages

Browser Permissions

Requires the clipboard-read permission. Users may be prompted to grant permission on first use.

deleteAll

Deletes all clipboard entries for the current session, including associated files. Source: src/App.jsx:225

Behavior

  1. Shows a confirmation dialog to the user
  2. Iterates through all history items and deletes associated files from storage
  3. Deletes all database records for the current session
  4. Clears the local history state

handleEdit

Loads a clipboard entry into the editor for modification. Source: src/App.jsx:249

Parameters

number
required
The unique identifier of the clipboard entry to edit.

Behavior

  1. Finds the entry in the history by ID
  2. Loads the content and file (if any) into the editor
  3. Deletes the entry from the database
  4. Updates the local history state
  5. Allows the user to modify and re-save the content

Real-time Subscription

ClipSync uses Supabase’s real-time features to sync clipboard updates across devices. Source: src/App.jsx:385

Behavior

  • INSERT events: Adds new clipboard entries to the history in real-time
  • DELETE events: Removes deleted entries from the history
  • Session filtering: Only processes events matching the current session code
  • Cleanup: Unsubscribes from the channel when the component unmounts

Event Types

  • INSERT: New clipboard content added
  • DELETE: Clipboard content removed
  • Automatically syncs across all connected devices in the session