ClipboardMonitor¶
Assembly:
ClipboardMonitor
Namespace: ClipboardMonitor¶
ClipboardConfig¶
Represents the configuration settings for the Clipboard Monitor application.
Methods¶
GetConfigPath()¶
Resolves the canonical path to clipboard-monitor-config.json under Roaming AppData.
Load()¶
Loads clipboard monitor configuration from canonical Smrt.Config storage.
Returns: A validated configuration instance; falls back to defaults if loading fails.
Save()¶
Persists the current settings to canonical Smrt.Config storage.
TryLoadDefaults()¶
Attempts to seed configuration from the packaged defaults payload.
ValidateOrThrow(ClipboardMonitor.ClipboardConfig param0)¶
Validates the provided configuration against the packaged JSON schema (if present).
Propertys¶
DuplicateDetection¶
Reserved toggle for runtime duplicate suppression; current implementation always suppresses duplicates but logs the configured intent.
EnableOcrHint¶
Enables the lightweight OCR hint pipeline for image fragments.
EndpointUrl¶
Endpoint that receives clipboard fragments (Python bridge /clipboard).
MaxJsonPreviewChars¶
Reserved for controlling log preview length when dynamic previews are enabled (diagnostic only).
OcrHintLanguageTag¶
Optional preferred OCR language tag (e.g., en-US).
OcrHintMaxEdgePx¶
Maximum edge length (pixels) for hint evaluation to control image workload.
OcrHintTimeoutMs¶
Timeout (milliseconds) applied to the OCR hint evaluation.
PollingIntervalMs¶
Polling interval (milliseconds) for the steady-state clipboard loop.
SchemaVersion¶
Gets or sets the schema version stamped into persisted configuration.
Program¶
Windows clipboard bridge that normalizes clipboard fragments and relays them to the SmrtHub Python core.
Remarks
Runs as a lightweight STA worker with no UI pump. The monitor polls the clipboard on a configurable interval, produces normalized fragment payloads (text, images, CF_HDROP file descriptors, additional hints), applies duplicate suppression, and posts the results to the Python HTTP bridge. This keeps the Python runtime reactive without owning Windows clipboard APIs directly.
Flow: Windows Clipboard → ExtractionFragmentUtils → ClipboardMonitor → HTTP POST → Python bridge_server → shared_state.
Fields¶
_config¶
Application configuration resolved from canonical Smrt.Config storage.
_extractCts¶
Cancellation token used to cancel in-flight extraction when a newer clipboard snapshot is available.
_lastClipboardSerialized¶
Stores the last processed clipboard payload (serialized JSON) to enable duplicate suppression.
Remarks
This field is critical for avoiding redundant HTTP requests when the clipboard content hasn't actually changed. The comparison is case-sensitive and includes whitespace, ensuring precise duplicate detection within the five-second window.
_lastNoFragLogUtc¶
Tracks the last time an "empty clipboard" informational log was produced to avoid console noise.
_lastProcessedAtUtc¶
Timestamp of the last fragment batch successfully forwarded to the Python core.
httpClient¶
HTTP client instance for communicating with the Python Flask server.
Remarks
Configured to send JSON payloads to the Python bridge server at localhost:5001/clipboard. The HttpClient is reused throughout the application lifecycle for optimal performance.
Target Endpoint: http://127.0.0.1:5001/clipboard Content Type: application/json Method: POST
Methods¶
ClipboardWatchLoop()¶
Core monitoring loop that extracts clipboard fragments and forwards new payloads to the Python core.
Remarks
Executes on the dedicated STA thread created in ClipboardMonitor.Program.Main. Each cycle cancels outstanding extraction work,
debounces rapid clipboard churn, invokes ExtractionFragmentUtilsLib.ExtractionFragmentUtils.ExtractFragmentsFromClipboardAsync(System.Threading.CancellationToken) synchronously,
and applies duplicate suppression (same serialized payload within a five-second window) before dispatching to the Python core.
Polling cadence is configuration-driven. Polling is bounded to between 100 ms and 300 ms for the debounce pass, then respects the
configured ClipboardMonitor.ClipboardConfig.PollingIntervalMs for the steady loop. Duplicate suppression currently uses a fixed
five-second window while the configuration toggle is validated.
Clipboard API conflicts (common when other applications interact with the clipboard) are logged but never break the loop.
LogFragments(Collections.Generic.List fragments)¶
Emits structured log entries describing each clipboard fragment for diagnostic purposes.
Parameters
fragments— The fragments that will be forwarded to the Python core.
Remarks
Text fragments are truncated to 40 characters to keep logs concise while still providing useful previews.
Main()¶
Application entry point that wires logging/configuration and starts the STA monitoring loop.
Remarks
Configures the application to run the clipboard monitoring loop in a separate STA (Single-Threaded Apartment) background thread, which is required for proper Windows clipboard API access. The main thread then blocks indefinitely to keep the application running.
Threading Model: • Main thread: Blocked indefinitely via Thread.Sleep(Timeout.Infinite) • Background thread: Runs ClipboardWatchLoop() with STA apartment state • No Windows message pump: Application doesn't need UI event processing
Loads runtime configuration via ClipboardMonitor.ClipboardConfig.Load, applies OCR hint options, and initializes SmrtHub.Logging.Logger
using canonical SmrtHub logging defaults.
SendFragmentsToFlask(Collections.Generic.List fragments)¶
Sends clipboard fragments (text, image, file) plus the encounter envelope to the Python Flask server via HTTP POST request.
Parameters
fragments— The list of clipboard fragments to send to the Python core for processing.
Remarks
Fire-and-forget wrapper that serializes fragments and the encounter envelope before posting to the configured endpoint (ClipboardMonitor.ClipboardConfig.EndpointUrl).
The method intentionally uses async void so the STA loop can continue without a blocking wait; errors are captured and logged.
Namespace: ClipboardMonitor.Encounter¶
ClipboardEncounterFactory¶
Builds enriched encounter envelopes for clipboard fragments including fragment digests and Storage Guard provenance.
Methods¶
CreateEnvelope(Collections.Generic.IReadOnlyList param0)¶
Constructs a canonical encounter envelope for the supplied clipboard fragments.
EncounterBuildResult¶
Result container for building clipboard encounters.
Methods¶
EncounterBuildResult(Smrt.Infrastructure.Encounters.ClipboardEncounterEnvelope param0, string param1)¶
Result container for building clipboard encounters.