@@ -99,8 +99,8 @@ export class ModPanelComponent implements OnInit, OnDestroy {
9999 versionsSubscription ! : Subscription ;
100100 loaderSubscription ! : Subscription ;
101101 curseforgeSupscription ! : Subscription ;
102- private finishedSubscription ! : Subscription ;
103- private percentSubscription ! : Subscription ;
102+ private finishedSubscription ? : Subscription ;
103+ private percentSubscription ? : Subscription ;
104104
105105 constructor ( ) { }
106106
@@ -195,6 +195,8 @@ export class ModPanelComponent implements OnInit, OnDestroy {
195195 this . versionsSubscription . unsubscribe ( ) ;
196196 this . loaderSubscription . unsubscribe ( ) ;
197197 this . curseforgeSupscription . unsubscribe ( ) ;
198+ this . finishedSubscription ?. unsubscribe ( ) ;
199+ this . percentSubscription ?. unsubscribe ( ) ;
198200 }
199201
200202 /**
@@ -984,16 +986,26 @@ export class ModPanelComponent implements OnInit, OnDestroy {
984986 * Orchestrates the entire update process, including file processing and dependency fetching.
985987 */
986988 async startUpdateMods ( ) {
989+ if ( this . loading ) {
990+ this . finishedSubscription ?. unsubscribe ( ) ;
991+ this . percentSubscription ?. unsubscribe ( ) ;
992+ this . loading = false ;
993+ this . loadingPercent = 0 ;
994+ return ;
995+ }
996+
997+ this . loading = true ;
998+ this . loadingPercent = 0 ;
999+
9871000 const [ anyToProcess , initialFinished$ , initialPercent$ ] =
9881001 await this . updateMods ( ) ;
9891002 if ( ! anyToProcess ) {
1003+ this . loading = false ;
9901004 return ;
9911005 }
9921006
993- this . loadingPercent = 0 ;
994- this . loading = true ;
995- if ( this . finishedSubscription ) this . finishedSubscription . unsubscribe ( ) ;
996- if ( this . percentSubscription ) this . percentSubscription . unsubscribe ( ) ;
1007+ this . finishedSubscription ?. unsubscribe ( ) ;
1008+ this . percentSubscription ?. unsubscribe ( ) ;
9971009
9981010 // assuming an average of 1-2 dependencies per mod batch
9991011 const dependencyProcessingWeight = 1.5 / this . files . length ;
@@ -1014,7 +1026,7 @@ export class ModPanelComponent implements OnInit, OnDestroy {
10141026 const { progress$, finished$ } = this . processDependencies ( mcVersion ) ;
10151027
10161028 // Switch from file progress to dependency progress
1017- if ( this . percentSubscription ) this . percentSubscription . unsubscribe ( ) ;
1029+ this . percentSubscription ? .unsubscribe ( ) ;
10181030 this . percentSubscription = progress$ . subscribe ( ( depPercent ) => {
10191031 this . loadingPercent =
10201032 fileProcessingWeight + depPercent * dependencyProcessingWeight ;
@@ -1030,7 +1042,7 @@ export class ModPanelComponent implements OnInit, OnDestroy {
10301042 )
10311043 . subscribe ( ( ) => {
10321044 this . loading = false ;
1033- if ( this . percentSubscription ) this . percentSubscription . unsubscribe ( ) ;
1045+ this . percentSubscription ? .unsubscribe ( ) ;
10341046 } ) ;
10351047 }
10361048
0 commit comments