Skip to content

fix(windows): 校准麦克风权限探测#53

Merged
appergb merged 1 commit into
Open-Less:mainfrom
Cooper-X-Oak:codex/windows-permission-probe-pr
Apr 30, 2026
Merged

fix(windows): 校准麦克风权限探测#53
appergb merged 1 commit into
Open-Less:mainfrom
Cooper-X-Oak:codex/windows-permission-probe-pr

Conversation

@Cooper-X-Oak
Copy link
Copy Markdown
Contributor

@Cooper-X-Oak Cooper-X-Oak commented Apr 30, 2026

摘要

关联 fork 验证:Cooper-X-Oak#12

本 PR 是从 fork/dev 已验证批次拆出的第四个最小 upstream 维护项:校准 Windows 麦克风隐私权限探测,并避免设置页每秒打开输入流导致隐私指示器频繁闪烁。

fork/dev 先行验证

修复 / 新增 / 改进

  • Windows check_microphone() 先读取 CapabilityAccessManager 麦克风隐私注册表 Deny 状态。
  • 覆盖全局 microphone、NonPackaged、当前 exe 对应 NonPackaged 路径。
  • 保留现有短生命周期 input stream probe,用于设备/权限真实可用性探测。
  • 设置页权限刷新拆成两路:hotkey 每 1 秒刷新,麦克风/辅助功能每 10 秒刷新。
  • 用户从系统设置切回窗口时仍立即刷新权限和 hotkey 状态。

兼容

  • 不包含:启动路径、热键 core、ASR、插入 fallback、凭据字段保存。
  • 对现有用户 / 本地环境 / 构建流程的影响:Windows 设置页不再每秒触发麦克风输入流探测;麦克风隐私被关闭时更早返回 Denied。

测试计划

  • 命令:npm run build
  • 结果:TypeScript + Vite build 通过。
  • 命令:openless-all/app/scripts/windows-build-gnu.ps1
  • 结果:Windows GNU build/msi/nsis 通过,仅既有 warning。
  • 命令:git diff --check
  • 结果:通过。
  • fork PR CI:test(windows): 收敛 fork dev 真机回归批次 Cooper-X-Oak/openless#12 Windows Tauri checks / Sourcery review 均通过。

Summary by Sourcery

Calibrate Windows microphone permission detection and reduce intrusive probing in the settings page.

Bug Fixes:

  • Return microphone permission as denied when Windows CapabilityAccessManager registry indicates microphone access is blocked, covering global, NonPackaged, and current executable-specific keys.

Enhancements:

  • Add registry-based precheck for Windows microphone privacy status before opening an input stream to avoid unnecessary device probing.
  • Adjust settings page refresh behavior to poll hotkey status every second while checking microphone and accessibility permissions less frequently and on window focus to reduce privacy indicator flicker.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 30, 2026

Reviewer's Guide

Adjusts Windows microphone permission detection to first consult privacy registry settings and reduces the frequency of microphone permission probing in the settings page to avoid constant input stream activation, while separating hotkey and permission refresh intervals.

Sequence diagram for split hotkey and permission refresh in settings page

sequenceDiagram
    actor User
    participant Window
    participant PermissionsSection
    participant TauriBackend

    User->>Window: open Settings page
    Window->>PermissionsSection: mount

    Note over PermissionsSection: Initial refresh
    PermissionsSection->>TauriBackend: checkAccessibilityPermission()
    PermissionsSection->>TauriBackend: checkMicrophonePermission()
    PermissionsSection->>TauriBackend: getHotkeyStatus()

    TauriBackend-->>PermissionsSection: accessibility status
    TauriBackend-->>PermissionsSection: microphone status
    TauriBackend-->>PermissionsSection: hotkey status

    Note over PermissionsSection: Start intervals
    PermissionsSection->>Window: setInterval(refreshHotkey, 1000ms)
    PermissionsSection->>Window: setInterval(refreshPermissions, 10000ms)

    loop every 1000ms
        Window->>PermissionsSection: refreshHotkey()
        PermissionsSection->>TauriBackend: getHotkeyStatus()
        TauriBackend-->>PermissionsSection: hotkey status
    end

    loop every 10000ms
        Window->>PermissionsSection: refreshPermissions()
        PermissionsSection->>TauriBackend: checkAccessibilityPermission()
        PermissionsSection->>TauriBackend: checkMicrophonePermission()
        TauriBackend-->>PermissionsSection: accessibility status
        TauriBackend-->>PermissionsSection: microphone status
    end

    Note over Window,PermissionsSection: User switches to system settings
    User-->>Window: blur (leave app)

    Note over Window,PermissionsSection: User returns from system settings
    User->>Window: focus
    Window->>PermissionsSection: onFocus handler
    PermissionsSection->>TauriBackend: checkAccessibilityPermission()
    PermissionsSection->>TauriBackend: checkMicrophonePermission()
    PermissionsSection->>TauriBackend: getHotkeyStatus()
    TauriBackend-->>PermissionsSection: updated accessibility
    TauriBackend-->>PermissionsSection: updated microphone
    TauriBackend-->>PermissionsSection: updated hotkey

    Note over PermissionsSection: On unmount, clear intervals
    PermissionsSection->>Window: clearInterval(hotkeyId)
    PermissionsSection->>Window: clearInterval(permissionId)
Loading

File-Level Changes

Change Details Files
Short-circuit Windows microphone permission checks based on CapabilityAccessManager registry deny state before opening an input stream.
  • Add helper that aggregates relevant CapabilityAccessManager microphone registry paths including global, NonPackaged, HKLM, and current exe-specific NonPackaged entries.
  • Introduce a function that uses the Windows reg command to query the Value entry and detect a Deny setting from REG_SZ data, with warning logs on failures.
  • Update the microphone permission check to return Denied immediately when any candidate registry path reports a Deny value, falling back to the existing cpal-based input stream probe otherwise.
openless-all/app/src-tauri/src/permissions.rs
Decouple and reschedule settings page refresh logic to probe microphone/accessibility permissions less frequently while keeping hotkey status responsive.
  • Split the combined permissions and hotkey refresh function into separate async functions, one for permissions and one for hotkey state.
  • Initialize both permissions and hotkey state on mount, then poll hotkey status every second and permissions (microphone/accessibility) every 10 seconds.
  • Ensure both permissions and hotkey status are refreshed immediately on window focus and update all call sites to invoke the new permission-only refresh helper after permission requests and system settings navigation.
openless-all/app/src/pages/Settings.tsx

Possibly linked issues

  • #: PR replaces unconditional Granted on Windows with registry+stream checks and updates settings to show real mic status.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The windows_microphone_registry_denied implementation shells out to reg and parses localized text output on every check; consider switching to a Win32 registry API (e.g., via winreg/windows crate) both for performance and to avoid locale/formatting fragility in registry_value_is_deny.
  • In registry_value_is_deny, a non-success reg exit status is treated as "not denied" without any logging, which could mask misconfigurations or missing keys; it may be safer to log at least a debug message or distinguish between "no key" and actual errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `windows_microphone_registry_denied` implementation shells out to `reg` and parses localized text output on every check; consider switching to a Win32 registry API (e.g., via `winreg`/`windows` crate) both for performance and to avoid locale/formatting fragility in `registry_value_is_deny`.
- In `registry_value_is_deny`, a non-success `reg` exit status is treated as "not denied" without any logging, which could mask misconfigurations or missing keys; it may be safer to log at least a debug message or distinguish between "no key" and actual errors.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@appergb appergb merged commit ce0f00f into Open-Less:main Apr 30, 2026
2 checks passed
appergb pushed a commit that referenced this pull request Apr 30, 2026
包含本轮所有合并:
- Codex 终审两条 HIGH (cancel race) 修复 (PR #79)
- 6 个 Cooper-X-Oak/Codex bot PRs 自动合并 (#44 #49 #53 #68 #72 #73)
- 2 个有冲突 PR 本地 rebase 后合并 (#66 cancel + 空转写并存 / #67 Windows docs)
- README 破图修复 (PR #80)
- workflow-scope 受限的 #48 + #75 由用户在 GitHub UI 直接合并

3 处版本字段同步:package.json + tauri.conf.json + Cargo.toml
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.

2 participants