use std::sync::Mutex;
use crate::ScreenshotOptions;
static SCREENSHOT_REQUEST: Mutex<Option<ScreenshotRequest>> = Mutex::new(None);
#[derive(Debug, Clone)]
pub struct ScreenshotRequest {
pub filename: Option<String>,
pub options: ScreenshotOptions,
}
pub fn screenshot() {
screenshot_with_options(ScreenshotOptions::default());
}
pub fn screenshot_with_options(options: ScreenshotOptions) {
if let Ok(mut guard) = SCREENSHOT_REQUEST.lock() {
*guard = Some(ScreenshotRequest {
filename: None,
options,
});
}
}
pub fn screenshot_to_file(filename: impl Into<String>) {
screenshot_to_file_with_options(filename, ScreenshotOptions::default());
}
pub fn screenshot_to_file_with_options(filename: impl Into<String>, options: ScreenshotOptions) {
if let Ok(mut guard) = SCREENSHOT_REQUEST.lock() {
*guard = Some(ScreenshotRequest {
filename: Some(filename.into()),
options,
});
}
}
pub(crate) fn take_screenshot_request() -> Option<ScreenshotRequest> {
SCREENSHOT_REQUEST
.lock()
.ok()
.and_then(|mut guard| guard.take())
}