-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(recording): replace blocking dialog with toast for mic not available errors #1974
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2370,18 +2370,25 @@ async fn handle_spawn_failure( | |
| } | ||
| .emit(app); | ||
|
|
||
| let mut dialog = MessageDialogBuilder::new( | ||
| app.dialog().clone(), | ||
| "An error occurred".to_string(), | ||
| message.clone(), | ||
| ) | ||
| .kind(tauri_plugin_dialog::MessageDialogKind::Error); | ||
| // DeviceNotFound errors are surfaced to the user via the frontend toast; skip the | ||
| // blocking native dialog so the overlay stays responsive and the error isn't repeated. | ||
| let is_device_not_found = message.contains("no longer available") | ||
| || message.contains("DeviceNotFound"); | ||
|
Comment on lines
+2373
to
+2376
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The same two substrings ( Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/desktop/src-tauri/src/recording.rs
Line: 2373-2376
Comment:
**Duplicate string-matching across Rust and TypeScript**
The same two substrings (`"no longer available"` and `"DeviceNotFound"`) are now hard-coded in both `recording.rs` (to suppress the native dialog) and `target-select-overlay.tsx` (to show the friendly toast). If the underlying audio library changes either error message, the two guards will diverge: the Rust side might still suppress the dialog while the TypeScript side falls through to the generic "Failed to start recording: …" message, or vice-versa. Centralising the classification — e.g., via a dedicated Tauri error variant instead of string matching — would make both sites resilient to message changes.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| if !is_device_not_found { | ||
| let mut dialog = MessageDialogBuilder::new( | ||
| app.dialog().clone(), | ||
| "An error occurred".to_string(), | ||
| message.clone(), | ||
| ) | ||
| .kind(tauri_plugin_dialog::MessageDialogKind::Error); | ||
|
|
||
| if let Some(window) = CapWindowId::RecordingControls.get(app) { | ||
| dialog = dialog.parent(&window); | ||
| } | ||
| if let Some(window) = CapWindowId::RecordingControls.get(app) { | ||
| dialog = dialog.parent(&window); | ||
| } | ||
|
|
||
| dialog.blocking_show(); | ||
| dialog.blocking_show(); | ||
| } | ||
|
|
||
| let mut state = state_mtx.write().await; | ||
| let _ = handle_recording_end( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1742,11 +1742,28 @@ function RecordingControls(props: { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| commands.startRecording({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capture_target: props.target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: rawOptions.mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capture_system_audio: rawOptions.captureSystemAudio, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .startRecording({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capture_target: props.target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: rawOptions.mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capture_system_audio: rawOptions.captureSystemAudio, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch((e: unknown) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const msg = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| e instanceof Error ? e.message : String(e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1752
to
+1753
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth logging the underlying error here too (like the screenshot path does) so we don’t lose stack/context when users report this.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| msg.includes("no longer available") || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| msg.includes("DeviceNotFound") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Selected microphone is not available. Please select a different microphone in settings.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1758
to
+1760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the original report mentions repeated clicks/loops, adding a stable
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `Failed to start recording: ${msg}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1762
to
+1764
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same idea for the generic failure path — stable
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1745
to
+1766
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/desktop/src/routes/target-select-overlay.tsx
Line: 1745-1766
Comment:
Add `console.error` to match the pattern used by the screenshot error handler and other catch blocks in this file, so there is always a log trail even when the toast copy differs from the raw error.
```suggestion
commands
.startRecording({
capture_target: props.target,
mode: rawOptions.mode,
capture_system_audio: rawOptions.captureSystemAudio,
})
.catch((e: unknown) => {
console.error("Failed to start recording", e);
const msg =
e instanceof Error ? e.message : String(e);
if (
msg.includes("no longer available") ||
msg.includes("DeviceNotFound")
) {
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);
} else {
toast.error(
`Failed to start recording: ${msg}`,
);
}
});
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The substring match here feels a bit brittle (casing/format can vary). Normalizing once keeps it from missing variants.