Desktop Application
Featured
Desktop Application (capture_app.cpp) Complete Guide
Comprehensive documentation for the Qt/C++ desktop capture application including architecture, features, and API integration.
214 views
Updated 2 days ago
# Desktop Application (capture_app.cpp) - Complete Documentation
## Overview
The WorkPulse desktop application is a Qt-based C++ application that monitors user activity and provides seamless integration with the SaaS platform.
## Core Architecture
### MainWindow Class
The central application component managing:
- User interface and interactions
- Time tracking and session management
- Activity monitoring and data collection
- API communication with the SaaS platform
### Key Components
#### Time Tracking System
```cpp
// Time tracking state variables
bool isRunning = false;
bool isOnBreak = false;
QDateTime sessionStartTime;
int workSeconds = 0;
int breakSeconds = 0;
int totalWorkedSeconds = 0;
```
**Features:**
- Work/break time separation
- Visual countdown with progress bar
- Real-time time display updates
- Session persistence across app restarts
#### Activity Monitoring
**Keyboard Monitoring:**
```cpp
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)) {
// Track key presses with timestamps
MainWindow::instance->key_count++;
// Store detailed key events
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
```
**Mouse Monitoring:**
```cpp
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION && (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN)) {
// Track mouse clicks with button type and timestamps
MainWindow::instance->click_count++;
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
```
#### Screenshot Capture
- Automatic screen captures at configurable intervals
- PNG format compression for efficient storage
- Multi-monitor support
- Privacy-aware capture regions
#### Camera Integration
**Modern Qt Multimedia:**
```cpp
void MainWindow::initializeCamera() {
QList cameras = QMediaDevices::videoInputs();
camera = new QCamera(cameraDevice, this);
imageCapture = new QImageCapture(this);
captureSession = new QMediaCaptureSession(this);
}
```
**Smart Resource Management:**
- Camera activated only during captures
- Automatic resource cleanup
- Error handling for missing/busy cameras
- Configurable enable/disable options
## Authentication System
### V3 API Integration
The application uses a sophisticated authentication system:
```cpp
bool MainWindow::performLoginFlow() {
// 1. Collect user credentials
QString email = QInputDialog::getText(this, "Login", "Email:");
QString password = QInputDialog::getText(this, "Login", "Password:");
// 2. Send login request
QNetworkRequest request(QUrl(apiBaseUrl() + "/auth/login"));
// 3. Handle tenant selection if required
// 4. Store authentication token
}
```
### Tenant Management
- Multi-tenant support with tenant switching
- Persistent tenant selection
- Tenant-specific project and data isolation
## API Communication
### Endpoint Integration
The desktop app communicates with these API endpoints:
**Session Management:**
- `POST /api/desktop/v3/sessions/start`
- `POST /api/desktop/v3/sessions/stop`
- `POST /api/desktop/v3/break/start`
- `POST /api/desktop/v3/break/stop`
**Data Upload:**
- `POST /api/desktop/v3/captures/log`
- Screenshots (PNG format)
- Activity data (JSON)
- Camera images (JPEG, optional)
**Real-time Communication:**
- `GET /api/desktop/v3/events` (Server-sent events)
- Push notifications for messages
- Live project updates
### Data Format
Activity data is sent in structured JSON:
```json
{
"start_time": "2025-10-03T10:00:00Z",
"end_time": "2025-10-03T10:05:00Z",
"key_count": 142,
"click_count": 23,
"key_events": [
{"key": "a", "timestamp": "2025-10-03T10:00:15Z"}
],
"click_events": [
{"button": "Left", "timestamp": "2025-10-03T10:00:20Z"}
],
"program_usage": {
"VS Code": {"duration": 180}
}
}
```
## User Interface
### Modern Qt Design
- Custom styling with gradients and modern colors
- Responsive layout for different screen sizes
- System tray integration for background operation
- Toast notifications for user feedback
### Key UI Components
**Time Display:**
```cpp
timeWorkedLabel->setText(QString("Work: %1 | Break: %2 | Total: %3")
.arg(workTime, breakTime, totalTime));
```
**Project Selector:**
- Dropdown with current projects
- Real-time project switching
- System tray project menu
**Message System:**
- Rich text message display
- File attachment support
- Two-way communication with server
## Configuration Options
### Environment Variables
- `CAPTURE_SHOW_LOG`: Enable debug logging UI
- `CAPTURE_ENABLE_CAMERA`: Enable camera capture
### Command Line Options
- `--show-log`: Force enable logging interface
- `--enable-camera`: Force enable camera
- `--disable-camera`: Force disable camera
### Persistent Settings
Using QSettings for:
- Authentication tokens
- User preferences
- Window geometry
- Last selected project
## Build and Deployment
### Development Setup
1. Install Qt 6.x development environment
2. Install MinGW compiler toolchain
3. Configure Qt Creator project
4. Build and test locally
### Distribution
1. Compile release build with optimizations
2. Create installer using Inno Setup script
3. Code sign executable for Windows SmartScreen
4. Distribute via secure download links
### Future Enhancements
- Auto-updater integration
- Cross-platform support (macOS, Linux)
- Enhanced privacy controls
- Offline mode with sync
This desktop application provides a robust, secure, and user-friendly way to track work activity while maintaining seamless integration with the web platform.
Was this article helpful?