1
- import { useState } from "react" ;
1
+ import { useRef , 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,6 +14,7 @@ import {
14
14
} from "../utils" ;
15
15
16
16
export function Networks ( ) {
17
+ const isStoppingRef = useRef ( false ) ;
17
18
const [ dlProgress , setDlProgress ] = useState ( 0 ) ;
18
19
const [ networkId , setNetworkId ] = useState ( "" ) ;
19
20
@@ -52,9 +53,9 @@ export function Networks() {
52
53
53
54
async function disconnect ( ) {
54
55
try {
56
+ isStoppingRef . current = true ;
55
57
await clientStop ( ) ;
56
58
setMessage ( "info" , "Disconnected from Network" ) ;
57
- consoleAddLine ( `Disconnected from network: ${ networkId } ` ) ;
58
59
} catch ( error : any ) {
59
60
log . error ( `${ error } ` ) ;
60
61
setMessage ( "error" , `${ error } ` ) ;
@@ -161,13 +162,13 @@ export function Networks() {
161
162
log . debug ( `spawning command: ${ cmd } ${ args . join ( " " ) } ` ) ;
162
163
163
164
command . on ( "close" , ( data ) => {
164
- // normal: code=null signal=9
165
- // error: code=2 signal=null
166
165
log . debug ( `closed: ${ cmd } code=${ data . code } signal=${ data . signal } ` ) ;
167
- if ( data . code !== null ) {
166
+ if ( ! isStoppingRef . current ) {
168
167
setMessage ( "error" , "Error: Network connection failed." ) ;
169
168
consoleAddLine ( `Network connection failed: ${ networkId } ` ) ;
170
169
}
170
+ isStoppingRef . current = false ;
171
+ consoleAddLine ( `Disconnected from network: ${ networkId } ` ) ;
171
172
setClientPid ( 0 ) ;
172
173
setIsConnected ( false ) ;
173
174
setNetworkConnected ( "" ) ;
0 commit comments