Skip to content

Commit 678a0b4

Browse files
Harden macOS capture setup and cursor moves
Updates CI on macOS to fully configure screen recording by writing replayd approval data, restarting replayd, and clarifying step messaging. In QtTrayMenu, adds a bounded cursor-position wait loop with polling and timeout so mouse move/restore checks are more reliable instead of relying on a single immediate position read.
1 parent 23c129f commit 678a0b4

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
)
124124
brew install "${dependencies[@]}"
125125
126-
- name: Fix macOS screen recording permissions
126+
- name: Configure macOS screen recording
127127
if: runner.os == 'macOS'
128128
run: |
129129
set -euo pipefail
@@ -156,7 +156,14 @@ jobs:
156156
configure_user_tccdb "$values,NULL,NULL,'UNUSED',${values##*,}"
157157
done
158158
159-
echo "macOS TCC permissions configured."
159+
approvalDirectory="$HOME/Library/Group Containers/group.com.apple.replayd"
160+
approvalPlist="$approvalDirectory/ScreenCaptureApprovals.plist"
161+
mkdir -p "$approvalDirectory"
162+
defaults write "$approvalPlist" "/bin/bash" -date "$(date -u '+%Y-%m-%d %H:%M:%S +0000')"
163+
defaults read "$approvalPlist" "/bin/bash"
164+
killall replayd 2>/dev/null || true
165+
166+
echo "macOS screen recording configured."
160167
161168
- name: Setup Dependencies Windows
162169
if: runner.os == 'Windows'

src/QtTrayMenu.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* @brief Definitions for Qt tray menu implemenation
44
*/
55
// standard includes
6+
#include <chrono>
67
#include <filesystem>
8+
#include <thread>
79

810
// qt includes
911
#include <QApplication>
@@ -22,12 +24,28 @@
2224

2325
namespace {
2426
constexpr int DEFAULT_PANEL_THICKNESS = 24;
27+
constexpr int CURSOR_POSITION_POLL_INTERVAL_MS = 10;
28+
constexpr int CURSOR_POSITION_TIMEOUT_MS = 500;
2529
constexpr int CURSOR_POSITION_TOLERANCE = 2;
2630

2731
bool positionsAreClose(const QPoint &first, const QPoint &second) {
2832
return (first - second).manhattanLength() <= CURSOR_POSITION_TOLERANCE;
2933
}
3034

35+
bool waitForCursorPosition(const QPoint &targetPosition, const QRect &targetGeometry = {}) {
36+
const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(CURSOR_POSITION_TIMEOUT_MS);
37+
do {
38+
const QPoint currentPosition = QCursor::pos();
39+
if (targetGeometry.isValid() ? targetGeometry.contains(currentPosition) : positionsAreClose(currentPosition, targetPosition)) {
40+
return true;
41+
}
42+
std::this_thread::sleep_for(std::chrono::milliseconds(CURSOR_POSITION_POLL_INTERVAL_MS));
43+
} while (std::chrono::steady_clock::now() < deadline);
44+
45+
const QPoint currentPosition = QCursor::pos();
46+
return targetGeometry.isValid() ? targetGeometry.contains(currentPosition) : positionsAreClose(currentPosition, targetPosition);
47+
}
48+
3149
bool fallbackTrayIconPosition(QPoint *position) {
3250
const QScreen *screen = QGuiApplication::primaryScreen();
3351
if (screen == nullptr) {
@@ -405,8 +423,7 @@ bool QtTrayMenu::positionMouseOverIcon() {
405423
mousePositionSaved = true;
406424
}
407425
QCursor::setPos(targetPosition);
408-
const QPoint currentPosition = QCursor::pos();
409-
const bool positioned = iconGeometry.isValid() ? iconGeometry.contains(currentPosition) : positionsAreClose(currentPosition, targetPosition);
426+
const bool positioned = waitForCursorPosition(targetPosition, iconGeometry);
410427
if (!positioned) {
411428
qWarning("QtTrayMenu: could not position the mouse over the tray icon");
412429
}
@@ -419,8 +436,8 @@ bool QtTrayMenu::restoreMousePosition() {
419436
}
420437

421438
QCursor::setPos(savedMousePosition);
439+
const bool restored = waitForCursorPosition(savedMousePosition);
422440
mousePositionSaved = false;
423-
const bool restored = positionsAreClose(QCursor::pos(), savedMousePosition);
424441
if (!restored) {
425442
qWarning("QtTrayMenu: could not restore the saved mouse position");
426443
}

0 commit comments

Comments
 (0)