Skip to content

fix: use CGRequestScreenCaptureAccess to request permission#34

Merged
hubo1989 merged 2 commits intomainfrom
feat/v1.3.0
Feb 27, 2026
Merged

fix: use CGRequestScreenCaptureAccess to request permission#34
hubo1989 merged 2 commits intomainfrom
feat/v1.3.0

Conversation

@hubo1989
Copy link
Owner

@hubo1989 hubo1989 commented Feb 27, 2026

Summary

  • Call CGRequestScreenCaptureAccess() when requesting permission (not just open System Settings)
  • Use CGPreflightScreenCaptureAccess() directly for checking (synchronous, no async)
  • Start polling for permission status after opening System Settings

Issue

Permission status still showed unauthorized after granting in System Settings

Solution

  • CGRequestScreenCaptureAccess() properly requests permission
  • Direct synchronous checks instead of going through ScreenDetector actor

Summary by CodeRabbit

发布说明

  • 优化改进
    • 优化屏幕录制权限检查流程,提升权限验证响应速度和效率
    • 改进系统权限请求对话框处理机制,提供更流畅的用户体验
    • 增强权限状态轮询机制,确保实时准确反映权限状态
    • 简化权限验证逻辑,整体提升应用性能

Hubert and others added 2 commits February 27, 2026 21:49
- Replace SCShareableContent.current with CGPreflightScreenCaptureAccess()
- This API is deprecated in macOS 15 but still works and does NOT trigger dialog
- SCShareableContent.current triggers system permission dialog on every call

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Call CGRequestScreenCaptureAccess() when requesting permission
- Use CGPreflightScreenCaptureAccess() directly for checking (sync, no async)
- Start polling for permission status after opening System Settings

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84eb78c and d087183.

📒 Files selected for processing (4)
  • ScreenTranslate/Features/Capture/CaptureManager.swift
  • ScreenTranslate/Features/Capture/ScreenDetector.swift
  • ScreenTranslate/Features/Onboarding/OnboardingViewModel.swift
  • ScreenTranslate/Features/Settings/SettingsViewModel.swift

📝 Walkthrough

Walkthrough

本PR重构屏幕录制权限检查机制,将多个组件的异步权限验证改为同步检查,使用系统API CGPreflightScreenCaptureAccess()和CGRequestScreenCaptureAccess()替代ScreenDetector的异步流程。

Changes

Cohort / File(s) Summary
权限管理核心
ScreenTranslate/Features/Capture/CaptureManager.swift, ScreenTranslate/Features/Capture/ScreenDetector.swift
将权限检查从异步改为同步实现。CaptureManager的hasPermission和requestPermission改为同步方法,直接使用CGPreflightScreenCaptureAccess()和CGRequestScreenCaptureAccess()。ScreenDetector添加SCShareableContent异步包装以支持现有代码。
ViewModel权限流程
ScreenTranslate/Features/Onboarding/OnboardingViewModel.swift, ScreenTranslate/Features/Settings/SettingsViewModel.swift
更新权限检查和请求流程,使用同步的CGPreflightScreenCaptureAccess()替代ScreenDetector异步检查。在权限未授予时,触发系统设置打开和轮询机制来跟踪权限状态变化。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 权限检查已同步,
异步流程化为简,
系统API轻盈舞,
屏幕录制更顺畅,
兔儿欢呼又跳跃!✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/v1.3.0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant