@@ -78,16 +78,19 @@ export const createNodeSlice = (set, get) => ({
7878 nodeInstallProgress : { pct : 0 , downloaded : 0 , total : 0 }
7979 } ) ) ;
8080
81+ let unlistenLogs = null ;
82+ let unlistenProgress = null ;
83+
8184 try {
8285 const { invoke } = await import ( '@tauri-apps/api/core' ) ;
8386 const { listen } = await import ( '@tauri-apps/api/event' ) ;
8487
85- const unlistenLogs = await listen ( 'node-install-log' , ( event ) => {
88+ unlistenLogs = await listen ( 'node-install-log' , ( event ) => {
8689 const line = event . payload ;
8790 set ( s => ( { nodeInstallLogs : [ ...s . nodeInstallLogs , { t : new Date ( ) . toLocaleTimeString ( ) , m : line , l : 'info' } ] } ) ) ;
8891 } ) ;
8992
90- const unlistenProgress = await listen ( 'download-progress' , ( event ) => {
93+ unlistenProgress = await listen ( 'download-progress' , ( event ) => {
9194 const { svcType, pct, downloaded, total } = event . payload || { } ;
9295 if ( svcType === 'node' ) {
9396 set ( {
@@ -108,10 +111,15 @@ export const createNodeSlice = (set, get) => ({
108111 expectedSizeMb : null
109112 } ) ;
110113
111- unlistenLogs ( ) ;
112- unlistenProgress ( ) ;
113-
114114 if ( result === 'SUCCESS' ) {
115+ set ( s => ( {
116+ nodeInstallProgress : {
117+ pct : 100 ,
118+ downloaded : s . nodeInstallProgress . total || s . nodeInstallProgress . downloaded ,
119+ total : s . nodeInstallProgress . total || s . nodeInstallProgress . downloaded
120+ } ,
121+ nodeInstallLogs : [ ...s . nodeInstallLogs , { t : new Date ( ) . toLocaleTimeString ( ) , m : 'Progress complete.' , l : 'info' } ]
122+ } ) ) ;
115123 await get ( ) . scanInstalledNode ( ) ;
116124 const activeNode = get ( ) . nodeVersions . find ( v => v . active ) ;
117125 if ( ! activeNode ) {
@@ -128,6 +136,13 @@ export const createNodeSlice = (set, get) => ({
128136 nodeInstallLogs : [ ...s . nodeInstallLogs , { t : new Date ( ) . toLocaleTimeString ( ) , m : `Error: ${ e } ` , l : 'err' } ]
129137 } ) ) ;
130138 get ( ) . showToast ( get ( ) . t ( 'nodeInstallFailed' , { error : `${ e } ` } ) , 'danger' ) ;
139+ } finally {
140+ if ( typeof unlistenLogs === 'function' ) {
141+ unlistenLogs ( ) ;
142+ }
143+ if ( typeof unlistenProgress === 'function' ) {
144+ unlistenProgress ( ) ;
145+ }
131146 }
132147 } ,
133148
0 commit comments