Skip to content

Commit

Permalink
stop engine when deselecting it (fixes #91)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Nov 13, 2023
1 parent f6ce7ee commit 9f16a37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src-tauri/src/chess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum EngineLog {
Engine(String),
}

#[derive(Debug)]
pub struct EngineProcess {
stdin: ChildStdin,
last_depth: u8,
Expand Down
13 changes: 9 additions & 4 deletions src/components/panels/analysis/EngineSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined>(undefined);
const [, setEngines] = useAtom(enginesAtom);
const activeTab = useAtomValue(activeTabAtom);

useEffect(() => {
(async () => {
Expand All @@ -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
)
)
}
);
}}
/>
</Grid.Col>
);
Expand Down

0 comments on commit 9f16a37

Please sign in to comment.