forked from 1b-agent/opencadstudio-upstream
Merge pull request #1363 from ramox81/codex/capture-minimized-guard
Refuse an automation capture while the window is minimized
This commit is contained in:
commit
edc45caa14
1 file changed
+13
-3
+13
-3
@@ -866,8 +866,17 @@ impl OpenCADStudio {
|
|||||||
.main_window
|
.main_window
|
||||||
.ok_or_else(|| failure("gui_required", "Capture requires a GUI window"))?;
|
.ok_or_else(|| failure("gui_required", "Capture requires a GUI window"))?;
|
||||||
let path = string(req, "path")?.to_owned();
|
let path = string(req, "path")?.to_owned();
|
||||||
iced::window::screenshot(window)
|
// A minimized window has a 0x0 surface and the renderer
|
||||||
.map(move |s| Message::ControlScreenshot(path.clone(), Some(s)))
|
// panics reading it back, so report instead of capturing.
|
||||||
|
iced::window::size(window).then(move |size| {
|
||||||
|
let path = path.clone();
|
||||||
|
if size.width <= 0.0 || size.height <= 0.0 {
|
||||||
|
Task::done(Message::ControlScreenshot(path, None))
|
||||||
|
} else {
|
||||||
|
iced::window::screenshot(window)
|
||||||
|
.map(move |s| Message::ControlScreenshot(path.clone(), Some(s)))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
"stop" => {
|
"stop" => {
|
||||||
self.control.enabled = false;
|
self.control.enabled = false;
|
||||||
@@ -1062,7 +1071,8 @@ impl OpenCADStudio {
|
|||||||
screenshot: Option<iced::window::Screenshot>,
|
screenshot: Option<iced::window::Screenshot>,
|
||||||
) {
|
) {
|
||||||
let result = (|| -> Result<Value, String> {
|
let result = (|| -> Result<Value, String> {
|
||||||
let s = screenshot.ok_or("Renderer did not return an image")?;
|
let s = screenshot
|
||||||
|
.ok_or("The window is minimized or has no size; restore it and capture again")?;
|
||||||
let requested_scope = self
|
let requested_scope = self
|
||||||
.control
|
.control
|
||||||
.pending
|
.pending
|
||||||
|
|||||||
Reference in new issue
Block a user