agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

Extract device management logic into useMediaDevices hook

Open shomix opened this issue 5 months ago • 17 comments

Summary

Extracts device management logic from App.tsx into a dedicated useMediaDevices hook, and moves shared utility functions into standalone library modules for better code organization.

Problem

App.tsx had grown large and difficult to manage, with device enumeration logic, localStorage helpers, and permission-related utilities all co-located inline. This made the component harder to read and maintain.

Solution

Device state and logic were extracted into a useMediaDevices hook. Reusable utility functions were moved into dedicated library files, keeping App.tsx focused on higher-level application concerns.

Key Changes

  • New src/hooks/useMediaDevices.ts: Contains all device state (cameraId, micId, cameraLabel, micLabel, camera/mic device lists), enumeration logic (loadDevices), label-unlocking, and requestDeviceAccess. Exposes a clean interface consumed by App.tsx.
  • New src/lib/storage.ts: Centralizes loadString, loadStringAllowEmpty, loadBool, saveString, and saveBool localStorage helpers, previously defined inline in App.tsx.
  • New src/lib/permissions.ts: Centralizes MACOS_CAPTURE_PERMISSION_MESSAGE, MACOS_SPEECH_PERMISSION_MESSAGE, and isHardCapturePermissionError, previously defined inline in App.tsx.
  • App.tsx cleanup: Removes ~200 lines of device/storage/permission code, replacing them with a single useMediaDevices hook call and imports from the new library modules. No logic changes were made.

Edit in Builder  Preview


To clone this PR locally use the Github CLI with command gh pr checkout 1326

You can tag me at @builderio for anything you want me to fix or change

shomix avatar Jun 19 '26 15:06 shomix

Deploy Preview for agent-native-scheduling ready!

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-scheduling/deploys/6a35656277148b000883b76d
Deploy Preview https://deploy-preview-1326--agent-native-scheduling.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-meeting-notes ready!

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-meeting-notes/deploys/6a3565627cd9f400087c9572
Deploy Preview https://deploy-preview-1326--agent-native-meeting-notes.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for nutritrack-daily-calories canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/nutritrack-daily-calories/deploys/6a356562323f380008f30857

netlify avatar Jun 19 '26 15:06 netlify

Visual recap — generation failed

The visual recap could not be generated for this pull request. This is informational only and does not block the PR.

Diagnostic:

No plan URL: recap-url.txt was not created.

github-actions[bot] avatar Jun 19 '26 15:06 github-actions[bot]

Deploy Preview for agent-native-voice ready!

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-voice/deploys/6a356562e84234000838fa87
Deploy Preview https://deploy-preview-1326--agent-native-voice.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-design ready!

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-design/deploys/6a356562f001a30008b345fb
Deploy Preview https://deploy-preview-1326--agent-native-design.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-images canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-images/deploys/6a356562e84234000838fa8b

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-content canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-content/deploys/6a3565622783900008b5ce84

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-calendar canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-calendar/deploys/6a3565621dd2a90008eedaee

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-brain canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-brain/deploys/6a356562c8b6d20008b472bd

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-macros canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-macros/deploys/6a3565627cd9f400087c9578

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-dispatch canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-dispatch/deploys/6a356562d06aa40008700cf7

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-forms canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-forms/deploys/6a3565621eadf50008edaf69

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-slides canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-slides/deploys/6a3565621eadf50008edaf6e

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-mail canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-mail/deploys/6a356562d06aa40008700cfc

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-videos canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-videos/deploys/6a356562e84234000838fa93

netlify avatar Jun 19 '26 15:06 netlify

Deploy Preview for agent-native-starter canceled.

Name Link
Latest commit 626bef5074b9a51e31bc2b1a32af0f0e2cb5bd4e
Latest deploy log https://app.netlify.com/projects/agent-native-starter/deploys/6a3565621ec3720008eb6bc2

netlify avatar Jun 19 '26 15:06 netlify