Skip to content

Commit 7f6c531

Browse files
committed
fix: cross-platform handling of client stop vs fail
1 parent 20651b1 commit 7f6c531

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/pages/Networks.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useRef, useState } from "react";
22
import * as log from "@tauri-apps/plugin-log";
33
import * as path from "@tauri-apps/api/path";
44
import { exists, mkdir } from "@tauri-apps/plugin-fs";
@@ -14,6 +14,7 @@ import {
1414
} from "../utils";
1515

1616
export function Networks() {
17+
const isStoppingRef = useRef(false);
1718
const [dlProgress, setDlProgress] = useState(0);
1819
const [networkId, setNetworkId] = useState("");
1920

@@ -52,9 +53,9 @@ export function Networks() {
5253

5354
async function disconnect() {
5455
try {
56+
isStoppingRef.current = true;
5557
await clientStop();
5658
setMessage("info", "Disconnected from Network");
57-
consoleAddLine(`Disconnected from network: ${networkId}`);
5859
} catch (error: any) {
5960
log.error(`${error}`);
6061
setMessage("error", `${error}`);
@@ -161,13 +162,13 @@ export function Networks() {
161162
log.debug(`spawning command: ${cmd} ${args.join(" ")}`);
162163

163164
command.on("close", (data) => {
164-
// normal: code=null signal=9
165-
// error: code=2 signal=null
166165
log.debug(`closed: ${cmd} code=${data.code} signal=${data.signal}`);
167-
if (data.code !== null) {
166+
if (!isStoppingRef.current) {
168167
setMessage("error", "Error: Network connection failed.");
169168
consoleAddLine(`Network connection failed: ${networkId}`);
170169
}
170+
isStoppingRef.current = false;
171+
consoleAddLine(`Disconnected from network: ${networkId}`);
171172
setClientPid(0);
172173
setIsConnected(false);
173174
setNetworkConnected("");

0 commit comments

Comments
 (0)