From 9f16a3732bd08298ee1081fe28781ecc7fefea9a Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Mon, 13 Nov 2023 23:00:27 +0000 Subject: [PATCH] stop engine when deselecting it (fixes #91) --- src-tauri/src/chess.rs | 1 + src/components/panels/analysis/EngineSelection.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/chess.rs b/src-tauri/src/chess.rs index b4fb511a..093f1f19 100644 --- a/src-tauri/src/chess.rs +++ b/src-tauri/src/chess.rs @@ -35,6 +35,7 @@ pub enum EngineLog { Engine(String), } +#[derive(Debug)] pub struct EngineProcess { stdin: ChildStdin, last_depth: u8, diff --git a/src/components/panels/analysis/EngineSelection.tsx b/src/components/panels/analysis/EngineSelection.tsx index fd41327e..97d1a783 100644 --- a/src/components/panels/analysis/EngineSelection.tsx +++ b/src/components/panels/analysis/EngineSelection.tsx @@ -7,11 +7,13 @@ import { Engine } from "@/utils/engines"; import ImageCheckbox from "./ImageCheckbox"; import { convertFileSrc } from "@tauri-apps/api/tauri"; import { useAtom, useAtomValue } from "jotai"; -import { enginesAtom } from "@/atoms/atoms"; +import { activeTabAtom, enginesAtom } from "@/atoms/atoms"; +import { commands } from "@/bindings"; function EngineBox({ engine }: { engine: Engine }) { const [imageSrc, setImageSrc] = useState(undefined); const [, setEngines] = useAtom(enginesAtom); + const activeTab = useAtomValue(activeTabAtom); useEffect(() => { (async () => { @@ -29,13 +31,16 @@ function EngineBox({ engine }: { engine: Engine }) { title={engine.name} image={imageSrc} checked={engine.loaded} - onChange={(checked) => + onChange={(checked) => { + if (!checked) { + commands.stopEngine(engine.path, activeTab!); + } setEngines(async (engines) => (await engines).map((e) => e.name === engine.name ? { ...e, loaded: checked } : e ) - ) - } + ); + }} /> );