Skip to content

fix: microphone permission for MacOS#3182

Closed
ctrlVnt wants to merge 2 commits into
fossasia:flutterfrom
ctrlVnt:flutter
Closed

fix: microphone permission for MacOS#3182
ctrlVnt wants to merge 2 commits into
fossasia:flutterfrom
ctrlVnt:flutter

Conversation

@ctrlVnt

@ctrlVnt ctrlVnt commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #3181

Changes

I added MacOS exception for microphone. To do that I import a new library : flutter_macos_permissions, under licence GPL-3.0

I also added microphone permission in Configs file in macos -> Runner folder

I didn't find any other permission requests

Screenshots / Recordings

N/A

Checklist:

  • No hard coding: I have used values from constants.dart or localization files instead of hard-coded values.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have formatted the code using dart format or the IDE formatter.
  • Code analysis: My code passes checks run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Add macOS-specific handling for requesting microphone permissions when selecting the in-built microphone and declare the corresponding macOS permission usage metadata.

New Features:

  • Introduce macOS microphone permission request using the flutter_macos_permissions package.

Enhancements:

  • Update the channel parameters widget to conditionally request microphone permissions differently on macOS versus other platforms.

Build:

  • Add flutter_macos_permissions dependency and configure macOS Info.plist with microphone usage description.

@sourcery-ai

sourcery-ai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds macOS-specific microphone permission handling using a new plugin and updates macOS app configuration to declare microphone usage.

Sequence diagram for macOS-specific microphone permission request

sequenceDiagram
  actor User
  participant ChannelParametersWidget
  participant Platform
  participant PermissionHandler
  participant FlutterMacosPermissions
  participant MacOS
  participant OtherOS

  User->>ChannelParametersWidget: toggleInBuiltMIC(value)
  ChannelParametersWidget->>Platform: isMacOS
  alt Platform_is_macOS
    ChannelParametersWidget->>FlutterMacosPermissions: requestMicrophone()
    FlutterMacosPermissions->>MacOS: request_microphone_permission
    MacOS-->>FlutterMacosPermissions: permission_status
    FlutterMacosPermissions-->>ChannelParametersWidget: permission_status
  else Platform_is_not_macOS
    ChannelParametersWidget->>PermissionHandler: Permission.microphone.request()
    PermissionHandler->>OtherOS: request_microphone_permission
    OtherOS-->>PermissionHandler: permission_status
    PermissionHandler-->>ChannelParametersWidget: permission_status
  end
  ChannelParametersWidget->>ChannelParametersWidget: setState(update_inBuiltMIC_selection)
Loading

File-Level Changes

Change Details Files
Add macOS-specific microphone permission request logic around microphone selection.
  • Import dart:io to detect current platform at runtime.
  • Import flutter_macos_permissions for macOS permission handling.
  • Wrap microphone permission request in a Platform.isMacOS check to call FlutterMacosPermissions.requestMicrophone() on macOS and fall back to Permission.microphone.request() on other platforms.
  • Ensure state is still updated after the permission request flow completes.
lib/view/widgets/channel_parameters_widget.dart
Declare microphone usage description for macOS and add the macOS permissions package dependency.
  • Add NSMicrophoneUsageDescription key and explanatory string to macOS Info.plist so macOS shows a rationale when requesting microphone access.
  • Add flutter_macos_permissions: ^2.0.8 to pubspec dependencies so the macOS permission APIs are available.
  • Touch macOS entitlements files (DebugProfile.entitlements and Release.entitlements), likely to ensure correct codesigning/permissions configuration, but with no visible diff content in the snippet.
macos/Runner/Info.plist
pubspec.yaml
macos/Runner/DebugProfile.entitlements
macos/Runner/Release.entitlements

Assessment against linked issues

Issue Objective Addressed Explanation
#3181 Make the In-built Mic option in the oscilloscope work on macOS without throwing a MissingPluginException when requesting microphone permission.
#3181 Configure macOS-specific microphone permission (Info.plist and related setup) so that microphone access can be requested/used properly on macOS.

Possibly linked issues


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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • Introducing flutter_macos_permissions under GPL-3.0 may have licensing implications for the overall project; please confirm this is compatible with the app’s current license and distribution model or consider a more permissively licensed alternative.
  • The platform-specific permission handling is now embedded directly in ChannelParametersWidget; consider extracting this mic permission logic into a dedicated service or helper so that platform differences are centralized and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Introducing `flutter_macos_permissions` under GPL-3.0 may have licensing implications for the overall project; please confirm this is compatible with the app’s current license and distribution model or consider a more permissively licensed alternative.
- The platform-specific permission handling is now embedded directly in `ChannelParametersWidget`; consider extracting this mic permission logic into a dedicated service or helper so that platform differences are centralized and easier to maintain.

## Individual Comments

### Comment 1
<location path="lib/view/widgets/channel_parameters_widget.dart" line_range="255" />
<code_context>
                           oscilloscopeStateProvider.isInBuiltMICSelected,
                       onChanged: (bool? value) async {
-                        await Permission.microphone.request();
+                        if (Platform.isMacOS) {
+                          await FlutterMacosPermissions.requestMicrophone();
+                        }else{
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard `Platform.isMacOS` usage to avoid issues on web/unsupported platforms.

Using `Platform` from `dart:io` inside a widget will cause web builds (and any target without `dart:io`) to fail to compile. If this widget can appear in a web build, use a conditional approach (e.g. `kIsWeb`, conditional imports, or platform‑specific entry points) so `Platform` is never referenced on unsupported targets. Otherwise, ensure this code is isolated to desktop/mobile code paths that are not compiled for web.
</issue_to_address>

### Comment 2
<location path="macos/Runner/Info.plist" line_range="33-34" />
<code_context>
 	<string>NSApplication</string>
 	<key>NSLocationUsageDescription</key>
 	<string>This app needs access to location.</string>
+	<key>NSMicrophoneUsageDescription</key>
+    <string>Some message to describe why you need this permission</string>
 </dict>
 </plist>
</code_context>
<issue_to_address>
**suggestion:** Use a concrete, user-facing microphone usage description string.

The `NSMicrophoneUsageDescription` is still a placeholder. Since this text appears in the macOS permission prompt, please replace it with a specific explanation of how the app uses the microphone (e.g., for oscilloscope or recording features) to make the request clearer to users.

```suggestion
	<key>NSMicrophoneUsageDescription</key>
	<string>This app uses the microphone to capture and analyze audio for oscilloscope and recording features.</string>
```
</issue_to_address>

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.

oscilloscopeStateProvider.isInBuiltMICSelected,
onChanged: (bool? value) async {
await Permission.microphone.request();
if (Platform.isMacOS) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Guard Platform.isMacOS usage to avoid issues on web/unsupported platforms.

Using Platform from dart:io inside a widget will cause web builds (and any target without dart:io) to fail to compile. If this widget can appear in a web build, use a conditional approach (e.g. kIsWeb, conditional imports, or platform‑specific entry points) so Platform is never referenced on unsupported targets. Otherwise, ensure this code is isolated to desktop/mobile code paths that are not compiled for web.

Comment thread macos/Runner/Info.plist Outdated
@ctrlVnt ctrlVnt changed the title Added exception for MacOS fix microphone permission for MacOS Apr 15, 2026
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@ctrlVnt ctrlVnt changed the title fix microphone permission for MacOS fix: microphone permission for MacOS Apr 15, 2026
@ctrlVnt ctrlVnt closed this Apr 15, 2026
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.

In-built Mic on MacOS doesn't work in oscilloscope

1 participant