Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): restore camera window safely and widen settings layout

Richie McIlroyfa938a655483
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 673811df8..a2138e14c 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -2147,7 +2147,7 @@ async fn generate_keyboard_segments(
let mut all_events = cap_project::KeyboardEvents { presses: vec![] };
for segment in segments {
- let events = segment.keyboard_events(&meta);
+ let events = segment.keyboard_events(meta);
all_events.presses.extend(events.presses);
}
@@ -3719,13 +3719,14 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
id,
CapWindowId::TargetSelectOverlay { .. }
| CapWindowId::Main
- | CapWindowId::Camera
)
{
let _ = window.show();
}
}
+ restore_camera_window(app);
+
#[cfg(target_os = "windows")]
if !has_open_editor_window(app) {
reopen_main_window(app);
@@ -3740,12 +3741,12 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
id,
CapWindowId::TargetSelectOverlay { .. }
| CapWindowId::Main
- | CapWindowId::Camera
)
{
let _ = window.show();
}
}
+ restore_camera_window(app);
return;
}
CapWindowId::TargetSelectOverlay { display_id } => {
@@ -3947,9 +3948,25 @@ fn restore_main_windows_if_no_editors(app: &AppHandle) {
if let Some(main) = CapWindowId::Main.get(app) {
let _ = main.show();
}
- if let Some(camera) = CapWindowId::Camera.get(app) {
- let _ = camera.show();
- }
+
+ restore_camera_window(app);
+ }
+}
+
+fn restore_camera_window(app: &AppHandle) {
+ let should_restore_camera = app
+ .state::<ArcLock<App>>()
+ .try_read()
+ .map(|state| state.selected_camera_id.is_some())
+ .unwrap_or(false);
+
+ if should_restore_camera {
+ let app = app.clone();
+ tokio::spawn(async move {
+ let operation_lock = app.state::<CameraWindowOperationLock>();
+ let _operation_guard = operation_lock.lock().await;
+ let _ = ShowCapWindow::Camera { centered: false }.show(&app).await;
+ });
}
}
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index d04e8039e..5e0b2beed 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -95,6 +95,31 @@ fn hide_recording_windows(app: &AppHandle) {
}
}
+async fn ensure_camera_input_active(app_state: &mut App) {
+ if let Some(id) = app_state.selected_camera_id.clone()
+ && !app_state.camera_in_use
+ {
+ match app_state
+ .camera_feed
+ .ask(feeds::camera::SetInput { id })
+ .await
+ {
+ Ok(ready_future) => {
+ if let Err(err) = ready_future.await {
+ error!("Camera failed to initialize: {err}");
+ return;
+ }
+ }
+ Err(err) => {
+ error!("Failed to send SetInput to camera feed: {err}");
+ return;
+ }
+ }
+
+ app_state.camera_in_use = true;
+ }
+}
+
async fn cleanup_camera_window(
app: &AppHandle,
window: Option<&WebviewWindow>,
@@ -517,7 +542,7 @@ impl CapWindowId {
Self::Main => (330.0, 395.0),
Self::Editor { .. } => (1275.0, 800.0),
Self::ScreenshotEditor { .. } => (800.0, 600.0),
- Self::Settings => (700.0, 540.0),
+ Self::Settings => (800.0, 580.0),
Self::Camera => (200.0, 200.0),
Self::Upgrade => (950.0, 850.0),
Self::ModeSelect => (580.0, 340.0),
@@ -693,6 +718,8 @@ impl ShowCapWindow {
None
};
+ ensure_camera_input_active(&mut app_state).await;
+
if enable_native_camera_preview {
let camera_feed = app_state.camera_feed.clone();
if let Err(err) = app_state
@@ -773,6 +800,8 @@ impl ShowCapWindow {
None
};
+ ensure_camera_input_active(&mut app_state).await;
+
if enable_native_camera_preview && !app_state.camera_preview.is_initialized() {
let camera_feed = app_state.camera_feed.clone();
if let Err(err) = app_state
@@ -1244,19 +1273,19 @@ impl ShowCapWindow {
app,
format!("/settings/{}", page.clone().unwrap_or_default()),
)
- .inner_size(600.0, 465.0)
- .min_inner_size(600.0, 465.0)
+ .inner_size(800.0, 580.0)
+ .min_inner_size(800.0, 580.0)
.resizable(true)
.maximized(false)
.build()?;
- let (pos_x, pos_y) = cursor_monitor.center_position(600.0, 465.0);
+ let (pos_x, pos_y) = cursor_monitor.center_position(800.0, 580.0);
let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));
#[cfg(windows)]
{
use tauri::LogicalSize;
- if let Err(e) = window.set_size(LogicalSize::new(600.0, 465.0)) {
+ if let Err(e) = window.set_size(LogicalSize::new(800.0, 580.0)) {
warn!("Failed to set Settings window size on Windows: {}", e);
}
if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {
@@ -1576,21 +1605,7 @@ impl ShowCapWindow {
.set_position(tauri::LogicalPosition::new(camera_pos_x, camera_pos_y));
}
- if let Some(id) = state.selected_camera_id.clone()
- && !state.camera_in_use
- {
- match state.camera_feed.ask(feeds::camera::SetInput { id }).await {
- Ok(ready_future) => {
- if let Err(err) = ready_future.await {
- error!("Camera failed to initialize: {err}");
- }
- }
- Err(err) => {
- error!("Failed to send SetInput to camera feed: {err}");
- }
- }
- state.camera_in_use = true;
- }
+ ensure_camera_input_active(&mut state).await;
#[cfg(target_os = "macos")]
{