A simple cross-platform command-line application that connects to a WebSocket server using configuration from a .env file. The application also includes screen sharing permission management, platform-specific application identification, and high-quality screenshot capabilities.
- Connect to a WebSocket server specified in the
.envfile - Receive and display messages from the WebSocket server
- Send periodic ping messages to keep the connection alive
- Graceful shutdown on interrupt signals (Ctrl+C)
- Verbose mode for additional logging
- Cross-platform screen sharing permission management
- Platform-specific application identification
- Support for connecting to a TypeScript WebSocket server
- High-quality screenshot capture across platforms (Windows, macOS, Linux)
- Screenshot region selection and quality settings
- Image format conversion and compression
The project is organized into the following directories:
app/: Main Go application codeclient/: WebSocket client implementationpkg/: Shared packagesappid/: Application identificationpermissions/: Permission managementscreenshot/: Cross-platform screenshot functionality
ws-server/: TypeScript WebSocket server
- Go 1.21 or higher
- Node.js 14.x or higher (for TypeScript WebSocket server)
- npm 6.x or higher (for TypeScript WebSocket server)
-
Clone the repository:
git clone https://github.com/adamrobbie/go-support.git cd go-support -
Install dependencies:
make deps -
Create a
.envfile in the app directory with your WebSocket URLs and screenshot configuration:cd app cp .env.example .envThen edit the
.envfile to set your WebSocket URLs:WEBSOCKET_URL=wss://your-websocket-server.com/ws TS_WEBSOCKET_URL=ws://localhost:8080
The application includes a cross-platform screenshot module that works on Windows, macOS, and Linux. The module provides the following features:
- Capture full-screen screenshots with different quality settings
- Capture screenshots of specific regions
- Save screenshots to a configurable directory
- Convert between image formats (PNG, JPEG)
- Compress images to reduce file size
- Resize images with high-quality interpolation
- Send screenshots through WebSocket to a server
You can configure the screenshot functionality using the following environment variables or command-line flags:
SCREENSHOT_DIRor--screenshot-dir: Directory to save screenshots (default:~/Screenshots)
The screenshot module supports three quality settings:
Low: Faster capture with smaller file sizeMedium: Balanced quality and performanceHigh: Highest quality with larger file size
The application supports sending screenshots through WebSocket connections. You can use the following commands in the console:
screenshot: Take and send a medium-quality screenshotscreenshot low: Take and send a low-quality screenshotscreenshot high: Take and send a high-quality screenshotregion x y w h: Take and send a screenshot of a specific regionmessage <text>: Send a chat messagehelp: Show available commandsexit: Exit the application
The server can request screenshots by sending a message with the type request_screenshot. The message can include the following fields:
quality: Quality setting (low,medium, orhigh)message: Description of the screenshot requestregion: Region to capture (object withx,y,width, andheightproperties)
Example server request for a full screenshot:
{
"type": "request_screenshot",
"message": "Please send a screenshot of your desktop",
"metadata": {
"quality": "high"
}
}Example server request for a region screenshot:
{
"type": "request_screenshot",
"message": "Please send a screenshot of the specified region",
"metadata": {
"quality": "medium",
"region": {
"x": 100,
"y": 100,
"width": 800,
"height": 600
}
}
}When a screenshot is sent through the WebSocket connection, it uses the following format:
{
"type": "screenshot",
"message": "Screenshot description",
"timestamp": "2023-03-07T12:34:56Z",
"screenshotData": "base64-encoded-image-data",
"imageFormat": "png",
"width": 1920,
"height": 1080,
"metadata": {
"platform": "darwin",
"arch": "amd64"
}
}// Capture a full-screen screenshot with high quality
ss, err := screenshot.Capture(screenshot.High)
if err != nil {
log.Fatalf("Failed to capture screenshot: %v", err)
}
// Save the screenshot to a file
if err := ss.SaveToFile("screenshot.png"); err != nil {
log.Fatalf("Failed to save screenshot: %v", err)
}
// Capture a specific region of the screen
region := screenshot.Region{
X: 100,
Y: 100,
Width: 800,
Height: 600,
}
ss, err = screenshot.CaptureRegion(region, screenshot.High)
if err != nil {
log.Fatalf("Failed to capture region: %v", err)
}
// Resize the screenshot
if err := ss.Resize(400, 300); err != nil {
log.Fatalf("Failed to resize screenshot: %v", err)
}
// Compress the screenshot
if err := ss.Compress(80); err != nil {
log.Fatalf("Failed to compress screenshot: %v", err)
}
// Convert to JPEG format
if err := ss.ConvertToFormat("jpeg"); err != nil {
log.Fatalf("Failed to convert format: %v", err)
}
// Send the screenshot through WebSocket
base64Data := ss.ToBase64()
err = wsClient.SendScreenshot(base64Data, ss.Format, ss.Width, ss.Height, "Screenshot description")
if err != nil {
log.Fatalf("Failed to send screenshot: %v", err)
}The application supports the following command-line flags:
--verbose: Enable verbose logging--skip-permissions: Skip permission checks--use-ts-ws: Use TypeScript WebSocket server--ws: WebSocket server URL (overrides environment variable)--ts-ws: TypeScript WebSocket server URL (overrides environment variable)--screenshot-dir: Directory to save screenshots (overrides environment variable)
The project includes a Makefile with the following commands:
make deps: Install dependenciesmake build: Build the applicationmake clean: Clean build artifactsmake test: Run testsmake test-verbose: Run tests with verbose outputmake test-coverage: Run tests with coverage and open the coverage reportmake run: Build and run the applicationmake run-verbose: Run with verbose loggingmake run-skip-permissions: Run with permissions skippedmake run-ts-ws: Run with TypeScript WebSocket servermake run-ts-ws-verbose: Run with TypeScript WebSocket server and verbose loggingmake ts-install: Install TypeScript WebSocket server dependenciesmake ts-build: Build the TypeScript WebSocket servermake ts-dev: Start the TypeScript WebSocket server in development modemake ts-start: Start the TypeScript WebSocket server in production modemake ts-stop: Stop the TypeScript WebSocket servermake run-all: Run both the Go application and TypeScript server togethermake deps: Update dependencies for both Go and TypeScriptmake release-dry-run: Test the release process with a snapshot buildmake release: Create a release (requires a tag)make tag: Create a new Git tag for release
The application includes a comprehensive test suite:
# Run all tests
make test
# Run tests with verbose output
make test-verbose
# Run tests with coverage and open the coverage report
make test-coverageThe test suite includes:
- Unit tests: Test individual functions and methods
- Integration tests: Test the interaction between components
- Mock implementations: Test components in isolation
The tests are organized by package:
pkg/permissions: Tests for the permission managerpkg/appid: Tests for the application identifierpkg/screenshot: Tests for the screenshot functionalityapp: Tests for the main application logic
This project uses GoReleaser to automate the release process:
-
Create a new tag:
make tag -
Push the tag to GitHub:
git push origin <tag> -
GitHub Actions will automatically build and publish the release
Alternatively, you can manually create a release:
-
Create and push a tag:
git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0 -
Run GoReleaser:
make release