Skip to content

Commit ff490a9

Browse files
committed
fix: support CGO_ENABLED=0 cross-compilation for permissions module
Split CGo-dependent screen recording detection into build-tagged files: screen_recording_cgo.go (darwin+cgo) provides the real macOS API call, screen_recording_other.go provides a no-op fallback for cross-compilation in CI (CGO_ENABLED=0).
1 parent cffa247 commit ff490a9

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

internal/permissions/screen_recording.go renamed to internal/permissions/screen_recording_cgo.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin && cgo
2+
13
package permissions
24

35
import (
@@ -11,15 +13,10 @@ import (
1113
*/
1214
import "C"
1315

14-
// HasScreenRecordingPermission checks if the application has screen recording permission.
15-
// It uses CGPreflightScreenCaptureAccess() from the macOS CoreGraphics framework.
16-
// This function works on macOS 10.15+ (all supported macOS versions for this project).
1716
func HasScreenRecordingPermission() bool {
1817
return bool(C.CGPreflightScreenCaptureAccess())
1918
}
2019

21-
// OpenScreenRecordingSettings opens the macOS System Preferences screen recording settings.
22-
// It uses the x-apple.systempreferences URL scheme to navigate to the Privacy > Screen Recording settings.
2320
func OpenScreenRecordingSettings() error {
2421
cmd := exec.Command("open", "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")
2522
if err := cmd.Run(); err != nil {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !darwin || !cgo
2+
3+
package permissions
4+
5+
func HasScreenRecordingPermission() bool {
6+
return false
7+
}
8+
9+
func OpenScreenRecordingSettings() error {
10+
return nil
11+
}

internal/permissions/screen_recording_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ import (
66
"github.com/stretchr/testify/assert"
77
)
88

9-
// TestHasScreenRecordingPermission_Returns verifies that HasScreenRecordingPermission
10-
// returns a boolean value without panicking. This is an actual system call to the
11-
// macOS CoreGraphics framework, so the result depends on the system state.
129
func TestHasScreenRecordingPermission_Returns(t *testing.T) {
1310
result := HasScreenRecordingPermission()
1411
assert.IsType(t, true, result)
1512
}
1613

17-
// TestOpenScreenRecordingSettings_NoError verifies that OpenScreenRecordingSettings
18-
// executes without panicking and returns an error type (even if nil).
1914
func TestOpenScreenRecordingSettings_NoError(t *testing.T) {
2015
err := OpenScreenRecordingSettings()
21-
// The function should return an error type (may be nil or non-nil depending on system state)
2216
assert.IsType(t, (*error)(nil), &err)
2317
}

0 commit comments

Comments
 (0)