use std::sync::OnceLock;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ScreenshotBackend {
#[allow(dead_code, reason = "constructed in the WkWebView milestone")]
WkWebViewSnapshot,
CgWindowList,
ScreencaptureProbe,
#[allow(dead_code, reason = "kept for the exhaustive match in the macOS dispatcher")]
PlatformUnsupported,
}
static BACKEND: OnceLock<ScreenshotBackend> = OnceLock::new();
#[must_use]
pub(crate) fn selected_backend() -> ScreenshotBackend {
*BACKEND.get_or_init(probe_backend)
}
fn probe_backend() -> ScreenshotBackend {
if screencapture_probe_allows_window_capture() {
ScreenshotBackend::ScreencaptureProbe
} else {
ScreenshotBackend::CgWindowList
}
}
fn screencapture_probe_allows_window_capture() -> bool {
core_graphics::access::ScreenCaptureAccess.preflight()
}