Extract device management logic into useMediaDevices hook
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, andrequestDeviceAccess. Exposes a clean interface consumed byApp.tsx. - New
src/lib/storage.ts: CentralizesloadString,loadStringAllowEmpty,loadBool,saveString, andsaveBoollocalStorage helpers, previously defined inline inApp.tsx. - New
src/lib/permissions.ts: CentralizesMACOS_CAPTURE_PERMISSION_MESSAGE,MACOS_SPEECH_PERMISSION_MESSAGE, andisHardCapturePermissionError, previously defined inline inApp.tsx. App.tsxcleanup: Removes ~200 lines of device/storage/permission code, replacing them with a singleuseMediaDeviceshook call and imports from the new library modules. No logic changes were made.
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
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...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.
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...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.
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 |
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.
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...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.
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...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.
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |