Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Adjust main window size and improve camera cleanup

Richie McIlroy44e508050ba6
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 9c118be36..8381ce3cc 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -754,32 +754,43 @@ async fn cleanup_camera_window(app: AppHandle) {
async fn cleanup_camera_after_overlay_close(app: AppHandle) {
let state = app.state::<ArcLock<App>>();
- let mut app_state = state.write().await;
- if app_state.camera_cleanup_done {
- return;
- }
+ let camera_feed = {
+ let mut app_state = state.write().await;
- if app_state.is_recording_active_or_pending() {
- return;
- }
+ if app_state.camera_cleanup_done {
+ return;
+ }
- let has_camera_window = CapWindowId::Camera.get(&app).is_some();
- if has_camera_window {
- return;
- }
+ if app_state.is_recording_active_or_pending() {
+ return;
+ }
- let has_visible_target_overlay = app.webview_windows().iter().any(|(label, window)| {
- label.starts_with("target-select-overlay-") && window.is_visible().unwrap_or(false)
- });
- if has_visible_target_overlay {
- return;
- }
+ let has_camera_window = CapWindowId::Camera.get(&app).is_some();
+ if has_camera_window {
+ return;
+ }
- if app_state.camera_in_use {
- let _ = app_state.camera_feed.ask(feeds::camera::RemoveInput).await;
- app_state.camera_in_use = false;
- }
+ let has_visible_target_overlay = app.webview_windows().iter().any(|(label, window)| {
+ label.starts_with("target-select-overlay-") && window.is_visible().unwrap_or(false)
+ });
+ if has_visible_target_overlay {
+ return;
+ }
+
+ app_state.camera_cleanup_done = true;
+
+ if !app_state.camera_in_use {
+ return;
+ }
+
+ app_state.camera_feed.clone()
+ };
+
+ let _ = camera_feed.ask(feeds::camera::RemoveInput).await;
+
+ let mut app_state = state.write().await;
+ app_state.camera_in_use = false;
}
fn spawn_microphone_watcher(app_handle: AppHandle) {
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index 76905a5aa..93f2d25f9 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -273,7 +273,7 @@ impl CapWindowId {
pub fn min_size(&self) -> Option<(f64, f64)> {
Some(match self {
Self::Setup => (600.0, 600.0),
- Self::Main => (330.0, 408.0),
+ Self::Main => (330.0, 395.0),
Self::Editor { .. } => (1275.0, 800.0),
Self::ScreenshotEditor { .. } => (800.0, 600.0),
Self::Settings => (700.0, 540.0),
@@ -371,7 +371,7 @@ impl ShowCapWindow {
match self {
Self::Main { .. } => {
let cursor_monitor = CursorMonitorInfo::get();
- let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 408.0);
+ let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 395.0);
let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));
if let Some(camera_window) = CapWindowId::Camera.get(app) {
@@ -499,7 +499,7 @@ impl ShowCapWindow {
))
.build()?;
- let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 408.0);
+ let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 395.0);
let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));
#[cfg(target_os = "macos")]
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetTypeButton.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetTypeButton.tsx
index 059996cbf..eea046c31 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetTypeButton.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetTypeButton.tsx
@@ -24,7 +24,7 @@ function TargetTypeButton(props: TargetTypeButtonProps) {
disabled={local.disabled}
aria-pressed={local.selected ? "true" : "false"}
class={cx(
- "flex flex-1 flex-col items-center justify-end gap-1 rounded-lg border border-gray-5 bg-gray-3 py-2.5 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-9 focus-visible:ring-offset-2 focus-visible:ring-offset-gray-1",
+ "flex flex-1 flex-col items-center justify-end gap-1 rounded-lg border border-gray-5 bg-gray-3 py-2 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-9 focus-visible:ring-offset-2 focus-visible:ring-offset-gray-1",
local.selected ? "text-gray-12" : "text-gray-12 hover:bg-gray-4",
local.disabled && "pointer-events-none opacity-60",
local.class,
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
index fb787a0fd..3f0403420 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
@@ -89,7 +89,7 @@ import TargetDropdownButton from "./TargetDropdownButton";
import TargetMenuGrid from "./TargetMenuGrid";
import TargetTypeButton from "./TargetTypeButton";
-const WINDOW_SIZE = { width: 330, height: 408 } as const;
+const WINDOW_SIZE = { width: 330, height: 395 } as const;
const findCamera = (cameras: CameraInfo[], id: DeviceOrModelID) => {
return cameras.find((c) => {
@@ -1192,7 +1192,7 @@ function Page() {
</div>
</WindowChromeHeader>
<Show when={!activeMenu()}>
- <div class="flex items-center justify-between mt-[18px] mb-[6px]">
+ <div class="flex items-center justify-between mt-[16px] mb-[6px]">
<div class="flex items-center space-x-1">
<a
class="*:w-[92px] *:h-auto text-[--text-primary]"
diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsx
index 96e084999..54227f6d6 100644
--- a/apps/desktop/src/routes/target-select-overlay.tsx
+++ b/apps/desktop/src/routes/target-select-overlay.tsx
@@ -1004,6 +1004,10 @@ function CameraPreviewInline() {
const clamped = new Uint8ClampedArray(buffer);
if (clamped.length < 24) return;
+ const MAX_FRAME_DIMENSION = 8192;
+ const MAX_STRIDE_BYTES = MAX_FRAME_DIMENSION * 4 * 2;
+ const MAX_FRAME_SIZE = MAX_FRAME_DIMENSION * MAX_FRAME_DIMENSION * 4;
+
const metadataOffset = clamped.length - 24;
const meta = new DataView(buffer, metadataOffset, 24);
const strideBytes = meta.getUint32(0, true);
@@ -1012,14 +1016,30 @@ function CameraPreviewInline() {
if (!width || !height || strideBytes === 0) return;
+ if (
+ width > MAX_FRAME_DIMENSION ||
+ height > MAX_FRAME_DIMENSION ||
+ strideBytes > MAX_STRIDE_BYTES
+ )
+ return;
+
const source = clamped.subarray(0, metadataOffset);
const expectedRowBytes = width * 4;
const availableLength = strideBytes * height;
+ if (
+ expectedRowBytes > MAX_STRIDE_BYTES ||
+ availableLength > MAX_FRAME_SIZE
+ )
+ return;
+
if (strideBytes < expectedRowBytes || source.length < availableLength)
return;
const expectedLength = expectedRowBytes * height;
+
+ if (expectedLength > MAX_FRAME_SIZE) return;
+
let pixels: Uint8ClampedArray;
if (strideBytes === expectedRowBytes) {
diff --git a/crates/recording/src/lib.rs b/crates/recording/src/lib.rs
index eeab265b1..38a9deda2 100644
--- a/crates/recording/src/lib.rs
+++ b/crates/recording/src/lib.rs
@@ -73,7 +73,7 @@ pub struct SendableShareableContent(
#[cfg(target_os = "macos")]
impl SendableShareableContent {
pub fn retained(&self) -> cidre::arc::R<cidre::sc::ShareableContent> {
- self.0.lock().unwrap().clone()
+ self.0.lock().unwrap_or_else(|e| e.into_inner()).clone()
}
}