How quackduck/uniclip works
Main Components
• CLI/Entry Point: The main function in uniclip.go parses command-line arguments (like --secure, --debug, the address, or port) and directs execution either to start a new clipboard (i.e. acting as a server) or to join an existing one (i.e. as a client).
• Network Module: Whether running in server or client mode, the tool establishes a TCP connection (or similar socket communication) to either listen for incoming connections or connect to a host.
• Clipboard Manager: This component interacts with the system’s clipboard (using libraries or commands like xsel, xclip, or platform-specific APIs) to copy or paste data across devices.
• Optional Features:
• Security Layer: When the --secure flag is active, an encryption module or logic might be invoked to secure clipboard data.
• Debugging/Logging: Integrated through the command-line flag to print more verbose output.
Understand the Interactions
• In server (host) mode: The CLI sets up a listener on a specific port and prints out the connection info. It then waits for incoming connection requests from client devices.
• In client (joining) mode: The CLI connects to the provided host address and port, establishing a communication channel with the server.
• Once connected, both modules interact by sending clipboard updates between the host and its connected peers.
• That since multiple devices can join the same clipboard session, the server component needs to handle multiple peer connections concurrently.
Architectural Patterns and Design Principles
• Separation of Concerns: Even within a single file, think of logical separation between CLI processing, network communication, and clipboard management.
• A “Security Module” connected between the network transmission lines and the Clipboard Manager if the secure flag is enabled.