Skip to content

fix: make hasPermission synchronous#28

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

fix: make hasPermission synchronous#28
hubo1989 merged 2 commits intomainfrom
feat/v1.3.0

Conversation

@hubo1989
Copy link
Owner

@hubo1989 hubo1989 commented Feb 27, 2026

Summary

  • Change ScreenDetector.hasPermission() from async to sync
  • CGPreflightScreenCaptureAccess() is synchronous, no need for async wrapper
  • Update all call sites to remove await where appropriate
  • Keep CaptureManager.hasPermission with get async for actor isolation

Issue

Permissions showed unauthorized even when granted in System Settings

Root Cause

The async wrapper on hasPermission() was causing timing issues with permission checks

Solution

Make the underlying function synchronous since CGPreflightScreenCaptureAccess() is already synchronous

Summary by CodeRabbit

发布说明

  • Bug Fixes

    • 优化权限检查流程
  • Refactor

    • 简化关于页面的更新检查界面
    • 提升权限检查性能
  • Chores

    • 应用版本号更新至1.3.1

Hubert and others added 2 commits February 27, 2026 20:20
- Update MARKETING_VERSION to 1.3.1 and CURRENT_PROJECT_VERSION to 6
- Remove update status section from AboutView (Sparkle handles its own UI)
- Remove unused state variables (isCheckingUpdates, updateStatus, updateAvailable)

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Change ScreenDetector.hasPermission() from async to sync
- CGPreflightScreenCaptureAccess() is synchronous, no need for async
- Update all call sites to remove await where appropriate
- Keep CaptureManager.hasPermission with get async for actor isolation

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@hubo1989 hubo1989 merged commit 3970088 into main Feb 27, 2026
1 check was pending
@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 6fa79a8 and 892212b.

📒 Files selected for processing (6)
  • ScreenTranslate.xcodeproj/project.pbxproj
  • ScreenTranslate/Features/About/AboutView.swift
  • ScreenTranslate/Features/Capture/CaptureManager.swift
  • ScreenTranslate/Features/Capture/ScreenDetector.swift
  • ScreenTranslate/Features/Onboarding/OnboardingViewModel.swift
  • ScreenTranslate/Features/Settings/SettingsViewModel.swift

📝 Walkthrough

概述

此 PR 将应用版本从 1.3.0 更新至 1.3.1,简化了 About 视图中的更新状态管理 UI,并将 ScreenDetector.hasPermission 方法从异步转换为同步调用,影响权限检查的整个流程。

变更内容

场景 / 文件 摘要
版本更新
ScreenTranslate.xcodeproj/project.pbxproj
CURRENT_PROJECT_VERSION 从 5 升至 6,MARKETING_VERSION 从 1.3.0 升至 1.3.1,在 Debug 和 Release 配置中更新。
About 视图简化
ScreenTranslate/Features/About/AboutView.swift
移除了 updateStatus 和 updateAvailable 状态属性,删除了更新状态 UI 部分及 onChange 处理器,将"检查更新"按钮操作改为直接发送通知而非展示进度状态。
权限检查异步转同步重构
ScreenTranslate/Features/Capture/ScreenDetector.swift, ScreenTranslate/Features/Capture/CaptureManager.swift, ScreenTranslate/Features/Onboarding/OnboardingViewModel.swift, ScreenTranslate/Features/Settings/SettingsViewModel.swift
将 ScreenDetector.hasPermission 从异步方法改为同步方法,并移除所有调用点处的 await 关键字,权限检查现在进行同步读取。

预计代码审查工作量

🎯 3 (中等复杂度) | ⏱️ ~20 分钟

可能相关的 PR

  • PR #20: About 视图的简化与"检查更新"通知集成直接涉及此 PR 中修改的同一 UI 和更新检查机制。
  • PR #26: 主 PR 对权限处理和 About UI 进行的修改涉及与该 PR 相同的函数和视图,存在直接的代码级关联。

庆祝诗

🐰 版本轻轻升至一点三,
异步变同步,权限管理更纯简。
About 视图去繁存简,
代码流畅如兔足跃,
每次提交都是美满! 🎉

✨ 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