Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,13 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
#[cfg(target_os = "macos")]
app.manage(crate::platform::ScreenCapturePrewarmer::default());

tokio::spawn({
let app = app.clone();
async move {
target_select_overlay::init(&app).await;
}
});

tokio::spawn({
let camera_feed = camera_feed.clone();
let app = app.clone();
Expand Down Expand Up @@ -2351,7 +2358,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
if let Ok(CapWindowId::TargetSelectOverlay { .. }) =
CapWindowId::from_str(&id)
{
let _ = window.close();
let _ = window.hide();
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub async fn start_recording(
.filter_map(|(label, win)| CapWindowId::from_str(label).ok().map(|id| (id, win)))
{
if matches!(id, CapWindowId::TargetSelectOverlay { .. }) {
win.close().ok();
win.hide().ok();
}
}
let _ = ShowCapWindow::InProgressRecording { countdown }
Expand Down
57 changes: 47 additions & 10 deletions apps/desktop/src-tauri/src/target_select_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use base64::prelude::*;
use cap_recording::screen_capture::ScreenCaptureTarget;
use futures::future::join_all;

use crate::windows::{CapWindowId, ShowCapWindow};
use scap_targets::{
Expand Down Expand Up @@ -41,6 +42,31 @@ pub struct DisplayInformation {
refresh_rate: String,
}

// We create the windows hidden at app launch so they are ready when used.
// Otherwise we have noticed they can take a while to load on first interaction (especially on Windows).
pub async fn init(app: &AppHandle) {
join_all(
scap_targets::Display::list()
.into_iter()
.map(|d| d.id())
.map(|display_id| {
let app = app.clone();

async move {
let result = ShowCapWindow::TargetSelectOverlay { display_id }
.show(&app)
.await
.map_err(|err| error!("Error initializing target select overlay: {err}"));

if let Ok(window) = result {
window.hide().ok();
}
}
}),
)
.await;
}

#[specta::specta]
#[tauri::command]
#[instrument(skip(app, state))]
Expand All @@ -49,15 +75,23 @@ pub async fn open_target_select_overlays(
state: tauri::State<'_, WindowFocusManager>,
focused_target: Option<ScreenCaptureTarget>,
) -> Result<(), String> {
let displays = scap_targets::Display::list()
.into_iter()
.map(|d| d.id())
.collect::<Vec<_>>();
for display_id in displays {
let _ = ShowCapWindow::TargetSelectOverlay { display_id }
.show(&app)
.await;
}
join_all(
scap_targets::Display::list()
.into_iter()
.map(|d| d.id())
.map(|display_id| {
let app = app.clone();

async move {
ShowCapWindow::TargetSelectOverlay { display_id }
.show(&app)
.await
.map_err(|err| error!("Error initializing target select overlay: {err}"))
.ok();
}
}),
)
.await;

let handle = tokio::spawn({
let app = app.clone();
Expand Down Expand Up @@ -116,7 +150,10 @@ pub async fn open_target_select_overlays(
pub async fn close_target_select_overlays(app: AppHandle) -> Result<(), String> {
for (id, window) in app.webview_windows() {
if let Ok(CapWindowId::TargetSelectOverlay { .. }) = CapWindowId::from_str(&id) {
let _ = window.close();
window
.hide()
.map_err(|err| error!("Error hiding target select overlay: {err}"))
.ok();
}
}

Expand Down
6 changes: 0 additions & 6 deletions apps/desktop/src/routes/target-select-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,3 @@ function ResizeHandle(
/>
);
}

function getDisplayId(displayId: string | undefined) {
const id = Number(displayId);
if (Number.isNaN(id)) return 0;
return id;
}
Loading