1
- import { useRef , useState } from "react" ;
1
+ import { useState } from "react" ;
2
2
import * as log from "@tauri-apps/plugin-log" ;
3
3
import * as path from "@tauri-apps/api/path" ;
4
4
import { exists , mkdir } from "@tauri-apps/plugin-fs" ;
@@ -14,7 +14,6 @@ import {
14
14
} from "../utils" ;
15
15
16
16
export function Networks ( ) {
17
- const isStoppingRef = useRef ( false ) ;
18
17
const [ dlProgress , setDlProgress ] = useState ( 0 ) ;
19
18
const [ networkId , setNetworkId ] = useState ( "" ) ;
20
19
@@ -31,6 +30,7 @@ export function Networks() {
31
30
const consoleAddLine = useStore ( ( s ) => s . consoleAddLine ) ;
32
31
const setClientPid = useStore ( ( s ) => s . setClientPid ) ;
33
32
const setIsConnected = useStore ( ( s ) => s . setIsConnected ) ;
33
+ const setIsStopping = useStore ( ( s ) => s . setIsStopping ) ;
34
34
const setMessage = useStore ( ( s ) => s . setMessage ) ;
35
35
const setNetworkConnected = useStore ( ( s ) => s . setNetworkConnected ) ;
36
36
const setNetworks = useStore ( ( s ) => s . setNetworks ) ;
@@ -53,7 +53,7 @@ export function Networks() {
53
53
54
54
async function disconnect ( ) {
55
55
try {
56
- isStoppingRef . current = true ;
56
+ setIsStopping ( true ) ;
57
57
await clientStop ( ) ;
58
58
setMessage ( "info" , "Disconnected from Network" ) ;
59
59
} catch ( error : any ) {
@@ -163,14 +163,15 @@ export function Networks() {
163
163
164
164
command . on ( "close" , ( data ) => {
165
165
log . debug ( `closed: ${ cmd } code=${ data . code } signal=${ data . signal } ` ) ;
166
- if ( ! isStoppingRef . current ) {
166
+ const isStopping = useStore . getState ( ) . isStopping ;
167
+ if ( isStopping !== true ) {
167
168
setMessage ( "error" , "Error: Network connection failed." ) ;
168
169
consoleAddLine ( `Network connection failed: ${ networkId } ` ) ;
169
170
}
170
- isStoppingRef . current = false ;
171
171
consoleAddLine ( `Disconnected from network: ${ networkId } ` ) ;
172
172
setClientPid ( 0 ) ;
173
173
setIsConnected ( false ) ;
174
+ setIsStopping ( false ) ;
174
175
setNetworkConnected ( "" ) ;
175
176
} ) ;
176
177
0 commit comments