Skip to content

Commit 26eba96

Browse files
Native camera preview fixes (#895)
* timeout * enable in dev and on macOS only * remove window on failure
1 parent f35e0dc commit 26eba96

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

apps/desktop/src-tauri/src/general_settings.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ pub struct GeneralSettingsStore {
9999
}
100100

101101
fn default_enable_native_camera_preview() -> bool {
102-
// TODO:
103-
// cfg!(target_os = "macos")
104-
false
102+
// This will help us with testing it
103+
cfg!(all(debug_assertions, target_os = "macos"))
105104
}
106105

107106
fn default_enable_new_recording_flow() -> bool {

apps/desktop/src-tauri/src/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use serde_json::json;
5656
use specta::Type;
5757
use std::collections::BTreeMap;
5858
use std::path::Path;
59+
use std::time::Duration;
5960
use std::{
6061
fs::File,
6162
future::Future,
@@ -77,6 +78,7 @@ use tauri_plugin_shell::ShellExt;
7778
use tauri_specta::Event;
7879
use tokio::sync::mpsc;
7980
use tokio::sync::{Mutex, RwLock};
81+
use tokio::time::timeout;
8082
use tracing::debug;
8183
use tracing::error;
8284
use tracing::trace;
@@ -286,10 +288,25 @@ async fn set_camera_input(
286288
.unwrap_or_default()
287289
{
288290
let (camera_tx, camera_rx) = flume::bounded::<RawCameraFrame>(4);
289-
camera_preview
290-
.init_preview_window(window, camera_rx)
291-
.await
292-
.unwrap();
291+
292+
let prev_err = &mut None;
293+
if timeout(Duration::from_secs(3), async {
294+
while let Err(err) = camera_preview
295+
.init_preview_window(window.clone(), camera_rx.clone())
296+
.await
297+
{
298+
error!("Error initializing camera feed: {err}");
299+
*prev_err = Some(err);
300+
tokio::time::sleep(Duration::from_millis(200)).await;
301+
}
302+
})
303+
.await
304+
.is_err()
305+
{
306+
let _ = window.close();
307+
return Err(format!("Timeout initializing camera preview: {prev_err:?}"));
308+
};
309+
293310
Some(camera_tx)
294311
} else {
295312
None

0 commit comments

Comments
 (0)