@@ -24,6 +24,7 @@ export type CliProgressDownloadEngineOptions = {
2424
2525class GlobalCLI {
2626 private _multiDownloadEngine = this . _createMultiDownloadEngine ( ) ;
27+ private _eventsRegistered = new Set < DownloadEngineMultiAllowedEngines > ( ) ;
2728 private _transferCLI = GlobalCLI . _createOptions ( { } ) ;
2829 private _cliActive = false ;
2930 private _downloadOptions = new WeakMap < AllowedDownloadEngine , CliProgressDownloadEngineOptions > ( ) ;
@@ -78,34 +79,39 @@ class GlobalCLI {
7879 } ;
7980
8081 const checkPauseCLI = ( ) => {
81- if ( ! isDownloadActive ( ) ) {
82+ if ( this . _cliActive && ! isDownloadActive ( ) ) {
8283 this . _transferCLI . stop ( ) ;
8384 this . _cliActive = false ;
8485 }
8586 } ;
8687
88+ const checkCloseCLI = ( engine : DownloadEngineMultiAllowedEngines ) => {
89+ this . _eventsRegistered . delete ( engine ) ;
90+ checkPauseCLI ( ) ;
91+ } ;
92+
8793 const checkResumeCLI = ( engine : DownloadEngineMultiAllowedEngines ) => {
8894 if ( engine . status . downloadStatus === DownloadStatus . Active ) {
8995 this . _transferCLI . start ( ) ;
9096 this . _cliActive = true ;
9197 }
9298 } ;
9399
94- this . _multiDownloadEngine . on ( "start" , ( ) => {
95- this . _transferCLI . start ( ) ;
96- this . _cliActive = true ;
97- } ) ;
98-
99100 this . _multiDownloadEngine . on ( "finished" , ( ) => {
100- this . _transferCLI . stop ( ) ;
101- this . _cliActive = false ;
102101 this . _multiDownloadEngine = this . _createMultiDownloadEngine ( ) ;
102+ this . _eventsRegistered = new Set ( ) ;
103103 } ) ;
104104
105+ const eventsRegistered = this . _eventsRegistered ;
105106 this . _multiDownloadEngine . on ( "childDownloadStarted" , function registerEngineStatus ( engine ) {
106- engine . on ( "closed" , checkPauseCLI ) ;
107+ if ( eventsRegistered . has ( engine ) ) return ;
108+ eventsRegistered . add ( engine ) ;
109+
110+ checkResumeCLI ( engine ) ;
107111 engine . on ( "paused" , checkPauseCLI ) ;
112+ engine . on ( "closed" , ( ) => checkCloseCLI ( engine ) ) ;
108113 engine . on ( "resumed" , ( ) => checkResumeCLI ( engine ) ) ;
114+ engine . on ( "start" , ( ) => checkResumeCLI ( engine ) ) ;
109115
110116 if ( engine instanceof DownloadEngineMultiDownload ) {
111117 engine . on ( "childDownloadStarted" , registerEngineStatus ) ;
0 commit comments