Skip to content

Add mic-detection #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2025
Merged

Add mic-detection #751

merged 3 commits into from
May 29, 2025

Conversation

yujonglee
Copy link
Contributor

@yujonglee yujonglee commented May 8, 2025

Resolves #675

Summary by CodeRabbit

  • New Features
    • Introduced microphone usage detection with platform-specific implementations for macOS and Windows.
    • Enhanced detection to monitor microphone activity and default audio input device changes on macOS.
  • Bug Fixes
    • None.
  • Documentation
    • None.
  • Refactor
    • None.
  • Style
    • None.
  • Tests
    • None.
  • Chores
    • None.
  • Revert
    • None.

Copy link

coderabbitai bot commented May 29, 2025

"""

Walkthrough

A new microphone detection subsystem is introduced with platform-specific implementations for macOS and Windows. The Detector struct is extended to include a mic_detector field, replacing previous app and browser detectors. The mic module is added and publicly re-exported. The macOS implementation actively listens for audio input device changes and usage, while the Windows implementation currently provides empty stub methods.

Changes

Files / Modules Change Summary
crates/detect/src/lib.rs Added mic module, re-exported it, replaced app_detector and browser_detector with mic_detector in Detector.
crates/detect/src/mic/mod.rs Added MicDetector struct with platform-specific submodules; delegated Observer trait implementation.
crates/detect/src/mic/macos.rs Added macOS-specific Detector using Core Audio property listeners to monitor default input device and usage.
crates/detect/src/mic/windows.rs Added Windows-specific Detector stub with empty start and stop methods implementing Observer trait.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Detector
    participant MicDetector
    participant PlatformDetector (macOS/Windows)

    App->>Detector: start()
    Detector->>MicDetector: start(callback)
    MicDetector->>PlatformDetector: start(callback)
    alt macOS
        PlatformDetector-->>PlatformDetector: Listen for audio device changes
        PlatformDetector->>callback: Notify on mic usage or device change
    else Windows
        PlatformDetector-->>PlatformDetector: (No-op)
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Detect microphone usage and send notifications (#675) Microphone usage detection implemented, but notification sending and integration with app logic are not present.

Poem

A twitch of the whiskers, a hop in the code,
Microphone magic, new pathways bestowed.
On Mac it now listens, on Windows it waits,
Awaiting the chatter that meeting creates.
With ears ever open, this rabbit’s delight—
Detecting your voice in the digital night!
🐰🎤
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
crates/detect/src/mic/windows.rs (1)

1-7: Document the stub implementation.

The Windows implementation provides stub methods which is acceptable for initial development. However, consider adding documentation to clarify this is a placeholder.

Apply this diff to improve documentation:

+/// Windows stub implementation for microphone detection.
+/// TODO: Implement actual microphone detection for Windows platform.
#[derive(Default)]
pub struct Detector {}

impl crate::Observer for Detector {
+   /// Stub implementation - no microphone detection on Windows yet.
    fn start(&mut self, f: crate::DetectCallback) {}
+   /// Stub implementation - no cleanup needed.
    fn stop(&mut self) {}
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a48c6b1 and db89c17.

📒 Files selected for processing (4)
  • crates/detect/src/lib.rs (2 hunks)
  • crates/detect/src/mic/macos.rs (1 hunks)
  • crates/detect/src/mic/mod.rs (1 hunks)
  • crates/detect/src/mic/windows.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/detect/src/mic/windows.rs (3)
crates/detect/src/mic/mod.rs (2)
  • start (17-19)
  • stop (20-22)
crates/detect/src/lib.rs (4)
  • start (22-22)
  • start (65-68)
  • stop (23-23)
  • stop (70-73)
crates/detect/src/mic/macos.rs (2)
  • start (13-52)
  • stop (53-53)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (2)
crates/detect/src/lib.rs (1)

3-3: LGTM! Module addition is correctly structured.

The mic module is properly added and re-exported following the same pattern as existing modules.

Also applies to: 8-8

crates/detect/src/mic/mod.rs (1)

1-23: Excellent platform abstraction design!

The conditional compilation approach cleanly separates platform-specific implementations while providing a unified interface through MicDetector. The delegation pattern is well-implemented.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
crates/detect/src/mic/macos.rs (1)

55-63: Only “start-using” events are emitted – no symmetrical “stop-using” notification

device_listener calls the callback only when is_running != 0, i.e. when the mic starts being used.
When the value toggles back to 0 nothing is sent, so consumers cannot know that microphone usage ended.

Consider emitting a second event (or passing a boolean) so downstream logic can react symmetrically:

let state = is_running != 0;
if let Ok(guard) = callback.lock() {
    (*guard)(format!("microphone_in_use:{state}"));
}

This will make the API far more useful.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db89c17 and 82539f5.

📒 Files selected for processing (2)
  • crates/detect/src/lib.rs (3 hunks)
  • crates/detect/src/mic/macos.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/detect/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (1)
crates/detect/src/mic/macos.rs (1)

214-216: Verify that BackgroundTask::stop() actually terminates the spawned thread

stop() merely delegates to background.stop(), but the thread created in start() is detached (std::thread::spawn) and holds native Core Audio resources.
Please ensure BackgroundTask:

  • signals the thread to exit,
  • joins it, and
  • guarantees listeners are removed exactly once.

If that is not the case, we risk leaking a thread or removing listeners twice (use-after-free).

@yujonglee yujonglee merged commit f9b939e into main May 29, 2025
4 checks passed
@yujonglee yujonglee deleted the mic-detection branch May 29, 2025 19:18
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.

Detect microphone usage and send notifications
1 participant