diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 9be11aa..b4e1f2a 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -7,13 +7,8 @@ export function Footer() { const consoleLines = useStore((s) => s.consoleLines); return ( - + ); } diff --git a/src/pages/Networks.tsx b/src/pages/Networks.tsx index 90b5d0c..b9b8985 100644 --- a/src/pages/Networks.tsx +++ b/src/pages/Networks.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import { useState } from "react"; import * as log from "@tauri-apps/plugin-log"; import * as path from "@tauri-apps/api/path"; import { exists, mkdir } from "@tauri-apps/plugin-fs"; @@ -14,7 +14,6 @@ import { } from "../utils"; export function Networks() { - const isStoppingRef = useRef(false); const [dlProgress, setDlProgress] = useState(0); const [networkId, setNetworkId] = useState(""); @@ -31,6 +30,7 @@ export function Networks() { const consoleAddLine = useStore((s) => s.consoleAddLine); const setClientPid = useStore((s) => s.setClientPid); const setIsConnected = useStore((s) => s.setIsConnected); + const setIsStopping = useStore((s) => s.setIsStopping); const setMessage = useStore((s) => s.setMessage); const setNetworkConnected = useStore((s) => s.setNetworkConnected); const setNetworks = useStore((s) => s.setNetworks); @@ -53,7 +53,7 @@ export function Networks() { async function disconnect() { try { - isStoppingRef.current = true; + setIsStopping(true); await clientStop(); setMessage("info", "Disconnected from Network"); } catch (error: any) { @@ -163,14 +163,15 @@ export function Networks() { command.on("close", (data) => { log.debug(`closed: ${cmd} code=${data.code} signal=${data.signal}`); - if (!isStoppingRef.current) { + const isStopping = useStore.getState().isStopping; + if (isStopping !== true) { setMessage("error", "Error: Network connection failed."); consoleAddLine(`Network connection failed: ${networkId}`); } - isStoppingRef.current = false; consoleAddLine(`Disconnected from network: ${networkId}`); setClientPid(0); setIsConnected(false); + setIsStopping(false); setNetworkConnected(""); }); diff --git a/src/store/index.ts b/src/store/index.ts index 3c24d11..68d7753 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -12,6 +12,7 @@ export const useStore = create( consoleLines: [] as string[], consoleLinesLimit: 100, isConnected: false, + isStopping: false, isPlatformSupported: false, message: "", messageType: "", @@ -30,6 +31,7 @@ export const useStore = create( setAppVersion: (appVersion: string) => set({ appVersion }), setClientPid: (clientPid: number) => set({ clientPid }), setIsConnected: (isConnected: boolean) => set({ isConnected }), + setIsStopping: (isStopping: boolean) => set({ isStopping }), setIsPlatformSupported: (isPlatformSupported: boolean) => set({ isPlatformSupported }), setMessage: (