-
Notifications
You must be signed in to change notification settings - Fork 755
Native camera preview fixes #895
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
Conversation
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
apps/desktop/src-tauri/src/lib.rs (1)
266-279
: New init attempts aren’t cancelable externally due to not updating the shutdown handleIf a previous initialization was in progress, you send a cancel to the old handle but don’t store the new shutdown_tx. That leaves the new init attempt without an externally reachable cancel handle (app.camera_feed_initialization still points at the old sender).
Make sure to replace the stored sender unconditionally when starting a new init:
// Always replace the previous handle with the new one so external code can cancel this attempt. if let Some(prev) = app.camera_feed_initialization.replace(shutdown_tx.clone()) { // Ask currently running setup to abort prev.send(()).await.ok(); // We can assume a window was already initialized. if let Some(win) = CapWindowId::Camera.get(&app_handle) { let _ = win.close(); } }This preserves the ability to cancel the most recent initialization attempt at any time.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/desktop/src-tauri/src/general_settings.rs
(1 hunks)apps/desktop/src-tauri/src/lib.rs
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
- GitHub Check: Analyze (rust)
🔇 Additional comments (3)
apps/desktop/src-tauri/src/general_settings.rs (1)
102-104
: Enable-by-default on macOS debug builds looks goodThe gated default via cfg!(all(debug_assertions, target_os = "macos")) aligns with the PR goal to exercise the feature in dev on macOS.
apps/desktop/src-tauri/src/lib.rs (2)
59-59
: Necessary import addedImporting Duration is required for the timeout/sleep logic.
81-81
: Timeout import added appropriatelytokio::time::timeout is correctly brought into scope.
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.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
apps/desktop/src-tauri/src/lib.rs (1)
266-279
: Cancellation handle is not updated; new attempts can’t be cancelledWhen a previous initialization is in-flight, you send a cancel signal but don’t replace
app.camera_feed_initialization
with the newshutdown_tx
. Subsequent cancellations target the stale sender and won’t abort the current attempt. Also, avoidunwrap()
onclose()
.Apply:
- let (shutdown_tx, mut shutdown_rx) = mpsc::channel(1); - if let Some(cancel) = app.camera_feed_initialization.as_ref() { + let (shutdown_tx, mut shutdown_rx) = mpsc::channel(1); + if let Some(cancel) = app.camera_feed_initialization.replace(shutdown_tx) { // Ask currently running setup to abort cancel.send(()).await.ok(); // We can assume a window was already initialized. // Stop it so we can recreate it with the correct `camera_tx` if let Some(win) = CapWindowId::Camera.get(&app_handle) { - win.close().unwrap(); // TODO: Error handling + let _ = win.close(); }; - } else { - app.camera_feed_initialization = Some(shutdown_tx); - } + }
♻️ Duplicate comments (1)
apps/desktop/src-tauri/src/lib.rs (1)
292-309
: Make retry loop cancellable and report last error as a stringTwo issues:
- Not cancellable: The retry loop ignores
shutdown_rx
, so a new call cannot abort preview init immediately.- Error accumulation:
&mut None
+ storing raw error is awkward and may capture a non-Send error type; preferOption<String>
.You already fixed the orphan-window by closing on timeout—nice.
Proposed refactor (cancellable, cleaner error message):
- let prev_err = &mut None; - if timeout(Duration::from_secs(3), async { - while let Err(err) = camera_preview - .init_preview_window(window.clone(), camera_rx.clone()) - .await - { - error!("Error initializing camera feed: {err}"); - *prev_err = Some(err); - tokio::time::sleep(Duration::from_millis(200)).await; - } - }) - .await - .is_err() - { - let _ = window.close(); - return Err(format!("Timeout initializing camera preview: {prev_err:?}")); - }; + let mut last_err: Option<String> = None; + let last_err_ref = &mut last_err; + let init_result = timeout(Duration::from_secs(3), async { + loop { + tokio::select! { + // Abort immediately if a new init request cancels this attempt + _ = shutdown_rx.recv() => return Err::<(), ()>(()), + res = camera_preview.init_preview_window(window.clone(), camera_rx.clone()) => { + match res { + Ok(()) => return Ok(()), + Err(err) => { + error!("Error initializing camera feed: {err}"); + *last_err_ref = Some(err.to_string()); + tokio::time::sleep(Duration::from_millis(200)).await; + } + } + } + } + } + }) + .await; + match init_result { + Ok(Ok(())) => {} + Ok(Err(())) => { + let _ = window.close(); + return Ok(false); + } + Err(_) => { + let _ = window.close(); + return Err(format!( + "Timeout initializing camera preview: {}", + last_err.as_deref().unwrap_or("unknown error") + )); + } + }
🧹 Nitpick comments (1)
apps/desktop/src-tauri/src/lib.rs (1)
280-281
: Avoid unwrap on window creation
ShowCapWindow::Camera.show(...).await.unwrap()
will crash the app if the window fails to build (the very case you’re mitigating). Propagate a typed error instead.Apply:
- let window = ShowCapWindow::Camera.show(&app_handle).await.unwrap(); + let window = ShowCapWindow::Camera + .show(&app_handle) + .await + .map_err(|e| format!("Failed to show camera window: {e}"))?;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/desktop/src-tauri/src/lib.rs
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
- GitHub Check: Analyze (rust)
🔇 Additional comments (2)
apps/desktop/src-tauri/src/lib.rs (2)
59-59
: LGTM: Needed import for timeout durationImporting Duration is correct for the retry/timeout logic.
81-81
: LGTM: tokio timeout import addedImporting tokio::time::timeout is appropriate for the new retry logic.
Summary by CodeRabbit
Bug Fixes
Chores